Search in sources :

Example 1 with PacketLockHit

use of net.mcft.copy.betterstorage.network.packet.PacketLockHit 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)1 ILockable (net.mcft.copy.betterstorage.api.lock.ILockable)1 PacketLockHit (net.mcft.copy.betterstorage.network.packet.PacketLockHit)1 EntityItem (net.minecraft.entity.item.EntityItem)1 ItemStack (net.minecraft.item.ItemStack)1 AxisAlignedBB (net.minecraft.util.AxisAlignedBB)1