use of pl.asie.charset.api.lib.IMovable 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.IMovable in project Charset by CharsetMC.
the class CarryHandler method place.
public boolean place(World world, BlockPos pos, EnumFacing facing, EntityPlayer player) {
if (block != null) {
if (hasTileEntity()) {
IMovable movable = CapabilityHelper.get(Capabilities.MOVABLE, getTile(), null);
if (movable != null && !movable.canMoveTo(world, pos)) {
return false;
}
}
if (world.isBlockModifiable(player, pos) && world.mayPlace(block.getBlock(), pos, false, facing, player)) {
// TODO: Implement PlaceEvent (ForgeHooks.onPlaceItemIntoWorld)
world.setBlockState(pos, block);
IBlockState oldBlock = block;
if (tile != null) {
tile.setInteger("x", pos.getX());
tile.setInteger("y", pos.getY());
tile.setInteger("z", pos.getZ());
world.setTileEntity(pos, TileEntity.create(world, tile));
setTile(null);
}
if (customCarryHandler != null) {
customCarryHandler.onPlace(world, pos);
}
float yawDiff = player != null ? grabbedYaw - player.rotationYaw : 0.0F;
while (yawDiff < 0) yawDiff += 360.0F;
int rotCycles = MathHelper.floor((double) (yawDiff * 4.0F / 360.0F) + 0.5D) & 3;
if (rotCycles > 0) {
RotationUtils.rotateAround(world, pos, EnumFacing.UP, rotCycles);
}
block = null;
IBlockState newState = world.getBlockState(pos);
if (player instanceof EntityPlayer) {
SoundType soundtype = newState.getBlock().getSoundType(newState, world, pos, player);
world.playSound((EntityPlayer) player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
}
// TODO: Check if I break something
try {
newState.neighborChanged(world, pos, oldBlock.getBlock(), pos);
} catch (Throwable throwable) {
throwable.printStackTrace();
}
CharsetTweakBlockCarrying.syncCarryWithAllClients(player);
setCustomCarryHandler(true);
return true;
} else {
return false;
}
} else {
return false;
}
}
Aggregations