Reduce some block updates

- Fix double updateOutput() call in TileComputerBase - I guess a
   merge/rebase gone wrong in the past.
 - Don't call updateBlock() when creating a server computer. This used
   to be needed when we sent the computer to the client, but this is no
   longer the case.
 - Don't call updateBlock() on TileMonitors when updating from the
   client. We don't need to do a redraw here, as this is all stored in
   the block state now.
 - Don't update the block when reading turtle upgrades. See #643 for
   some background here.

See #658
This commit is contained in:
Jonathan Coates 2021-06-01 18:55:12 +01:00
parent d5be1aca0e
commit 02695aea51
No known key found for this signature in database
GPG Key ID: B9E431FF07C98D06
3 changed files with 21 additions and 22 deletions

View File

@ -175,12 +175,12 @@ public void tick()
label = computer.getLabel();
on = computer.isOn();
if( computer.hasOutputChanged() ) updateOutput();
// Update the block state if needed. We don't fire a block update intentionally,
// as this only really is needed on the client side.
updateBlockState( computer.getState() );
// TODO: This should ideally be split up into label/id/on (which should save NBT and sync to client) and
// redstone (which should update outputs)
if( computer.hasOutputChanged() ) updateOutput();
}
}
@ -376,11 +376,8 @@ public ServerComputer createServerComputer()
fresh = true;
changed = true;
}
if( changed )
{
updateBlock();
updateInput();
}
if( changed ) updateInput();
return ComputerCraft.serverComputerRegistry.get( instanceID );
}

View File

@ -148,7 +148,7 @@ public void load( @Nonnull CompoundNBT tag )
@Override
public void blockTick()
{
if ( needsUpdate )
if( needsUpdate )
{
needsUpdate = false;
updateNeighbors();
@ -278,8 +278,6 @@ protected final void readDescription( @Nonnull CompoundNBT nbt )
int oldXIndex = xIndex;
int oldYIndex = yIndex;
int oldWidth = width;
int oldHeight = height;
xIndex = nbt.getInt( NBT_X );
yIndex = nbt.getInt( NBT_Y );
@ -299,13 +297,6 @@ protected final void readDescription( @Nonnull CompoundNBT nbt )
// If we're the origin terminal then create it.
if( clientMonitor == null ) clientMonitor = new ClientMonitor( advanced, this );
}
if( oldXIndex != xIndex || oldYIndex != yIndex ||
oldWidth != width || oldHeight != height )
{
// One of our properties has changed, so ensure we redraw the block
updateBlock();
}
}
public final void read( TerminalState state )

View File

@ -160,8 +160,8 @@ private void readCommon( CompoundNBT nbt )
overlay = nbt.contains( NBT_OVERLAY ) ? new ResourceLocation( nbt.getString( NBT_OVERLAY ) ) : null;
// Read upgrades
setUpgrade( TurtleSide.LEFT, nbt.contains( NBT_LEFT_UPGRADE ) ? TurtleUpgrades.get( nbt.getString( NBT_LEFT_UPGRADE ) ) : null );
setUpgrade( TurtleSide.RIGHT, nbt.contains( NBT_RIGHT_UPGRADE ) ? TurtleUpgrades.get( nbt.getString( NBT_RIGHT_UPGRADE ) ) : null );
setUpgradeDirect( TurtleSide.LEFT, nbt.contains( NBT_LEFT_UPGRADE ) ? TurtleUpgrades.get( nbt.getString( NBT_LEFT_UPGRADE ) ) : null );
setUpgradeDirect( TurtleSide.RIGHT, nbt.contains( NBT_RIGHT_UPGRADE ) ? TurtleUpgrades.get( nbt.getString( NBT_RIGHT_UPGRADE ) ) : null );
// NBT
upgradeNBTData.clear();
@ -618,16 +618,26 @@ public ITurtleUpgrade getUpgrade( @Nonnull TurtleSide side )
@Override
public void setUpgrade( @Nonnull TurtleSide side, ITurtleUpgrade upgrade )
{
if( !setUpgradeDirect( side, upgrade ) ) return;
// This is a separate function to avoid updating the block when reading the NBT. We don't need to do this as
// either the block is newly placed (and so won't have changed) or is being updated with /data, which calls
// updateBlock for us.
if( owner.getLevel() != null ) owner.updateBlock();
}
private boolean setUpgradeDirect( @Nonnull TurtleSide side, ITurtleUpgrade upgrade )
{
// Remove old upgrade
if( upgrades.containsKey( side ) )
{
if( upgrades.get( side ) == upgrade ) return;
if( upgrades.get( side ) == upgrade ) return false;
upgrades.remove( side );
}
else
{
if( upgrade == null ) return;
if( upgrade == null ) return false;
}
upgradeNBTData.remove( side );
@ -639,8 +649,9 @@ public void setUpgrade( @Nonnull TurtleSide side, ITurtleUpgrade upgrade )
if( owner.getLevel() != null )
{
updatePeripherals( owner.createServerComputer() );
owner.updateBlock();
}
return true;
}
@Override