1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-09-12 07:15:59 +00:00

Defer monitor tile update when placed by another TE

This commit is contained in:
Euric
2021-05-04 14:24:58 -07:00
committed by Jummit
parent ccdd2bf477
commit 4a20eea852
2 changed files with 28 additions and 3 deletions

View File

@@ -9,6 +9,7 @@ package dan200.computercraft.shared.peripheral.monitor;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import dan200.computercraft.api.turtle.FakePlayer;
import dan200.computercraft.shared.common.BlockGeneric; import dan200.computercraft.shared.common.BlockGeneric;
import net.minecraft.block.Block; import net.minecraft.block.Block;
@@ -71,9 +72,14 @@ public class BlockMonitor extends BlockGeneric {
BlockEntity entity = world.getBlockEntity(pos); BlockEntity entity = world.getBlockEntity(pos);
if (entity instanceof TileMonitor && !world.isClient) { if (entity instanceof TileMonitor && !world.isClient) {
TileMonitor monitor = (TileMonitor) entity; TileMonitor monitor = (TileMonitor) entity;
monitor.contractNeighbours(); // Defer the block update if we're being placed by another TE. See #691
monitor.contract(); if ( livingEntity == null || livingEntity instanceof FakePlayer )
monitor.expand(); {
monitor.updateNeighborsDeferred();
return;
}
monitor.updateNeighbors();
} }
} }

View File

@@ -54,6 +54,7 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile {
private ServerMonitor m_serverMonitor; private ServerMonitor m_serverMonitor;
private ClientMonitor m_clientMonitor; private ClientMonitor m_clientMonitor;
private MonitorPeripheral peripheral; private MonitorPeripheral peripheral;
private boolean needsUpdate = false;
private boolean m_destroyed = false; private boolean m_destroyed = false;
private boolean visiting = false; private boolean visiting = false;
private int m_width = 1; private int m_width = 1;
@@ -98,6 +99,12 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile {
@Override @Override
public void blockTick() { public void blockTick() {
if ( needsUpdate )
{
needsUpdate = false;
updateNeighbors();
}
if (this.m_xIndex != 0 || this.m_yIndex != 0 || this.m_serverMonitor == null) { if (this.m_xIndex != 0 || this.m_yIndex != 0 || this.m_serverMonitor == null) {
return; return;
} }
@@ -530,6 +537,18 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile {
return true; return true;
} }
void updateNeighborsDeferred()
{
needsUpdate = true;
}
void updateNeighbors()
{
contractNeighbours();
contract();
expand();
}
@SuppressWarnings ("StatementWithEmptyBody") @SuppressWarnings ("StatementWithEmptyBody")
void expand() { void expand() {
while (this.mergeLeft() || this.mergeRight() || this.mergeUp() || this.mergeDown()) { while (this.mergeLeft() || this.mergeRight() || this.mergeUp() || this.mergeDown()) {