mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2024-09-29 23:40:46 +00:00
commit
17a3e120e8
@ -162,6 +162,17 @@ public abstract class BlockGeneric extends Block implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final void onNeighborChange( IBlockAccess world, BlockPos pos, BlockPos neighbour )
|
||||||
|
{
|
||||||
|
TileEntity tile = world.getTileEntity( pos );
|
||||||
|
if( tile instanceof TileGeneric )
|
||||||
|
{
|
||||||
|
TileGeneric generic = (TileGeneric)tile;
|
||||||
|
generic.onNeighbourTileEntityChange( neighbour );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final boolean isSideSolid( IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing side )
|
public final boolean isSideSolid( IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing side )
|
||||||
{
|
{
|
||||||
|
@ -95,6 +95,10 @@ public abstract class TileGeneric extends TileEntity
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onNeighbourTileEntityChange( BlockPos neighbour )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isSolidOnSide( int side )
|
public boolean isSolidOnSide( int side )
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
|
@ -197,6 +197,12 @@ public abstract class TileComputerBase extends TileGeneric
|
|||||||
updateInput();
|
updateInput();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onNeighbourTileEntityChange( BlockPos neighbour )
|
||||||
|
{
|
||||||
|
updateInput( neighbour );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update()
|
public void update()
|
||||||
{
|
{
|
||||||
@ -308,6 +314,21 @@ public abstract class TileComputerBase extends TileGeneric
|
|||||||
return localSide;
|
return localSide;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateSideInput( ServerComputer computer, EnumFacing dir, BlockPos offset )
|
||||||
|
{
|
||||||
|
EnumFacing offsetSide = dir.getOpposite();
|
||||||
|
int localDir = remapLocalSide( DirectionUtil.toLocal( this, dir ) );
|
||||||
|
if( !isRedstoneBlockedOnSide( localDir ) )
|
||||||
|
{
|
||||||
|
computer.setRedstoneInput( localDir, RedstoneUtil.getRedstoneOutput( worldObj, offset, offsetSide ) );
|
||||||
|
computer.setBundledRedstoneInput( localDir, RedstoneUtil.getBundledRedstoneOutput( worldObj, offset, offsetSide ) );
|
||||||
|
}
|
||||||
|
if( !isPeripheralBlockedOnSide( localDir ) )
|
||||||
|
{
|
||||||
|
computer.setPeripheral( localDir, PeripheralUtil.getPeripheral( worldObj, offset, offsetSide ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void updateInput()
|
public void updateInput()
|
||||||
{
|
{
|
||||||
if( worldObj == null || worldObj.isRemote )
|
if( worldObj == null || worldObj.isRemote )
|
||||||
@ -322,17 +343,29 @@ public abstract class TileComputerBase extends TileGeneric
|
|||||||
BlockPos pos = computer.getPosition();
|
BlockPos pos = computer.getPosition();
|
||||||
for( EnumFacing dir : EnumFacing.VALUES )
|
for( EnumFacing dir : EnumFacing.VALUES )
|
||||||
{
|
{
|
||||||
BlockPos offset = pos.offset( dir );
|
updateSideInput( computer, dir, pos.offset( dir ) );
|
||||||
EnumFacing offsetSide = dir.getOpposite();
|
|
||||||
int localDir = remapLocalSide( DirectionUtil.toLocal( this, dir ) );
|
|
||||||
if( !isRedstoneBlockedOnSide( localDir ) )
|
|
||||||
{
|
|
||||||
computer.setRedstoneInput( localDir, RedstoneUtil.getRedstoneOutput( worldObj, offset, offsetSide ) );
|
|
||||||
computer.setBundledRedstoneInput( localDir, RedstoneUtil.getBundledRedstoneOutput( worldObj, offset, offsetSide ) );
|
|
||||||
}
|
}
|
||||||
if( !isPeripheralBlockedOnSide( localDir ) )
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateInput( BlockPos neighbour )
|
||||||
{
|
{
|
||||||
computer.setPeripheral( localDir, PeripheralUtil.getPeripheral( worldObj, offset, offsetSide ) );
|
if( worldObj == null || worldObj.isRemote )
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ServerComputer computer = getServerComputer();
|
||||||
|
if( computer != null )
|
||||||
|
{
|
||||||
|
BlockPos pos = computer.getPosition();
|
||||||
|
for( EnumFacing dir : EnumFacing.VALUES )
|
||||||
|
{
|
||||||
|
BlockPos offset = pos.offset( dir );
|
||||||
|
if ( offset.equals( neighbour ) )
|
||||||
|
{
|
||||||
|
updateSideInput( computer, dir, offset );
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,11 +47,18 @@ public class TileTurtle extends TileComputerBase
|
|||||||
|
|
||||||
// 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 )
|
||||||
{
|
{
|
||||||
@ -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,8 +505,17 @@ public class TurtleBrain implements ITurtleAccess
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( !world.isBlockLoaded( pos ) )
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
oldOwner.notifyMoveStart();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
// Create a new turtle
|
// Create a new turtle
|
||||||
if( world.isBlockLoaded( pos ) && world.setBlockState( pos, oldBlock.getDefaultState(), 0 ) )
|
if( world.setBlockState( pos, oldBlock.getDefaultState(), 0 ) )
|
||||||
{
|
{
|
||||||
Block block = world.getBlockState( pos ).getBlock();
|
Block block = world.getBlockState( pos ).getBlock();
|
||||||
if( block == oldBlock )
|
if( block == oldBlock )
|
||||||
@ -517,7 +527,7 @@ public class TurtleBrain implements ITurtleAccess
|
|||||||
TileTurtle newTurtle = (TileTurtle)newTile;
|
TileTurtle newTurtle = (TileTurtle)newTile;
|
||||||
newTurtle.setWorldObj( world );
|
newTurtle.setWorldObj( world );
|
||||||
newTurtle.setPos( pos );
|
newTurtle.setPos( pos );
|
||||||
newTurtle.transferStateFrom( m_owner );
|
newTurtle.transferStateFrom( oldOwner );
|
||||||
newTurtle.createServerComputer().setWorld( world );
|
newTurtle.createServerComputer().setWorld( world );
|
||||||
newTurtle.createServerComputer().setPosition( pos );
|
newTurtle.createServerComputer().setPosition( pos );
|
||||||
|
|
||||||
@ -535,6 +545,12 @@ public class TurtleBrain implements ITurtleAccess
|
|||||||
// 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…
Reference in New Issue
Block a user