Skip to content

Commit a0076aa

Browse files
authored
Annotate animation in ClientboundAnimatePacket as Nullable (#743)
1 parent d84fa71 commit a0076aa

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/main/java/com/github/steveice10/mc/protocol/data/game/entity/player/Animation.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
44
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
5+
import org.jetbrains.annotations.Nullable;
56

67
public enum Animation {
78
SWING_ARM(0),
@@ -20,8 +21,9 @@ public int getId() {
2021
return id;
2122
}
2223

23-
private static Int2ObjectMap<Animation> VALUES = new Int2ObjectOpenHashMap<>();
24+
private static final Int2ObjectMap<Animation> VALUES = new Int2ObjectOpenHashMap<>();
2425

26+
@Nullable
2527
public static Animation from(int id) {
2628
return VALUES.get(id);
2729
}

src/main/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/entity/ClientboundAnimatePacket.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
import io.netty.buffer.ByteBuf;
77
import lombok.AllArgsConstructor;
88
import lombok.Data;
9-
import lombok.NonNull;
109
import lombok.With;
10+
import org.jetbrains.annotations.Nullable;
1111

1212
import java.io.IOException;
1313

@@ -16,7 +16,7 @@
1616
@AllArgsConstructor
1717
public class ClientboundAnimatePacket implements MinecraftPacket {
1818
private final int entityId;
19-
private final @NonNull Animation animation;
19+
private final @Nullable Animation animation;
2020

2121
public ClientboundAnimatePacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
2222
this.entityId = helper.readVarInt(in);
@@ -26,6 +26,10 @@ public ClientboundAnimatePacket(ByteBuf in, MinecraftCodecHelper helper) throws
2626
@Override
2727
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
2828
helper.writeVarInt(out, this.entityId);
29-
out.writeByte(this.animation.getId());
29+
if (this.animation == null) {
30+
out.writeByte(-1); // Client does nothing on unknown ID
31+
} else {
32+
out.writeByte(this.animation.getId());
33+
}
3034
}
3135
}

0 commit comments

Comments
 (0)