Annotate animation in ClientboundAnimatePacket as Nullable (#743)

This commit is contained in:
Konicai 2023-07-31 16:20:40 -04:00 committed by GitHub
parent d84fa717fa
commit a0076aac3e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 4 deletions

View file

@ -2,6 +2,7 @@ package com.github.steveice10.mc.protocol.data.game.entity.player;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import org.jetbrains.annotations.Nullable;
public enum Animation { public enum Animation {
SWING_ARM(0), SWING_ARM(0),
@ -20,8 +21,9 @@ public enum Animation {
return id; return id;
} }
private static Int2ObjectMap<Animation> VALUES = new Int2ObjectOpenHashMap<>(); private static final Int2ObjectMap<Animation> VALUES = new Int2ObjectOpenHashMap<>();
@Nullable
public static Animation from(int id) { public static Animation from(int id) {
return VALUES.get(id); return VALUES.get(id);
} }

View file

@ -6,8 +6,8 @@ import com.github.steveice10.mc.protocol.data.game.entity.player.Animation;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NonNull;
import lombok.With; import lombok.With;
import org.jetbrains.annotations.Nullable;
import java.io.IOException; import java.io.IOException;
@ -16,7 +16,7 @@ import java.io.IOException;
@AllArgsConstructor @AllArgsConstructor
public class ClientboundAnimatePacket implements MinecraftPacket { public class ClientboundAnimatePacket implements MinecraftPacket {
private final int entityId; private final int entityId;
private final @NonNull Animation animation; private final @Nullable Animation animation;
public ClientboundAnimatePacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException { public ClientboundAnimatePacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
this.entityId = helper.readVarInt(in); this.entityId = helper.readVarInt(in);
@ -26,6 +26,10 @@ public class ClientboundAnimatePacket implements MinecraftPacket {
@Override @Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException { public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
helper.writeVarInt(out, this.entityId); helper.writeVarInt(out, this.entityId);
out.writeByte(this.animation.getId()); if (this.animation == null) {
out.writeByte(-1); // Client does nothing on unknown ID
} else {
out.writeByte(this.animation.getId());
}
} }
} }