I have been making a plugin where the armours actually work (blocking damages etc), but using getDamage() and setDamage() doesn't seems to work. Are those the correct functions? If they are, the are they broken or something? PHP: $victim = $event->getEntity(); $inv = $victim->getInventory(); $helmet = $inv->getHelmet()->getID(); $chestplate = $inv->getChestplate()->getID(); $leggings = $inv->getLeggings()->getID(); $boots = $inv->getBoots()->getID(); $damage = $event->getDamage(); $cause = $event->getCause(); Also, the plugins is keeping on giving me the error on getInventory() function being undefined, but not crashing. I did use pocketmine\inventory\PlayerInventory;, so I don't understand why this error is happening.
1. Does that ever look like a full code? That is not even a full function. 2. If I was talking about armours and inventory, I would obviously test it on myself, not on a pig/zombie/etc.
Armor does work. Please look at the second parameter of EntityDamageEvent->setDamage. Also, these fixes should be done in PocketMine itself. Feel free to create pull requests to fix them.
Oh god, I was quite curious on what you were saying when I saw the reply thought the EMail Anyway, I was creating a plugin that was meant to check people's armour upon damage, calculate the damage and set the correct damage. However, after adding lots of debug messages, the getDamage() seems to give me 1 all the time, and setDamage() didn't work. So that's why I created this thread, just in case these functions are broken like setHealth(). I may make PR if I both find out how to create one and when I make a working way to do it.
Kind of off topic, but does anyone know how to calculate the damage dealt for every armour points? I can't understand the formula on the Minecraft Wiki.
Is the setDamage function broken, or did I use it incorrectly? I have written: PHP: $event->setDamage($newdamage, $cause); where $newdamage is the new damage that should be dealt. However, the damage is not dealt.
There are other modifiers. The second parameter is the modifier, not cause. EntityDamageEvent is composed of multiple damage modifiers. One is the MODIFIER_BASE, which is the normal damage. Other common ones include MODIFIER_ARMOR, MODIFIER_RESISTANCE, etc. Refer to EntityDamageEvent.php for these constants. The final damage dealt to the player is the sum of all modifiers.
Okay, I have fixed the code, but it still doesn't affect it at all. I tried to dive into lava with full set of diamond set and still deals 4 health points of damage, despite the fact that I have made a debug message to send message to the victim, and it clearly said I would only receive 1 health point of damage. Instead, I just get killed almost instantly. Is it that setDamage() just damages the player additionally during the event?
If you want to reduce the damage, the modifier should be negative. Use $event->getFinalDamage() to see the final damage you will be dealing.