Search in sources :

Example 1 with IKey

use of net.mcft.copy.betterstorage.api.lock.IKey in project BetterStorage by copygirl.

the class LockAttachment method use.

private boolean use(EntityPlayer player, ItemStack holding) {
    if (player.worldObj.isRemote)
        return false;
    ILockable lockable = (ILockable) tileEntity;
    ItemStack lock = lockable.getLock();
    if (lock == null) {
        if (StackUtils.isLock(holding) && lockable.isLockValid(holding)) {
            lockable.setLock(holding);
            player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
            return true;
        }
    } else if (StackUtils.isKey(holding)) {
        IKey keyType = (IKey) holding.getItem();
        ILock lockType = (ILock) lock.getItem();
        boolean success = keyType.unlock(holding, lock, true);
        lockType.onUnlock(lock, holding, lockable, player, success);
        if (!success)
            return true;
        if (player.isSneaking()) {
            AxisAlignedBB box = getHighlightBox();
            double x = (box.minX + box.maxX) / 2;
            double y = (box.minY + box.maxY) / 2;
            double z = (box.minZ + box.maxZ) / 2;
            EntityItem item = WorldUtils.spawnItem(player.worldObj, x, y, z, lock);
            lockable.setLock(null);
        } else
            lockable.useUnlocked(player);
        return true;
    }
    return false;
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) IKey(net.mcft.copy.betterstorage.api.lock.IKey) ItemStack(net.minecraft.item.ItemStack) ILock(net.mcft.copy.betterstorage.api.lock.ILock) EntityItem(net.minecraft.entity.item.EntityItem) ILockable(net.mcft.copy.betterstorage.api.lock.ILockable)

Aggregations

IKey (net.mcft.copy.betterstorage.api.lock.IKey)1 ILock (net.mcft.copy.betterstorage.api.lock.ILock)1 ILockable (net.mcft.copy.betterstorage.api.lock.ILockable)1 EntityItem (net.minecraft.entity.item.EntityItem)1 ItemStack (net.minecraft.item.ItemStack)1 AxisAlignedBB (net.minecraft.util.AxisAlignedBB)1