From 4a20eea852198307d73b90af4d4c823a703b54c6 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 ce4eb0879..ebd2799bb 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/monitor/BlockMonitor.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/monitor/BlockMonitor.java @@ -9,6 +9,7 @@ package dan200.computercraft.shared.peripheral.monitor; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import dan200.computercraft.api.turtle.FakePlayer; import dan200.computercraft.shared.common.BlockGeneric; import net.minecraft.block.Block; @@ -71,9 +72,14 @@ public class BlockMonitor extends BlockGeneric { BlockEntity entity = world.getBlockEntity(pos); if (entity instanceof TileMonitor && !world.isClient) { 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 9ef392b25..cddd4e3f5 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/monitor/TileMonitor.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/monitor/TileMonitor.java @@ -54,6 +54,7 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile { private ServerMonitor m_serverMonitor; private ClientMonitor m_clientMonitor; private MonitorPeripheral peripheral; + private boolean needsUpdate = false; private boolean m_destroyed = false; private boolean visiting = false; private int m_width = 1; @@ -98,6 +99,12 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile { @Override public void blockTick() { + if ( needsUpdate ) + { + needsUpdate = false; + updateNeighbors(); + } + if (this.m_xIndex != 0 || this.m_yIndex != 0 || this.m_serverMonitor == null) { return; } @@ -530,6 +537,18 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile { return true; } + void updateNeighborsDeferred() + { + needsUpdate = true; + } + + void updateNeighbors() + { + contractNeighbours(); + contract(); + expand(); + } + @SuppressWarnings ("StatementWithEmptyBody") void expand() { while (this.mergeLeft() || this.mergeRight() || this.mergeUp() || this.mergeDown()) {