mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-07-05 11:32:53 +00:00
Different fix for shadow turtles
This commit is contained in:
parent
5284b145f8
commit
4eb4bb933f
@ -46,12 +46,19 @@ public class TileTurtle extends TileComputerBase
|
|||||||
public static final int INVENTORY_HEIGHT = 4;
|
public static final int INVENTORY_HEIGHT = 4;
|
||||||
|
|
||||||
// Members
|
// Members
|
||||||
|
|
||||||
|
enum MoveState
|
||||||
|
{
|
||||||
|
NOT_MOVED,
|
||||||
|
IN_PROGRESS,
|
||||||
|
MOVED
|
||||||
|
}
|
||||||
|
|
||||||
private ItemStack[] m_inventory;
|
private ItemStack[] m_inventory;
|
||||||
private ItemStack[] m_previousInventory;
|
private ItemStack[] m_previousInventory;
|
||||||
private boolean m_inventoryChanged;
|
private boolean m_inventoryChanged;
|
||||||
private TurtleBrain m_brain;
|
private TurtleBrain m_brain;
|
||||||
private boolean m_moved;
|
private MoveState m_moveState;
|
||||||
|
|
||||||
public TileTurtle()
|
public TileTurtle()
|
||||||
{
|
{
|
||||||
@ -59,12 +66,12 @@ public class TileTurtle extends TileComputerBase
|
|||||||
m_previousInventory = new ItemStack[ getSizeInventory() ];
|
m_previousInventory = new ItemStack[ getSizeInventory() ];
|
||||||
m_inventoryChanged = false;
|
m_inventoryChanged = false;
|
||||||
m_brain = createBrain();
|
m_brain = createBrain();
|
||||||
m_moved = false;
|
m_moveState = MoveState.NOT_MOVED;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasMoved()
|
public boolean hasMoved()
|
||||||
{
|
{
|
||||||
return m_moved;
|
return m_moveState == MoveState.MOVED;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected TurtleBrain createBrain()
|
protected TurtleBrain createBrain()
|
||||||
@ -276,6 +283,41 @@ public class TileTurtle extends TileComputerBase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onNeighbourChange()
|
||||||
|
{
|
||||||
|
if ( m_moveState == MoveState.NOT_MOVED )
|
||||||
|
{
|
||||||
|
super.onNeighbourChange();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onNeighbourTileEntityChange(BlockPos neighbour)
|
||||||
|
{
|
||||||
|
if ( m_moveState == MoveState.NOT_MOVED )
|
||||||
|
{
|
||||||
|
super.onNeighbourTileEntityChange( neighbour );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void notifyMoveStart()
|
||||||
|
{
|
||||||
|
if (m_moveState == MoveState.NOT_MOVED)
|
||||||
|
{
|
||||||
|
m_moveState = MoveState.IN_PROGRESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void notifyMoveEnd()
|
||||||
|
{
|
||||||
|
// MoveState.MOVED is final
|
||||||
|
if (m_moveState == MoveState.IN_PROGRESS)
|
||||||
|
{
|
||||||
|
m_moveState = MoveState.NOT_MOVED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readFromNBT( NBTTagCompound nbttagcompound )
|
public void readFromNBT( NBTTagCompound nbttagcompound )
|
||||||
{
|
{
|
||||||
@ -401,7 +443,7 @@ public class TileTurtle extends TileComputerBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
// IInventory
|
// IInventory
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getSizeInventory()
|
public int getSizeInventory()
|
||||||
{
|
{
|
||||||
@ -431,7 +473,7 @@ public class TileTurtle extends TileComputerBase
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack decrStackSize( int slot, int count )
|
public ItemStack decrStackSize( int slot, int count )
|
||||||
{
|
{
|
||||||
@ -447,13 +489,13 @@ public class TileTurtle extends TileComputerBase
|
|||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( stack.stackSize <= count )
|
if( stack.stackSize <= count )
|
||||||
{
|
{
|
||||||
setInventorySlotContents( slot, null );
|
setInventorySlotContents( slot, null );
|
||||||
return stack;
|
return stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemStack part = stack.splitStack( count );
|
ItemStack part = stack.splitStack( count );
|
||||||
onInventoryDefinitelyChanged();
|
onInventoryDefinitelyChanged();
|
||||||
return part;
|
return part;
|
||||||
@ -496,7 +538,7 @@ public class TileTurtle extends TileComputerBase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName()
|
public String getName()
|
||||||
{
|
{
|
||||||
@ -550,7 +592,7 @@ public class TileTurtle extends TileComputerBase
|
|||||||
public void openInventory( EntityPlayer player )
|
public void openInventory( EntityPlayer player )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void closeInventory( EntityPlayer player )
|
public void closeInventory( EntityPlayer player )
|
||||||
{
|
{
|
||||||
@ -561,7 +603,7 @@ public class TileTurtle extends TileComputerBase
|
|||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void markDirty()
|
public void markDirty()
|
||||||
{
|
{
|
||||||
@ -664,6 +706,6 @@ public class TileTurtle extends TileComputerBase
|
|||||||
m_inventoryChanged = copy.m_inventoryChanged;
|
m_inventoryChanged = copy.m_inventoryChanged;
|
||||||
m_brain = copy.m_brain;
|
m_brain = copy.m_brain;
|
||||||
m_brain.setOwner( this );
|
m_brain.setOwner( this );
|
||||||
copy.m_moved = true;
|
copy.m_moveState = MoveState.MOVED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -495,6 +495,7 @@ public class TurtleBrain implements ITurtleAccess
|
|||||||
|
|
||||||
// Cache info about the old turtle (so we don't access this after we delete ourselves)
|
// Cache info about the old turtle (so we don't access this after we delete ourselves)
|
||||||
World oldWorld = getWorld();
|
World oldWorld = getWorld();
|
||||||
|
TileTurtle oldOwner = m_owner;
|
||||||
BlockPos oldPos = m_owner.getPos();
|
BlockPos oldPos = m_owner.getPos();
|
||||||
Block oldBlock = m_owner.getBlock();
|
Block oldBlock = m_owner.getBlock();
|
||||||
|
|
||||||
@ -504,36 +505,51 @@ public class TurtleBrain implements ITurtleAccess
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a new turtle
|
if ( !world.isBlockLoaded( pos ) )
|
||||||
if( world.isBlockLoaded( pos ) && world.setBlockState( pos, oldBlock.getDefaultState(), 0 ) )
|
|
||||||
{
|
{
|
||||||
Block block = world.getBlockState( pos ).getBlock();
|
return false;
|
||||||
if( block == oldBlock )
|
}
|
||||||
|
|
||||||
|
oldOwner.notifyMoveStart();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Create a new turtle
|
||||||
|
if( world.setBlockState( pos, oldBlock.getDefaultState(), 0 ) )
|
||||||
{
|
{
|
||||||
TileEntity newTile = world.getTileEntity( pos );
|
Block block = world.getBlockState( pos ).getBlock();
|
||||||
if( newTile != null && newTile instanceof TileTurtle )
|
if( block == oldBlock )
|
||||||
{
|
{
|
||||||
// Copy the old turtle state into the new turtle
|
TileEntity newTile = world.getTileEntity( pos );
|
||||||
TileTurtle newTurtle = (TileTurtle)newTile;
|
if( newTile != null && newTile instanceof TileTurtle )
|
||||||
newTurtle.setWorldObj( world );
|
{
|
||||||
newTurtle.setPos( pos );
|
// Copy the old turtle state into the new turtle
|
||||||
newTurtle.transferStateFrom( m_owner );
|
TileTurtle newTurtle = (TileTurtle)newTile;
|
||||||
newTurtle.createServerComputer().setWorld( world );
|
newTurtle.setWorldObj( world );
|
||||||
newTurtle.createServerComputer().setPosition( pos );
|
newTurtle.setPos( pos );
|
||||||
|
newTurtle.transferStateFrom( oldOwner );
|
||||||
|
newTurtle.createServerComputer().setWorld( world );
|
||||||
|
newTurtle.createServerComputer().setPosition( pos );
|
||||||
|
|
||||||
// Remove the old turtle
|
// Remove the old turtle
|
||||||
oldWorld.setBlockToAir( oldPos );
|
oldWorld.setBlockToAir( oldPos );
|
||||||
|
|
||||||
// Make sure everybody knows about it
|
// Make sure everybody knows about it
|
||||||
newTurtle.updateBlock();
|
newTurtle.updateBlock();
|
||||||
newTurtle.updateInput();
|
newTurtle.updateInput();
|
||||||
newTurtle.updateOutput();
|
newTurtle.updateOutput();
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Something went wrong, remove the newly created turtle
|
// Something went wrong, remove the newly created turtle
|
||||||
world.setBlockToAir( pos );
|
world.setBlockToAir( pos );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
// whatever happens, unblock old turtle in case it's still in world
|
||||||
|
oldOwner.notifyMoveEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user