The same __on_player_takes_damage event with same parameters is fired twice from approximately the same place for players
James103 opened this issue ยท 4 comments
As of Carpet mod 1.4.11 in Minecraft 1.16.3, if you run the following command and then take damage (e.g. by falling 4 blocks), it will out two lines (not one) of the following: Player took 1.00 damage from fall (null)
The command is: /script run __on_player_takes_damage(player, amount, source, source_entity) -> print(str('%s takes %.2f damage from %s (%s) - %s HP remain', player, amount, source, source_entity, player~'health'));
Try this:
- Run the command
/script run __on_player_takes_damage(player, amount, source, source_entity) -> modify(player, 'health', 0);
- Punch any mob (such as a pig, a zombie, or anything else, even if it has way more than 1 HP).
- From my testing, the mob dies in one hit.
Here are the logs from my testing (click to view).
This could explain the bug as the __on_player_takes_damage
event is being called if any entity (not just players) takes damage, in addition to the player taking damage. Since a player fits both categories of "any entity" and "player", the event is fired twice.
Closing as works as intended - a repeating command block with the following command was causing the effect to be run twice:
/script run for( entity_selector( '@e[type=!ender_dragon,type=!wither]'), entity_event(_, 'on_damaged', '__on_player_takes_damage'));