public final String NBTTunnelDirection = "TTEnchantTunnelDir";
@SubscribeEvent
public void onEntityDamaged(LivingHurtEvent event) {
if (event.source.getEntity() instanceof EntityLivingBase) {
EntityLivingBase attacker = (EntityLivingBase) event.source.getEntity();
ItemStack heldItem = attacker.getHeldItem();
if (heldItem == null)
return;
if (attacker instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) attacker;
ItemStack legs = player.getCurrentArmor(1);
int pounce = EnchantmentHelper.getEnchantmentLevel(LibEnchantIDs.pounce, legs);
if (pounce > 0) {
if (player.worldObj.getBlock((int) Math.floor(player.posX), (int) Math.floor(player.posY) - 1, (int) Math.floor(player.posZ)) == net.minecraft.init.Blocks.air) {
event.ammount *= 1 + (.25 * pounce);
}
}
}
int finalStrike = EnchantmentHelper.getEnchantmentLevel(LibEnchantIDs.finalStrike, heldItem);
if (finalStrike > 0) {
Random rand = new Random();
if (rand.nextInt(20 - finalStrike) == 0) {
event.ammount *= 3;
}
}
int valiance = EnchantmentHelper.getEnchantmentLevel(LibEnchantIDs.valiance, heldItem);
if (valiance > 0) {
if (attacker.getHealth() / attacker.getMaxHealth() < .5F) {
event.ammount *= (1 + .1 * valiance);
}
}
int focusedStrikes = EnchantmentHelper.getEnchantmentLevel(LibEnchantIDs.focusedStrike, heldItem);
int dispersedStrikes = EnchantmentHelper.getEnchantmentLevel(LibEnchantIDs.dispersedStrikes, heldItem);
if (focusedStrikes > 0 || dispersedStrikes > 0) {
if (heldItem.stackTagCompound == null) {
heldItem.stackTagCompound = new NBTTagCompound();
}
int lastTarget = heldItem.stackTagCompound.getInteger(NBTLastTarget);
int successiveStrikes = heldItem.stackTagCompound.getInteger(NBTSuccessiveStrike);
int entityId = event.entityLiving.getEntityId();
if (lastTarget != entityId) {
heldItem.stackTagCompound.setInteger(NBTSuccessiveStrike, 0);
successiveStrikes = 0;
} else {
heldItem.stackTagCompound.setInteger(NBTSuccessiveStrike, successiveStrikes + 1);
successiveStrikes = 1;
}
if (focusedStrikes > 0) {
event.ammount /= 2;
event.ammount += (.5 * successiveStrikes * event.ammount * focusedStrikes);
}
if (dispersedStrikes > 0) {
event.ammount *= 1 + (successiveStrikes / 5);
event.ammount /= (1 + (successiveStrikes * 2));
}
heldItem.stackTagCompound.setInteger("TTEnchantLastTarget", entityId);
}
int vampirism = EnchantmentHelper.getEnchantmentLevel(LibEnchantIDs.idVampirism, heldItem);
if (vampirism > 0) {
attacker.heal(vampirism);
event.entityLiving.worldObj.playSoundAtEntity(event.entityLiving, "thaumcraft:zap", 0.6F, 1F);
}
}
}