diff --git a/src/main/java/dan200/computercraft/shared/common/TileGeneric.java b/src/main/java/dan200/computercraft/shared/common/TileGeneric.java index a4bb2ca94..09565cf01 100644 --- a/src/main/java/dan200/computercraft/shared/common/TileGeneric.java +++ b/src/main/java/dan200/computercraft/shared/common/TileGeneric.java @@ -73,42 +73,14 @@ public boolean isUsable( Player player, boolean ignoreRange ) player.distanceToSqr( pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5 ) <= range * range; } - protected void writeDescription( @Nonnull CompoundTag nbt ) - { - } - - protected void readDescription( @Nonnull CompoundTag nbt ) - { - } - - @Nonnull - @Override - public final ClientboundBlockEntityDataPacket getUpdatePacket() - { - CompoundTag nbt = new CompoundTag(); - writeDescription( nbt ); - return new ClientboundBlockEntityDataPacket( worldPosition, 0, nbt ); - } - @Override public final void onDataPacket( Connection net, ClientboundBlockEntityDataPacket packet ) { - if( packet.getType() == 0 ) readDescription( packet.getTag() ); - } - - @Nonnull - @Override - public CompoundTag getUpdateTag() - { - CompoundTag tag = super.getUpdateTag(); - writeDescription( tag ); - return tag; + if( packet.getType() == 0 ) handleUpdateTag( packet.getTag() ); } @Override public void handleUpdateTag( @Nonnull CompoundTag tag ) { - super.handleUpdateTag( tag ); - readDescription( tag ); } } diff --git a/src/main/java/dan200/computercraft/shared/computer/blocks/BlockComputerBase.java b/src/main/java/dan200/computercraft/shared/computer/blocks/BlockComputerBase.java index 06731d660..fd3241a37 100644 --- a/src/main/java/dan200/computercraft/shared/computer/blocks/BlockComputerBase.java +++ b/src/main/java/dan200/computercraft/shared/computer/blocks/BlockComputerBase.java @@ -59,7 +59,7 @@ public void onPlace( @Nonnull BlockState state, @Nonnull Level world, @Nonnull B super.onPlace( state, world, pos, oldState, isMoving ); BlockEntity tile = world.getBlockEntity( pos ); - if( tile instanceof TileComputerBase computer ) computer.updateInputsImmediately( ); + if( tile instanceof TileComputerBase computer ) computer.updateInputsImmediately(); } @Override diff --git a/src/main/java/dan200/computercraft/shared/computer/blocks/TileComputerBase.java b/src/main/java/dan200/computercraft/shared/computer/blocks/TileComputerBase.java index 27b13e1ec..3c8848cf2 100644 --- a/src/main/java/dan200/computercraft/shared/computer/blocks/TileComputerBase.java +++ b/src/main/java/dan200/computercraft/shared/computer/blocks/TileComputerBase.java @@ -24,6 +24,7 @@ import net.minecraft.network.chat.Component; import net.minecraft.network.chat.TextComponent; import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.MenuProvider; @@ -383,18 +384,27 @@ public ServerComputer getServerComputer() // Networking stuff + @Nonnull @Override - protected void writeDescription( @Nonnull CompoundTag nbt ) + public final ClientboundBlockEntityDataPacket getUpdatePacket() { - super.writeDescription( nbt ); + return new ClientboundBlockEntityDataPacket( worldPosition, 0, getUpdateTag() ); + } + + @Nonnull + @Override + public CompoundTag getUpdateTag() + { + // We need this for pick block on the client side. + CompoundTag nbt = super.getUpdateTag(); if( label != null ) nbt.putString( NBT_LABEL, label ); if( computerID >= 0 ) nbt.putInt( NBT_ID, computerID ); + return nbt; } @Override - protected void readDescription( @Nonnull CompoundTag nbt ) + public void handleUpdateTag( @Nonnull CompoundTag nbt ) { - super.readDescription( nbt ); label = nbt.contains( NBT_LABEL ) ? nbt.getString( NBT_LABEL ) : null; computerID = nbt.contains( NBT_ID ) ? nbt.getInt( NBT_ID ) : -1; } diff --git a/src/main/java/dan200/computercraft/shared/peripheral/monitor/TileMonitor.java b/src/main/java/dan200/computercraft/shared/peripheral/monitor/TileMonitor.java index 65ff5ab04..666385150 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/monitor/TileMonitor.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/monitor/TileMonitor.java @@ -17,6 +17,7 @@ import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.player.Player; @@ -236,7 +237,6 @@ private ServerMonitor createServerMonitor() { // Otherwise fetch the origin and attempt to get its monitor // Note this may load chunks, but we don't really have a choice here. - BlockPos pos = getBlockPos(); BlockEntity te = level.getBlockEntity( toWorldPos( 0, 0 ) ); if( !(te instanceof TileMonitor) ) return null; @@ -249,7 +249,6 @@ public ClientMonitor getClientMonitor() { if( clientMonitor != null ) return clientMonitor; - BlockPos pos = getBlockPos(); BlockEntity te = level.getBlockEntity( toWorldPos( 0, 0 ) ); if( !(te instanceof TileMonitor) ) return null; @@ -258,20 +257,29 @@ public ClientMonitor getClientMonitor() // Networking stuff + @Nonnull @Override - protected void writeDescription( @Nonnull CompoundTag nbt ) + public final ClientboundBlockEntityDataPacket getUpdatePacket() { - super.writeDescription( nbt ); + return new ClientboundBlockEntityDataPacket( worldPosition, 0, getUpdateTag() ); + } + + @Nonnull + @Override + public final CompoundTag getUpdateTag() + { + CompoundTag nbt = super.getUpdateTag(); nbt.putInt( NBT_X, xIndex ); nbt.putInt( NBT_Y, yIndex ); nbt.putInt( NBT_WIDTH, width ); nbt.putInt( NBT_HEIGHT, height ); + return nbt; } @Override - protected final void readDescription( @Nonnull CompoundTag nbt ) + public final void handleUpdateTag( @Nonnull CompoundTag nbt ) { - super.readDescription( nbt ); + super.handleUpdateTag( nbt ); int oldXIndex = xIndex; int oldYIndex = yIndex; diff --git a/src/main/java/dan200/computercraft/shared/turtle/blocks/TileTurtle.java b/src/main/java/dan200/computercraft/shared/turtle/blocks/TileTurtle.java index 6e94af153..0380393c5 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/blocks/TileTurtle.java +++ b/src/main/java/dan200/computercraft/shared/turtle/blocks/TileTurtle.java @@ -504,17 +504,19 @@ public void onTileEntityChange() // Networking stuff + @Nonnull @Override - protected void writeDescription( @Nonnull CompoundTag nbt ) + public CompoundTag getUpdateTag() { - super.writeDescription( nbt ); + CompoundTag nbt = super.getUpdateTag(); brain.writeDescription( nbt ); + return nbt; } @Override - protected void readDescription( @Nonnull CompoundTag nbt ) + public void handleUpdateTag( @Nonnull CompoundTag nbt ) { - super.readDescription( nbt ); + super.handleUpdateTag( nbt ); brain.readDescription( nbt ); }