Heltrato Posted January 14, 2018 Share 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 Link to comment Share on other sites More sharing options...
oldcheese Posted January 14, 2018 Share 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 Link to comment Share on other sites More sharing options...
Heltrato Posted January 14, 2018 Author Share 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 Link to comment Share on other sites More sharing options...
oldcheese Posted January 14, 2018 Share 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 Link to comment Share on other sites More sharing options...
Heltrato Posted January 15, 2018 Author Share 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 Link to comment Share on other sites More sharing options...
Daeruin Posted January 15, 2018 Share 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 Link to comment Share on other sites More sharing options...
Recommended Posts
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.