Fix LivingEntity Damage Event Packet (#2209)

This commit is contained in:
GreatWyrm 2024-06-25 05:25:16 -07:00 committed by GitHub
parent e513efb393
commit d5c6126a6b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 7 deletions

View File

@ -21,10 +21,7 @@ import net.minestom.server.inventory.EquipmentHandler;
import net.minestom.server.item.ItemStack;
import net.minestom.server.network.ConnectionState;
import net.minestom.server.network.packet.server.LazyPacket;
import net.minestom.server.network.packet.server.play.CollectItemPacket;
import net.minestom.server.network.packet.server.play.EntityAnimationPacket;
import net.minestom.server.network.packet.server.play.EntityAttributesPacket;
import net.minestom.server.network.packet.server.play.SoundEffectPacket;
import net.minestom.server.network.packet.server.play.*;
import net.minestom.server.network.player.PlayerConnection;
import net.minestom.server.registry.DynamicRegistry;
import net.minestom.server.scoreboard.Team;
@ -333,8 +330,7 @@ public class LivingEntity extends Entity implements EquipmentHandler {
sendPacketToViewersAndSelf(new EntityAnimationPacket(getEntityId(), EntityAnimationPacket.Animation.TAKE_DAMAGE));
}
//todo
// sendPacketToViewersAndSelf(new DamageEventPacket(getEntityId(), damage.getType().id(), 0, 0, null));
sendPacketToViewersAndSelf(new DamageEventPacket(getEntityId(), damage.getTypeId(), damage.getAttacker() == null ? 0 : damage.getAttacker().getEntityId() + 1, damage.getSource() == null ? 0 : damage.getSource().getEntityId() + 1, damage.getSourcePosition()));
// Additional hearts support
if (this instanceof Player player) {

View File

@ -35,8 +35,11 @@ public class Damage implements Taggable {
/**
* Creates a new damage type.
*
* @param attacker The attacker that initiated this damage
* @param source The source of the damage. For direct hits (melee), this will be the same as the attacker. For indirect hits (projectiles), this will be the projectile
* @param type the type of this damage
* @param amount amount of damage
* @param sourcePosition The position of the source of damage
*/
public Damage(@NotNull DynamicRegistry.Key<DamageType> type, @Nullable Entity source, @Nullable Entity attacker, @Nullable Point sourcePosition, float amount) {
this.typeKey = type;
@ -51,7 +54,7 @@ public class Damage implements Taggable {
/**
* Gets the type of this damage.
* <p>
* It does not have to be unique to this object.o
* It does not have to be unique to this object.
*
* @return the damage type
*/
@ -59,6 +62,12 @@ public class Damage implements Taggable {
return typeKey;
}
/**
* Gets the integer id of the damage type that has been set
* @return The integer id of the damage type
*/
public int getTypeId() { return DAMAGE_TYPE_REGISTRY.getId(typeKey); }
/**
* Gets the "attacker" of the damage.
* This is the indirect cause of the damage, like the shooter of a projectile, or null if there was none.