fix: write metadata optvarint as varint + 1 || 0

This commit is contained in:
mworzala 2024-04-23 23:17:50 -04:00
parent e28adbca3e
commit f76d421744
No known key found for this signature in database
GPG Key ID: B148F922E64797C7
2 changed files with 11 additions and 2 deletions

View File

@ -101,7 +101,17 @@ public final class Metadata {
}
public static Entry<Integer> OptVarInt(@Nullable Integer value) {
return new MetadataImpl.EntryImpl<>(TYPE_OPTVARINT, value, NetworkBuffer.OPT_VAR_INT);
return new MetadataImpl.EntryImpl<>(TYPE_OPTVARINT, value, new NetworkBuffer.Type<>() {
@Override
public void write(@NotNull NetworkBuffer buffer, Integer value) {
buffer.write(NetworkBuffer.VAR_INT, value == null ? 0 : value + 1);
}
@Override
public Integer read(@NotNull NetworkBuffer buffer) {
return buffer.read(NetworkBuffer.VAR_INT) - 1;
}
});
}
public static Entry<Entity.Pose> Pose(@NotNull Entity.Pose value) {

View File

@ -65,7 +65,6 @@ public final class NetworkBuffer {
public static final Type<Point> OPT_BLOCK_POSITION = NetworkBufferTypeImpl.fromOptional(BLOCK_POSITION);
public static final Type<UUID> OPT_UUID = NetworkBufferTypeImpl.fromOptional(UUID);
public static final Type<Integer> OPT_BLOCK_STATE = NetworkBufferTypeImpl.fromOptional(BLOCK_STATE);
public static final Type<Integer> OPT_VAR_INT = NetworkBufferTypeImpl.fromOptional(VAR_INT);
public static final Type<Direction> DIRECTION = NetworkBufferTypeImpl.fromEnum(Direction.class);
public static final Type<Entity.Pose> POSE = NetworkBufferTypeImpl.fromEnum(Entity.Pose.class);