Switch from OpenNBT to Cloudburst NBT (#799)

This commit is contained in:
Alex 2024-04-27 03:32:57 +02:00 committed by GitHub
parent 1e053f0daf
commit 98410a1c02
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 230 additions and 239 deletions

View file

@ -3,7 +3,7 @@ metadata.format.version = "1.1"
[versions] [versions]
adventure = "4.15.0" adventure = "4.15.0"
opennbt = "1.6" cloudburstnbt = "3.0.0.Final"
mcauthlib = "6621fd0" mcauthlib = "6621fd0"
math = "2.0" math = "2.0"
fastutil-maps = "8.5.3" fastutil-maps = "8.5.3"
@ -22,7 +22,7 @@ lombok-plugin = "8.4"
adventure-text-serializer-gson = { module = "net.kyori:adventure-text-serializer-gson", version.ref = "adventure" } adventure-text-serializer-gson = { module = "net.kyori:adventure-text-serializer-gson", version.ref = "adventure" }
adventure-text-serializer-json-legacy-impl = { module = "net.kyori:adventure-text-serializer-json-legacy-impl", version.ref = "adventure" } adventure-text-serializer-json-legacy-impl = { module = "net.kyori:adventure-text-serializer-json-legacy-impl", version.ref = "adventure" }
opennbt = { module = "com.github.steveice10:opennbt", version.ref = "opennbt" } cloudburstnbt = { module = "org.cloudburstmc:nbt", version.ref = "cloudburstnbt" }
mcauthlib = { module = "com.github.GeyserMC:mcauthlib", version.ref = "mcauthlib" } mcauthlib = { module = "com.github.GeyserMC:mcauthlib", version.ref = "mcauthlib" }
math-api = { module = "org.cloudburstmc.math:api", version.ref = "math" } math-api = { module = "org.cloudburstmc.math:api", version.ref = "math" }

View file

@ -7,7 +7,7 @@ description = "MCProtocolLib is a simple library for communicating with Minecraf
dependencies { dependencies {
// Minecraft related libraries // Minecraft related libraries
api(libs.opennbt) api(libs.cloudburstnbt)
api(libs.mcauthlib) api(libs.mcauthlib)
// Kyori adventure // Kyori adventure

View file

@ -1,13 +1,13 @@
package org.geysermc.mcprotocollib.protocol; package org.geysermc.mcprotocollib.protocol;
import com.github.steveice10.mc.auth.data.GameProfile; import com.github.steveice10.mc.auth.data.GameProfile;
import org.cloudburstmc.nbt.NbtMap;
import org.cloudburstmc.nbt.NbtUtils;
import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodec; import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodec;
import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper; import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper;
import org.geysermc.mcprotocollib.protocol.codec.PacketCodec; import org.geysermc.mcprotocollib.protocol.codec.PacketCodec;
import org.geysermc.mcprotocollib.protocol.codec.PacketStateCodec; import org.geysermc.mcprotocollib.protocol.codec.PacketStateCodec;
import org.geysermc.mcprotocollib.protocol.data.ProtocolState; import org.geysermc.mcprotocollib.protocol.data.ProtocolState;
import com.github.steveice10.opennbt.NBTIO;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import org.geysermc.mcprotocollib.network.Server; import org.geysermc.mcprotocollib.network.Server;
import org.geysermc.mcprotocollib.network.Session; import org.geysermc.mcprotocollib.network.Session;
import org.geysermc.mcprotocollib.network.codec.PacketCodecHelper; import org.geysermc.mcprotocollib.network.codec.PacketCodecHelper;
@ -23,14 +23,11 @@ import lombok.NonNull;
import lombok.Setter; import lombok.Setter;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
import java.io.DataInput;
import java.io.DataInputStream;
import java.io.InputStream; import java.io.InputStream;
import java.security.GeneralSecurityException; import java.security.GeneralSecurityException;
import java.security.Key; import java.security.Key;
import java.util.Objects; import java.util.Objects;
import java.util.UUID; import java.util.UUID;
import java.util.zip.GZIPInputStream;
/** /**
* Implements the Minecraft protocol. * Implements the Minecraft protocol.
@ -43,7 +40,7 @@ public class MinecraftProtocol extends PacketProtocol {
* if {@link #isUseDefaultListeners()} is true. * if {@link #isUseDefaultListeners()} is true.
*/ */
@Nullable @Nullable
private static CompoundTag DEFAULT_NETWORK_CODEC; private static NbtMap DEFAULT_NETWORK_CODEC;
/** /**
* The codec used for the Minecraft protocol. * The codec used for the Minecraft protocol.
@ -251,10 +248,9 @@ public class MinecraftProtocol extends PacketProtocol {
return this.stateCodec.getClientboundDefinition(id); return this.stateCodec.getClientboundDefinition(id);
} }
public static CompoundTag loadNetworkCodec() { public static NbtMap loadNetworkCodec() {
try (InputStream inputStream = Objects.requireNonNull(MinecraftProtocol.class.getClassLoader().getResourceAsStream("networkCodec.nbt")) ; try (InputStream inputStream = Objects.requireNonNull(MinecraftProtocol.class.getClassLoader().getResourceAsStream("networkCodec.nbt"))) {
DataInputStream stream = new DataInputStream(new GZIPInputStream(inputStream))) { return (NbtMap) NbtUtils.createGZIPReader(inputStream).readTag();
return (CompoundTag) NBTIO.readTag((DataInput) stream);
} catch (Exception e) { } catch (Exception e) {
throw new AssertionError("Unable to load network codec.", e); throw new AssertionError("Unable to load network codec.", e);
} }

View file

@ -3,6 +3,8 @@ package org.geysermc.mcprotocollib.protocol;
import com.github.steveice10.mc.auth.data.GameProfile; import com.github.steveice10.mc.auth.data.GameProfile;
import com.github.steveice10.mc.auth.exception.request.RequestException; import com.github.steveice10.mc.auth.exception.request.RequestException;
import com.github.steveice10.mc.auth.service.SessionService; import com.github.steveice10.mc.auth.service.SessionService;
import org.cloudburstmc.nbt.NbtMap;
import org.cloudburstmc.nbt.NbtType;
import org.geysermc.mcprotocollib.protocol.data.ProtocolState; import org.geysermc.mcprotocollib.protocol.data.ProtocolState;
import org.geysermc.mcprotocollib.protocol.data.game.RegistryEntry; import org.geysermc.mcprotocollib.protocol.data.game.RegistryEntry;
import org.geysermc.mcprotocollib.protocol.data.status.PlayerInfo; import org.geysermc.mcprotocollib.protocol.data.status.PlayerInfo;
@ -28,11 +30,6 @@ import org.geysermc.mcprotocollib.protocol.packet.status.clientbound.Clientbound
import org.geysermc.mcprotocollib.protocol.packet.status.clientbound.ClientboundStatusResponsePacket; import org.geysermc.mcprotocollib.protocol.packet.status.clientbound.ClientboundStatusResponsePacket;
import org.geysermc.mcprotocollib.protocol.packet.status.serverbound.ServerboundPingRequestPacket; import org.geysermc.mcprotocollib.protocol.packet.status.serverbound.ServerboundPingRequestPacket;
import org.geysermc.mcprotocollib.protocol.packet.status.serverbound.ServerboundStatusRequestPacket; import org.geysermc.mcprotocollib.protocol.packet.status.serverbound.ServerboundStatusRequestPacket;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.IntTag;
import com.github.steveice10.opennbt.tag.builtin.ListTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import org.geysermc.mcprotocollib.network.Session; import org.geysermc.mcprotocollib.network.Session;
import org.geysermc.mcprotocollib.network.event.session.ConnectedEvent; import org.geysermc.mcprotocollib.network.event.session.ConnectedEvent;
import org.geysermc.mcprotocollib.network.event.session.DisconnectingEvent; import org.geysermc.mcprotocollib.network.event.session.DisconnectingEvent;
@ -46,13 +43,7 @@ import java.security.KeyPair;
import java.security.KeyPairGenerator; import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey; import java.security.PrivateKey;
import java.util.AbstractList; import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.UUID;
/** /**
* Handles initial login and status requests for servers. * Handles initial login and status requests for servers.
@ -74,7 +65,7 @@ public class ServerListener extends SessionAdapter {
} }
} }
private final CompoundTag networkCodec; private final NbtMap networkCodec;
private final byte[] challenge = new byte[4]; private final byte[] challenge = new byte[4];
private String username = ""; private String username = "";
@ -82,7 +73,7 @@ public class ServerListener extends SessionAdapter {
private long lastPingTime = 0; private long lastPingTime = 0;
private int lastPingId = 0; private int lastPingId = 0;
public ServerListener(CompoundTag networkCodec) { public ServerListener(NbtMap networkCodec) {
this.networkCodec = networkCodec; this.networkCodec = networkCodec;
new Random().nextBytes(this.challenge); new Random().nextBytes(this.challenge);
} }
@ -139,19 +130,18 @@ public class ServerListener extends SessionAdapter {
protocol.setState(ProtocolState.CONFIGURATION); protocol.setState(ProtocolState.CONFIGURATION);
// Credit ViaVersion: https://github.com/ViaVersion/ViaVersion/blob/dev/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/rewriter/EntityPacketRewriter1_20_5.java // Credit ViaVersion: https://github.com/ViaVersion/ViaVersion/blob/dev/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/rewriter/EntityPacketRewriter1_20_5.java
for (Map.Entry<String, Tag> entry : networkCodec.getValue().entrySet()) { for (Map.Entry<String, Object> entry : networkCodec.entrySet()) {
CompoundTag entryTag = (CompoundTag) entry.getValue(); NbtMap entryTag = (NbtMap) entry.getValue();
StringTag typeTag = entryTag.get("type"); String typeTag = entryTag.getString("type");
ListTag valueTag = entryTag.get("value"); List<NbtMap> valueTag = entryTag.getList("value", NbtType.COMPOUND);
List<RegistryEntry> entries = new ArrayList<>(); List<RegistryEntry> entries = new ArrayList<>();
for (Tag tag : valueTag) { for (NbtMap compoundTag : valueTag) {
CompoundTag compoundTag = (CompoundTag) tag; String nameTag = compoundTag.getString("name");
StringTag nameTag = compoundTag.get("name"); int id = compoundTag.getInt("id");
int id = ((IntTag) compoundTag.get("id")).getValue(); entries.add(id, new RegistryEntry(nameTag, compoundTag.getCompound("element")));
entries.add(id, new RegistryEntry(nameTag.getValue(), compoundTag.get("element")));
} }
session.send(new ClientboundRegistryDataPacket(typeTag.getValue(), entries)); session.send(new ClientboundRegistryDataPacket(typeTag, entries));
} }
session.send(new ClientboundFinishConfigurationPacket()); session.send(new ClientboundFinishConfigurationPacket());

View file

@ -1,6 +1,9 @@
package org.geysermc.mcprotocollib.protocol.codec; package org.geysermc.mcprotocollib.protocol.codec;
import com.github.steveice10.mc.auth.data.GameProfile; import com.github.steveice10.mc.auth.data.GameProfile;
import io.netty.buffer.ByteBufInputStream;
import io.netty.buffer.ByteBufOutputStream;
import org.cloudburstmc.nbt.*;
import org.geysermc.mcprotocollib.protocol.data.DefaultComponentSerializer; import org.geysermc.mcprotocollib.protocol.data.DefaultComponentSerializer;
import org.geysermc.mcprotocollib.protocol.data.game.Holder; import org.geysermc.mcprotocollib.protocol.data.game.Holder;
import org.geysermc.mcprotocollib.protocol.data.game.Identifier; import org.geysermc.mcprotocollib.protocol.data.game.Identifier;
@ -24,7 +27,6 @@ import org.geysermc.mcprotocollib.protocol.data.game.entity.attribute.ModifierOp
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.ArmadilloState; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.ArmadilloState;
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata;
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.GlobalPos; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.GlobalPos;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.BannerPatternLayer;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponent; import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponent;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponents; import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponents;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponentType; import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponentType;
@ -66,9 +68,6 @@ import org.geysermc.mcprotocollib.protocol.data.game.level.sound.SoundCategory;
import org.geysermc.mcprotocollib.protocol.data.game.recipe.Ingredient; import org.geysermc.mcprotocollib.protocol.data.game.recipe.Ingredient;
import org.geysermc.mcprotocollib.protocol.data.game.statistic.StatisticCategory; import org.geysermc.mcprotocollib.protocol.data.game.statistic.StatisticCategory;
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundLoginPacket; import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundLoginPacket;
import com.github.steveice10.opennbt.NBTIO;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import org.geysermc.mcprotocollib.network.codec.BasePacketCodecHelper; import org.geysermc.mcprotocollib.network.codec.BasePacketCodecHelper;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
@ -82,23 +81,16 @@ import org.cloudburstmc.math.vector.Vector4f;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.io.IOException; import java.io.*;
import java.io.InputStream; import java.util.*;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
import java.util.function.Function; import java.util.function.Function;
import java.util.function.IntFunction; import java.util.function.IntFunction;
import java.util.function.ObjIntConsumer; import java.util.function.ObjIntConsumer;
import java.util.function.ToIntFunction; import java.util.function.ToIntFunction;
import static org.cloudburstmc.nbt.NbtType.byClass;
@RequiredArgsConstructor @RequiredArgsConstructor
public class MinecraftCodecHelper extends BasePacketCodecHelper { public class MinecraftCodecHelper extends BasePacketCodecHelper {
private static final int POSITION_X_SIZE = 38; private static final int POSITION_X_SIZE = 38;
@ -110,7 +102,7 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper {
private final Int2ObjectMap<LevelEventType> levelEvents; private final Int2ObjectMap<LevelEventType> levelEvents;
private final Map<String, BuiltinSound> soundNames; private final Map<String, BuiltinSound> soundNames;
protected CompoundTag registry; protected NbtMap registry;
@Nullable @Nullable
public <T> T readNullable(ByteBuf buf, Function<ByteBuf, T> ifPresent) { public <T> T readNullable(ByteBuf buf, Function<ByteBuf, T> ifPresent) {
@ -211,52 +203,66 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper {
} }
@Nullable @Nullable
public CompoundTag readAnyTag(ByteBuf buf) { public NbtMap readCompoundTag(ByteBuf buf) {
return readAnyTag(buf, CompoundTag.class); return readAnyTag(buf, NbtType.COMPOUND);
} }
@NonNull @NonNull
public CompoundTag readAnyTagOrThrow(ByteBuf buf) { public NbtMap readCompoundTagOrThrow(ByteBuf buf) {
CompoundTag tag = readAnyTag(buf); NbtMap tag = readCompoundTag(buf);
if (tag == null) { if (tag == null) {
throw new IllegalArgumentException("Got end-tag when trying to read CompoundTag"); throw new IllegalArgumentException("Got end-tag when trying to read NbtMap");
} }
return tag; return tag;
} }
@Nullable @Nullable
public <T extends Tag> T readAnyTag(ByteBuf buf, Class<T> expected) { public <T> T readAnyTag(ByteBuf buf, NbtType<T> expected) {
Tag tag; Object tag = this.readAnyTag(buf);
try {
tag = NBTIO.readAnyTag(new InputStream() {
@Override
public int read() {
return buf.readUnsignedByte();
}
});
} catch (IOException e) {
throw new IllegalArgumentException(e);
}
if (tag == null) { if (tag == null) {
return null; return null;
} }
if (!expected.isInstance(tag)) { Class<T> tagClass = expected.getTagClass();
throw new IllegalArgumentException("Expected tag of type " + expected.getName() + " but got " + tag.getClass().getName()); if (!tagClass.isInstance(tag)) {
throw new IllegalArgumentException("Expected tag of type " + tagClass.getName() + " but got " + tag.getClass().getName());
} }
return expected.cast(tag); return tagClass.cast(tag);
} }
public <T extends Tag> void writeAnyTag(ByteBuf buf, @Nullable T tag) { @Nullable
public Object readAnyTag(ByteBuf buf) {
try { try {
NBTIO.writeAnyTag(new OutputStream() { ByteBufInputStream input = new ByteBufInputStream(buf);
@Override
public void write(int b) { int typeId = input.readUnsignedByte();
buf.writeByte(b); if (typeId == 0) {
} return null;
}, tag); }
NbtType<?> type = NbtType.byId(typeId);
return new NBTInputStream(input).readValue(type);
} catch (IOException e) {
throw new IllegalArgumentException(e);
}
}
public void writeAnyTag(ByteBuf buf, @Nullable Object tag) {
try {
ByteBufOutputStream output = new ByteBufOutputStream(buf);
if (tag == null) {
output.writeByte(0);
return;
}
NbtType<?> type = NbtType.byClass(tag.getClass());
output.writeByte(type.getId());
new NBTOutputStream(output).writeValue(tag);
} catch (IOException e) { } catch (IOException e) {
throw new IllegalArgumentException(e); throw new IllegalArgumentException(e);
} }
@ -474,8 +480,8 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper {
} }
public Component readComponent(ByteBuf buf) { public Component readComponent(ByteBuf buf) {
// do not use CompoundTag, as mojang serializes a plaintext component as just a single StringTag // do not use NbtMap, as mojang serializes a plaintext component as just a single StringTag
Tag tag = readAnyTag(buf, Tag.class); Object tag = readAnyTag(buf);
if (tag == null) { if (tag == null) {
throw new IllegalArgumentException("Got end-tag when trying to read Component"); throw new IllegalArgumentException("Got end-tag when trying to read Component");
} }
@ -485,7 +491,7 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper {
public void writeComponent(ByteBuf buf, Component component) { public void writeComponent(ByteBuf buf, Component component) {
JsonElement json = DefaultComponentSerializer.get().serializeToTree(component); JsonElement json = DefaultComponentSerializer.get().serializeToTree(component);
Tag tag = NbtComponentSerializer.jsonComponentToTag(json); Object tag = NbtComponentSerializer.jsonComponentToTag(json);
writeAnyTag(buf, tag); writeAnyTag(buf, tag);
} }
@ -658,7 +664,7 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper {
int id = this.readVarInt(buf); int id = this.readVarInt(buf);
return switch (id) { return switch (id) {
case 0 -> BlankFormat.INSTANCE; case 0 -> BlankFormat.INSTANCE;
case 1 -> new StyledFormat(this.readAnyTagOrThrow(buf)); case 1 -> new StyledFormat(this.readCompoundTagOrThrow(buf));
case 2 -> new FixedFormat(this.readComponent(buf)); case 2 -> new FixedFormat(this.readComponent(buf));
default -> throw new IllegalArgumentException("Unknown number format type: " + id); default -> throw new IllegalArgumentException("Unknown number format type: " + id);
}; };
@ -1022,11 +1028,11 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper {
* @return the game registry * @return the game registry
*/ */
@Nullable @Nullable
public CompoundTag getRegistry() { public NbtMap getRegistry() {
return this.registry; return this.registry;
} }
public void setRegistry(CompoundTag registry) { public void setRegistry(NbtMap registry) {
this.registry = registry; this.registry = registry;
} }
} }

View file

@ -1,18 +1,5 @@
package org.geysermc.mcprotocollib.protocol.codec; package org.geysermc.mcprotocollib.protocol.codec;
import com.github.steveice10.opennbt.tag.builtin.ByteArrayTag;
import com.github.steveice10.opennbt.tag.builtin.ByteTag;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.DoubleTag;
import com.github.steveice10.opennbt.tag.builtin.FloatTag;
import com.github.steveice10.opennbt.tag.builtin.IntArrayTag;
import com.github.steveice10.opennbt.tag.builtin.IntTag;
import com.github.steveice10.opennbt.tag.builtin.ListTag;
import com.github.steveice10.opennbt.tag.builtin.LongArrayTag;
import com.github.steveice10.opennbt.tag.builtin.LongTag;
import com.github.steveice10.opennbt.tag.builtin.ShortTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
@ -20,6 +7,10 @@ import com.google.gson.JsonPrimitive;
import com.google.gson.internal.LazilyParsedNumber; import com.google.gson.internal.LazilyParsedNumber;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
import org.cloudburstmc.nbt.NbtList;
import org.cloudburstmc.nbt.NbtMap;
import org.cloudburstmc.nbt.NbtMapBuilder;
import org.cloudburstmc.nbt.NbtType;
import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.Contract;
import java.util.Arrays; import java.util.Arrays;
@ -34,16 +25,16 @@ import java.util.UUID;
*/ */
public class NbtComponentSerializer { public class NbtComponentSerializer {
private static final Set<String> BOOLEAN_TYPES = new HashSet<>(Arrays.asList( private static final Set<String> BOOLEAN_TYPES = Set.of(
"interpret", "interpret",
"bold", "bold",
"italic", "italic",
"underlined", "underlined",
"strikethrough", "strikethrough",
"obfuscated" "obfuscated"
)); );
// Order is important // Order is important
private static final List<Pair<String, String>> COMPONENT_TYPES = Arrays.asList( private static final List<Pair<String, String>> COMPONENT_TYPES = List.of(
new Pair<>("text", "text"), new Pair<>("text", "text"),
new Pair<>("translatable", "translate"), new Pair<>("translatable", "translate"),
new Pair<>("score", "score"), new Pair<>("score", "score"),
@ -57,72 +48,86 @@ public class NbtComponentSerializer {
} }
@Contract("null -> null") @Contract("null -> null")
public static JsonElement tagComponentToJson(@Nullable final Tag tag) { public static JsonElement tagComponentToJson(@Nullable final Object tag) {
return convertToJson(null, tag); return convertToJson(null, tag);
} }
public static @Nullable Tag jsonComponentToTag(@Nullable final JsonElement component) { public static @Nullable Object jsonComponentToTag(@Nullable final JsonElement component) {
return convertToTag("", component); return convertToTag(component);
} }
@Contract("_, null -> null") @Contract("null -> null")
private static Tag convertToTag(String name, final @Nullable JsonElement element) { private static Object convertToTag(final @Nullable JsonElement element) {
if (element == null || element.isJsonNull()) { if (element == null || element.isJsonNull()) {
return null; return null;
} else if (element.isJsonObject()) { } else if (element.isJsonObject()) {
final CompoundTag tag = new CompoundTag(name); final NbtMapBuilder tag = NbtMap.builder();
final JsonObject jsonObject = element.getAsJsonObject(); final JsonObject jsonObject = element.getAsJsonObject();
for (final Map.Entry<String, JsonElement> entry : jsonObject.entrySet()) { for (final Map.Entry<String, JsonElement> entry : jsonObject.entrySet()) {
convertObjectEntry(entry.getKey(), entry.getValue(), tag); convertObjectEntry(entry.getKey(), entry.getValue(), tag);
} }
addComponentType(jsonObject, tag); addComponentType(jsonObject, tag);
return tag; return tag.build();
} else if (element.isJsonArray()) { } else if (element.isJsonArray()) {
return convertJsonArray(name, element.getAsJsonArray()); return convertJsonArray(element.getAsJsonArray());
} else if (element.isJsonPrimitive()) { } else if (element.isJsonPrimitive()) {
final JsonPrimitive primitive = element.getAsJsonPrimitive(); final JsonPrimitive primitive = element.getAsJsonPrimitive();
if (primitive.isString()) { if (primitive.isString()) {
return new StringTag(name, primitive.getAsString()); return primitive.getAsString();
} else if (primitive.isBoolean()) { } else if (primitive.isBoolean()) {
return new ByteTag(name, (byte) (primitive.getAsBoolean() ? 1 : 0)); return (byte) (primitive.getAsBoolean() ? 1 : 0);
} }
final Number number = primitive.getAsNumber(); final Number number = primitive.getAsNumber();
if (number instanceof Integer) { if (number instanceof Integer) {
return new IntTag(name, number.intValue()); return number.intValue();
} else if (number instanceof Byte) { } else if (number instanceof Byte) {
return new ByteTag(name, number.byteValue()); return number.byteValue();
} else if (number instanceof Short) { } else if (number instanceof Short) {
return new ShortTag(name, number.shortValue()); return number.shortValue();
} else if (number instanceof Long) { } else if (number instanceof Long) {
return new LongTag(name, number.longValue()); return number.longValue();
} else if (number instanceof Double) { } else if (number instanceof Double) {
return new DoubleTag(name, number.doubleValue()); return number.doubleValue();
} else if (number instanceof Float) { } else if (number instanceof Float) {
return new FloatTag(name, number.floatValue()); return number.floatValue();
} else if (number instanceof LazilyParsedNumber) { } else if (number instanceof LazilyParsedNumber) {
// TODO: This might need better handling // TODO: This might need better handling
return new IntTag(name, number.intValue()); return number.intValue();
} }
return new IntTag(name, number.intValue()); // ??? return number.intValue(); // ???
} }
throw new IllegalArgumentException("Unhandled json type " + element.getClass().getSimpleName() + " with value " + element.getAsString()); throw new IllegalArgumentException("Unhandled json type " + element.getClass().getSimpleName() + " with value " + element.getAsString());
} }
private static ListTag convertJsonArray(String name, final JsonArray array) { private static <T> void addToListOrFail(final NbtList<T> list, final Object tag) {
Class<T> listClass = list.getType().getTagClass();
if (listClass.isInstance(tag)) {
list.add(listClass.cast(tag));
} else {
throw new IllegalArgumentException("Cannot add " + tag.getClass().getSimpleName() + " to list of " + listClass.getSimpleName());
}
}
private static NbtList<?> convertJsonArray(final JsonArray array) {
// TODO Number arrays? // TODO Number arrays?
final ListTag listTag = new ListTag(name); NbtList<?> listTag = null;
boolean singleType = true; boolean singleType = true;
for (final JsonElement entry : array) { for (final JsonElement entry : array) {
final Tag convertedEntryTag = convertToTag("", entry); final Object convertedEntryTag = convertToTag(entry);
if (listTag.getElementType() != null && listTag.getElementType() != convertedEntryTag.getClass()) { if (listTag == null) {
listTag = new NbtList<>(NbtType.byClass(convertedEntryTag.getClass()));
}
if (listTag.getType() != NbtType.byClass(convertedEntryTag.getClass())) {
singleType = false; singleType = false;
break; break;
} }
listTag.add(convertedEntryTag); addToListOrFail(listTag, convertedEntryTag);
} }
if (singleType) { if (singleType) {
@ -131,24 +136,24 @@ public class NbtComponentSerializer {
// Generally, vanilla-esque serializers should not produce this format, so it should be rare // Generally, vanilla-esque serializers should not produce this format, so it should be rare
// Lists are only used for lists of components ("extra" and "with") // Lists are only used for lists of components ("extra" and "with")
final ListTag processedListTag = new ListTag(name); final NbtList<NbtMap> processedListTag = new NbtList<>(NbtType.COMPOUND);
for (final JsonElement entry : array) { for (final JsonElement entry : array) {
final Tag convertedTag = convertToTag("", entry); final Object convertedTag = convertToTag(entry);
if (convertedTag instanceof CompoundTag) { if (convertedTag instanceof NbtMap nbtMap) {
processedListTag.add(convertedTag); processedListTag.add(nbtMap);
continue; continue;
} }
// Wrap all entries in compound tags, as lists can only consist of one type of tag // Wrap all entries in compound tags, as lists can only consist of one type of tag
final CompoundTag compoundTag = new CompoundTag(""); final NbtMapBuilder compoundTag = NbtMap.builder();
compoundTag.put(new StringTag("type", "text")); compoundTag.put("type", "text");
if (convertedTag instanceof ListTag) { if (convertedTag instanceof NbtList<?> list) {
compoundTag.put(new StringTag("text")); compoundTag.put("text", "");
compoundTag.put(new ListTag("extra", ((ListTag) convertedTag).getValue())); compoundTag.put("extra", list);
} else { } else {
compoundTag.put(new StringTag("text", stringValue(convertedTag))); compoundTag.put("text", stringValue(convertedTag));
} }
processedListTag.add(compoundTag); processedListTag.add(compoundTag.build());
} }
return processedListTag; return processedListTag;
} }
@ -160,7 +165,7 @@ public class NbtComponentSerializer {
* @param value value of the entry * @param value value of the entry
* @param tag the resulting compound tag * @param tag the resulting compound tag
*/ */
private static void convertObjectEntry(final String key, final JsonElement value, final CompoundTag tag) { private static void convertObjectEntry(final String key, final JsonElement value, final NbtMapBuilder tag) {
if ((key.equals("contents")) && value.isJsonObject()) { if ((key.equals("contents")) && value.isJsonObject()) {
// Store show_entity id as int array instead of uuid string // Store show_entity id as int array instead of uuid string
// Not really required, but we might as well make it more compact // Not really required, but we might as well make it more compact
@ -170,17 +175,17 @@ public class NbtComponentSerializer {
if (id != null && id.isJsonPrimitive() && (uuid = parseUUID(id.getAsString())) != null) { if (id != null && id.isJsonPrimitive() && (uuid = parseUUID(id.getAsString())) != null) {
hoverEvent.remove("id"); hoverEvent.remove("id");
final CompoundTag convertedTag = (CompoundTag) convertToTag(key, value); final NbtMapBuilder convertedTag = ((NbtMap) convertToTag(value)).toBuilder();
convertedTag.put(new IntArrayTag("id", toIntArray(uuid))); convertedTag.put("id", toIntArray(uuid));
tag.put(convertedTag); tag.put(key, convertedTag.build());
return; return;
} }
} }
tag.put(convertToTag(key, value)); tag.put(key, convertToTag(value));
} }
private static void addComponentType(final JsonObject object, final CompoundTag tag) { private static void addComponentType(final JsonObject object, final NbtMapBuilder tag) {
if (object.has("type")) { if (object.has("type")) {
return; return;
} }
@ -188,54 +193,54 @@ public class NbtComponentSerializer {
// Add the type to speed up deserialization and make DFU errors slightly more useful // Add the type to speed up deserialization and make DFU errors slightly more useful
for (final Pair<String, String> pair : COMPONENT_TYPES) { for (final Pair<String, String> pair : COMPONENT_TYPES) {
if (object.has(pair.value)) { if (object.has(pair.value)) {
tag.put(new StringTag("type", pair.key)); tag.put("type", pair.key);
return; return;
} }
} }
} }
private static @Nullable JsonElement convertToJson(final @Nullable String key, final @Nullable Tag tag) { private static @Nullable JsonElement convertToJson(final @Nullable String key, final @Nullable Object tag) {
if (tag == null) { if (tag == null) {
return null; return null;
} else if (tag instanceof CompoundTag) { } else if (tag instanceof NbtMap nbtMap) {
final JsonObject object = new JsonObject(); final JsonObject object = new JsonObject();
if (!"value".equals(key)) { if (!"value".equals(key)) {
removeComponentType(object); removeComponentType(object);
} }
for (final Tag entry : ((CompoundTag) tag)) { for (Map.Entry<String, Object> entry : nbtMap.entrySet()) {
convertCompoundTagEntry(entry.getName(), entry, object); convertNbtMapEntry(entry.getKey(), entry.getValue(), object);
} }
return object; return object;
} else if (tag instanceof ListTag list) { } else if (tag instanceof NbtList<?> list) {
final JsonArray array = new JsonArray(); final JsonArray array = new JsonArray();
for (final Tag listEntry : list) { for (final Object listEntry : list) {
array.add(convertToJson(null, listEntry)); array.add(convertToJson(null, listEntry));
} }
return array; return array;
} else if (tag.getValue() instanceof Number number) { } else if (tag instanceof Number number) {
if (key != null && BOOLEAN_TYPES.contains(key)) { if (key != null && BOOLEAN_TYPES.contains(key)) {
// Booleans don't have a direct representation in nbt // Booleans don't have a direct representation in nbt
return new JsonPrimitive(number.byteValue() != 0); return new JsonPrimitive(number.byteValue() != 0);
} }
return new JsonPrimitive(number); return new JsonPrimitive(number);
} else if (tag instanceof StringTag) { } else if (tag instanceof String string) {
return new JsonPrimitive(((StringTag) tag).getValue()); return new JsonPrimitive(string);
} else if (tag instanceof ByteArrayTag arrayTag) { } else if (tag instanceof byte[] arrayTag) {
final JsonArray array = new JsonArray(); final JsonArray array = new JsonArray();
for (final byte num : arrayTag.getValue()) { for (final byte num : arrayTag) {
array.add(num); array.add(num);
} }
return array; return array;
} else if (tag instanceof IntArrayTag arrayTag) { } else if (tag instanceof int[] arrayTag) {
final JsonArray array = new JsonArray(); final JsonArray array = new JsonArray();
for (final int num : arrayTag.getValue()) { for (final int num : arrayTag) {
array.add(num); array.add(num);
} }
return array; return array;
} else if (tag instanceof LongArrayTag arrayTag) { } else if (tag instanceof long[] arrayTag) {
final JsonArray array = new JsonArray(); final JsonArray array = new JsonArray();
for (final long num : arrayTag.getValue()) { for (final long num : arrayTag) {
array.add(num); array.add(num);
} }
return array; return array;
@ -243,15 +248,13 @@ public class NbtComponentSerializer {
throw new IllegalArgumentException("Unhandled tag type " + tag.getClass().getSimpleName()); throw new IllegalArgumentException("Unhandled tag type " + tag.getClass().getSimpleName());
} }
private static void convertCompoundTagEntry(final String key, final Tag tag, final JsonObject object) { private static void convertNbtMapEntry(final String key, final Object tag, final JsonObject object) {
if ((key.equals("contents")) && tag instanceof CompoundTag showEntity) { if ((key.equals("contents")) && tag instanceof NbtMap showEntity) {
// Back to a UUID string // Back to a UUID string
final Tag idTag = showEntity.get("id"); final Object idTag = showEntity.get("id");
if (idTag instanceof IntArrayTag) { if (idTag instanceof int[] array) {
showEntity.remove("id");
final JsonObject convertedElement = (JsonObject) convertToJson(key, tag); final JsonObject convertedElement = (JsonObject) convertToJson(key, tag);
final UUID uuid = fromIntArray(((IntArrayTag) idTag).getValue()); final UUID uuid = fromIntArray(array);
convertedElement.addProperty("id", uuid.toString()); convertedElement.addProperty("id", uuid.toString());
object.add(key, convertedElement); object.add(key, convertedElement);
return; return;
@ -302,29 +305,29 @@ public class NbtComponentSerializer {
} }
// Last adopted from https://github.com/ViaVersion/ViaNBT/commit/ad8ac024c48c2fc25e18dc689b3ca62602420ab9 // Last adopted from https://github.com/ViaVersion/ViaNBT/commit/ad8ac024c48c2fc25e18dc689b3ca62602420ab9
private static String stringValue(Tag tag) { private static String stringValue(Object tag) {
if (tag instanceof ByteArrayTag) { if (tag instanceof byte[] bytes) {
return Arrays.toString(((ByteArrayTag) tag).getValue()); return Arrays.toString(bytes);
} else if (tag instanceof ByteTag) { } else if (tag instanceof Byte byteTag) {
return Byte.toString(((ByteTag) tag).getValue()); return Byte.toString(byteTag);
} else if (tag instanceof DoubleTag) { } else if (tag instanceof Double doubleTag) {
return Double.toString(((DoubleTag) tag).getValue()); return Double.toString(doubleTag);
} else if (tag instanceof FloatTag) { } else if (tag instanceof Float floatTag) {
return Float.toString(((FloatTag) tag).getValue()); return Float.toString(floatTag);
} else if (tag instanceof IntArrayTag) { } else if (tag instanceof int[] intArray) {
return Arrays.toString(((IntArrayTag) tag).getValue()); return Arrays.toString(intArray);
} else if (tag instanceof IntTag) { } else if (tag instanceof Integer integer) {
return Integer.toString(((IntTag) tag).getValue()); return Integer.toString(integer);
} else if (tag instanceof LongArrayTag) { } else if (tag instanceof long[] longs) {
return Arrays.toString(((LongArrayTag) tag).getValue()); return Arrays.toString(longs);
} else if (tag instanceof LongTag) { } else if (tag instanceof Long longTag) {
return Long.toString(((LongTag) tag).getValue()); return Long.toString(longTag);
} else if (tag instanceof ShortTag) { } else if (tag instanceof Short shortTag) {
return Short.toString(((ShortTag) tag).getValue()); return Short.toString(shortTag);
} else if (tag instanceof StringTag) { } else if (tag instanceof String string) {
return ((StringTag) tag).getValue(); return string;
} else { } else {
return tag.getValue().toString(); return tag.toString();
} }
} }

View file

@ -1,13 +1,13 @@
package org.geysermc.mcprotocollib.protocol.data.game; package org.geysermc.mcprotocollib.protocol.data.game;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import org.cloudburstmc.nbt.NbtMap;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@Data @Data
@AllArgsConstructor @AllArgsConstructor
public class RegistryEntry { public class RegistryEntry {
private final String id; private final String id;
private final @Nullable CompoundTag data; private final @Nullable NbtMap data;
} }

View file

@ -1,10 +1,10 @@
package org.geysermc.mcprotocollib.protocol.data.game.chat.numbers; package org.geysermc.mcprotocollib.protocol.data.game.chat.numbers;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NonNull; import lombok.NonNull;
import net.kyori.adventure.text.format.Style; import net.kyori.adventure.text.format.Style;
import org.cloudburstmc.nbt.NbtMap;
@Data @Data
@AllArgsConstructor @AllArgsConstructor
@ -13,5 +13,5 @@ public class StyledFormat implements NumberFormat {
/** /**
* Serialized {@link Style} * Serialized {@link Style}
*/ */
private final @NonNull CompoundTag style; private final @NonNull NbtMap style;
} }

View file

@ -1,5 +1,6 @@
package org.geysermc.mcprotocollib.protocol.data.game.entity.metadata; package org.geysermc.mcprotocollib.protocol.data.game.entity.metadata;
import org.cloudburstmc.nbt.NbtMap;
import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper; import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper;
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata;
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ByteEntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ByteEntityMetadata;
@ -10,9 +11,7 @@ import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.Object
import org.geysermc.mcprotocollib.protocol.data.game.entity.object.Direction; import org.geysermc.mcprotocollib.protocol.data.game.entity.object.Direction;
import org.geysermc.mcprotocollib.protocol.data.game.entity.type.PaintingType; import org.geysermc.mcprotocollib.protocol.data.game.entity.type.PaintingType;
import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack; import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponentType;
import org.geysermc.mcprotocollib.protocol.data.game.level.particle.Particle; import org.geysermc.mcprotocollib.protocol.data.game.level.particle.Particle;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import lombok.Getter; import lombok.Getter;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
@ -45,7 +44,7 @@ public class MetadataType<T> {
public static final MetadataType<Optional<UUID>> OPTIONAL_UUID = new MetadataType<>(optionalReader(MinecraftCodecHelper::readUUID), optionalWriter(MinecraftCodecHelper::writeUUID), ObjectEntityMetadata::new); public static final MetadataType<Optional<UUID>> OPTIONAL_UUID = new MetadataType<>(optionalReader(MinecraftCodecHelper::readUUID), optionalWriter(MinecraftCodecHelper::writeUUID), ObjectEntityMetadata::new);
public static final IntMetadataType BLOCK_STATE = new IntMetadataType(MinecraftCodecHelper::readVarInt, MinecraftCodecHelper::writeVarInt, IntEntityMetadata::new); public static final IntMetadataType BLOCK_STATE = new IntMetadataType(MinecraftCodecHelper::readVarInt, MinecraftCodecHelper::writeVarInt, IntEntityMetadata::new);
public static final IntMetadataType OPTIONAL_BLOCK_STATE = new IntMetadataType(MinecraftCodecHelper::readVarInt, MinecraftCodecHelper::writeVarInt, IntEntityMetadata::new); public static final IntMetadataType OPTIONAL_BLOCK_STATE = new IntMetadataType(MinecraftCodecHelper::readVarInt, MinecraftCodecHelper::writeVarInt, IntEntityMetadata::new);
public static final MetadataType<CompoundTag> NBT_TAG = new MetadataType<>(MinecraftCodecHelper::readAnyTag, MinecraftCodecHelper::writeAnyTag, ObjectEntityMetadata::new); public static final MetadataType<NbtMap> NBT_TAG = new MetadataType<>(MinecraftCodecHelper::readCompoundTag, MinecraftCodecHelper::writeAnyTag, ObjectEntityMetadata::new);
public static final MetadataType<Particle> PARTICLE = new MetadataType<>(MinecraftCodecHelper::readParticle, MinecraftCodecHelper::writeParticle, ObjectEntityMetadata::new); public static final MetadataType<Particle> PARTICLE = new MetadataType<>(MinecraftCodecHelper::readParticle, MinecraftCodecHelper::writeParticle, ObjectEntityMetadata::new);
public static final MetadataType<List<Particle>> PARTICLES = new MetadataType<>(listReader(MinecraftCodecHelper::readParticle), listWriter(MinecraftCodecHelper::writeParticle), ObjectEntityMetadata::new); public static final MetadataType<List<Particle>> PARTICLES = new MetadataType<>(listReader(MinecraftCodecHelper::readParticle), listWriter(MinecraftCodecHelper::writeParticle), ObjectEntityMetadata::new);
public static final MetadataType<VillagerData> VILLAGER_DATA = new MetadataType<>(MinecraftCodecHelper::readVillagerData, MinecraftCodecHelper::writeVillagerData, ObjectEntityMetadata::new); public static final MetadataType<VillagerData> VILLAGER_DATA = new MetadataType<>(MinecraftCodecHelper::readVillagerData, MinecraftCodecHelper::writeVillagerData, ObjectEntityMetadata::new);

View file

@ -1,8 +1,8 @@
package org.geysermc.mcprotocollib.protocol.data.game.item.component; package org.geysermc.mcprotocollib.protocol.data.game.item.component;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import org.cloudburstmc.nbt.NbtMap;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.List; import java.util.List;
@ -19,7 +19,7 @@ public class AdventureModePredicate {
private final @Nullable String location; private final @Nullable String location;
private final int @Nullable[] holders; private final int @Nullable[] holders;
private final @Nullable List<PropertyMatcher> properties; private final @Nullable List<PropertyMatcher> properties;
private final @Nullable CompoundTag nbt; private final @Nullable NbtMap nbt;
} }
@Data @Data

View file

@ -1,13 +1,13 @@
package org.geysermc.mcprotocollib.protocol.data.game.item.component; package org.geysermc.mcprotocollib.protocol.data.game.item.component;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import org.cloudburstmc.nbt.NbtMap;
@Data @Data
@AllArgsConstructor @AllArgsConstructor
public class BeehiveOccupant { public class BeehiveOccupant {
private final CompoundTag entityData; private final NbtMap entityData;
private final int ticksInHive; private final int ticksInHive;
private final int minTicksInHive; private final int minTicksInHive;
} }

View file

@ -1,15 +1,14 @@
package org.geysermc.mcprotocollib.protocol.data.game.item.component; package org.geysermc.mcprotocollib.protocol.data.game.item.component;
import com.github.steveice10.mc.auth.data.GameProfile; import com.github.steveice10.mc.auth.data.GameProfile;
import org.cloudburstmc.nbt.NbtList;
import org.cloudburstmc.nbt.NbtMap;
import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper; import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper;
import org.geysermc.mcprotocollib.protocol.data.game.Holder; import org.geysermc.mcprotocollib.protocol.data.game.Holder;
import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack; import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.type.BooleanDataComponent; import org.geysermc.mcprotocollib.protocol.data.game.item.component.type.BooleanDataComponent;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.type.IntDataComponent; import org.geysermc.mcprotocollib.protocol.data.game.item.component.type.IntDataComponent;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.type.ObjectDataComponent; import org.geysermc.mcprotocollib.protocol.data.game.item.component.type.ObjectDataComponent;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.ListTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import lombok.Getter; import lombok.Getter;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
@ -21,7 +20,7 @@ import java.util.List;
public class DataComponentType<T> { public class DataComponentType<T> {
private static final List<DataComponentType<?>> VALUES = new ArrayList<>(); private static final List<DataComponentType<?>> VALUES = new ArrayList<>();
public static final DataComponentType<CompoundTag> CUSTOM_DATA = new DataComponentType<>(ItemCodecHelper::readAnyTag, ItemCodecHelper::writeAnyTag, ObjectDataComponent::new); public static final DataComponentType<NbtMap> CUSTOM_DATA = new DataComponentType<>(ItemCodecHelper::readCompoundTag, ItemCodecHelper::writeAnyTag, ObjectDataComponent::new);
public static final IntComponentType MAX_STACK_SIZE = new IntComponentType(ItemCodecHelper::readVarInt, ItemCodecHelper::writeVarInt, IntDataComponent::new); public static final IntComponentType MAX_STACK_SIZE = new IntComponentType(ItemCodecHelper::readVarInt, ItemCodecHelper::writeVarInt, IntDataComponent::new);
public static final IntComponentType MAX_DAMAGE = new IntComponentType(ItemCodecHelper::readVarInt, ItemCodecHelper::writeVarInt, IntDataComponent::new); public static final IntComponentType MAX_DAMAGE = new IntComponentType(ItemCodecHelper::readVarInt, ItemCodecHelper::writeVarInt, IntDataComponent::new);
public static final IntComponentType DAMAGE = new IntComponentType(ItemCodecHelper::readVarInt, ItemCodecHelper::writeVarInt, IntDataComponent::new); public static final IntComponentType DAMAGE = new IntComponentType(ItemCodecHelper::readVarInt, ItemCodecHelper::writeVarInt, IntDataComponent::new);
@ -40,7 +39,7 @@ public class DataComponentType<T> {
public static final IntComponentType REPAIR_COST = new IntComponentType(ItemCodecHelper::readVarInt, ItemCodecHelper::writeVarInt, IntDataComponent::new); public static final IntComponentType REPAIR_COST = new IntComponentType(ItemCodecHelper::readVarInt, ItemCodecHelper::writeVarInt, IntDataComponent::new);
public static final DataComponentType<Unit> CREATIVE_SLOT_LOCK = new DataComponentType<>(unitReader(), unitWriter(), ObjectDataComponent::new); public static final DataComponentType<Unit> CREATIVE_SLOT_LOCK = new DataComponentType<>(unitReader(), unitWriter(), ObjectDataComponent::new);
public static final BooleanComponentType ENCHANTMENT_GLINT_OVERRIDE = new BooleanComponentType(ByteBuf::readBoolean, ByteBuf::writeBoolean, BooleanDataComponent::new); public static final BooleanComponentType ENCHANTMENT_GLINT_OVERRIDE = new BooleanComponentType(ByteBuf::readBoolean, ByteBuf::writeBoolean, BooleanDataComponent::new);
public static final DataComponentType<CompoundTag> INTANGIBLE_PROJECTILE = new DataComponentType<>(ItemCodecHelper::readAnyTag, ItemCodecHelper::writeAnyTag, ObjectDataComponent::new); public static final DataComponentType<NbtMap> INTANGIBLE_PROJECTILE = new DataComponentType<>(ItemCodecHelper::readCompoundTag, ItemCodecHelper::writeAnyTag, ObjectDataComponent::new);
public static final DataComponentType<FoodProperties> FOOD = new DataComponentType<>(ItemCodecHelper::readFoodProperties, ItemCodecHelper::writeFoodProperties, ObjectDataComponent::new); public static final DataComponentType<FoodProperties> FOOD = new DataComponentType<>(ItemCodecHelper::readFoodProperties, ItemCodecHelper::writeFoodProperties, ObjectDataComponent::new);
public static final DataComponentType<Unit> FIRE_RESISTANT = new DataComponentType<>(unitReader(), unitWriter(), ObjectDataComponent::new); public static final DataComponentType<Unit> FIRE_RESISTANT = new DataComponentType<>(unitReader(), unitWriter(), ObjectDataComponent::new);
public static final DataComponentType<ToolData> TOOL = new DataComponentType<>(ItemCodecHelper::readToolData, ItemCodecHelper::writeToolData, ObjectDataComponent::new); public static final DataComponentType<ToolData> TOOL = new DataComponentType<>(ItemCodecHelper::readToolData, ItemCodecHelper::writeToolData, ObjectDataComponent::new);
@ -48,7 +47,7 @@ public class DataComponentType<T> {
public static final DataComponentType<DyedItemColor> DYED_COLOR = new DataComponentType<>(ItemCodecHelper::readDyedItemColor, ItemCodecHelper::writeDyedItemColor, ObjectDataComponent::new); public static final DataComponentType<DyedItemColor> DYED_COLOR = new DataComponentType<>(ItemCodecHelper::readDyedItemColor, ItemCodecHelper::writeDyedItemColor, ObjectDataComponent::new);
public static final IntComponentType MAP_COLOR = new IntComponentType((helper, input) -> input.readInt(), (helper, output, value) -> output.writeInt(value), IntDataComponent::new); public static final IntComponentType MAP_COLOR = new IntComponentType((helper, input) -> input.readInt(), (helper, output, value) -> output.writeInt(value), IntDataComponent::new);
public static final IntComponentType MAP_ID = new IntComponentType(ItemCodecHelper::readVarInt, ItemCodecHelper::writeVarInt, IntDataComponent::new); public static final IntComponentType MAP_ID = new IntComponentType(ItemCodecHelper::readVarInt, ItemCodecHelper::writeVarInt, IntDataComponent::new);
public static final DataComponentType<CompoundTag> MAP_DECORATIONS = new DataComponentType<>(ItemCodecHelper::readAnyTag, ItemCodecHelper::writeAnyTag, ObjectDataComponent::new); public static final DataComponentType<NbtMap> MAP_DECORATIONS = new DataComponentType<>(ItemCodecHelper::readCompoundTag, ItemCodecHelper::writeAnyTag, ObjectDataComponent::new);
public static final IntComponentType MAP_POST_PROCESSING = new IntComponentType(ItemCodecHelper::readVarInt, ItemCodecHelper::writeVarInt, IntDataComponent::new); public static final IntComponentType MAP_POST_PROCESSING = new IntComponentType(ItemCodecHelper::readVarInt, ItemCodecHelper::writeVarInt, IntDataComponent::new);
public static final DataComponentType<List<ItemStack>> CHARGED_PROJECTILES = new DataComponentType<>(listReader(ItemCodecHelper::readItemStack), listWriter(ItemCodecHelper::writeItemStack), ObjectDataComponent::new); public static final DataComponentType<List<ItemStack>> CHARGED_PROJECTILES = new DataComponentType<>(listReader(ItemCodecHelper::readItemStack), listWriter(ItemCodecHelper::writeItemStack), ObjectDataComponent::new);
public static final DataComponentType<List<ItemStack>> BUNDLE_CONTENTS = new DataComponentType<>(listReader(ItemCodecHelper::readItemStack), listWriter(ItemCodecHelper::writeItemStack), ObjectDataComponent::new); public static final DataComponentType<List<ItemStack>> BUNDLE_CONTENTS = new DataComponentType<>(listReader(ItemCodecHelper::readItemStack), listWriter(ItemCodecHelper::writeItemStack), ObjectDataComponent::new);
@ -57,13 +56,13 @@ public class DataComponentType<T> {
public static final DataComponentType<WritableBookContent> WRITABLE_BOOK_CONTENT = new DataComponentType<>(ItemCodecHelper::readWritableBookContent, ItemCodecHelper::writeWritableBookContent, ObjectDataComponent::new); public static final DataComponentType<WritableBookContent> WRITABLE_BOOK_CONTENT = new DataComponentType<>(ItemCodecHelper::readWritableBookContent, ItemCodecHelper::writeWritableBookContent, ObjectDataComponent::new);
public static final DataComponentType<WrittenBookContent> WRITTEN_BOOK_CONTENT = new DataComponentType<>(ItemCodecHelper::readWrittenBookContent, ItemCodecHelper::writeWrittenBookContent, ObjectDataComponent::new); public static final DataComponentType<WrittenBookContent> WRITTEN_BOOK_CONTENT = new DataComponentType<>(ItemCodecHelper::readWrittenBookContent, ItemCodecHelper::writeWrittenBookContent, ObjectDataComponent::new);
public static final DataComponentType<ArmorTrim> TRIM = new DataComponentType<>(ItemCodecHelper::readArmorTrim, ItemCodecHelper::writeArmorTrim, ObjectDataComponent::new); public static final DataComponentType<ArmorTrim> TRIM = new DataComponentType<>(ItemCodecHelper::readArmorTrim, ItemCodecHelper::writeArmorTrim, ObjectDataComponent::new);
public static final DataComponentType<CompoundTag> DEBUG_STICK_STATE = new DataComponentType<>(ItemCodecHelper::readAnyTag, ItemCodecHelper::writeAnyTag, ObjectDataComponent::new); public static final DataComponentType<NbtMap> DEBUG_STICK_STATE = new DataComponentType<>(ItemCodecHelper::readCompoundTag, ItemCodecHelper::writeAnyTag, ObjectDataComponent::new);
public static final DataComponentType<CompoundTag> ENTITY_DATA = new DataComponentType<>(ItemCodecHelper::readAnyTag, ItemCodecHelper::writeAnyTag, ObjectDataComponent::new); public static final DataComponentType<NbtMap> ENTITY_DATA = new DataComponentType<>(ItemCodecHelper::readCompoundTag, ItemCodecHelper::writeAnyTag, ObjectDataComponent::new);
public static final DataComponentType<CompoundTag> BUCKET_ENTITY_DATA = new DataComponentType<>(ItemCodecHelper::readAnyTag, ItemCodecHelper::writeAnyTag, ObjectDataComponent::new); public static final DataComponentType<NbtMap> BUCKET_ENTITY_DATA = new DataComponentType<>(ItemCodecHelper::readCompoundTag, ItemCodecHelper::writeAnyTag, ObjectDataComponent::new);
public static final DataComponentType<CompoundTag> BLOCK_ENTITY_DATA = new DataComponentType<>(ItemCodecHelper::readAnyTag, ItemCodecHelper::writeAnyTag, ObjectDataComponent::new); public static final DataComponentType<NbtMap> BLOCK_ENTITY_DATA = new DataComponentType<>(ItemCodecHelper::readCompoundTag, ItemCodecHelper::writeAnyTag, ObjectDataComponent::new);
public static final DataComponentType<Holder<Instrument>> INSTRUMENT = new DataComponentType<>(ItemCodecHelper::readInstrument, ItemCodecHelper::writeInstrument, ObjectDataComponent::new); public static final DataComponentType<Holder<Instrument>> INSTRUMENT = new DataComponentType<>(ItemCodecHelper::readInstrument, ItemCodecHelper::writeInstrument, ObjectDataComponent::new);
public static final IntComponentType OMINOUS_BOTTLE_AMPLIFIER = new IntComponentType(ItemCodecHelper::readVarInt, ItemCodecHelper::writeVarInt, IntDataComponent::new); public static final IntComponentType OMINOUS_BOTTLE_AMPLIFIER = new IntComponentType(ItemCodecHelper::readVarInt, ItemCodecHelper::writeVarInt, IntDataComponent::new);
public static final DataComponentType<ListTag> RECIPES = new DataComponentType<>(ItemCodecHelper::readRecipes, ItemCodecHelper::writeRecipes, ObjectDataComponent::new); public static final DataComponentType<NbtList<?>> RECIPES = new DataComponentType<>(ItemCodecHelper::readRecipes, ItemCodecHelper::writeRecipes, ObjectDataComponent::new);
public static final DataComponentType<LodestoneTracker> LODESTONE_TRACKER = new DataComponentType<>(ItemCodecHelper::readLodestoneTarget, ItemCodecHelper::writeLodestoneTarget, ObjectDataComponent::new); public static final DataComponentType<LodestoneTracker> LODESTONE_TRACKER = new DataComponentType<>(ItemCodecHelper::readLodestoneTarget, ItemCodecHelper::writeLodestoneTarget, ObjectDataComponent::new);
public static final DataComponentType<Fireworks.FireworkExplosion> FIREWORK_EXPLOSION = new DataComponentType<>(ItemCodecHelper::readFireworkExplosion, ItemCodecHelper::writeFireworkExplosion, ObjectDataComponent::new); public static final DataComponentType<Fireworks.FireworkExplosion> FIREWORK_EXPLOSION = new DataComponentType<>(ItemCodecHelper::readFireworkExplosion, ItemCodecHelper::writeFireworkExplosion, ObjectDataComponent::new);
public static final DataComponentType<Fireworks> FIREWORKS = new DataComponentType<>(ItemCodecHelper::readFireworks, ItemCodecHelper::writeFireworks, ObjectDataComponent::new); public static final DataComponentType<Fireworks> FIREWORKS = new DataComponentType<>(ItemCodecHelper::readFireworks, ItemCodecHelper::writeFireworks, ObjectDataComponent::new);
@ -75,8 +74,8 @@ public class DataComponentType<T> {
public static final DataComponentType<List<ItemStack>> CONTAINER = new DataComponentType<>(listReader(ItemCodecHelper::readOptionalItemStack), listWriter(MinecraftCodecHelper::writeOptionalItemStack), ObjectDataComponent::new); public static final DataComponentType<List<ItemStack>> CONTAINER = new DataComponentType<>(listReader(ItemCodecHelper::readOptionalItemStack), listWriter(MinecraftCodecHelper::writeOptionalItemStack), ObjectDataComponent::new);
public static final DataComponentType<BlockStateProperties> BLOCK_STATE = new DataComponentType<>(ItemCodecHelper::readBlockStateProperties, ItemCodecHelper::writeBlockStateProperties, ObjectDataComponent::new); public static final DataComponentType<BlockStateProperties> BLOCK_STATE = new DataComponentType<>(ItemCodecHelper::readBlockStateProperties, ItemCodecHelper::writeBlockStateProperties, ObjectDataComponent::new);
public static final DataComponentType<List<BeehiveOccupant>> BEES = new DataComponentType<>(listReader(ItemCodecHelper::readBeehiveOccupant), listWriter(ItemCodecHelper::writeBeehiveOccupant), ObjectDataComponent::new); public static final DataComponentType<List<BeehiveOccupant>> BEES = new DataComponentType<>(listReader(ItemCodecHelper::readBeehiveOccupant), listWriter(ItemCodecHelper::writeBeehiveOccupant), ObjectDataComponent::new);
public static final DataComponentType<StringTag> LOCK = new DataComponentType<>(ItemCodecHelper::readLock, ItemCodecHelper::writeLock, ObjectDataComponent::new); public static final DataComponentType<String> LOCK = new DataComponentType<>(ItemCodecHelper::readLock, ItemCodecHelper::writeLock, ObjectDataComponent::new);
public static final DataComponentType<CompoundTag> CONTAINER_LOOT = new DataComponentType<>(ItemCodecHelper::readAnyTag, ItemCodecHelper::writeAnyTag, ObjectDataComponent::new); public static final DataComponentType<NbtMap> CONTAINER_LOOT = new DataComponentType<>(ItemCodecHelper::readCompoundTag, ItemCodecHelper::writeAnyTag, ObjectDataComponent::new);
protected final int id; protected final int id;
protected final Reader<T> reader; protected final Reader<T> reader;

View file

@ -1,14 +1,14 @@
package org.geysermc.mcprotocollib.protocol.data.game.item.component; package org.geysermc.mcprotocollib.protocol.data.game.item.component;
import com.github.steveice10.mc.auth.data.GameProfile; import com.github.steveice10.mc.auth.data.GameProfile;
import org.cloudburstmc.nbt.NbtList;
import org.cloudburstmc.nbt.NbtType;
import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper; import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper;
import org.geysermc.mcprotocollib.protocol.data.game.Holder; import org.geysermc.mcprotocollib.protocol.data.game.Holder;
import org.geysermc.mcprotocollib.protocol.data.game.entity.attribute.ModifierOperation; import org.geysermc.mcprotocollib.protocol.data.game.entity.attribute.ModifierOperation;
import org.geysermc.mcprotocollib.protocol.data.game.level.sound.BuiltinSound; import org.geysermc.mcprotocollib.protocol.data.game.level.sound.BuiltinSound;
import org.geysermc.mcprotocollib.protocol.data.game.level.sound.CustomSound; import org.geysermc.mcprotocollib.protocol.data.game.level.sound.CustomSound;
import org.geysermc.mcprotocollib.protocol.data.game.level.sound.Sound; import org.geysermc.mcprotocollib.protocol.data.game.level.sound.Sound;
import com.github.steveice10.opennbt.tag.builtin.ListTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectMaps; import it.unimi.dsi.fastutil.ints.Int2ObjectMaps;
@ -120,7 +120,7 @@ public class ItemCodecHelper extends MinecraftCodecHelper {
} }
} }
return new AdventureModePredicate.BlockPredicate(location, holders, propertyMatchers, this.readNullable(buf, this::readAnyTag)); return new AdventureModePredicate.BlockPredicate(location, holders, propertyMatchers, this.readNullable(buf, this::readCompoundTag));
} }
public void writeBlockPredicate(ByteBuf buf, AdventureModePredicate.BlockPredicate blockPredicate) { public void writeBlockPredicate(ByteBuf buf, AdventureModePredicate.BlockPredicate blockPredicate) {
@ -466,11 +466,11 @@ public class ItemCodecHelper extends MinecraftCodecHelper {
}); });
} }
public ListTag readRecipes(ByteBuf buf) { public NbtList<?> readRecipes(ByteBuf buf) {
return this.readAnyTag(buf, ListTag.class); return this.readAnyTag(buf, NbtType.LIST);
} }
public void writeRecipes(ByteBuf buf, ListTag recipes) { public void writeRecipes(ByteBuf buf, NbtList<?> recipes) {
this.writeAnyTag(buf, recipes); this.writeAnyTag(buf, recipes);
} }
@ -601,7 +601,7 @@ public class ItemCodecHelper extends MinecraftCodecHelper {
} }
public BeehiveOccupant readBeehiveOccupant(ByteBuf buf) { public BeehiveOccupant readBeehiveOccupant(ByteBuf buf) {
return new BeehiveOccupant(this.readAnyTag(buf), this.readVarInt(buf), this.readVarInt(buf)); return new BeehiveOccupant(this.readCompoundTag(buf), this.readVarInt(buf), this.readVarInt(buf));
} }
public void writeBeehiveOccupant(ByteBuf buf, BeehiveOccupant occupant) { public void writeBeehiveOccupant(ByteBuf buf, BeehiveOccupant occupant) {
@ -610,11 +610,11 @@ public class ItemCodecHelper extends MinecraftCodecHelper {
this.writeVarInt(buf, occupant.getMinTicksInHive()); this.writeVarInt(buf, occupant.getMinTicksInHive());
} }
public StringTag readLock(ByteBuf buf) { public String readLock(ByteBuf buf) {
return this.readAnyTag(buf, StringTag.class); return this.readAnyTag(buf, NbtType.STRING);
} }
public void writeLock(ByteBuf buf, StringTag key) { public void writeLock(ByteBuf buf, String key) {
this.writeAnyTag(buf, key); this.writeAnyTag(buf, key);
} }
} }

View file

@ -1,9 +1,9 @@
package org.geysermc.mcprotocollib.protocol.data.game.level.block; package org.geysermc.mcprotocollib.protocol.data.game.level.block;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
import org.cloudburstmc.nbt.NbtMap;
@Data @Data
@AllArgsConstructor @AllArgsConstructor
@ -12,5 +12,5 @@ public class BlockEntityInfo {
private final int y; private final int y;
private final int z; private final int z;
private final BlockEntityType type; private final BlockEntityType type;
private final @Nullable CompoundTag nbt; private final @Nullable NbtMap nbt;
} }

View file

@ -24,7 +24,7 @@ public class ClientboundRegistryDataPacket implements MinecraftPacket {
int entryCount = helper.readVarInt(in); int entryCount = helper.readVarInt(in);
for (int i = 0; i < entryCount; i++) { for (int i = 0; i < entryCount; i++) {
this.entries.add(new RegistryEntry(helper.readResourceLocation(in), helper.readNullable(in, helper::readAnyTag))); this.entries.add(new RegistryEntry(helper.readResourceLocation(in), helper.readNullable(in, helper::readCompoundTag)));
} }
} }

View file

@ -3,13 +3,11 @@ package org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity;
import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper; import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper;
import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket; import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket;
import org.geysermc.mcprotocollib.protocol.data.game.entity.Effect; import org.geysermc.mcprotocollib.protocol.data.game.entity.Effect;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
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.NonNull;
import lombok.With; import lombok.With;
import org.checkerframework.checker.nullness.qual.Nullable;
@Data @Data
@With @With

View file

@ -1,9 +1,9 @@
package org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.level; package org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.level;
import org.cloudburstmc.nbt.NbtMap;
import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper; import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper;
import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket; import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket;
import org.geysermc.mcprotocollib.protocol.data.game.level.block.BlockEntityType; import org.geysermc.mcprotocollib.protocol.data.game.level.block.BlockEntityType;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
@ -18,12 +18,12 @@ import org.checkerframework.checker.nullness.qual.Nullable;
public class ClientboundBlockEntityDataPacket implements MinecraftPacket { public class ClientboundBlockEntityDataPacket implements MinecraftPacket {
private final @NonNull Vector3i position; private final @NonNull Vector3i position;
private final @NonNull BlockEntityType type; private final @NonNull BlockEntityType type;
private final @Nullable CompoundTag nbt; private final @Nullable NbtMap nbt;
public ClientboundBlockEntityDataPacket(ByteBuf in, MinecraftCodecHelper helper) { public ClientboundBlockEntityDataPacket(ByteBuf in, MinecraftCodecHelper helper) {
this.position = helper.readPosition(in); this.position = helper.readPosition(in);
this.type = helper.readBlockEntityType(in); this.type = helper.readBlockEntityType(in);
this.nbt = helper.readAnyTag(in); this.nbt = helper.readCompoundTag(in);
} }
@Override @Override

View file

@ -1,11 +1,11 @@
package org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.level; package org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.level;
import org.cloudburstmc.nbt.NbtMap;
import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper; import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper;
import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket; import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket;
import org.geysermc.mcprotocollib.protocol.data.game.level.LightUpdateData; import org.geysermc.mcprotocollib.protocol.data.game.level.LightUpdateData;
import org.geysermc.mcprotocollib.protocol.data.game.level.block.BlockEntityInfo; import org.geysermc.mcprotocollib.protocol.data.game.level.block.BlockEntityInfo;
import org.geysermc.mcprotocollib.protocol.data.game.level.block.BlockEntityType; import org.geysermc.mcprotocollib.protocol.data.game.level.block.BlockEntityType;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
@ -19,14 +19,14 @@ public class ClientboundLevelChunkWithLightPacket implements MinecraftPacket {
private final int x; private final int x;
private final int z; private final int z;
private final byte @NonNull [] chunkData; private final byte @NonNull [] chunkData;
private final @NonNull CompoundTag heightMaps; private final @NonNull NbtMap heightMaps;
private final @NonNull BlockEntityInfo @NonNull [] blockEntities; private final @NonNull BlockEntityInfo @NonNull [] blockEntities;
private final @NonNull LightUpdateData lightData; private final @NonNull LightUpdateData lightData;
public ClientboundLevelChunkWithLightPacket(ByteBuf in, MinecraftCodecHelper helper) { public ClientboundLevelChunkWithLightPacket(ByteBuf in, MinecraftCodecHelper helper) {
this.x = in.readInt(); this.x = in.readInt();
this.z = in.readInt(); this.z = in.readInt();
this.heightMaps = helper.readAnyTagOrThrow(in); this.heightMaps = helper.readCompoundTagOrThrow(in);
this.chunkData = helper.readByteArray(in); this.chunkData = helper.readByteArray(in);
this.blockEntities = new BlockEntityInfo[helper.readVarInt(in)]; this.blockEntities = new BlockEntityInfo[helper.readVarInt(in)];
@ -36,7 +36,7 @@ public class ClientboundLevelChunkWithLightPacket implements MinecraftPacket {
int blockEntityZ = xz & 15; int blockEntityZ = xz & 15;
int blockEntityY = in.readShort(); int blockEntityY = in.readShort();
BlockEntityType type = helper.readBlockEntityType(in); BlockEntityType type = helper.readBlockEntityType(in);
CompoundTag tag = helper.readAnyTag(in); NbtMap tag = helper.readCompoundTag(in);
this.blockEntities[i] = new BlockEntityInfo(blockEntityX, blockEntityY, blockEntityZ, type, tag); this.blockEntities[i] = new BlockEntityInfo(blockEntityX, blockEntityY, blockEntityZ, type, tag);
} }

View file

@ -1,8 +1,8 @@
package org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.level; package org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.level;
import org.cloudburstmc.nbt.NbtMap;
import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper; import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper;
import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket; import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
@ -14,11 +14,11 @@ import org.checkerframework.checker.nullness.qual.Nullable;
@AllArgsConstructor @AllArgsConstructor
public class ClientboundTagQueryPacket implements MinecraftPacket { public class ClientboundTagQueryPacket implements MinecraftPacket {
private final int transactionId; private final int transactionId;
private final @Nullable CompoundTag nbt; private final @Nullable NbtMap nbt;
public ClientboundTagQueryPacket(ByteBuf in, MinecraftCodecHelper helper) { public ClientboundTagQueryPacket(ByteBuf in, MinecraftCodecHelper helper) {
this.transactionId = helper.readVarInt(in); this.transactionId = helper.readVarInt(in);
this.nbt = helper.readAnyTag(in); this.nbt = helper.readCompoundTag(in);
} }
@Override @Override

View file

@ -1,10 +1,10 @@
package org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.level; package org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.level;
import org.cloudburstmc.nbt.NbtMap;
import org.geysermc.mcprotocollib.protocol.data.game.level.LightUpdateData; import org.geysermc.mcprotocollib.protocol.data.game.level.LightUpdateData;
import org.geysermc.mcprotocollib.protocol.data.game.level.block.BlockEntityInfo; import org.geysermc.mcprotocollib.protocol.data.game.level.block.BlockEntityInfo;
import org.geysermc.mcprotocollib.protocol.data.game.level.block.BlockEntityType; import org.geysermc.mcprotocollib.protocol.data.game.level.block.BlockEntityType;
import org.geysermc.mcprotocollib.protocol.packet.PacketTest; import org.geysermc.mcprotocollib.protocol.packet.PacketTest;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import java.util.BitSet; import java.util.BitSet;
@ -15,11 +15,11 @@ public class ClientboundLevelChunkWithLightPacketTest extends PacketTest {
public void setup() { public void setup() {
this.setPackets( this.setPackets(
new ClientboundLevelChunkWithLightPacket(0, 0, new ClientboundLevelChunkWithLightPacket(0, 0,
new byte[0], new CompoundTag(""), new BlockEntityInfo[0], new byte[0], NbtMap.EMPTY, new BlockEntityInfo[0],
new LightUpdateData(new BitSet(), new BitSet(), new BitSet(), new BitSet(), Collections.emptyList(), Collections.emptyList()) new LightUpdateData(new BitSet(), new BitSet(), new BitSet(), new BitSet(), Collections.emptyList(), Collections.emptyList())
), ),
new ClientboundLevelChunkWithLightPacket(1, 1, new ClientboundLevelChunkWithLightPacket(1, 1,
new byte[256], new CompoundTag(""), new BlockEntityInfo[] { new byte[256], NbtMap.EMPTY, new BlockEntityInfo[] {
new BlockEntityInfo(1, 0, 1, BlockEntityType.CHEST, null) new BlockEntityInfo(1, 0, 1, BlockEntityType.CHEST, null)
}, new LightUpdateData(new BitSet(), new BitSet(), new BitSet(), new BitSet(), Collections.emptyList(), Collections.emptyList()) }, new LightUpdateData(new BitSet(), new BitSet(), new BitSet(), new BitSet(), Collections.emptyList(), Collections.emptyList())
) )