mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-01-06 07:20:30 +00:00
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:
parent
d5be1aca0e
commit
02695aea51
@ -175,12 +175,12 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
|
||||
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 abstract class TileComputerBase extends TileGeneric implements IComputerT
|
||||
fresh = true;
|
||||
changed = true;
|
||||
}
|
||||
if( changed )
|
||||
{
|
||||
updateBlock();
|
||||
updateInput();
|
||||
}
|
||||
|
||||
if( changed ) updateInput();
|
||||
return ComputerCraft.serverComputerRegistry.get( instanceID );
|
||||
}
|
||||
|
||||
|
@ -148,7 +148,7 @@ public class TileMonitor extends TileGeneric
|
||||
@Override
|
||||
public void blockTick()
|
||||
{
|
||||
if ( needsUpdate )
|
||||
if( needsUpdate )
|
||||
{
|
||||
needsUpdate = false;
|
||||
updateNeighbors();
|
||||
@ -278,8 +278,6 @@ public class TileMonitor extends TileGeneric
|
||||
|
||||
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 @@ public class TileMonitor extends TileGeneric
|
||||
// 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 )
|
||||
|
@ -160,8 +160,8 @@ public class TurtleBrain implements ITurtleAccess
|
||||
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 class TurtleBrain implements ITurtleAccess
|
||||
|
||||
@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 class TurtleBrain implements ITurtleAccess
|
||||
if( owner.getLevel() != null )
|
||||
{
|
||||
updatePeripherals( owner.createServerComputer() );
|
||||
owner.updateBlock();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user