From 99b719299c24903d840648b3c894451f430b3d16 Mon Sep 17 00:00:00 2001 From: Euric Date: Tue, 4 May 2021 14:24:58 -0700 Subject: [PATCH] Defer monitor tile update when placed by another TE --- .../peripheral/monitor/BlockMonitor.java | 12 +++++++++--- .../peripheral/monitor/TileMonitor.java | 19 +++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/main/java/dan200/computercraft/shared/peripheral/monitor/BlockMonitor.java b/src/main/java/dan200/computercraft/shared/peripheral/monitor/BlockMonitor.java index 3e6efdbc0..e51362843 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/monitor/BlockMonitor.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/monitor/BlockMonitor.java @@ -20,6 +20,7 @@ import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; +import net.minecraftforge.common.util.FakePlayer; import net.minecraftforge.fml.RegistryObject; import javax.annotation.Nonnull; @@ -85,9 +86,14 @@ public void setPlacedBy( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull B if( entity instanceof TileMonitor && !world.isClientSide ) { TileMonitor monitor = (TileMonitor) entity; - monitor.contractNeighbours(); - monitor.contract(); - monitor.expand(); + // Defer the block update if we're being placed by another TE. See #691 + if ( livingEntity == null || livingEntity instanceof FakePlayer ) + { + monitor.updateNeighborsDeferred(); + return; + } + + monitor.updateNeighbors(); } } } 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 dabb2feee..1c0b10075 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/monitor/TileMonitor.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/monitor/TileMonitor.java @@ -55,6 +55,7 @@ public class TileMonitor extends TileGeneric private LazyOptional peripheralCap; private final Set computers = new HashSet<>(); + private boolean needsUpdate = false; private boolean destroyed = false; private boolean visiting = false; @@ -147,6 +148,12 @@ public void load( @Nonnull CompoundNBT tag ) @Override public void blockTick() { + if ( needsUpdate ) + { + needsUpdate = false; + updateNeighbors(); + } + if( xIndex != 0 || yIndex != 0 || serverMonitor == null ) return; serverMonitor.clearChanged(); @@ -525,6 +532,18 @@ private boolean mergeDown() return true; } + void updateNeighborsDeferred() + { + needsUpdate = true; + } + + void updateNeighbors() + { + contractNeighbours(); + contract(); + expand(); + } + @SuppressWarnings( "StatementWithEmptyBody" ) void expand() {