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 )
|
public final void neighborChanged( IBlockState state, World world, BlockPos pos, Block block, BlockPos neighbour )
|
||||||
{
|
{
|
||||||
TileEntity tile = world.getTileEntity( pos );
|
TileEntity tile = world.getTileEntity( pos );
|
||||||
if( tile instanceof TileGeneric )
|
if( tile instanceof TileGeneric ) ((TileGeneric) tile).onNeighbourChange( neighbour );
|
||||||
{
|
|
||||||
TileGeneric generic = (TileGeneric) tile;
|
|
||||||
generic.onNeighbourChange();
|
|
||||||
generic.onNeighbourChange( neighbour );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -63,8 +63,10 @@ public abstract class TileGeneric extends TileEntity
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings( "deprecation" )
|
||||||
public void onNeighbourChange( @Nonnull BlockPos neighbour )
|
public void onNeighbourChange( @Nonnull BlockPos neighbour )
|
||||||
{
|
{
|
||||||
|
onNeighbourChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onNeighbourTileEntityChange( @Nonnull BlockPos neighbour )
|
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_inventory = NonNullList.withSize( INVENTORY_SIZE, ItemStack.EMPTY );
|
||||||
m_previousInventory = NonNullList.withSize( INVENTORY_SIZE, ItemStack.EMPTY );
|
m_previousInventory = NonNullList.withSize( INVENTORY_SIZE, ItemStack.EMPTY );
|
||||||
m_inventoryChanged = false;
|
m_inventoryChanged = false;
|
||||||
m_brain = createBrain();
|
m_brain = new TurtleBrain( this );
|
||||||
m_moveState = MoveState.NOT_MOVED;
|
m_moveState = MoveState.NOT_MOVED;
|
||||||
m_family = family;
|
m_family = family;
|
||||||
}
|
}
|
||||||
@ -90,21 +90,12 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
|
|||||||
return m_moveState == MoveState.MOVED;
|
return m_moveState == MoveState.MOVED;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected TurtleBrain createBrain()
|
@Override
|
||||||
{
|
protected ServerComputer createComputer( int instanceID, int id )
|
||||||
return new TurtleBrain( this );
|
|
||||||
}
|
|
||||||
|
|
||||||
protected final ServerComputer createComputer( int instanceID, int id, int termWidth, int termHeight )
|
|
||||||
{
|
{
|
||||||
ServerComputer computer = new ServerComputer(
|
ServerComputer computer = new ServerComputer(
|
||||||
getWorld(),
|
getWorld(), id, m_label, instanceID, getFamily(),
|
||||||
id,
|
ComputerCraft.terminalWidth_turtle, ComputerCraft.terminalHeight_turtle
|
||||||
m_label,
|
|
||||||
instanceID,
|
|
||||||
getFamily(),
|
|
||||||
termWidth,
|
|
||||||
termHeight
|
|
||||||
);
|
);
|
||||||
computer.setPosition( getPos() );
|
computer.setPosition( getPos() );
|
||||||
computer.addAPI( new TurtleAPI( computer.getAPIEnvironment(), getAccess() ) );
|
computer.addAPI( new TurtleAPI( computer.getAPIEnvironment(), getAccess() ) );
|
||||||
@ -112,12 +103,6 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
|
|||||||
return computer;
|
return computer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ServerComputer createComputer( int instanceID, int id )
|
|
||||||
{
|
|
||||||
return createComputer( instanceID, id, ComputerCraft.terminalWidth_turtle, ComputerCraft.terminalHeight_turtle );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ComputerProxy createProxy()
|
public ComputerProxy createProxy()
|
||||||
{
|
{
|
||||||
|
@ -54,7 +54,7 @@ public class TurtleBrain implements ITurtleAccess
|
|||||||
private int m_commandsIssued = 0;
|
private int m_commandsIssued = 0;
|
||||||
|
|
||||||
private Map<TurtleSide, ITurtleUpgrade> m_upgrades = new EnumMap<>( TurtleSide.class );
|
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 Map<TurtleSide, NBTTagCompound> m_upgradeNBTData = new EnumMap<>( TurtleSide.class );
|
||||||
|
|
||||||
private int m_selectedSlot = 0;
|
private int m_selectedSlot = 0;
|
||||||
@ -824,9 +824,9 @@ public class TurtleBrain implements ITurtleAccess
|
|||||||
@Override
|
@Override
|
||||||
public IPeripheral getPeripheral( @Nonnull TurtleSide side )
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
@ -924,13 +924,9 @@ public class TurtleBrain implements ITurtleAccess
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updatePeripherals( ServerComputer serverComputer )
|
private void updatePeripherals( ServerComputer serverComputer )
|
||||||
{
|
{
|
||||||
if( serverComputer == null )
|
if( serverComputer == null ) return;
|
||||||
{
|
|
||||||
// Nothing to do
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update peripherals
|
// Update peripherals
|
||||||
for( TurtleSide side : TurtleSide.values() )
|
for( TurtleSide side : TurtleSide.values() )
|
||||||
@ -942,26 +938,20 @@ public class TurtleBrain implements ITurtleAccess
|
|||||||
peripheral = upgrade.createPeripheral( this, side );
|
peripheral = upgrade.createPeripheral( this, side );
|
||||||
}
|
}
|
||||||
|
|
||||||
int dir = toDirection( side );
|
IPeripheral existing = peripherals.get( side );
|
||||||
if( peripheral != null )
|
if( existing == peripheral || (existing != null && peripheral != null && existing.equals( peripheral )) )
|
||||||
{
|
{
|
||||||
if( !m_peripherals.containsKey( side ) )
|
// If the peripheral is the same, just use that.
|
||||||
{
|
peripheral = existing;
|
||||||
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 );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if( m_peripherals.containsKey( side ) )
|
else
|
||||||
{
|
{
|
||||||
serverComputer.setPeripheral( dir, null );
|
// Otherwise update our map
|
||||||
m_peripherals.remove( side );
|
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