fix: correct entity opt_block_state metadata serializer

This commit is contained in:
mworzala 2024-04-30 16:50:46 -04:00
parent e18d7fb798
commit fe8a230abb
No known key found for this signature in database
GPG Key ID: B148F922E64797C7
2 changed files with 13 additions and 3 deletions

View File

@ -81,12 +81,23 @@ public final class Metadata {
return new MetadataImpl.EntryImpl<>(TYPE_OPTUUID, value, NetworkBuffer.OPT_UUID);
}
public static Entry<Integer> BlockState(@Nullable Integer value) {
public static Entry<Integer> BlockState(@NotNull Integer value) {
return new MetadataImpl.EntryImpl<>(TYPE_BLOCKSTATE, value, NetworkBuffer.BLOCK_STATE);
}
public static Entry<Integer> OptBlockState(@Nullable Integer value) {
return new MetadataImpl.EntryImpl<>(TYPE_OPTBLOCKSTATE, value, NetworkBuffer.OPT_BLOCK_STATE);
return new MetadataImpl.EntryImpl<>(TYPE_OPTBLOCKSTATE, value, new NetworkBuffer.Type<>() {
@Override
public void write(@NotNull NetworkBuffer buffer, Integer value) {
buffer.write(NetworkBuffer.VAR_INT, value == null ? 0 : value);
}
@Override
public Integer read(@NotNull NetworkBuffer buffer) {
int value = buffer.read(NetworkBuffer.VAR_INT);
return value == 0 ? null : value;
}
});
}
public static Entry<NBT> NBT(@NotNull NBT nbt) {

View File

@ -64,7 +64,6 @@ public final class NetworkBuffer {
public static final Type<Component> OPT_CHAT = NetworkBufferTypeImpl.fromOptional(COMPONENT);
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<Direction> DIRECTION = NetworkBufferTypeImpl.fromEnum(Direction.class);
public static final Type<Entity.Pose> POSE = NetworkBufferTypeImpl.fromEnum(Entity.Pose.class);