|
1 | 1 | package me.tofaa.entitylib.wrapper; |
2 | 2 |
|
| 3 | +import com.github.retrooper.packetevents.manager.server.ServerVersion; |
3 | 4 | import com.github.retrooper.packetevents.protocol.entity.type.EntityType; |
4 | 5 | import com.github.retrooper.packetevents.protocol.nbt.NBTCompound; |
5 | 6 | import com.github.retrooper.packetevents.protocol.potion.PotionType; |
6 | 7 | import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerEntityAnimation; |
7 | 8 | import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerEntityEffect; |
| 9 | +import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerHurtAnimation; |
8 | 10 | import me.tofaa.entitylib.EntityLib; |
9 | 11 | import me.tofaa.entitylib.meta.EntityMeta; |
| 12 | +import me.tofaa.entitylib.utils.VersionUtil; |
10 | 13 | import org.jetbrains.annotations.Nullable; |
11 | 14 |
|
12 | 15 | import java.util.UUID; |
@@ -110,7 +113,29 @@ public void playWakeupAnimation() { |
110 | 113 | sendAnimation(WrapperPlayServerEntityAnimation.EntityAnimationType.WAKE_UP); |
111 | 114 | } |
112 | 115 |
|
| 116 | + /** |
| 117 | + * Plays the hurt animation of the entity. |
| 118 | + * This method is deprecated and should use {@link #playHurtAnimation(int)} instead. |
| 119 | + */ |
| 120 | + @Deprecated |
113 | 121 | 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 | + } |
114 | 139 | sendAnimation(WrapperPlayServerEntityAnimation.EntityAnimationType.HURT); |
115 | 140 | } |
116 | 141 |
|
|
0 commit comments