use of pl.asie.charset.api.lib.IMultiblockStructure in project Charset by CharsetMC.
the class CarryHandler method canPickUp.
private boolean canPickUp(World world, BlockPos pos, IBlockState block) {
if (player instanceof EntityPlayer && ((EntityPlayer) player).isCreative()) {
return true;
}
// Check TileEntityLockable
TileEntity tile = world.getTileEntity(pos);
if (tile instanceof TileEntityLockable && ((TileEntityLockable) tile).isLocked()) {
return false;
}
// Check IMultiblockStructure
IMultiblockStructure structure = CapabilityHelper.get(world, pos, Capabilities.MULTIBLOCK_STRUCTURE, null, true, true, false);
if (structure != null && !structure.isSeparable()) {
int count = 0;
Iterator<BlockPos> it = structure.iterator();
while (it.hasNext()) {
if (++count >= 2)
return false;
}
}
// Check IMovable
IMovable movable = CapabilityHelper.get(world, pos, Capabilities.MOVABLE, null, true, true, false);
if (movable != null && !movable.canMoveFrom()) {
return false;
}
// Check Lock
Lockable lockable = CapabilityHelper.get(world, pos, Capabilities.LOCKABLE, null, true, true, false);
if (lockable != null && lockable.hasLock()) {
return false;
}
return true;
}
use of pl.asie.charset.api.lib.IMultiblockStructure in project Charset by CharsetMC.
the class LockEventHandler method getLock.
// ENSURE LocksCapabilityHandler has all of the capabilities used here whitelisted!
public static Lockable getLock(TileEntity tile) {
if (tile != null) {
if (tile.hasCapability(Capabilities.MULTIBLOCK_STRUCTURE, null)) {
IMultiblockStructure structure = tile.getCapability(Capabilities.MULTIBLOCK_STRUCTURE, null);
Iterator<BlockPos> iterator = structure.iterator();
while (iterator.hasNext()) {
TileEntity tile2 = tile.getWorld().getTileEntity(iterator.next());
if (tile2 != null && tile2.hasCapability(Capabilities.LOCKABLE, null)) {
Lockable lock = tile2.getCapability(Capabilities.LOCKABLE, null);
if (lock.hasLock() && lock.getLock().isLockValid(tile2) && lock.getLock().isLocked()) {
return lock;
}
}
}
} else if (tile.hasCapability(Capabilities.LOCKABLE, null)) {
Lockable lock = tile.getCapability(Capabilities.LOCKABLE, null);
if (lock.hasLock() && lock.getLock().isLockValid(tile) && lock.getLock().isLocked()) {
return lock;
}
}
}
return null;
}
Aggregations