use of WayofTime.alchemicalWizardry.common.items.armour.OmegaArmour in project BloodMagic by WayofTime.
the class AlchemicalWizardryEventHooks method onLivingHurtEvent.
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onLivingHurtEvent(LivingHurtEvent event) {
if (!event.isCanceled() && event.entityLiving instanceof EntityPlayer && !event.entityLiving.worldObj.isRemote) {
EntityPlayer player = (EntityPlayer) event.entityLiving;
if (APISpellHelper.getCurrentAdditionalMaxHP(player) > 0) {
APISpellHelper.setPlayerReagentRegenCooldownTag(player, 20 * 20);
}
float prevHp = APISpellHelper.getCurrentAdditionalHP((EntityPlayer) event.entityLiving);
if (prevHp > 0) {
float recalculatedAmount = ArmorProperties.ApplyArmor(player, player.inventory.armorInventory, event.source, event.ammount);
if (recalculatedAmount <= 0)
return;
// Recalculated damage
recalculatedAmount = SpellHelper.applyPotionDamageCalculations(player, event.source, recalculatedAmount);
float ratio = recalculatedAmount / event.ammount;
float f1 = recalculatedAmount;
recalculatedAmount = Math.max(recalculatedAmount - player.getAbsorptionAmount(), 0.0F);
player.setAbsorptionAmount(player.getAbsorptionAmount() - (f1 - recalculatedAmount));
if (prevHp > recalculatedAmount) {
// New HP - this is obviously > 0...
float hp = (prevHp - recalculatedAmount);
// event.setCanceled(true);
event.ammount = 0;
Reagent reagent = APISpellHelper.getPlayerReagentType(player);
OmegaParadigm paradigm = OmegaRegistry.getParadigmForReagent(reagent);
if (paradigm != null) {
ItemStack chestStack = player.inventory.armorInventory[2];
if (chestStack != null && chestStack.getItem() instanceof OmegaArmour) {
if (((OmegaArmour) chestStack.getItem()).paradigm == paradigm) {
paradigm.onHPBarDepleted(player, chestStack);
}
}
}
APISpellHelper.setCurrentAdditionalHP(player, hp);
NewPacketHandler.INSTANCE.sendTo(NewPacketHandler.getAddedHPPacket(hp, APISpellHelper.getCurrentAdditionalMaxHP(player)), (EntityPlayerMP) player);
// if(event.ammount <= 0.3)
// {
// event.ammount++;
// }
} else {
APISpellHelper.setCurrentAdditionalHP(player, 0);
NewPacketHandler.INSTANCE.sendTo(NewPacketHandler.getAddedHPPacket(0, APISpellHelper.getCurrentAdditionalMaxHP(player)), (EntityPlayerMP) player);
event.ammount -= prevHp / ratio;
if (event.ammount < 0) {
event.ammount = 0;
}
}
}
}
}
Aggregations