From 745b732e87c3036cb482fc90414750bdd53f3ec1 Mon Sep 17 00:00:00 2001 From: Toad-Dev <748280+Toad-Dev@users.noreply.github.com> Date: Sun, 5 Dec 2021 11:50:00 -0800 Subject: [PATCH] Fix BlockEntity syncing. Fabric does not have a separate handler for update packets vs load. Perhaps we should check if the CompoundTag contains an animation value in TurtleBrain#readDescription but nbt.getInt defaults to 0 and that's TurtleAnimation.NONE so... --- .../computer/blocks/TileComputerBase.java | 14 ++-- .../peripheral/monitor/TileMonitor.java | 73 ++++++++++++------- .../shared/turtle/blocks/TileTurtle.java | 15 ++-- 3 files changed, 60 insertions(+), 42 deletions(-) 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 55d77855b..440c9f7cb 100644 --- a/src/main/java/dan200/computercraft/shared/computer/blocks/TileComputerBase.java +++ b/src/main/java/dan200/computercraft/shared/computer/blocks/TileComputerBase.java @@ -205,6 +205,13 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT on = startOn = nbt.getBoolean( NBT_ON ); } + // @Override + // public void handleUpdateTag( @Nonnull CompoundTag nbt ) + // { + // label = nbt.contains( NBT_LABEL ) ? nbt.getString( NBT_LABEL ) : null; + // computerID = nbt.contains( NBT_ID ) ? nbt.getInt( NBT_ID ) : -1; + // } + protected boolean isPeripheralBlockedOnSide( ComputerSide localSide ) { return false; @@ -396,13 +403,6 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT return nbt; } - // @Override - // public void handleUpdateTag( @Nonnull CompoundTag nbt ) - // { - // label = nbt.contains( NBT_LABEL ) ? nbt.getString( NBT_LABEL ) : null; - // computerID = nbt.contains( NBT_ID ) ? nbt.getInt( NBT_ID ) : -1; - // } - protected void transferStateFrom( TileComputerBase copy ) { if( copy.computerID != computerID || copy.instanceID != instanceID ) 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 bcd3bae94..4f082b0f6 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/monitor/TileMonitor.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/monitor/TileMonitor.java @@ -137,12 +137,57 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile { super.load( nbt ); + int oldXIndex = xIndex; + int oldYIndex = yIndex; + xIndex = nbt.getInt( NBT_X ); yIndex = nbt.getInt( NBT_Y ); width = nbt.getInt( NBT_WIDTH ); height = nbt.getInt( NBT_HEIGHT ); + + if( oldXIndex != xIndex || oldYIndex != yIndex ) + { + // If our index has changed then it's possible the origin monitor has changed. Thus + // we'll clear our cache. If we're the origin then we'll need to remove the glList as well. + if( oldXIndex == 0 && oldYIndex == 0 && clientMonitor != null ) clientMonitor.destroy(); + clientMonitor = null; + } + + if( xIndex == 0 && yIndex == 0 ) + { + // If we're the origin terminal then create it. + if( clientMonitor == null ) clientMonitor = new ClientMonitor( advanced, this ); + } } + // @Override + // public final void handleUpdateTag( @Nonnull CompoundTag nbt ) + // { + // super.handleUpdateTag( nbt ); + // + // int oldXIndex = xIndex; + // int oldYIndex = yIndex; + // + // xIndex = nbt.getInt( NBT_X ); + // yIndex = nbt.getInt( NBT_Y ); + // width = nbt.getInt( NBT_WIDTH ); + // height = nbt.getInt( NBT_HEIGHT ); + // + // if( oldXIndex != xIndex || oldYIndex != yIndex ) + // { + // // If our index has changed then it's possible the origin monitor has changed. Thus + // // we'll clear our cache. If we're the origin then we'll need to remove the glList as well. + // if( oldXIndex == 0 && oldYIndex == 0 && clientMonitor != null ) clientMonitor.destroy(); + // clientMonitor = null; + // } + // + // if( xIndex == 0 && yIndex == 0 ) + // { + // // If we're the origin terminal then create it. + // if( clientMonitor == null ) clientMonitor = new ClientMonitor( advanced, this ); + // } + // } + @Override public void blockTick() { @@ -258,34 +303,6 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile return nbt; } - // @Override - // public final void handleUpdateTag( @Nonnull CompoundTag nbt ) - // { - // super.handleUpdateTag( nbt ); - // - // int oldXIndex = xIndex; - // int oldYIndex = yIndex; - // - // xIndex = nbt.getInt( NBT_X ); - // yIndex = nbt.getInt( NBT_Y ); - // width = nbt.getInt( NBT_WIDTH ); - // height = nbt.getInt( NBT_HEIGHT ); - // - // if( oldXIndex != xIndex || oldYIndex != yIndex ) - // { - // // If our index has changed then it's possible the origin monitor has changed. Thus - // // we'll clear our cache. If we're the origin then we'll need to remove the glList as well. - // if( oldXIndex == 0 && oldYIndex == 0 && clientMonitor != null ) clientMonitor.destroy(); - // clientMonitor = null; - // } - // - // if( xIndex == 0 && yIndex == 0 ) - // { - // // If we're the origin terminal then create it. - // if( clientMonitor == null ) clientMonitor = new ClientMonitor( advanced, this ); - // } - // } - public final void read( TerminalState state ) { if( xIndex != 0 || yIndex != 0 ) 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 0f66c5f3e..5ea3fdad3 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/blocks/TileTurtle.java +++ b/src/main/java/dan200/computercraft/shared/turtle/blocks/TileTurtle.java @@ -267,8 +267,16 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default // Read state brain.readFromNBT( nbt ); + brain.readDescription( nbt ); } + // @Override + // public void handleUpdateTag( @Nonnull CompoundTag nbt ) + // { + // super.handleUpdateTag( nbt ); + // brain.readDescription( nbt ); + // } + @Override public void saveAdditional( @Nonnull CompoundTag nbt ) { @@ -492,13 +500,6 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default return nbt; } - // @Override - // public void handleUpdateTag( @Nonnull CompoundTag nbt ) - // { - // super.handleUpdateTag( nbt ); - // brain.readDescription( nbt ); - // } - // Privates private boolean hasPeripheralUpgradeOnSide( ComputerSide side )