Jump to content
  • Home
  • Files
  • Docs
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • LivingHurtEvent not working?
Currently Supported: 1.16.X (Latest) and 1.15.X (LTS)
Sign in to follow this  
Followers 0
Heltrato

LivingHurtEvent not working?

By Heltrato, January 14, 2018 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

Heltrato    1

Heltrato

Heltrato    1

  • Diamond Finder
  • Heltrato
  • Members
  • 1
  • 259 posts
Posted January 14, 2018 (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 January 14, 2018 by Heltrato
  • Quote

Share this post


Link to post
Share on other sites

oldcheese    16

oldcheese

oldcheese    16

  • Creeper Killer
  • oldcheese
  • Members
  • 16
  • 108 posts
Posted January 14, 2018
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.

 

 

  • Quote

Share this post


Link to post
Share on other sites

Heltrato    1

Heltrato

Heltrato    1

  • Diamond Finder
  • Heltrato
  • Members
  • 1
  • 259 posts
Posted January 14, 2018
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?

  • Quote

Share this post


Link to post
Share on other sites

oldcheese    16

oldcheese

oldcheese    16

  • Creeper Killer
  • oldcheese
  • Members
  • 16
  • 108 posts
Posted January 14, 2018

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. 

  • Quote

Share this post


Link to post
Share on other sites

Heltrato    1

Heltrato

Heltrato    1

  • Diamond Finder
  • Heltrato
  • Members
  • 1
  • 259 posts
Posted January 15, 2018
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 :) 

  • Quote

Share this post


Link to post
Share on other sites

Daeruin    24

Daeruin

Daeruin    24

  • Diamond Finder
  • Daeruin
  • Members
  • 24
  • 401 posts
Posted January 15, 2018

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.

  • Quote

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

    • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 0
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • domi0908
      fix hitbox red baby mobs version forge

      By domi0908 · Posted 6 minutes ago

    • Leronus
      1.12.2 Custom Furnace Issues

      By Leronus · Posted 8 minutes ago

      Please share your code.... Having the exact same issues you mentioned but even with those answers I can't figure it out...
    • diesieben07
      My modpack takes years to load

      By diesieben07 · Posted 9 minutes ago

      Please let it start up properly and post the log when its started up.
    • domi0908
      fix hitboxes red baby mobs please

      By domi0908 · Posted 16 minutes ago

      forge, do and turn on hit boxes in little mobs
    • domi0908
      fix hitboxes red baby mobs please

      By domi0908 · Posted 17 minutes ago

      pls fix hitboxes red baby mobs
  • Topics

    • domi0908
      0
      fix hitbox red baby mobs version forge

      By domi0908
      Started 7 minutes ago

    • Will11690
      8
      1.12.2 Custom Furnace Issues

      By Will11690
      Started September 10, 2018

    • BBoi69
      7
      My modpack takes years to load

      By BBoi69
      Started 7 hours ago

    • domi0908
      2
      fix hitboxes red baby mobs please

      By domi0908
      Started 19 minutes ago

    • MasterQuentus
      2
      Minecraft says 200 mods installed 198 loaded

      By MasterQuentus
      Started 41 minutes ago

  • Who's Online (See full list)

    • awesomeJVR
    • MemeKing
    • Leronus
    • diesieben07
    • Mihran
    • SaltBeard
    • Bailym
    • Klarks
    • Draco18s
    • domi0908
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • LivingHurtEvent not working?
  • Theme

Copyright © 2019 ForgeDevelopment LLC · Ads by Longitude Ads LLC Powered by Invision Community