Skip to content

Commit 244145e

Browse files
authored
Merge pull request #26 from LoJoSho/hurt_animation_fix
Fix PlayHurtAnimation not working on modern Minecraft verions
2 parents e1477bb + f819cdb commit 244145e

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

api/src/main/java/me/tofaa/entitylib/wrapper/WrapperLivingEntity.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
package me.tofaa.entitylib.wrapper;
22

3+
import com.github.retrooper.packetevents.manager.server.ServerVersion;
34
import com.github.retrooper.packetevents.protocol.entity.type.EntityType;
45
import com.github.retrooper.packetevents.protocol.nbt.NBTCompound;
56
import com.github.retrooper.packetevents.protocol.potion.PotionType;
67
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerEntityAnimation;
78
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerEntityEffect;
9+
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerHurtAnimation;
810
import me.tofaa.entitylib.EntityLib;
911
import me.tofaa.entitylib.meta.EntityMeta;
12+
import me.tofaa.entitylib.utils.VersionUtil;
1013
import org.jetbrains.annotations.Nullable;
1114

1215
import java.util.UUID;
@@ -110,7 +113,29 @@ public void playWakeupAnimation() {
110113
sendAnimation(WrapperPlayServerEntityAnimation.EntityAnimationType.WAKE_UP);
111114
}
112115

116+
/**
117+
* Plays the hurt animation of the entity.
118+
* This method is deprecated and should use {@link #playHurtAnimation(int)} instead.
119+
*/
120+
@Deprecated
113121
public void playHurtAnimation() {
122+
playHurtAnimation(0);
123+
}
124+
125+
/**
126+
* Plays the hurt animation of the entity.
127+
* @param yaw The yaw of the entity when the hurt animation is played.
128+
* For any entity other than a player it's safe to simply put 0, as it's not used.
129+
* The yaw is only used on 1.19.4+.
130+
*/
131+
public void playHurtAnimation(int yaw) {
132+
// 1.19.4+ uses a different packet for hurt animation than previous versions
133+
if (VersionUtil.isNewerThan(ServerVersion.V_1_19_4)) {
134+
sendPacketToViewers(
135+
new WrapperPlayServerHurtAnimation(getEntityId(), yaw)
136+
);
137+
return;
138+
}
114139
sendAnimation(WrapperPlayServerEntityAnimation.EntityAnimationType.HURT);
115140
}
116141

0 commit comments

Comments
 (0)