Search in sources :

Example 6 with OmegaArmour

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;
                }
            }
        }
    }
}
Also used : OmegaArmour(WayofTime.alchemicalWizardry.common.items.armour.OmegaArmour) EntityPlayer(net.minecraft.entity.player.EntityPlayer) OmegaParadigm(WayofTime.alchemicalWizardry.common.omega.OmegaParadigm) ItemStack(net.minecraft.item.ItemStack) Reagent(WayofTime.alchemicalWizardry.api.alchemy.energy.Reagent) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Aggregations

OmegaArmour (WayofTime.alchemicalWizardry.common.items.armour.OmegaArmour)6 ItemStack (net.minecraft.item.ItemStack)6 EntityPlayer (net.minecraft.entity.player.EntityPlayer)3 Reagent (WayofTime.alchemicalWizardry.api.alchemy.energy.Reagent)2 ReagentStack (WayofTime.alchemicalWizardry.api.alchemy.energy.ReagentStack)2 OmegaParadigm (WayofTime.alchemicalWizardry.common.omega.OmegaParadigm)2 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)2 OmegaParadigmEarth (WayofTime.alchemicalWizardry.common.omega.OmegaParadigmEarth)1 OmegaParadigmFire (WayofTime.alchemicalWizardry.common.omega.OmegaParadigmFire)1 OmegaParadigmWater (WayofTime.alchemicalWizardry.common.omega.OmegaParadigmWater)1 OmegaParadigmWind (WayofTime.alchemicalWizardry.common.omega.OmegaParadigmWind)1 ReagentRegenConfiguration (WayofTime.alchemicalWizardry.common.omega.ReagentRegenConfiguration)1 GuiChat (net.minecraft.client.gui.GuiChat)1 ScaledResolution (net.minecraft.client.gui.ScaledResolution)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1