From 8bd41d17a25c44abf72d0530401e3b0f6e201a1d Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Tue, 4 Jul 2023 06:55:14 +1000 Subject: [PATCH] #1189: Add LivingEntity#playHurtAnimation() By: Collin --- .../craftbukkit/entity/CraftLivingEntity.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java index 7bd2c8876c..7d24c149e3 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java @@ -8,6 +8,8 @@ import java.util.Iterator; import java.util.List; import java.util.Set; import java.util.UUID; +import net.minecraft.network.protocol.game.ClientboundHurtAnimationPacket; +import net.minecraft.server.level.WorldServer; import net.minecraft.sounds.SoundEffect; import net.minecraft.world.EnumHand; import net.minecraft.world.damagesource.DamageSource; @@ -682,6 +684,20 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity { getHandle().swing(EnumHand.OFF_HAND, true); } + @Override + public void playHurtAnimation(float yaw) { + if (getHandle().level() instanceof WorldServer world) { + /* + * Vanilla degrees state that 0 = left, 90 = front, 180 = right, and 270 = behind. + * This makes no sense. We'll add 90 to it so that 0 = front, clockwise from there. + */ + float actualYaw = yaw + 90; + ClientboundHurtAnimationPacket packet = new ClientboundHurtAnimationPacket(getEntityId(), actualYaw); + + world.getChunkSource().broadcastAndSend(getHandle(), packet); + } + } + @Override public void setCollidable(boolean collidable) { getHandle().collides = collidable;