mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-01-07 16:00:31 +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();
|
label = computer.getLabel();
|
||||||
on = computer.isOn();
|
on = computer.isOn();
|
||||||
|
|
||||||
if( computer.hasOutputChanged() ) updateOutput();
|
|
||||||
|
|
||||||
// Update the block state if needed. We don't fire a block update intentionally,
|
// Update the block state if needed. We don't fire a block update intentionally,
|
||||||
// as this only really is needed on the client side.
|
// as this only really is needed on the client side.
|
||||||
updateBlockState( computer.getState() );
|
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();
|
if( computer.hasOutputChanged() ) updateOutput();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -376,11 +376,8 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
|
|||||||
fresh = true;
|
fresh = true;
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
if( changed )
|
|
||||||
{
|
if( changed ) updateInput();
|
||||||
updateBlock();
|
|
||||||
updateInput();
|
|
||||||
}
|
|
||||||
return ComputerCraft.serverComputerRegistry.get( instanceID );
|
return ComputerCraft.serverComputerRegistry.get( instanceID );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,7 +148,7 @@ public class TileMonitor extends TileGeneric
|
|||||||
@Override
|
@Override
|
||||||
public void blockTick()
|
public void blockTick()
|
||||||
{
|
{
|
||||||
if ( needsUpdate )
|
if( needsUpdate )
|
||||||
{
|
{
|
||||||
needsUpdate = false;
|
needsUpdate = false;
|
||||||
updateNeighbors();
|
updateNeighbors();
|
||||||
@ -278,8 +278,6 @@ public class TileMonitor extends TileGeneric
|
|||||||
|
|
||||||
int oldXIndex = xIndex;
|
int oldXIndex = xIndex;
|
||||||
int oldYIndex = yIndex;
|
int oldYIndex = yIndex;
|
||||||
int oldWidth = width;
|
|
||||||
int oldHeight = height;
|
|
||||||
|
|
||||||
xIndex = nbt.getInt( NBT_X );
|
xIndex = nbt.getInt( NBT_X );
|
||||||
yIndex = nbt.getInt( NBT_Y );
|
yIndex = nbt.getInt( NBT_Y );
|
||||||
@ -299,13 +297,6 @@ public class TileMonitor extends TileGeneric
|
|||||||
// If we're the origin terminal then create it.
|
// If we're the origin terminal then create it.
|
||||||
if( clientMonitor == null ) clientMonitor = new ClientMonitor( advanced, this );
|
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 )
|
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;
|
overlay = nbt.contains( NBT_OVERLAY ) ? new ResourceLocation( nbt.getString( NBT_OVERLAY ) ) : null;
|
||||||
|
|
||||||
// Read upgrades
|
// Read upgrades
|
||||||
setUpgrade( TurtleSide.LEFT, nbt.contains( NBT_LEFT_UPGRADE ) ? TurtleUpgrades.get( nbt.getString( NBT_LEFT_UPGRADE ) ) : null );
|
setUpgradeDirect( 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.RIGHT, nbt.contains( NBT_RIGHT_UPGRADE ) ? TurtleUpgrades.get( nbt.getString( NBT_RIGHT_UPGRADE ) ) : null );
|
||||||
|
|
||||||
// NBT
|
// NBT
|
||||||
upgradeNBTData.clear();
|
upgradeNBTData.clear();
|
||||||
@ -618,16 +618,26 @@ public class TurtleBrain implements ITurtleAccess
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setUpgrade( @Nonnull TurtleSide side, ITurtleUpgrade upgrade )
|
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
|
// Remove old upgrade
|
||||||
if( upgrades.containsKey( side ) )
|
if( upgrades.containsKey( side ) )
|
||||||
{
|
{
|
||||||
if( upgrades.get( side ) == upgrade ) return;
|
if( upgrades.get( side ) == upgrade ) return false;
|
||||||
upgrades.remove( side );
|
upgrades.remove( side );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if( upgrade == null ) return;
|
if( upgrade == null ) return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
upgradeNBTData.remove( side );
|
upgradeNBTData.remove( side );
|
||||||
@ -639,8 +649,9 @@ public class TurtleBrain implements ITurtleAccess
|
|||||||
if( owner.getLevel() != null )
|
if( owner.getLevel() != null )
|
||||||
{
|
{
|
||||||
updatePeripherals( owner.createServerComputer() );
|
updatePeripherals( owner.createServerComputer() );
|
||||||
owner.updateBlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user