Search in sources :

Example 1 with IMultiblockStructure

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;
}
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 IMultiblockStructure

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

Aggregations

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