#1189: Add LivingEntity#playHurtAnimation()

By: Collin <collinjbarber@gmail.com>
This commit is contained in:
CraftBukkit/Spigot 2023-07-04 06:55:14 +10:00
parent 8b30feb641
commit 8bd41d17a2

View file

@ -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;