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