mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-01-20 22:16:57 +00:00
Fix turtle peripherals becoming desynced
When a turtle was unloaded but not actually disposed of, the m_peripheral map hangs around. As a result, when creating a new ServerComputer, the peripherals aren't considered changed and so they're never attached. Fixes #50. Also fix that blumin' deprecated method which has been around for a wee while now.
This commit is contained in:
parent
e46ab1e267
commit
11e4d0de82
@ -55,12 +55,7 @@ public abstract class BlockGeneric extends Block implements ITileEntityProvider
|
||||
public final void neighborChanged( IBlockState state, World world, BlockPos pos, Block block, BlockPos neighbour )
|
||||
{
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
if( tile instanceof TileGeneric )
|
||||
{
|
||||
TileGeneric generic = (TileGeneric) tile;
|
||||
generic.onNeighbourChange();
|
||||
generic.onNeighbourChange( neighbour );
|
||||
}
|
||||
if( tile instanceof TileGeneric ) ((TileGeneric) tile).onNeighbourChange( neighbour );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -63,8 +63,10 @@ public abstract class TileGeneric extends TileEntity
|
||||
{
|
||||
}
|
||||
|
||||
@SuppressWarnings( "deprecation" )
|
||||
public void onNeighbourChange( @Nonnull BlockPos neighbour )
|
||||
{
|
||||
onNeighbourChange();
|
||||
}
|
||||
|
||||
public void onNeighbourTileEntityChange( @Nonnull BlockPos neighbour )
|
||||
|
@ -80,7 +80,7 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
|
||||
m_inventory = NonNullList.withSize( INVENTORY_SIZE, ItemStack.EMPTY );
|
||||
m_previousInventory = NonNullList.withSize( INVENTORY_SIZE, ItemStack.EMPTY );
|
||||
m_inventoryChanged = false;
|
||||
m_brain = createBrain();
|
||||
m_brain = new TurtleBrain( this );
|
||||
m_moveState = MoveState.NOT_MOVED;
|
||||
m_family = family;
|
||||
}
|
||||
@ -90,21 +90,12 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
|
||||
return m_moveState == MoveState.MOVED;
|
||||
}
|
||||
|
||||
protected TurtleBrain createBrain()
|
||||
{
|
||||
return new TurtleBrain( this );
|
||||
}
|
||||
|
||||
protected final ServerComputer createComputer( int instanceID, int id, int termWidth, int termHeight )
|
||||
@Override
|
||||
protected ServerComputer createComputer( int instanceID, int id )
|
||||
{
|
||||
ServerComputer computer = new ServerComputer(
|
||||
getWorld(),
|
||||
id,
|
||||
m_label,
|
||||
instanceID,
|
||||
getFamily(),
|
||||
termWidth,
|
||||
termHeight
|
||||
getWorld(), id, m_label, instanceID, getFamily(),
|
||||
ComputerCraft.terminalWidth_turtle, ComputerCraft.terminalHeight_turtle
|
||||
);
|
||||
computer.setPosition( getPos() );
|
||||
computer.addAPI( new TurtleAPI( computer.getAPIEnvironment(), getAccess() ) );
|
||||
@ -112,12 +103,6 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
|
||||
return computer;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ServerComputer createComputer( int instanceID, int id )
|
||||
{
|
||||
return createComputer( instanceID, id, ComputerCraft.terminalWidth_turtle, ComputerCraft.terminalHeight_turtle );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ComputerProxy createProxy()
|
||||
{
|
||||
|
@ -54,7 +54,7 @@ public class TurtleBrain implements ITurtleAccess
|
||||
private int m_commandsIssued = 0;
|
||||
|
||||
private Map<TurtleSide, ITurtleUpgrade> m_upgrades = new EnumMap<>( TurtleSide.class );
|
||||
private Map<TurtleSide, IPeripheral> m_peripherals = new EnumMap<>( TurtleSide.class );
|
||||
private Map<TurtleSide, IPeripheral> peripherals = new EnumMap<>( TurtleSide.class );
|
||||
private Map<TurtleSide, NBTTagCompound> m_upgradeNBTData = new EnumMap<>( TurtleSide.class );
|
||||
|
||||
private int m_selectedSlot = 0;
|
||||
@ -824,9 +824,9 @@ public class TurtleBrain implements ITurtleAccess
|
||||
@Override
|
||||
public IPeripheral getPeripheral( @Nonnull TurtleSide side )
|
||||
{
|
||||
if( m_peripherals.containsKey( side ) )
|
||||
if( peripherals.containsKey( side ) )
|
||||
{
|
||||
return m_peripherals.get( side );
|
||||
return peripherals.get( side );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -924,13 +924,9 @@ public class TurtleBrain implements ITurtleAccess
|
||||
}
|
||||
}
|
||||
|
||||
public void updatePeripherals( ServerComputer serverComputer )
|
||||
private void updatePeripherals( ServerComputer serverComputer )
|
||||
{
|
||||
if( serverComputer == null )
|
||||
{
|
||||
// Nothing to do
|
||||
return;
|
||||
}
|
||||
if( serverComputer == null ) return;
|
||||
|
||||
// Update peripherals
|
||||
for( TurtleSide side : TurtleSide.values() )
|
||||
@ -942,26 +938,20 @@ public class TurtleBrain implements ITurtleAccess
|
||||
peripheral = upgrade.createPeripheral( this, side );
|
||||
}
|
||||
|
||||
int dir = toDirection( side );
|
||||
if( peripheral != null )
|
||||
IPeripheral existing = peripherals.get( side );
|
||||
if( existing == peripheral || (existing != null && peripheral != null && existing.equals( peripheral )) )
|
||||
{
|
||||
if( !m_peripherals.containsKey( side ) )
|
||||
{
|
||||
serverComputer.setPeripheral( dir, peripheral );
|
||||
m_peripherals.put( side, peripheral );
|
||||
}
|
||||
else if( !m_peripherals.get( side ).equals( peripheral ) )
|
||||
{
|
||||
serverComputer.setPeripheral( dir, peripheral );
|
||||
m_peripherals.remove( side );
|
||||
m_peripherals.put( side, peripheral );
|
||||
}
|
||||
// If the peripheral is the same, just use that.
|
||||
peripheral = existing;
|
||||
}
|
||||
else if( m_peripherals.containsKey( side ) )
|
||||
else
|
||||
{
|
||||
serverComputer.setPeripheral( dir, null );
|
||||
m_peripherals.remove( side );
|
||||
// Otherwise update our map
|
||||
peripherals.put( side, peripheral );
|
||||
}
|
||||
|
||||
// Always update the computer: it may not be the same computer as before!
|
||||
serverComputer.setPeripheral( toDirection( side ), peripheral );
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user