Jump to content

Recommended Posts

Posted (edited)

Hello im having an issue with my event, i want it to make that whenever my custom entity base class attacks my own custom armor base class it deals the damage based on the calculations shown in the code. but what happens is i think it does not work and the system print wont show.. i have registered the event btw.

 

@SubscribeEvent
    public static void onDamageDealtToArmor(LivingHurtEvent event) {
        ArmorBase armor = ArmorBase.instance;
        DamageSource damageSrc = event.getSource();
        double damage = event.getAmount();
        Entity ent = event.getEntity();
        if (ent != null && ent instanceof EntityPlayer) {
            if(damageSrc.getSourceOfDamage() instanceof EntityMHFCBase)
            if (ent.getArmorInventoryList() != null && ent.getArmorInventoryList() instanceof ArmorBase) {
                /** Refines the damage analyzer based from Monster Hunter Series but in a special case which
                 *  the default health is set to 20 for players. **/
                    float newDamage = (float) Math.abs(((damage * 80) / (armor.getInitialDefenseValue() + 80)) * 0.20);
                    event.setAmount(newDamage);
                    //event.getEntity().attackEntityFrom(damageSrc, newDamage);
                    System.out.println("Current AI Damage = " + damage + " Current New Damage = " + newDamage);
                    }
                }
            }    

 

Edited by Heltrato
Posted
10 minutes ago, Heltrato said:

Hello im having an issue with my event, i want it to make that whenever my custom entity base class attacks my own custom armor base class it deals the damage based on the calculations shown in the code. but what happens is i think it does not work and the system print wont show.. i have registered the event btw.

 


@SubscribeEvent
    public static void onDamageDealtToArmor(LivingHurtEvent event) {
        ArmorBase armor = ArmorBase.instance;
        DamageSource damageSrc = event.getSource();
        double damage = event.getAmount();
        Entity ent = event.getEntity();
        if (ent != null && ent instanceof EntityPlayer) {
            if(damageSrc.getSourceOfDamage() instanceof EntityMHFCBase)
            if (ent.getArmorInventoryList() != null && ent.getArmorInventoryList() instanceof ArmorBase) {
                /** Refines the damage analyzer based from Monster Hunter Series but in a special case which
                 *  the default health is set to 20 for players. **/
                    float newDamage = (float) Math.abs(((damage * 80) / (armor.getInitialDefenseValue() + 80)) * 0.20);
                    event.setAmount(newDamage);
                    //event.getEntity().attackEntityFrom(damageSrc, newDamage);
                    System.out.println("Current AI Damage = " + damage + " Current New Damage = " + newDamage);
                    }
                }
            }    

 

 

Re-check your If statements. If the comment doesn't fire then your code doesn't reach the if statements. I also believe you're missing an bracket. I'm not sure if it'd make a difference here since Java should decide it belongs to the first applicable clause to which it could belong.  

 

I do believe you might not get past the ent.getArmorInventoryList() instanceof ArmorBase), since that'll return an Iterable of the Itemstack.  Again, I'm not 100% sure. But you could start to check by inserting comments to see where exactly you're not getting further.

 

 

Posted
34 minutes ago, oldcheese said:

 

Re-check your If statements. If the comment doesn't fire then your code doesn't reach the if statements. I also believe you're missing an bracket. I'm not sure if it'd make a difference here since Java should decide it belongs to the first applicable clause to which it could belong.  

 

I do believe you might not get past the ent.getArmorInventoryList() instanceof ArmorBase), since that'll return an Iterable of the Itemstack.  Again, I'm not 100% sure. But you could start to check by inserting comments to see where exactly you're not getting further.

 

 

So i need to check per equipment slots?

Posted

The Iterable is basically just a list with one item from each of your armor slots, so yes. If you want to check if the player has every single part equipped then you'd want to check every armorslot to see if your armor was there. 

 

you could do this with a for loop. 

Posted
12 hours ago, oldcheese said:

The Iterable is basically just a list with one item from each of your armor slots, so yes. If you want to check if the player has every single part equipped then you'd want to check every armorslot to see if your armor was there. 

 

you could do this with a for loop. 

Well i just want to have a check whether a player is wearing any equipment with the instanceof my custom armor, no need to check if the player wears it all. I just want to make the armor equipments damage calculation same in my arithmetic :) 

Posted

The point still stands that getArmorInventoryList returns an object of type Iterable, and will therefore never be an instanceof your armor class. You can instead begin iterating through the list and break out of the iteration as soon as you find one instance of your armor.

 

I'll also echo the advice you were already given to add println statements in between every if statement to make sure the statements are true at each step along the way.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.