mirror of
				https://github.com/SquidDev-CC/CC-Tweaked
				synced 2025-10-30 13:13:00 +00:00 
			
		
		
		
	Merge branch 'mc-1.14.x' into mc-1.15.x
This commit is contained in:
		| @@ -46,10 +46,9 @@ public final class FixedWidthFontRenderer | ||||
|         return (float) ((rgb[0] + rgb[1] + rgb[2]) / 3); | ||||
|     } | ||||
|  | ||||
|     private static int getColour( char c ) | ||||
|     private static int getColour( char c, Colour def ) | ||||
|     { | ||||
|         int i = "0123456789abcdef".indexOf( c ); | ||||
|         return i < 0 ? 0 : 15 - i; | ||||
|         return 15 - Terminal.getColour( c, def ); | ||||
|     } | ||||
|  | ||||
|     private static void drawChar( Matrix4f transform, IVertexBuilder buffer, float x, float y, int index, float r, float g, float b ) | ||||
| @@ -83,7 +82,7 @@ public final class FixedWidthFontRenderer | ||||
|  | ||||
|     private static void drawQuad( Matrix4f transform, IVertexBuilder buffer, float x, float y, float width, float height, Palette palette, boolean greyscale, char colourIndex ) | ||||
|     { | ||||
|         double[] colour = palette.getColour( getColour( colourIndex ) ); | ||||
|         double[] colour = palette.getColour( getColour( colourIndex, Colour.BLACK ) ); | ||||
|         float r, g, b; | ||||
|         if( greyscale ) | ||||
|         { | ||||
| @@ -151,7 +150,7 @@ public final class FixedWidthFontRenderer | ||||
|  | ||||
|         for( int i = 0; i < text.length(); i++ ) | ||||
|         { | ||||
|             double[] colour = palette.getColour( 15 - "0123456789abcdef".indexOf( textColour.charAt( i ) ) ); | ||||
|             double[] colour = palette.getColour( getColour( textColour.charAt( i ), Colour.BLACK ) ); | ||||
|             float r, g, b; | ||||
|             if( greyscale ) | ||||
|             { | ||||
|   | ||||
| @@ -5,18 +5,20 @@ | ||||
|  */ | ||||
| package dan200.computercraft.core.terminal; | ||||
|  | ||||
| import dan200.computercraft.shared.util.Colour; | ||||
| import dan200.computercraft.shared.util.Palette; | ||||
| import net.minecraft.nbt.CompoundNBT; | ||||
| import net.minecraft.network.PacketBuffer; | ||||
|  | ||||
| public class Terminal | ||||
| { | ||||
|     private static final String base16 = "0123456789abcdef"; | ||||
|  | ||||
|     private int m_cursorX; | ||||
|     private int m_cursorY; | ||||
|     private boolean m_cursorBlink; | ||||
|     private int m_cursorColour; | ||||
|     private int m_cursorBackgroundColour; | ||||
|     private int m_cursorX = 0; | ||||
|     private int m_cursorY = 0; | ||||
|     private boolean m_cursorBlink = false; | ||||
|     private int m_cursorColour = 0; | ||||
|     private int m_cursorBackgroundColour = 15; | ||||
|  | ||||
|     private int m_width; | ||||
|     private int m_height; | ||||
| @@ -25,9 +27,9 @@ public class Terminal | ||||
|     private TextBuffer[] m_textColour; | ||||
|     private TextBuffer[] m_backgroundColour; | ||||
|  | ||||
|     private final Palette m_palette; | ||||
|     private final Palette m_palette = new Palette(); | ||||
|  | ||||
|     private boolean m_changed; | ||||
|     private boolean m_changed = false; | ||||
|     private final Runnable onChanged; | ||||
|  | ||||
|     public Terminal( int width, int height ) | ||||
| @@ -41,9 +43,6 @@ public class Terminal | ||||
|         m_height = height; | ||||
|         onChanged = changedCallback; | ||||
|  | ||||
|         m_cursorColour = 0; | ||||
|         m_cursorBackgroundColour = 15; | ||||
|  | ||||
|         m_text = new TextBuffer[m_height]; | ||||
|         m_textColour = new TextBuffer[m_height]; | ||||
|         m_backgroundColour = new TextBuffer[m_height]; | ||||
| @@ -53,14 +52,6 @@ public class Terminal | ||||
|             m_textColour[i] = new TextBuffer( base16.charAt( m_cursorColour ), m_width ); | ||||
|             m_backgroundColour[i] = new TextBuffer( base16.charAt( m_cursorBackgroundColour ), m_width ); | ||||
|         } | ||||
|  | ||||
|         m_cursorX = 0; | ||||
|         m_cursorY = 0; | ||||
|         m_cursorBlink = false; | ||||
|  | ||||
|         m_changed = false; | ||||
|  | ||||
|         m_palette = new Palette(); | ||||
|     } | ||||
|  | ||||
|     public synchronized void reset() | ||||
| @@ -323,6 +314,62 @@ public class Terminal | ||||
|         m_changed = false; | ||||
|     } | ||||
|  | ||||
|     public synchronized void write( PacketBuffer buffer ) | ||||
|     { | ||||
|         buffer.writeInt( m_cursorX ); | ||||
|         buffer.writeInt( m_cursorY ); | ||||
|         buffer.writeBoolean( m_cursorBlink ); | ||||
|         buffer.writeByte( m_cursorBackgroundColour << 4 | m_cursorColour ); | ||||
|  | ||||
|         for( int y = 0; y < m_height; y++ ) | ||||
|         { | ||||
|             TextBuffer text = m_text[y]; | ||||
|             TextBuffer textColour = m_textColour[y]; | ||||
|             TextBuffer backColour = m_backgroundColour[y]; | ||||
|  | ||||
|             for( int x = 0; x < m_width; x++ ) | ||||
|             { | ||||
|                 buffer.writeByte( text.charAt( x ) & 0xFF ); | ||||
|                 buffer.writeByte( getColour( | ||||
|                     backColour.charAt( x ), Colour.BLACK ) << 4 | | ||||
|                     getColour( textColour.charAt( x ), Colour.WHITE ) | ||||
|                 ); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         m_palette.write( buffer ); | ||||
|     } | ||||
|  | ||||
|     public synchronized void read( PacketBuffer buffer ) | ||||
|     { | ||||
|         m_cursorX = buffer.readInt(); | ||||
|         m_cursorY = buffer.readInt(); | ||||
|         m_cursorBlink = buffer.readBoolean(); | ||||
|  | ||||
|         byte cursorColour = buffer.readByte(); | ||||
|         m_cursorBackgroundColour = (cursorColour >> 4) & 0xF; | ||||
|         m_cursorColour = cursorColour & 0xF; | ||||
|  | ||||
|         for( int y = 0; y < m_height; y++ ) | ||||
|         { | ||||
|             TextBuffer text = m_text[y]; | ||||
|             TextBuffer textColour = m_textColour[y]; | ||||
|             TextBuffer backColour = m_backgroundColour[y]; | ||||
|  | ||||
|             for( int x = 0; x < m_width; x++ ) | ||||
|             { | ||||
|                 text.setChar( x, (char) (buffer.readByte() & 0xFF) ); | ||||
|  | ||||
|                 byte colour = buffer.readByte(); | ||||
|                 backColour.setChar( x, base16.charAt( (colour >> 4) & 0xF ) ); | ||||
|                 textColour.setChar( x, base16.charAt( colour & 0xF ) ); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         m_palette.read( buffer ); | ||||
|         setChanged(); | ||||
|     } | ||||
|  | ||||
|     public synchronized CompoundNBT writeToNBT( CompoundNBT nbt ) | ||||
|     { | ||||
|         nbt.putInt( "term_cursorX", m_cursorX ); | ||||
| @@ -336,10 +383,8 @@ public class Terminal | ||||
|             nbt.putString( "term_textColour_" + n, m_textColour[n].toString() ); | ||||
|             nbt.putString( "term_textBgColour_" + n, m_backgroundColour[n].toString() ); | ||||
|         } | ||||
|         if( m_palette != null ) | ||||
|         { | ||||
|             m_palette.writeToNBT( nbt ); | ||||
|         } | ||||
|  | ||||
|         m_palette.writeToNBT( nbt ); | ||||
|         return nbt; | ||||
|     } | ||||
|  | ||||
| @@ -369,10 +414,15 @@ public class Terminal | ||||
|                 m_backgroundColour[n].write( nbt.getString( "term_textBgColour_" + n ) ); | ||||
|             } | ||||
|         } | ||||
|         if( m_palette != null ) | ||||
|         { | ||||
|             m_palette.readFromNBT( nbt ); | ||||
|         } | ||||
|  | ||||
|         m_palette.readFromNBT( nbt ); | ||||
|         setChanged(); | ||||
|     } | ||||
|  | ||||
|     public static int getColour( char c, Colour def ) | ||||
|     { | ||||
|         if( c >= '0' && c <= '9' ) return c - '0'; | ||||
|         if( c >= 'a' && c <= 'f' ) return c - 'a' + 10; | ||||
|         return 15 - def.ordinal(); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -8,6 +8,7 @@ package dan200.computercraft.data; | ||||
|  | ||||
| import dan200.computercraft.ComputerCraft; | ||||
| import dan200.computercraft.shared.data.BlockNamedEntityLootCondition; | ||||
| import dan200.computercraft.shared.data.HasComputerIdLootCondition; | ||||
| import dan200.computercraft.shared.data.PlayerCreativeLootCondition; | ||||
| import dan200.computercraft.shared.proxy.ComputerCraftProxyCommon; | ||||
| import net.minecraft.block.Block; | ||||
| @@ -73,6 +74,7 @@ public class LootTables extends LootTableProvider | ||||
|                 .addEntry( DynamicLootEntry.func_216162_a( new ResourceLocation( ComputerCraft.MOD_ID, "computer" ) ) ) | ||||
|                 .acceptCondition( Alternative.builder( | ||||
|                     BlockNamedEntityLootCondition.builder(), | ||||
|                     HasComputerIdLootCondition.builder(), | ||||
|                     PlayerCreativeLootCondition.builder().inverted() | ||||
|                 ) ) | ||||
|             ).build() ); | ||||
|   | ||||
| @@ -6,7 +6,9 @@ | ||||
| package dan200.computercraft.shared.common; | ||||
|  | ||||
| import dan200.computercraft.core.terminal.Terminal; | ||||
| import io.netty.buffer.Unpooled; | ||||
| import net.minecraft.nbt.CompoundNBT; | ||||
| import net.minecraft.network.PacketBuffer; | ||||
|  | ||||
| public class ClientTerminal implements ITerminal | ||||
| { | ||||
| @@ -53,7 +55,7 @@ public class ClientTerminal implements ITerminal | ||||
|         { | ||||
|             CompoundNBT terminal = nbt.getCompound( "terminal" ); | ||||
|             resizeTerminal( terminal.getInt( "term_width" ), terminal.getInt( "term_height" ) ); | ||||
|             m_terminal.readFromNBT( terminal ); | ||||
|             m_terminal.read( new PacketBuffer( Unpooled.wrappedBuffer( terminal.getByteArray( "term_contents" ) ) ) ); | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|   | ||||
| @@ -5,8 +5,12 @@ | ||||
|  */ | ||||
| package dan200.computercraft.shared.common; | ||||
|  | ||||
| import dan200.computercraft.ComputerCraft; | ||||
| import dan200.computercraft.core.terminal.Terminal; | ||||
| import io.netty.buffer.ByteBuf; | ||||
| import io.netty.buffer.Unpooled; | ||||
| import net.minecraft.nbt.CompoundNBT; | ||||
| import net.minecraft.network.PacketBuffer; | ||||
|  | ||||
| import java.util.concurrent.atomic.AtomicBoolean; | ||||
|  | ||||
| @@ -83,17 +87,28 @@ public class ServerTerminal implements ITerminal | ||||
|         return m_colour; | ||||
|     } | ||||
|  | ||||
|     // Networking stuff | ||||
|  | ||||
|     public void writeDescription( CompoundNBT nbt ) | ||||
|     { | ||||
|         nbt.putBoolean( "colour", m_colour ); | ||||
|         if( m_terminal != null ) | ||||
|         { | ||||
|             // We have a 10 byte header (2 integer positions, then blinking and current colours), followed by the | ||||
|             // contents and palette. | ||||
|             // Yes, this serialisation code is terrible, but we need to serialise to NBT in order to work with monitors | ||||
|             // (or rather tile entity serialisation). | ||||
|             final int length = 10 + (2 * m_terminal.getWidth() * m_terminal.getHeight()) + (16 * 3); | ||||
|             ByteBuf buffer = Unpooled.buffer( length ); | ||||
|             m_terminal.write( new PacketBuffer( buffer ) ); | ||||
|  | ||||
|             if( buffer.writableBytes() != 0 ) | ||||
|             { | ||||
|                 ComputerCraft.log.warn( "Should have written {} bytes, but have {} ({} remaining).", length, buffer.writerIndex(), buffer.writableBytes() ); | ||||
|             } | ||||
|  | ||||
|             CompoundNBT terminal = new CompoundNBT(); | ||||
|             terminal.putInt( "term_width", m_terminal.getWidth() ); | ||||
|             terminal.putInt( "term_height", m_terminal.getHeight() ); | ||||
|             m_terminal.writeToNBT( terminal ); | ||||
|             terminal.putByteArray( "term_contents", buffer.array() ); | ||||
|             nbt.put( "terminal", terminal ); | ||||
|         } | ||||
|     } | ||||
|   | ||||
| @@ -19,9 +19,7 @@ public final class ComputerItemFactory | ||||
|     @Nonnull | ||||
|     public static ItemStack create( TileComputer tile ) | ||||
|     { | ||||
|         String label = tile.getLabel(); | ||||
|         int id = label != null ? tile.getComputerID() : -1; | ||||
|         return create( id, label, tile.getFamily() ); | ||||
|         return create( tile.getComputerID(), tile.getLabel(), tile.getFamily() ); | ||||
|     } | ||||
|  | ||||
|     @Nonnull | ||||
|   | ||||
| @@ -37,7 +37,7 @@ public abstract class ItemComputerBase extends BlockItem implements IComputerIte | ||||
|     @Override | ||||
|     public void addInformation( @Nonnull ItemStack stack, @Nullable World world, @Nonnull List<ITextComponent> list, @Nonnull ITooltipFlag options ) | ||||
|     { | ||||
|         if( options.isAdvanced() ) | ||||
|         if( options.isAdvanced() || getLabel( stack ) == null ) | ||||
|         { | ||||
|             int id = getComputerID( stack ); | ||||
|             if( id >= 0 ) | ||||
|   | ||||
| @@ -0,0 +1,48 @@ | ||||
| /* | ||||
|  * This file is part of ComputerCraft - http://www.computercraft.info | ||||
|  * Copyright Daniel Ratcliffe, 2011-2020. Do not distribute without permission. | ||||
|  * Send enquiries to dratcliffe@gmail.com | ||||
|  */ | ||||
| package dan200.computercraft.shared.data; | ||||
|  | ||||
| import dan200.computercraft.shared.computer.blocks.IComputerTile; | ||||
| import net.minecraft.tileentity.TileEntity; | ||||
| import net.minecraft.world.storage.loot.LootContext; | ||||
| import net.minecraft.world.storage.loot.LootParameter; | ||||
| import net.minecraft.world.storage.loot.LootParameters; | ||||
| import net.minecraft.world.storage.loot.conditions.ILootCondition; | ||||
|  | ||||
| import javax.annotation.Nonnull; | ||||
| import java.util.Collections; | ||||
| import java.util.Set; | ||||
|  | ||||
| /** | ||||
|  * A loot condition which checks if the tile entity has has a non-0 ID. | ||||
|  */ | ||||
| public final class HasComputerIdLootCondition implements ILootCondition | ||||
| { | ||||
|     public static final HasComputerIdLootCondition INSTANCE = new HasComputerIdLootCondition(); | ||||
|  | ||||
|     private HasComputerIdLootCondition() | ||||
|     { | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public boolean test( LootContext lootContext ) | ||||
|     { | ||||
|         TileEntity tile = lootContext.get( LootParameters.BLOCK_ENTITY ); | ||||
|         return tile instanceof IComputerTile && ((IComputerTile) tile).getComputerID() >= 0; | ||||
|     } | ||||
|  | ||||
|     @Nonnull | ||||
|     @Override | ||||
|     public Set<LootParameter<?>> getRequiredParameters() | ||||
|     { | ||||
|         return Collections.singleton( LootParameters.BLOCK_ENTITY ); | ||||
|     } | ||||
|  | ||||
|     public static IBuilder builder() | ||||
|     { | ||||
|         return () -> INSTANCE; | ||||
|     } | ||||
| } | ||||
| @@ -184,7 +184,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I | ||||
|     @Override | ||||
|     public void addInformation( @Nonnull ItemStack stack, @Nullable World world, List<ITextComponent> list, ITooltipFlag flag ) | ||||
|     { | ||||
|         if( flag.isAdvanced() ) | ||||
|         if( flag.isAdvanced() || getLabel( stack ) == null ) | ||||
|         { | ||||
|             int id = getComputerID( stack ); | ||||
|             if( id >= 0 ) | ||||
|   | ||||
| @@ -19,6 +19,7 @@ import dan200.computercraft.shared.computer.core.IContainerComputer; | ||||
| import dan200.computercraft.shared.computer.core.ServerComputer; | ||||
| import dan200.computercraft.shared.data.BlockNamedEntityLootCondition; | ||||
| import dan200.computercraft.shared.data.ConstantLootConditionSerializer; | ||||
| import dan200.computercraft.shared.data.HasComputerIdLootCondition; | ||||
| import dan200.computercraft.shared.data.PlayerCreativeLootCondition; | ||||
| import dan200.computercraft.shared.media.items.RecordMedia; | ||||
| import dan200.computercraft.shared.network.NetworkHandler; | ||||
| @@ -79,6 +80,12 @@ public final class ComputerCraftProxyCommon | ||||
|             PlayerCreativeLootCondition.class, | ||||
|             PlayerCreativeLootCondition.INSTANCE | ||||
|         ) ); | ||||
|  | ||||
|         LootConditionManager.registerCondition( ConstantLootConditionSerializer.of( | ||||
|             new ResourceLocation( ComputerCraft.MOD_ID, "has_id" ), | ||||
|             HasComputerIdLootCondition.class, | ||||
|             HasComputerIdLootCondition.INSTANCE | ||||
|         ) ); | ||||
|     } | ||||
|  | ||||
|     private static void registerProviders() | ||||
|   | ||||
| @@ -6,6 +6,7 @@ | ||||
| package dan200.computercraft.shared.turtle.items; | ||||
|  | ||||
| import dan200.computercraft.ComputerCraft; | ||||
| import dan200.computercraft.api.turtle.ITurtleAccess; | ||||
| import dan200.computercraft.api.turtle.ITurtleUpgrade; | ||||
| import dan200.computercraft.api.turtle.TurtleSide; | ||||
| import dan200.computercraft.shared.computer.core.ComputerFamily; | ||||
| @@ -22,18 +23,13 @@ public final class TurtleItemFactory | ||||
|     @Nonnull | ||||
|     public static ItemStack create( ITurtleTile turtle ) | ||||
|     { | ||||
|         ITurtleUpgrade leftUpgrade = turtle.getAccess().getUpgrade( TurtleSide.LEFT ); | ||||
|         ITurtleUpgrade rightUpgrade = turtle.getAccess().getUpgrade( TurtleSide.RIGHT ); | ||||
|         ITurtleAccess access = turtle.getAccess(); | ||||
|  | ||||
|         String label = turtle.getLabel(); | ||||
|         if( label == null ) | ||||
|         { | ||||
|             return create( -1, null, turtle.getColour(), turtle.getFamily(), leftUpgrade, rightUpgrade, 0, turtle.getOverlay() ); | ||||
|         } | ||||
|  | ||||
|         int id = turtle.getComputerID(); | ||||
|         int fuelLevel = turtle.getAccess().getFuelLevel(); | ||||
|         return create( id, label, turtle.getColour(), turtle.getFamily(), leftUpgrade, rightUpgrade, fuelLevel, turtle.getOverlay() ); | ||||
|         return create( | ||||
|             turtle.getComputerID(), turtle.getLabel(), turtle.getColour(), turtle.getFamily(), | ||||
|             access.getUpgrade( TurtleSide.LEFT ), access.getUpgrade( TurtleSide.RIGHT ), | ||||
|             access.getFuelLevel(), turtle.getOverlay() | ||||
|         ); | ||||
|     } | ||||
|  | ||||
|     @Nonnull | ||||
|   | ||||
| @@ -6,6 +6,7 @@ | ||||
| package dan200.computercraft.shared.util; | ||||
|  | ||||
| import net.minecraft.nbt.CompoundNBT; | ||||
| import net.minecraft.network.PacketBuffer; | ||||
|  | ||||
| public class Palette | ||||
| { | ||||
| @@ -78,6 +79,22 @@ public class Palette | ||||
|         }; | ||||
|     } | ||||
|  | ||||
|     public void write( PacketBuffer buffer ) | ||||
|     { | ||||
|         for( double[] colour : colours ) | ||||
|         { | ||||
|             for( double channel : colour ) buffer.writeByte( (int) (channel * 0xFF) & 0xFF ); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public void read( PacketBuffer buffer ) | ||||
|     { | ||||
|         for( double[] colour : colours ) | ||||
|         { | ||||
|             for( int i = 0; i < colour.length; i++ ) colour[i] = buffer.readByte() * 255; | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public CompoundNBT writeToNBT( CompoundNBT nbt ) | ||||
|     { | ||||
|         int[] rgb8 = new int[colours.length]; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 SquidDev
					SquidDev