Search in sources :

Example 1 with IMovable

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;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityLockable(net.minecraft.tileentity.TileEntityLockable) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) TileEntityLockable(net.minecraft.tileentity.TileEntityLockable) Lockable(pl.asie.charset.api.locks.Lockable) IMovable(pl.asie.charset.api.lib.IMovable) IMultiblockStructure(pl.asie.charset.api.lib.IMultiblockStructure)

Example 2 with IMovable

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;
    }
}
Also used : SoundType(net.minecraft.block.SoundType) IBlockState(net.minecraft.block.state.IBlockState) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IMovable(pl.asie.charset.api.lib.IMovable)

Aggregations

EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 IMovable (pl.asie.charset.api.lib.IMovable)2 SoundType (net.minecraft.block.SoundType)1 IBlockState (net.minecraft.block.state.IBlockState)1 TileEntity (net.minecraft.tileentity.TileEntity)1 TileEntityLockable (net.minecraft.tileentity.TileEntityLockable)1 BlockPos (net.minecraft.util.math.BlockPos)1 IMultiblockStructure (pl.asie.charset.api.lib.IMultiblockStructure)1 Lockable (pl.asie.charset.api.locks.Lockable)1