Defer monitor tile update when placed by another TE

This commit is contained in:
Euric 2021-05-04 14:24:58 -07:00
parent 53dd15a213
commit 99b719299c
2 changed files with 28 additions and 3 deletions

View File

@ -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();
}
}
}

View File

@ -55,6 +55,7 @@ public class TileMonitor extends TileGeneric
private LazyOptional<IPeripheral> peripheralCap;
private final Set<IComputerAccess> 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()
{