Search in sources :

Example 1 with ILockable

use of net.mcft.copy.betterstorage.api.lock.ILockable 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)

Example 2 with ILockable

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

the class LockAttachment method attack.

private boolean attack(EntityPlayer player, ItemStack holding) {
    ILockable lockable = (ILockable) tileEntity;
    ItemStack lock = lockable.getLock();
    if (lock == null)
        return false;
    boolean canHurt = ((hit <= 0) && canHurtLock(holding));
    if (canHurt) {
        holding.damageItem(2, player);
        if (holding.stackSize <= 0)
            player.destroyCurrentEquippedItem();
    }
    if (!player.worldObj.isRemote) {
        if (canHurt) {
            hit = 10;
            int damage = (int) ((AttributeModifier) holding.getAttributeModifiers().get(SharedMonsterAttributes.attackDamage.getAttributeUnlocalizedName()).iterator().next()).getAmount();
            int sharpness = EnchantmentHelper.getEnchantmentLevel(Enchantment.sharpness.effectId, holding);
            int efficiency = EnchantmentHelper.getEnchantmentLevel(Enchantment.efficiency.effectId, holding);
            breakProgress += Math.min(damage, 10) / 2 + Math.min(Math.max(sharpness, efficiency), 5);
            int persistance = BetterStorageEnchantment.getLevel(lock, "persistance");
            if (breakProgress > 100 * (1 + persistance)) {
                int unbreaking = EnchantmentHelper.getEnchantmentLevel(Enchantment.unbreaking.effectId, lock);
                lock.setItemDamage(lock.getItemDamage() + 10 / (1 + unbreaking));
                if (lock.getItemDamage() < lock.getMaxDamage()) {
                    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(tileEntity.getWorldObj(), x, y, z, lock);
                }
                lockable.setLock(null);
                breakProgress = 0;
            }
            ((ILock) lock.getItem()).applyEffects(lock, lockable, player, EnumLockInteraction.ATTACK);
        }
        BetterStorage.networkChannel.sendToAllAround(new PacketLockHit(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord, canHurt), tileEntity.getWorldObj(), tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord, 32);
    } else
        hit(canHurt);
    return true;
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) PacketLockHit(net.mcft.copy.betterstorage.network.packet.PacketLockHit) 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

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