Rename NBT and NBT_ARRAY types, add TagType

In theory the nameless compound tag type doesn't exist as it is written as any tag, but in practice is almost always cast and checked for its type, so we keep the extra CompoundTagType (nameless) and add the proper TagType (nameless, any tag) used for components
This commit is contained in:
Nassim Jahnke 2023-10-06 21:37:52 +10:00
parent def3bf9d4a
commit c211b10eaa
No known key found for this signature in database
GPG Key ID: EF6771C01F6EF02F
59 changed files with 231 additions and 154 deletions

View File

@ -39,7 +39,7 @@ public enum MetaType1_12 implements MetaType {
Direction(10, Type.VAR_INT),
OptUUID(11, Type.OPTIONAL_UUID),
BlockID(12, Type.VAR_INT),
NBTTag(13, Type.NBT);
NBTTag(13, Type.NAMED_COMPOUND_TAG);
private final int typeID;
private final Type type;

View File

@ -42,7 +42,7 @@ public enum MetaType1_13 implements MetaType {
Direction(11, Type.VAR_INT),
OptUUID(12, Type.OPTIONAL_UUID),
BlockID(13, Type.VAR_INT),
NBTTag(14, Type.NBT),
NBTTag(14, Type.NAMED_COMPOUND_TAG),
PARTICLE(15, Types1_13.PARTICLE);
private final int typeID;

View File

@ -42,7 +42,7 @@ public enum MetaType1_13_2 implements MetaType {
Direction(11, Type.VAR_INT),
OptUUID(12, Type.OPTIONAL_UUID),
BlockID(13, Type.VAR_INT),
NBTTag(14, Type.NBT),
NBTTag(14, Type.NAMED_COMPOUND_TAG),
PARTICLE(15, Types1_13_2.PARTICLE);
private final int typeID;

View File

@ -42,7 +42,7 @@ public enum MetaType1_14 implements MetaType {
Direction(11, Type.VAR_INT),
OptUUID(12, Type.OPTIONAL_UUID),
BlockID(13, Type.VAR_INT),
NBTTag(14, Type.NBT),
NBTTag(14, Type.NAMED_COMPOUND_TAG),
PARTICLE(15, Types1_14.PARTICLE),
VillagerData(16, Type.VILLAGER_DATA),
OptVarInt(17, Type.OPTIONAL_VAR_INT),

View File

@ -42,7 +42,7 @@ public enum MetaType1_16 implements MetaType {
DIRECTION(11, Type.VAR_INT),
OPT_UUID(12, Type.OPTIONAL_UUID),
BLOCK_STATE(13, Type.VAR_INT),
NBT(14, Type.NBT),
NBT(14, Type.NAMED_COMPOUND_TAG),
PARTICLE(15, Types1_16.PARTICLE),
VILLAGER_DATA(16, Type.VILLAGER_DATA),
OPT_VAR_INT(17, Type.OPTIONAL_VAR_INT),

View File

@ -42,7 +42,7 @@ public enum MetaType1_17 implements MetaType {
DIRECTION(11, Type.VAR_INT),
OPT_UUID(12, Type.OPTIONAL_UUID),
BLOCK_STATE(13, Type.VAR_INT),
NBT(14, Type.NBT),
NBT(14, Type.NAMED_COMPOUND_TAG),
PARTICLE(15, Types1_17.PARTICLE),
VILLAGER_DATA(16, Type.VILLAGER_DATA),
OPT_VAR_INT(17, Type.OPTIONAL_VAR_INT),

View File

@ -42,7 +42,7 @@ public enum MetaType1_18 implements MetaType {
DIRECTION(11, Type.VAR_INT),
OPT_UUID(12, Type.OPTIONAL_UUID),
BLOCK_STATE(13, Type.VAR_INT),
NBT(14, Type.NBT),
NBT(14, Type.NAMED_COMPOUND_TAG),
PARTICLE(15, Types1_18.PARTICLE),
VILLAGER_DATA(16, Type.VILLAGER_DATA),
OPT_VAR_INT(17, Type.OPTIONAL_VAR_INT),

View File

@ -42,7 +42,7 @@ public final class MetaTypes1_13 extends AbstractMetaTypes {
public final MetaType directionType = add(11, Type.VAR_INT);
public final MetaType optionalUUIDType = add(12, Type.OPTIONAL_UUID);
public final MetaType blockStateType = add(13, Type.VAR_INT);
public final MetaType nbtType = add(14, Type.NBT);
public final MetaType nbtType = add(14, Type.NAMED_COMPOUND_TAG);
public final MetaType particleType;
public MetaTypes1_13(final ParticleType particleType) {

View File

@ -42,7 +42,7 @@ public final class MetaTypes1_13_2 extends AbstractMetaTypes {
public final MetaType directionType = add(11, Type.VAR_INT);
public final MetaType optionalUUIDType = add(12, Type.OPTIONAL_UUID);
public final MetaType blockStateType = add(13, Type.VAR_INT);
public final MetaType nbtType = add(14, Type.NBT);
public final MetaType nbtType = add(14, Type.NAMED_COMPOUND_TAG);
public final MetaType particleType;
public MetaTypes1_13_2(final ParticleType particleType) {

View File

@ -42,7 +42,7 @@ public final class MetaTypes1_14 extends AbstractMetaTypes {
public final MetaType directionType = add(11, Type.VAR_INT);
public final MetaType optionalUUIDType = add(12, Type.OPTIONAL_UUID);
public final MetaType blockStateType = add(13, Type.VAR_INT);
public final MetaType nbtType = add(14, Type.NBT);
public final MetaType nbtType = add(14, Type.NAMED_COMPOUND_TAG);
public final MetaType particleType;
public final MetaType villagerDatatType = add(16, Type.VILLAGER_DATA);
public final MetaType optionalVarIntType = add(17, Type.OPTIONAL_VAR_INT);

View File

@ -42,7 +42,7 @@ public final class MetaTypes1_19 extends AbstractMetaTypes {
public final MetaType directionType = add(11, Type.VAR_INT);
public final MetaType optionalUUIDType = add(12, Type.OPTIONAL_UUID);
public final MetaType blockStateType = add(13, Type.VAR_INT);
public final MetaType nbtType = add(14, Type.NBT);
public final MetaType nbtType = add(14, Type.NAMED_COMPOUND_TAG);
public final MetaType particleType;
public final MetaType villagerDatatType = add(16, Type.VILLAGER_DATA);
public final MetaType optionalVarIntType = add(17, Type.OPTIONAL_VAR_INT);

View File

@ -43,7 +43,7 @@ public final class MetaTypes1_19_3 extends AbstractMetaTypes {
public final MetaType directionType = add(12, Type.VAR_INT);
public final MetaType optionalUUIDType = add(13, Type.OPTIONAL_UUID);
public final MetaType blockStateType = add(14, Type.VAR_INT);
public final MetaType nbtType = add(15, Type.NBT);
public final MetaType nbtType = add(15, Type.NAMED_COMPOUND_TAG);
public final MetaType particleType;
public final MetaType villagerDatatType = add(17, Type.VILLAGER_DATA);
public final MetaType optionalVarIntType = add(18, Type.OPTIONAL_VAR_INT);

View File

@ -44,7 +44,7 @@ public final class MetaTypes1_19_4 extends AbstractMetaTypes {
public final MetaType optionalUUIDType = add(13, Type.OPTIONAL_UUID);
public final MetaType blockStateType = add(14, Type.VAR_INT);
public final MetaType optionalBlockStateType = add(15, Type.VAR_INT);
public final MetaType nbtType = add(16, Type.NBT);
public final MetaType nbtType = add(16, Type.NAMED_COMPOUND_TAG);
public final MetaType particleType;
public final MetaType villagerDatatType = add(18, Type.VILLAGER_DATA);
public final MetaType optionalVarIntType = add(19, Type.OPTIONAL_VAR_INT);

View File

@ -44,7 +44,7 @@ public final class MetaTypes1_20_2 extends AbstractMetaTypes {
public final MetaType optionalUUIDType = add(13, Type.OPTIONAL_UUID);
public final MetaType blockStateType = add(14, Type.VAR_INT);
public final MetaType optionalBlockStateType = add(15, Type.VAR_INT);
public final MetaType nbtType = add(16, Type.NAMELESS_NBT);
public final MetaType nbtType = add(16, Type.COMPOUND_TAG);
public final MetaType particleType;
public final MetaType villagerDatatType = add(18, Type.VILLAGER_DATA);
public final MetaType optionalVarIntType = add(19, Type.OPTIONAL_VAR_INT);

View File

@ -33,8 +33,8 @@ public final class MetaTypes1_20_3 extends AbstractMetaTypes {
public final MetaType longType = add(2, Type.VAR_LONG);
public final MetaType floatType = add(3, Type.FLOAT);
public final MetaType stringType = add(4, Type.STRING);
public final MetaType componentType = add(5, Type.NAMELESS_NBT);
public final MetaType optionalComponentType = add(6, Type.OPTIONAL_NAMELESS_NBT);
public final MetaType componentType = add(5, Type.COMPOUND_TAG);
public final MetaType optionalComponentType = add(6, Type.OPTIONAL_COMPOUND_TAG);
public final MetaType itemType = add(7, Type.ITEM1_20_2);
public final MetaType booleanType = add(8, Type.BOOLEAN);
public final MetaType rotationType = add(9, Type.ROTATION);
@ -44,7 +44,7 @@ public final class MetaTypes1_20_3 extends AbstractMetaTypes {
public final MetaType optionalUUIDType = add(13, Type.OPTIONAL_UUID);
public final MetaType blockStateType = add(14, Type.VAR_INT);
public final MetaType optionalBlockStateType = add(15, Type.VAR_INT);
public final MetaType nbtType = add(16, Type.NAMELESS_NBT);
public final MetaType nbtType = add(16, Type.COMPOUND_TAG);
public final MetaType particleType;
public final MetaType villagerDatatType = add(18, Type.VILLAGER_DATA);
public final MetaType optionalVarIntType = add(19, Type.OPTIONAL_VAR_INT);

View File

@ -23,6 +23,7 @@
package com.viaversion.viaversion.api.type;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.google.gson.JsonElement;
import com.viaversion.viaversion.api.minecraft.BlockChangeRecord;
import com.viaversion.viaversion.api.minecraft.EulerAngle;
@ -37,6 +38,7 @@ import com.viaversion.viaversion.api.minecraft.VillagerData;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.minecraft.metadata.ChunkPosition;
import com.viaversion.viaversion.api.type.types.ArrayType;
import com.viaversion.viaversion.api.type.types.BitSetType;
import com.viaversion.viaversion.api.type.types.BooleanType;
import com.viaversion.viaversion.api.type.types.ByteArrayType;
import com.viaversion.viaversion.api.type.types.ByteType;
@ -60,6 +62,7 @@ import com.viaversion.viaversion.api.type.types.VarLongType;
import com.viaversion.viaversion.api.type.types.VoidType;
import com.viaversion.viaversion.api.type.types.minecraft.BlockChangeRecordType;
import com.viaversion.viaversion.api.type.types.minecraft.ChunkPositionType;
import com.viaversion.viaversion.api.type.types.minecraft.CompoundTagType;
import com.viaversion.viaversion.api.type.types.minecraft.EulerAngleType;
import com.viaversion.viaversion.api.type.types.minecraft.FlatItemArrayType;
import com.viaversion.viaversion.api.type.types.minecraft.FlatItemType;
@ -69,14 +72,14 @@ import com.viaversion.viaversion.api.type.types.minecraft.GlobalPositionType;
import com.viaversion.viaversion.api.type.types.minecraft.Item1_20_2Type;
import com.viaversion.viaversion.api.type.types.minecraft.ItemArrayType;
import com.viaversion.viaversion.api.type.types.minecraft.ItemType;
import com.viaversion.viaversion.api.type.types.minecraft.NBTType;
import com.viaversion.viaversion.api.type.types.minecraft.NamelessNBTType;
import com.viaversion.viaversion.api.type.types.minecraft.NamedCompoundTagType;
import com.viaversion.viaversion.api.type.types.minecraft.OptionalVarIntType;
import com.viaversion.viaversion.api.type.types.minecraft.PlayerMessageSignatureType;
import com.viaversion.viaversion.api.type.types.minecraft.Position1_14Type;
import com.viaversion.viaversion.api.type.types.minecraft.PositionType;
import com.viaversion.viaversion.api.type.types.minecraft.ProfileKeyType;
import com.viaversion.viaversion.api.type.types.minecraft.QuaternionType;
import com.viaversion.viaversion.api.type.types.minecraft.TagType;
import com.viaversion.viaversion.api.type.types.minecraft.VarLongBlockChangeRecordType;
import com.viaversion.viaversion.api.type.types.minecraft.Vector3fType;
import com.viaversion.viaversion.api.type.types.minecraft.VectorType;
@ -165,10 +168,18 @@ public abstract class Type<T> implements ByteBufReader<T>, ByteBufWriter<T> {
public static final Type<Vector> VECTOR = new VectorType();
public static final Type<Vector3f> VECTOR3F = new Vector3fType();
public static final Type<Quaternion> QUATERNION = new QuaternionType();
public static final Type<CompoundTag> NBT = new NBTType();
public static final Type<CompoundTag> NAMELESS_NBT = new NamelessNBTType();
public static final Type<CompoundTag> OPTIONAL_NAMELESS_NBT = new NamelessNBTType.OptionalNamelessNBTType();
public static final Type<CompoundTag[]> NBT_ARRAY = new ArrayType<>(Type.NBT);
public static final Type<CompoundTag> NAMED_COMPOUND_TAG = new NamedCompoundTagType();
public static final Type<CompoundTag[]> NAMED_COMPOUND_TAG_ARRAY = new ArrayType<>(Type.NAMED_COMPOUND_TAG);
public static final Type<CompoundTag> COMPOUND_TAG = new CompoundTagType();
public static final Type<CompoundTag> OPTIONAL_COMPOUND_TAG = new CompoundTagType.OptionalCompoundTagType();
public static final Type<Tag> TAG = new TagType();
public static final Type<Tag> OPTIONAL_TAG = new TagType.OptionalTagType();
@Deprecated/*(forRemoval=true)*/
public static final Type<CompoundTag> NBT = NAMED_COMPOUND_TAG;
@Deprecated/*(forRemoval=true)*/
public static final Type<CompoundTag[]> NBT_ARRAY = NAMED_COMPOUND_TAG_ARRAY;
public static final Type<GlobalPosition> GLOBAL_POSITION = new GlobalPositionType();
public static final Type<GlobalPosition> OPTIONAL_GLOBAL_POSITION = new GlobalPositionType.OptionalGlobalPositionType();
public static final Type<ChunkPosition> CHUNK_POSITION = new ChunkPositionType();
@ -191,6 +202,10 @@ public abstract class Type<T> implements ByteBufReader<T>, ByteBufWriter<T> {
public static final Type<PlayerMessageSignature> OPTIONAL_PLAYER_MESSAGE_SIGNATURE = new PlayerMessageSignatureType.OptionalPlayerMessageSignatureType();
public static final Type<PlayerMessageSignature[]> PLAYER_MESSAGE_SIGNATURE_ARRAY = new ArrayType<>(PLAYER_MESSAGE_SIGNATURE);
public static final BitSetType PROFILE_ACTIONS_ENUM = new BitSetType(6);
public static final ByteArrayType SIGNATURE_BYTES = new ByteArrayType(256);
public static final ByteArrayType.OptionalByteArrayType OPTIONAL_SIGNATURE_BYTES = new ByteArrayType.OptionalByteArrayType(256);
/* 1.13 Flat Item (no data) */
public static final Type<Item> FLAT_ITEM = new FlatItemType();
public static final Type<Item> FLAT_VAR_INT_ITEM = new FlatVarIntItemType();

View File

@ -27,26 +27,33 @@ import com.viaversion.viaversion.api.type.OptionalType;
import com.viaversion.viaversion.api.type.Type;
import io.netty.buffer.ByteBuf;
public class NamelessNBTType extends Type<CompoundTag> {
public NamelessNBTType() {
/**
* Compound tag type, functionally equivalent to {@link TagType} with an additional cast.
* <p>
* On the network, this is technically written as any tag, but almost always cast to and checked
* as a CompoundTag, so we provide this type for convenience.
*/
public class CompoundTagType extends Type<CompoundTag> {
public CompoundTagType() {
super(CompoundTag.class);
}
@Override
public CompoundTag read(final ByteBuf buffer) throws Exception {
return NBTType.read(buffer, false);
return NamedCompoundTagType.read(buffer, false);
}
@Override
public void write(final ByteBuf buffer, final CompoundTag tag) throws Exception {
NBTType.write(buffer, tag, null);
public void write(final ByteBuf buffer, final CompoundTag object) throws Exception {
NamedCompoundTagType.write(buffer, object, null);
}
public static final class OptionalNamelessNBTType extends OptionalType<CompoundTag> {
public static final class OptionalCompoundTagType extends OptionalType<CompoundTag> {
public OptionalNamelessNBTType() {
super(Type.NAMELESS_NBT);
public OptionalCompoundTagType() {
super(Type.COMPOUND_TAG);
}
}
}

View File

@ -42,7 +42,7 @@ public class FlatItemType extends BaseItemType {
Item item = new DataItem();
item.setIdentifier(id);
item.setAmount(buffer.readByte());
item.setTag(Type.NBT.read(buffer));
item.setTag(Type.NAMED_COMPOUND_TAG.read(buffer));
return item;
}
}
@ -54,7 +54,7 @@ public class FlatItemType extends BaseItemType {
} else {
buffer.writeShort(object.identifier());
buffer.writeByte(object.amount());
Type.NBT.write(buffer, object.tag());
Type.NAMED_COMPOUND_TAG.write(buffer, object.tag());
}
}
}

View File

@ -41,7 +41,7 @@ public class FlatVarIntItemType extends BaseItemType {
Item item = new DataItem();
item.setIdentifier(VAR_INT.readPrimitive(buffer));
item.setAmount(buffer.readByte());
item.setTag(NBT.read(buffer));
item.setTag(NAMED_COMPOUND_TAG.read(buffer));
return item;
}
}
@ -54,7 +54,7 @@ public class FlatVarIntItemType extends BaseItemType {
buffer.writeBoolean(true);
VAR_INT.writePrimitive(buffer, object.identifier());
buffer.writeByte(object.amount());
NBT.write(buffer, object.tag());
NAMED_COMPOUND_TAG.write(buffer, object.tag());
}
}
}

View File

@ -42,7 +42,7 @@ public class Item1_20_2Type extends BaseItemType {
final Item item = new DataItem();
item.setIdentifier(VAR_INT.readPrimitive(buffer));
item.setAmount(buffer.readByte());
item.setTag(NAMELESS_NBT.read(buffer));
item.setTag(COMPOUND_TAG.read(buffer));
return item;
}
@ -54,7 +54,7 @@ public class Item1_20_2Type extends BaseItemType {
buffer.writeBoolean(true);
VAR_INT.writePrimitive(buffer, object.identifier());
buffer.writeByte(object.amount());
NAMELESS_NBT.write(buffer, object.tag());
COMPOUND_TAG.write(buffer, object.tag());
}
}
}

View File

@ -43,7 +43,7 @@ public class ItemType extends BaseItemType {
item.setIdentifier(id);
item.setAmount(buffer.readByte());
item.setData(buffer.readShort());
item.setTag(NBT.read(buffer));
item.setTag(NAMED_COMPOUND_TAG.read(buffer));
return item;
}
}
@ -56,7 +56,7 @@ public class ItemType extends BaseItemType {
buffer.writeShort(object.identifier());
buffer.writeByte(object.amount());
buffer.writeShort(object.data());
NBT.write(buffer, object.tag());
NAMED_COMPOUND_TAG.write(buffer, object.tag());
}
}
}

View File

@ -23,6 +23,7 @@
package com.viaversion.viaversion.api.type.types.minecraft;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.github.steveice10.opennbt.tag.limiter.TagLimiter;
import com.viaversion.viaversion.api.type.Type;
import io.netty.buffer.ByteBuf;
@ -31,12 +32,12 @@ import io.netty.buffer.ByteBufOutputStream;
import java.io.IOException;
import org.checkerframework.checker.nullness.qual.Nullable;
public class NBTType extends Type<CompoundTag> {
public class NamedCompoundTagType extends Type<CompoundTag> {
private static final int MAX_NBT_BYTES = 2097152; // 2mb
private static final int MAX_NESTING_LEVEL = 512;
public static final int MAX_NBT_BYTES = 2097152; // 2mb
public static final int MAX_NESTING_LEVEL = 512;
public NBTType() {
public NamedCompoundTagType() {
super(CompoundTag.class);
}
@ -69,14 +70,14 @@ public class NBTType extends Type<CompoundTag> {
return tag;
}
public static void write(final ByteBuf buffer, final CompoundTag tag, final @Nullable String name) throws Exception {
public static void write(final ByteBuf buffer, final Tag tag, final @Nullable String name) throws Exception {
if (tag == null) {
buffer.writeByte(0);
return;
}
final ByteBufOutputStream out = new ByteBufOutputStream(buffer);
out.writeByte(CompoundTag.ID);
out.writeByte(tag.getTagId());
if (name != null) {
out.writeUTF(name);
}

View File

@ -0,0 +1,63 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2023 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.type.types.minecraft;
import com.github.steveice10.opennbt.tag.TagRegistry;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.github.steveice10.opennbt.tag.limiter.TagLimiter;
import com.viaversion.viaversion.api.type.OptionalType;
import com.viaversion.viaversion.api.type.Type;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufInputStream;
public class TagType extends Type<Tag> {
public TagType() {
super(Tag.class);
}
@Override
public Tag read(final ByteBuf buffer) throws Exception {
final byte id = buffer.readByte();
if (id == 0) {
return null;
}
final TagLimiter tagLimiter = TagLimiter.create(NamedCompoundTagType.MAX_NBT_BYTES, NamedCompoundTagType.MAX_NESTING_LEVEL);
final Tag tag = TagRegistry.createInstance(id);
tag.read(new ByteBufInputStream(buffer), tagLimiter);
return tag;
}
@Override
public void write(final ByteBuf buffer, final Tag tag) throws Exception {
NamedCompoundTagType.write(buffer, tag, null);
}
public static final class OptionalTagType extends OptionalType<Tag> {
public OptionalTagType() {
super(Type.TAG);
}
}
}

View File

@ -39,7 +39,7 @@ public class BlockEntityType1_18 extends Type<BlockEntity> {
final byte xz = buffer.readByte();
final short y = buffer.readShort();
final int typeId = Type.VAR_INT.readPrimitive(buffer);
final CompoundTag tag = Type.NBT.read(buffer);
final CompoundTag tag = Type.NAMED_COMPOUND_TAG.read(buffer);
return new BlockEntityImpl(xz, y, typeId, tag);
}
@ -48,6 +48,6 @@ public class BlockEntityType1_18 extends Type<BlockEntity> {
buffer.writeByte(entity.packedXZ());
buffer.writeShort(entity.y());
Type.VAR_INT.writePrimitive(buffer, entity.typeId());
Type.NBT.write(buffer, entity.tag());
Type.NAMED_COMPOUND_TAG.write(buffer, entity.tag());
}
}

View File

@ -39,7 +39,7 @@ public class BlockEntityType1_20_2 extends Type<BlockEntity> {
final byte xz = buffer.readByte();
final short y = buffer.readShort();
final int typeId = Type.VAR_INT.readPrimitive(buffer);
final CompoundTag tag = Type.NAMELESS_NBT.read(buffer);
final CompoundTag tag = Type.COMPOUND_TAG.read(buffer);
return new BlockEntityImpl(xz, y, typeId, tag);
}
@ -48,6 +48,6 @@ public class BlockEntityType1_20_2 extends Type<BlockEntity> {
buffer.writeByte(entity.packedXZ());
buffer.writeShort(entity.y());
Type.VAR_INT.writePrimitive(buffer, entity.typeId());
Type.NAMELESS_NBT.write(buffer, entity.tag());
Type.COMPOUND_TAG.write(buffer, entity.tag());
}
}

View File

@ -20,7 +20,6 @@ package com.viaversion.viaversion.protocol;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.debug.DebugHandler;
import com.viaversion.viaversion.api.platform.ViaPlatform;
import com.viaversion.viaversion.api.protocol.AbstractSimpleProtocol;
import com.viaversion.viaversion.api.protocol.Protocol;
import com.viaversion.viaversion.api.protocol.ProtocolPipeline;
@ -126,14 +125,9 @@ public class ProtocolPipelineImpl extends AbstractSimpleProtocol implements Prot
}
private void logPacket(Direction direction, State state, PacketWrapper packetWrapper, int originalID) {
// Debug packet
int clientProtocol = userConnection.getProtocolInfo().getProtocolVersion();
ViaPlatform<?> platform = Via.getPlatform();
String actualUsername = packetWrapper.user().getProtocolInfo().getUsername();
String username = actualUsername != null ? actualUsername + " " : "";
platform.getLogger().log(Level.INFO, "{0}{1} {2}: {3} ({4}) -> {5} ({6}) [{7}] {8}",
Via.getPlatform().getLogger().log(Level.INFO, "{0}{1} {2}: {3} ({4}) -> {5} ({6}) [{7}] {8}",
new Object[]{
username,
direction,
@ -142,7 +136,7 @@ public class ProtocolPipelineImpl extends AbstractSimpleProtocol implements Prot
AbstractSimpleProtocol.toNiceHex(originalID),
packetWrapper.getId(),
AbstractSimpleProtocol.toNiceHex(packetWrapper.getId()),
Integer.toString(clientProtocol),
Integer.toString(userConnection.getProtocolInfo().getProtocolVersion()),
packetWrapper
});
}

View File

@ -84,6 +84,11 @@ public class BaseProtocol extends AbstractProtocol {
// Add Base Protocol
pipeline.add(Via.getManager().getProtocolManager().getBaseProtocol(serverProtocol));
if (Via.getManager().isDebug()) {
Via.getPlatform().getLogger().info("User connected with protocol: " + info.getProtocolVersion() + " and serverProtocol: " + info.getServerProtocolVersion());
Via.getPlatform().getLogger().info("Protocol pipeline: " + pipeline.pipes());
}
// Change state
if (state == 1) {
info.setState(State.STATUS);

View File

@ -190,10 +190,10 @@ public class Protocol1_11To1_10 extends AbstractProtocol<ClientboundPackets1_9_3
public void register() {
map(Type.POSITION); // 0 - Position
map(Type.UNSIGNED_BYTE); // 1 - Action
map(Type.NBT); // 2 - NBT data
map(Type.NAMED_COMPOUND_TAG); // 2 - NBT data
handler(wrapper -> {
CompoundTag tag = wrapper.get(Type.NBT, 0);
CompoundTag tag = wrapper.get(Type.NAMED_COMPOUND_TAG, 0);
if (wrapper.get(Type.UNSIGNED_BYTE, 0) == 1)
EntityIdRewriter.toClientSpawner(tag);

View File

@ -104,12 +104,12 @@ public class WorldPackets {
public void register() {
map(Type.POSITION); // 0 - Location
map(Type.UNSIGNED_BYTE); // 1 - Action
map(Type.NBT); // 2 - NBT data
map(Type.NAMED_COMPOUND_TAG); // 2 - NBT data
handler(wrapper -> {
Position position = wrapper.get(Type.POSITION, 0);
short action = wrapper.get(Type.UNSIGNED_BYTE, 0);
CompoundTag tag = wrapper.get(Type.NBT, 0);
CompoundTag tag = wrapper.get(Type.NAMED_COMPOUND_TAG, 0);
BlockEntityProvider provider = Via.getManager().getProviders().get(BlockEntityProvider.class);
int newId = provider.transform(wrapper.user(), position, tag, true);

View File

@ -73,7 +73,7 @@ public class Chunk1_13Type extends PartialType<Chunk, ClientWorld> {
}
}
List<CompoundTag> nbtData = new ArrayList<>(Arrays.asList(Type.NBT_ARRAY.read(input)));
List<CompoundTag> nbtData = new ArrayList<>(Arrays.asList(Type.NAMED_COMPOUND_TAG_ARRAY.read(input)));
// Read all the remaining bytes (workaround for #681)
if (input.readableBytes() > 0) {
@ -121,7 +121,7 @@ public class Chunk1_13Type extends PartialType<Chunk, ClientWorld> {
}
// Write Block Entities
Type.NBT_ARRAY.write(output, chunk.getBlockEntities().toArray(new CompoundTag[0]));
Type.NAMED_COMPOUND_TAG_ARRAY.write(output, chunk.getBlockEntities().toArray(new CompoundTag[0]));
}
@Override

View File

@ -43,7 +43,7 @@ public class Chunk1_14Type extends Type<Chunk> {
boolean fullChunk = input.readBoolean();
int primaryBitmask = Type.VAR_INT.readPrimitive(input);
CompoundTag heightMap = Type.NBT.read(input);
CompoundTag heightMap = Type.NAMED_COMPOUND_TAG.read(input);
Type.VAR_INT.readPrimitive(input);
@ -65,7 +65,7 @@ public class Chunk1_14Type extends Type<Chunk> {
}
}
List<CompoundTag> nbtData = new ArrayList<>(Arrays.asList(Type.NBT_ARRAY.read(input)));
List<CompoundTag> nbtData = new ArrayList<>(Arrays.asList(Type.NAMED_COMPOUND_TAG_ARRAY.read(input)));
// Read all the remaining bytes (workaround for #681)
if (input.readableBytes() > 0) {
@ -85,7 +85,7 @@ public class Chunk1_14Type extends Type<Chunk> {
output.writeBoolean(chunk.isFullChunk());
Type.VAR_INT.writePrimitive(output, chunk.getBitmask());
Type.NBT.write(output, chunk.getHeightMap());
Type.NAMED_COMPOUND_TAG.write(output, chunk.getHeightMap());
ByteBuf buf = output.alloc().buffer();
try {
@ -111,7 +111,7 @@ public class Chunk1_14Type extends Type<Chunk> {
}
// Write Block Entities
Type.NBT_ARRAY.write(output, chunk.getBlockEntities().toArray(new CompoundTag[0]));
Type.NAMED_COMPOUND_TAG_ARRAY.write(output, chunk.getBlockEntities().toArray(new CompoundTag[0]));
}
@Override

View File

@ -44,7 +44,7 @@ public class Chunk1_15Type extends Type<Chunk> {
boolean fullChunk = input.readBoolean();
int primaryBitmask = Type.VAR_INT.readPrimitive(input);
CompoundTag heightMap = Type.NBT.read(input);
CompoundTag heightMap = Type.NAMED_COMPOUND_TAG.read(input);
int[] biomeData = fullChunk ? new int[1024] : null;
if (fullChunk) {
@ -66,7 +66,7 @@ public class Chunk1_15Type extends Type<Chunk> {
sections[i] = section;
}
List<CompoundTag> nbtData = new ArrayList<>(Arrays.asList(Type.NBT_ARRAY.read(input)));
List<CompoundTag> nbtData = new ArrayList<>(Arrays.asList(Type.NAMED_COMPOUND_TAG_ARRAY.read(input)));
// Read all the remaining bytes (workaround for #681)
if (input.readableBytes() > 0) {
@ -86,7 +86,7 @@ public class Chunk1_15Type extends Type<Chunk> {
output.writeBoolean(chunk.isFullChunk());
Type.VAR_INT.writePrimitive(output, chunk.getBitmask());
Type.NBT.write(output, chunk.getHeightMap());
Type.NAMED_COMPOUND_TAG.write(output, chunk.getHeightMap());
// Write biome data
if (chunk.isBiomeData()) {
@ -112,7 +112,7 @@ public class Chunk1_15Type extends Type<Chunk> {
}
// Write Block Entities
Type.NBT_ARRAY.write(output, chunk.getBlockEntities().toArray(EMPTY_COMPOUNDS));
Type.NAMED_COMPOUND_TAG_ARRAY.write(output, chunk.getBlockEntities().toArray(EMPTY_COMPOUNDS));
}
@Override

View File

@ -52,12 +52,12 @@ public class EntityPackets {
map(Type.STRING_ARRAY); // World List
handler(wrapper -> {
// Throw away the old dimension registry, extra conversion would be too hard of a hit
wrapper.read(Type.NBT);
wrapper.write(Type.NBT, protocol.getMappingData().getDimensionRegistry());
wrapper.read(Type.NAMED_COMPOUND_TAG);
wrapper.write(Type.NAMED_COMPOUND_TAG, protocol.getMappingData().getDimensionRegistry());
// Instead of the dimension's resource key, it now just wants the data directly
String dimensionType = wrapper.read(Type.STRING);
wrapper.write(Type.NBT, getDimensionData(dimensionType));
wrapper.write(Type.NAMED_COMPOUND_TAG, getDimensionData(dimensionType));
});
map(Type.STRING); // Dimension
map(Type.LONG); // Seed
@ -69,7 +69,7 @@ public class EntityPackets {
protocol.registerClientbound(ClientboundPackets1_16.RESPAWN, wrapper -> {
String dimensionType = wrapper.read(Type.STRING);
wrapper.write(Type.NBT, getDimensionData(dimensionType));
wrapper.write(Type.NAMED_COMPOUND_TAG, getDimensionData(dimensionType));
});
}

View File

@ -44,7 +44,7 @@ public class Chunk1_16_2Type extends Type<Chunk> {
boolean fullChunk = input.readBoolean();
int primaryBitmask = Type.VAR_INT.readPrimitive(input);
CompoundTag heightMap = Type.NBT.read(input);
CompoundTag heightMap = Type.NAMED_COMPOUND_TAG.read(input);
int[] biomeData = null;
if (fullChunk) {
@ -64,7 +64,7 @@ public class Chunk1_16_2Type extends Type<Chunk> {
sections[i] = section;
}
List<CompoundTag> nbtData = new ArrayList<>(Arrays.asList(Type.NBT_ARRAY.read(input)));
List<CompoundTag> nbtData = new ArrayList<>(Arrays.asList(Type.NAMED_COMPOUND_TAG_ARRAY.read(input)));
// Read all the remaining bytes (workaround for #681)
if (input.readableBytes() > 0) {
@ -84,7 +84,7 @@ public class Chunk1_16_2Type extends Type<Chunk> {
output.writeBoolean(chunk.isFullChunk());
Type.VAR_INT.writePrimitive(output, chunk.getBitmask());
Type.NBT.write(output, chunk.getHeightMap());
Type.NAMED_COMPOUND_TAG.write(output, chunk.getHeightMap());
// Write biome data
if (chunk.isBiomeData()) {
@ -108,7 +108,7 @@ public class Chunk1_16_2Type extends Type<Chunk> {
}
// Write Block Entities
Type.NBT_ARRAY.write(output, chunk.getBlockEntities().toArray(EMPTY_COMPOUNDS));
Type.NAMED_COMPOUND_TAG_ARRAY.write(output, chunk.getBlockEntities().toArray(EMPTY_COMPOUNDS));
}
@Override

View File

@ -214,7 +214,7 @@ public class EntityPackets {
handler(wrapper -> {
wrapper.write(Type.BYTE, (byte) -1); // Previous gamemode, set to none
wrapper.write(Type.STRING_ARRAY, Arrays.copyOf(WORLD_NAMES, WORLD_NAMES.length)); // World list - only used for command completion
wrapper.write(Type.NBT, DIMENSIONS_TAG.clone()); // Dimension registry
wrapper.write(Type.NAMED_COMPOUND_TAG, DIMENSIONS_TAG.clone()); // Dimension registry
});
handler(DIMENSION_HANDLER); // Dimension
map(Type.LONG); // Seed

View File

@ -94,7 +94,7 @@ public class WorldPackets {
protocol.registerClientbound(ClientboundPackets1_15.BLOCK_ENTITY_DATA, wrapper -> {
wrapper.passthrough(Type.POSITION1_14); // Position
wrapper.passthrough(Type.UNSIGNED_BYTE); // Action
CompoundTag tag = wrapper.passthrough(Type.NBT);
CompoundTag tag = wrapper.passthrough(Type.NAMED_COMPOUND_TAG);
handleBlockEntity(protocol, tag);
});

View File

@ -45,7 +45,7 @@ public class Chunk1_16Type extends Type<Chunk> {
boolean fullChunk = input.readBoolean();
boolean ignoreOldLightData = input.readBoolean();
int primaryBitmask = Type.VAR_INT.readPrimitive(input);
CompoundTag heightMap = Type.NBT.read(input);
CompoundTag heightMap = Type.NAMED_COMPOUND_TAG.read(input);
int[] biomeData = fullChunk ? new int[1024] : null;
if (fullChunk) {
@ -67,7 +67,7 @@ public class Chunk1_16Type extends Type<Chunk> {
sections[i] = section;
}
List<CompoundTag> nbtData = new ArrayList<>(Arrays.asList(Type.NBT_ARRAY.read(input)));
List<CompoundTag> nbtData = new ArrayList<>(Arrays.asList(Type.NAMED_COMPOUND_TAG_ARRAY.read(input)));
// Read all the remaining bytes (workaround for #681)
if (input.readableBytes() > 0) {
@ -88,7 +88,7 @@ public class Chunk1_16Type extends Type<Chunk> {
output.writeBoolean(chunk.isFullChunk());
output.writeBoolean(chunk.isIgnoreOldLightData());
Type.VAR_INT.writePrimitive(output, chunk.getBitmask());
Type.NBT.write(output, chunk.getHeightMap());
Type.NAMED_COMPOUND_TAG.write(output, chunk.getHeightMap());
// Write biome data
if (chunk.isBiomeData()) {
@ -114,7 +114,7 @@ public class Chunk1_16Type extends Type<Chunk> {
}
// Write Block Entities
Type.NBT_ARRAY.write(output, chunk.getBlockEntities().toArray(EMPTY_COMPOUNDS));
Type.NAMED_COMPOUND_TAG_ARRAY.write(output, chunk.getBlockEntities().toArray(EMPTY_COMPOUNDS));
}
@Override

View File

@ -73,18 +73,18 @@ public final class EntityPackets extends EntityRewriter<ClientboundPackets1_16_2
map(Type.UNSIGNED_BYTE); // Gamemode
map(Type.BYTE); // Previous Gamemode
map(Type.STRING_ARRAY); // World List
map(Type.NBT); // Registry
map(Type.NBT); // Current dimension
map(Type.NAMED_COMPOUND_TAG); // Registry
map(Type.NAMED_COMPOUND_TAG); // Current dimension
handler(wrapper -> {
// Add new dimension fields
CompoundTag dimensionRegistry = wrapper.get(Type.NBT, 0).get("minecraft:dimension_type");
CompoundTag dimensionRegistry = wrapper.get(Type.NAMED_COMPOUND_TAG, 0).get("minecraft:dimension_type");
ListTag dimensions = dimensionRegistry.get("value");
for (Tag dimension : dimensions) {
CompoundTag dimensionCompound = ((CompoundTag) dimension).get("element");
addNewDimensionData(dimensionCompound);
}
CompoundTag currentDimensionTag = wrapper.get(Type.NBT, 1);
CompoundTag currentDimensionTag = wrapper.get(Type.NAMED_COMPOUND_TAG, 1);
addNewDimensionData(currentDimensionTag);
});
handler(playerTrackerHandler());
@ -92,7 +92,7 @@ public final class EntityPackets extends EntityRewriter<ClientboundPackets1_16_2
});
protocol.registerClientbound(ClientboundPackets1_16_2.RESPAWN, wrapper -> {
CompoundTag dimensionData = wrapper.passthrough(Type.NBT);
CompoundTag dimensionData = wrapper.passthrough(Type.NAMED_COMPOUND_TAG);
addNewDimensionData(dimensionData);
});

View File

@ -48,7 +48,7 @@ public final class Chunk1_17Type extends Type<Chunk> {
int chunkZ = input.readInt();
BitSet sectionsMask = BitSet.valueOf(Type.LONG_ARRAY_PRIMITIVE.read(input));
CompoundTag heightMap = Type.NBT.read(input);
CompoundTag heightMap = Type.NAMED_COMPOUND_TAG.read(input);
int[] biomeData = Type.VAR_INT_ARRAY_PRIMITIVE.read(input);
@ -65,7 +65,7 @@ public final class Chunk1_17Type extends Type<Chunk> {
sections[i] = section;
}
List<CompoundTag> nbtData = new ArrayList<>(Arrays.asList(Type.NBT_ARRAY.read(input)));
List<CompoundTag> nbtData = new ArrayList<>(Arrays.asList(Type.NAMED_COMPOUND_TAG_ARRAY.read(input)));
// Read all the remaining bytes (workaround for #681)
if (input.readableBytes() > 0) {
@ -84,7 +84,7 @@ public final class Chunk1_17Type extends Type<Chunk> {
output.writeInt(chunk.getZ());
Type.LONG_ARRAY_PRIMITIVE.write(output, chunk.getChunkMask().toLongArray());
Type.NBT.write(output, chunk.getHeightMap());
Type.NAMED_COMPOUND_TAG.write(output, chunk.getHeightMap());
// Write biome data
Type.VAR_INT_ARRAY_PRIMITIVE.write(output, chunk.getBiomeData());
@ -106,7 +106,7 @@ public final class Chunk1_17Type extends Type<Chunk> {
}
// Write Block Entities
Type.NBT_ARRAY.write(output, chunk.getBlockEntities().toArray(EMPTY_COMPOUNDS));
Type.NAMED_COMPOUND_TAG_ARRAY.write(output, chunk.getBlockEntities().toArray(EMPTY_COMPOUNDS));
}
@Override

View File

@ -65,22 +65,22 @@ public final class Protocol1_18_2To1_18 extends AbstractProtocol<ClientboundPack
map(Type.UNSIGNED_BYTE); // Gamemode
map(Type.BYTE); // Previous Gamemode
map(Type.STRING_ARRAY); // World List
map(Type.NBT); // Registry
map(Type.NBT); // Current dimension data
map(Type.NAMED_COMPOUND_TAG); // Registry
map(Type.NAMED_COMPOUND_TAG); // Current dimension data
handler(wrapper -> {
final CompoundTag registry = wrapper.get(Type.NBT, 0);
final CompoundTag registry = wrapper.get(Type.NAMED_COMPOUND_TAG, 0);
final CompoundTag dimensionsHolder = registry.get("minecraft:dimension_type");
final ListTag dimensions = dimensionsHolder.get("value");
for (final Tag dimension : dimensions) {
addTagPrefix(((CompoundTag) dimension).get("element"));
}
addTagPrefix(wrapper.get(Type.NBT, 1));
addTagPrefix(wrapper.get(Type.NAMED_COMPOUND_TAG, 1));
});
}
});
registerClientbound(ClientboundPackets1_18.RESPAWN, wrapper -> addTagPrefix(wrapper.passthrough(Type.NBT)));
registerClientbound(ClientboundPackets1_18.RESPAWN, wrapper -> addTagPrefix(wrapper.passthrough(Type.NAMED_COMPOUND_TAG)));
}
private void addTagPrefix(CompoundTag tag) {

View File

@ -48,8 +48,8 @@ public final class EntityPackets extends EntityRewriter<ClientboundPackets1_17_1
map(Type.UNSIGNED_BYTE); // Gamemode
map(Type.BYTE); // Previous Gamemode
map(Type.STRING_ARRAY); // World List
map(Type.NBT); // Registry
map(Type.NBT); // Current dimension data
map(Type.NAMED_COMPOUND_TAG); // Registry
map(Type.NAMED_COMPOUND_TAG); // Current dimension data
map(Type.STRING); // World
map(Type.LONG); // Seed
map(Type.VAR_INT); // Max players
@ -65,7 +65,7 @@ public final class EntityPackets extends EntityRewriter<ClientboundPackets1_17_1
protocol.registerClientbound(ClientboundPackets1_17_1.RESPAWN, new PacketHandlers() {
@Override
public void register() {
map(Type.NBT); // Current dimension data
map(Type.NAMED_COMPOUND_TAG); // Current dimension data
map(Type.STRING); // World
handler(wrapper -> {
final String world = wrapper.get(Type.STRING, 0);

View File

@ -57,7 +57,7 @@ public final class WorldPackets {
final int newId = BlockEntityIds.newId(id);
wrapper.write(Type.VAR_INT, newId);
handleSpawners(newId, wrapper.passthrough(Type.NBT));
handleSpawners(newId, wrapper.passthrough(Type.NAMED_COMPOUND_TAG));
});
}
});

View File

@ -46,7 +46,7 @@ public final class Chunk1_18Type extends Type<Chunk> {
public Chunk read(final ByteBuf buffer) throws Exception {
final int chunkX = buffer.readInt();
final int chunkZ = buffer.readInt();
final CompoundTag heightMap = Type.NBT.read(buffer);
final CompoundTag heightMap = Type.NAMED_COMPOUND_TAG.read(buffer);
// Read sections
final ByteBuf sectionsBuf = buffer.readBytes(Type.VAR_INT.readPrimitive(buffer));
@ -76,7 +76,7 @@ public final class Chunk1_18Type extends Type<Chunk> {
buffer.writeInt(chunk.getX());
buffer.writeInt(chunk.getZ());
Type.NBT.write(buffer, chunk.getHeightMap());
Type.NAMED_COMPOUND_TAG.write(buffer, chunk.getHeightMap());
final ByteBuf sectionBuffer = buffer.alloc().buffer();
try {

View File

@ -178,7 +178,7 @@ public final class Protocol1_19_1To1_19 extends AbstractProtocol<ClientboundPack
final ChatTypeStorage chatTypeStorage = wrapper.user().get(ChatTypeStorage.class);
chatTypeStorage.clear();
final CompoundTag registry = wrapper.passthrough(Type.NBT);
final CompoundTag registry = wrapper.passthrough(Type.NAMED_COMPOUND_TAG);
final ListTag chatTypes = ((CompoundTag) registry.get("minecraft:chat_type")).get("value");
for (final Tag chatType : chatTypes) {
final CompoundTag chatTypeCompound = (CompoundTag) chatType;

View File

@ -30,7 +30,6 @@ import com.viaversion.viaversion.api.protocol.packet.State;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.BitSetType;
import com.viaversion.viaversion.api.type.types.ByteArrayType;
import com.viaversion.viaversion.api.type.types.minecraft.ParticleType;
import com.viaversion.viaversion.api.type.types.version.Types1_19_3;
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
@ -51,8 +50,6 @@ import java.util.UUID;
public final class Protocol1_19_3To1_19_1 extends AbstractProtocol<ClientboundPackets1_19_1, ClientboundPackets1_19_3, ServerboundPackets1_19_1, ServerboundPackets1_19_3> {
public static final MappingData MAPPINGS = new MappingDataBase("1.19", "1.19.3");
private static final ByteArrayType.OptionalByteArrayType OPTIONAL_MESSAGE_SIGNATURE_BYTES_TYPE = new ByteArrayType.OptionalByteArrayType(256);
private static final ByteArrayType MESSAGE_SIGNATURE_BYTES_TYPE = new ByteArrayType(256);
private static final BitSetType ACKNOWLEDGED_BIT_SET_TYPE = new BitSetType(20);
private static final UUID ZERO_UUID = new UUID(0, 0);
private static final byte[] EMPTY_BYTES = new byte[0];
@ -216,7 +213,7 @@ public final class Protocol1_19_3To1_19_1 extends AbstractProtocol<ClientboundPa
wrapper.write(Type.VAR_INT, 0);
for (int i = 0; i < signatures; i++) {
wrapper.read(Type.STRING); // Argument name
wrapper.read(MESSAGE_SIGNATURE_BYTES_TYPE); // Signature
wrapper.read(Type.SIGNATURE_BYTES); // Signature
}
wrapper.write(Type.BOOLEAN, false); // No signed preview
@ -240,7 +237,7 @@ public final class Protocol1_19_3To1_19_1 extends AbstractProtocol<ClientboundPa
create(Type.LONG, 0L);
handler(wrapper -> {
// Remove signature
wrapper.read(OPTIONAL_MESSAGE_SIGNATURE_BYTES_TYPE); // Signature
wrapper.read(Type.OPTIONAL_SIGNATURE_BYTES); // Signature
wrapper.write(Type.BYTE_ARRAY_PRIMITIVE, EMPTY_BYTES);
wrapper.write(Type.BOOLEAN, false); // No signed preview

View File

@ -23,7 +23,6 @@ import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.BitSetType;
import com.viaversion.viaversion.api.type.types.version.Types1_19;
import com.viaversion.viaversion.api.type.types.version.Types1_19_3;
import com.viaversion.viaversion.protocols.protocol1_19_1to1_19.ClientboundPackets1_19_1;
@ -35,8 +34,6 @@ import java.util.UUID;
public final class EntityPackets extends EntityRewriter<ClientboundPackets1_19_1, Protocol1_19_3To1_19_1> {
private static final BitSetType PROFILE_ACTIONS_ENUM_TYPE = new BitSetType(6);
public EntityPackets(final Protocol1_19_3To1_19_1 protocol) {
super(protocol);
}
@ -55,7 +52,7 @@ public final class EntityPackets extends EntityRewriter<ClientboundPackets1_19_1
map(Type.UNSIGNED_BYTE); // Gamemode
map(Type.BYTE); // Previous Gamemode
map(Type.STRING_ARRAY); // World List
map(Type.NBT); // Dimension registry
map(Type.NAMED_COMPOUND_TAG); // Dimension registry
map(Type.STRING); // Dimension key
map(Type.STRING); // World
handler(dimensionDataHandler());
@ -116,7 +113,7 @@ public final class EntityPackets extends EntityRewriter<ClientboundPackets1_19_1
set.set(action == 1 ? action + 1 : action + 2);
}
wrapper.write(PROFILE_ACTIONS_ENUM_TYPE, set);
wrapper.write(Type.PROFILE_ACTIONS_ENUM, set);
final int entries = wrapper.passthrough(Type.VAR_INT);
for (int i = 0; i < entries; i++) {
wrapper.passthrough(Type.UUID); // UUID

View File

@ -51,7 +51,7 @@ public final class EntityPackets extends EntityRewriter<ClientboundPackets1_19_3
map(Type.UNSIGNED_BYTE); // Gamemode
map(Type.BYTE); // Previous Gamemode
map(Type.STRING_ARRAY); // World List
map(Type.NBT); // Dimension registry
map(Type.NAMED_COMPOUND_TAG); // Dimension registry
map(Type.STRING); // Dimension key
map(Type.STRING); // World
handler(dimensionDataHandler());
@ -59,7 +59,7 @@ public final class EntityPackets extends EntityRewriter<ClientboundPackets1_19_3
handler(worldDataTrackerHandlerByKey());
handler(playerTrackerHandler());
handler(wrapper -> {
final CompoundTag registry = wrapper.get(Type.NBT, 0);
final CompoundTag registry = wrapper.get(Type.NAMED_COMPOUND_TAG, 0);
final CompoundTag damageTypeRegistry = protocol.getMappingData().damageTypesRegistry();
registry.put("minecraft:damage_type", damageTypeRegistry);

View File

@ -207,9 +207,9 @@ public final class EntityPackets extends EntityRewriter<ClientboundPackets1_18,
map(Type.UNSIGNED_BYTE); // Gamemode
map(Type.BYTE); // Previous Gamemode
map(Type.STRING_ARRAY); // World List
map(Type.NBT); // Registry
map(Type.NAMED_COMPOUND_TAG); // Registry
handler(wrapper -> {
final CompoundTag tag = wrapper.get(Type.NBT, 0);
final CompoundTag tag = wrapper.get(Type.NAMED_COMPOUND_TAG, 0);
// Add necessary chat types
tag.put("minecraft:chat_type", CHAT_REGISTRY.clone());
@ -311,7 +311,7 @@ public final class EntityPackets extends EntityRewriter<ClientboundPackets1_18,
private static void writeDimensionKey(final PacketWrapper wrapper, final DimensionRegistryStorage registryStorage) throws Exception {
// Find dimension key by data
final CompoundTag currentDimension = wrapper.read(Type.NBT);
final CompoundTag currentDimension = wrapper.read(Type.NAMED_COMPOUND_TAG);
addMonsterSpawnData(currentDimension);
String dimensionKey = registryStorage.dimensionKey(currentDimension);
if (dimensionKey == null) {

View File

@ -276,7 +276,7 @@ public final class Protocol1_20_2To1_20 extends AbstractProtocol<ClientboundPack
protocolInfo.setServerState(State.CONFIGURATION);
final PacketWrapper registryDataPacket = PacketWrapper.create(ClientboundConfigurationPackets1_20_2.REGISTRY_DATA, connection);
registryDataPacket.write(Type.NAMELESS_NBT, dimensionRegistry);
registryDataPacket.write(Type.COMPOUND_TAG, dimensionRegistry);
registryDataPacket.send(Protocol1_20_2To1_20.class);
// Enabling features is only possible during the configuration phase

View File

@ -79,13 +79,13 @@ public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter<Clientboun
protocol.registerClientbound(ClientboundPackets1_19_4.NBT_QUERY, wrapper -> {
wrapper.passthrough(Type.VAR_INT); // Transaction id
wrapper.write(Type.NAMELESS_NBT, wrapper.read(Type.NBT));
wrapper.write(Type.COMPOUND_TAG, wrapper.read(Type.NAMED_COMPOUND_TAG));
});
protocol.registerClientbound(ClientboundPackets1_19_4.BLOCK_ENTITY_DATA, wrapper -> {
wrapper.passthrough(Type.POSITION1_14); // Position
wrapper.passthrough(Type.VAR_INT); // Type
wrapper.write(Type.NAMELESS_NBT, handleBlockEntity(wrapper.read(Type.NBT)));
wrapper.write(Type.COMPOUND_TAG, handleBlockEntity(wrapper.read(Type.NAMED_COMPOUND_TAG)));
});
protocol.registerClientbound(ClientboundPackets1_19_4.CHUNK_DATA, wrapper -> {

View File

@ -76,7 +76,7 @@ public final class EntityPacketRewriter1_20_2 extends EntityRewriter<Clientbound
wrapper.passthrough(Type.STRING_ARRAY); // World List
final CompoundTag dimensionRegistry = wrapper.read(Type.NBT);
final CompoundTag dimensionRegistry = wrapper.read(Type.NAMED_COMPOUND_TAG);
final String dimensionType = wrapper.read(Type.STRING);
final String world = wrapper.read(Type.STRING);
final long seed = wrapper.read(Type.LONG);
@ -160,7 +160,7 @@ public final class EntityPacketRewriter1_20_2 extends EntityRewriter<Clientbound
wrapper.passthrough(Type.VAR_INT); // Duration
wrapper.passthrough(Type.BYTE); // Flags
if (wrapper.passthrough(Type.BOOLEAN)) {
wrapper.write(Type.NAMELESS_NBT, wrapper.read(Type.NBT)); // Factor data
wrapper.write(Type.COMPOUND_TAG, wrapper.read(Type.NAMED_COMPOUND_TAG)); // Factor data
}
});

View File

@ -46,7 +46,7 @@ public final class ChunkType1_20_2 extends Type<Chunk> {
public Chunk read(final ByteBuf buffer) throws Exception {
final int chunkX = buffer.readInt();
final int chunkZ = buffer.readInt();
final CompoundTag heightMap = Type.NAMELESS_NBT.read(buffer);
final CompoundTag heightMap = Type.COMPOUND_TAG.read(buffer);
// Read sections
final ByteBuf sectionsBuf = buffer.readBytes(Type.VAR_INT.readPrimitive(buffer));
@ -73,7 +73,7 @@ public final class ChunkType1_20_2 extends Type<Chunk> {
buffer.writeInt(chunk.getX());
buffer.writeInt(chunk.getZ());
Type.NAMELESS_NBT.write(buffer, chunk.getHeightMap());
Type.COMPOUND_TAG.write(buffer, chunk.getHeightMap());
final ByteBuf sectionBuffer = buffer.alloc().buffer();
try {

View File

@ -19,6 +19,7 @@ package com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.viaversion.viaversion.api.connection.UserConnection;
@ -31,8 +32,6 @@ import com.viaversion.viaversion.api.protocol.packet.State;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.BitSetType;
import com.viaversion.viaversion.api.type.types.ByteArrayType;
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.packet.ClientboundConfigurationPackets1_20_2;
import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.packet.ClientboundPackets1_20_2;
@ -43,9 +42,7 @@ import java.util.BitSet;
import org.checkerframework.checker.nullness.qual.Nullable;
public final class Protocol1_20_3To1_20_2 extends AbstractProtocol<ClientboundPackets1_20_2, ClientboundPackets1_20_2, ServerboundPackets1_20_2, ServerboundPackets1_20_2> {
private static final BitSetType PROFILE_ACTIONS_ENUM_TYPE = new BitSetType(6);
private static final ByteArrayType.OptionalByteArrayType OPTIONAL_SIGNATURE_BYTES_TYPE = new ByteArrayType.OptionalByteArrayType(256);
private static final ByteArrayType SIGNATURE_BYTES_TYPE = new ByteArrayType(256);
private final EntityPacketRewriter1_20_3 entityRewriter = new EntityPacketRewriter1_20_3(this);
public Protocol1_20_3To1_20_2() {
@ -119,7 +116,7 @@ public final class Protocol1_20_3To1_20_2 extends AbstractProtocol<ClientboundPa
registerClientbound(ClientboundPackets1_20_2.PLAYER_CHAT, wrapper -> {
wrapper.passthrough(Type.UUID); // Sender
wrapper.passthrough(Type.VAR_INT); // Index
wrapper.passthrough(OPTIONAL_SIGNATURE_BYTES_TYPE); // Signature
wrapper.passthrough(Type.OPTIONAL_SIGNATURE_BYTES); // Signature
wrapper.passthrough(Type.STRING); // Plain content
wrapper.passthrough(Type.LONG); // Timestamp
wrapper.passthrough(Type.LONG); // Salt
@ -128,7 +125,7 @@ public final class Protocol1_20_3To1_20_2 extends AbstractProtocol<ClientboundPa
for (int i = 0; i < lastSeen; i++) {
final int index = wrapper.passthrough(Type.VAR_INT);
if (index == 0) {
wrapper.passthrough(SIGNATURE_BYTES_TYPE);
wrapper.passthrough(Type.SIGNATURE_BYTES);
}
}
@ -195,8 +192,7 @@ public final class Protocol1_20_3To1_20_2 extends AbstractProtocol<ClientboundPa
}
});
registerClientbound(ClientboundPackets1_20_2.PLAYER_INFO_UPDATE, wrapper -> {
wrapper.cancel();
final BitSet actions = wrapper.passthrough(PROFILE_ACTIONS_ENUM_TYPE);
final BitSet actions = wrapper.passthrough(Type.PROFILE_ACTIONS_ENUM);
final int entries = wrapper.passthrough(Type.VAR_INT);
for (int i = 0; i < entries; i++) {
wrapper.passthrough(Type.UUID);
@ -240,25 +236,27 @@ public final class Protocol1_20_3To1_20_2 extends AbstractProtocol<ClientboundPa
}
private void convertComponent(final PacketWrapper wrapper) throws Exception {
wrapper.write(Type.NAMELESS_NBT, jsonComponentToTag(wrapper.read(Type.COMPONENT)));
wrapper.write(Type.TAG, jsonComponentToTag(wrapper.read(Type.COMPONENT)));
}
private void convertOptionalComponent(final PacketWrapper wrapper) throws Exception {
wrapper.write(Type.OPTIONAL_NAMELESS_NBT, jsonComponentToTag(wrapper.read(Type.OPTIONAL_COMPONENT)));
wrapper.write(Type.OPTIONAL_TAG, jsonComponentToTag(wrapper.read(Type.OPTIONAL_COMPONENT)));
}
public static @Nullable JsonElement tagComponentToJson(@Nullable final CompoundTag tag) {
public static @Nullable JsonElement tagComponentToJson(@Nullable final Tag tag) {
if (tag == null) {
return null;
}
System.out.println(tag);
final JsonObject object = new JsonObject();
// TODO
object.addProperty("text", "Subscribe to ViaVersion+ to see this message");
return object;
}
public static @Nullable CompoundTag jsonComponentToTag(@Nullable final JsonElement component) {
public static @Nullable Tag jsonComponentToTag(@Nullable final JsonElement component) {
if (component == null) {
return null;
}

View File

@ -57,7 +57,7 @@ public final class EntityPackets extends EntityRewriter<ClientboundPackets1_19_4
map(Type.UNSIGNED_BYTE); // Gamemode
map(Type.BYTE); // Previous Gamemode
map(Type.STRING_ARRAY); // World List
map(Type.NBT); // Dimension registry
map(Type.NAMED_COMPOUND_TAG); // Dimension registry
map(Type.STRING); // Dimension key
map(Type.STRING); // World
map(Type.LONG); // Seed
@ -75,7 +75,7 @@ public final class EntityPackets extends EntityRewriter<ClientboundPackets1_19_4
handler(biomeSizeTracker()); // Tracks the amount of biomes sent for chunk data
handler(worldDataTrackerHandlerByKey()); // Tracks world height and name for chunk data and entity (un)tracking
handler(wrapper -> {
final CompoundTag registry = wrapper.get(Type.NBT, 0);
final CompoundTag registry = wrapper.get(Type.NAMED_COMPOUND_TAG, 0);
final CompoundTag damageTypeRegistry = registry.get("minecraft:damage_type");
final ListTag damageTypes = damageTypeRegistry.get("value");
int highestId = -1;

View File

@ -81,7 +81,7 @@ public class Protocol1_9_3To1_9_1_2 extends AbstractProtocol<ClientboundPackets1
tag.put("Text" + (i + 1), new StringTag(lines[i].toString()));
}
wrapper.write(Type.NBT, tag);
wrapper.write(Type.NAMED_COMPOUND_TAG, tag);
});
registerClientbound(ClientboundPackets1_9.CHUNK_DATA, wrapper -> {

View File

@ -68,7 +68,7 @@ public class Chunk1_9_3_4Type extends PartialType<Chunk, ClientWorld> {
}
}
List<CompoundTag> nbtData = new ArrayList<>(Arrays.asList(Type.NBT_ARRAY.read(input)));
List<CompoundTag> nbtData = new ArrayList<>(Arrays.asList(Type.NAMED_COMPOUND_TAG_ARRAY.read(input)));
// Read all the remaining bytes (workaround for #681)
if (input.readableBytes() > 0) {
@ -115,7 +115,7 @@ public class Chunk1_9_3_4Type extends PartialType<Chunk, ClientWorld> {
}
// Write Block Entities
Type.NBT_ARRAY.write(output, chunk.getBlockEntities().toArray(new CompoundTag[0]));
Type.NAMED_COMPOUND_TAG_ARRAY.write(output, chunk.getBlockEntities().toArray(new CompoundTag[0]));
}
@Override

View File

@ -209,11 +209,11 @@ public class WorldPackets {
public void register() {
map(Type.POSITION); // 0 - Block Position
map(Type.UNSIGNED_BYTE); // 1 - Action
map(Type.NBT); // 2 - NBT (Might not be present)
map(Type.NAMED_COMPOUND_TAG); // 2 - NBT (Might not be present)
handler(wrapper -> {
int action = wrapper.get(Type.UNSIGNED_BYTE, 0);
if (action == 1) { // Update Spawner
CompoundTag tag = wrapper.get(Type.NBT, 0);
CompoundTag tag = wrapper.get(Type.NAMED_COMPOUND_TAG, 0);
if (tag != null) {
if (tag.contains("EntityId")) {
String entity = (String) tag.get("EntityId").getValue();
@ -229,7 +229,7 @@ public class WorldPackets {
}
if (action == 2) { // Update Command Block
CommandBlockProvider provider = Via.getManager().getProviders().get(CommandBlockProvider.class);
provider.addOrUpdateBlock(wrapper.user(), wrapper.get(Type.POSITION, 0), wrapper.get(Type.NBT, 0));
provider.addOrUpdateBlock(wrapper.user(), wrapper.get(Type.POSITION, 0), wrapper.get(Type.NAMED_COMPOUND_TAG, 0));
// To prevent window issues don't send updates
wrapper.cancel();
@ -396,7 +396,7 @@ public class WorldPackets {
updateBlockEntity.write(Type.POSITION, pos);
updateBlockEntity.write(Type.UNSIGNED_BYTE, (short) 2);
updateBlockEntity.write(Type.NBT, tag.get());
updateBlockEntity.write(Type.NAMED_COMPOUND_TAG, tag.get());
updateBlockEntity.scheduleSend(Protocol1_9To1_8.class);
}

View File

@ -45,7 +45,7 @@ public class BlockRewriter<C extends ClientboundPacketType> {
private final Type<CompoundTag> nbtType;
public BlockRewriter(Protocol<C, ?, ?, ?> protocol, Type<Position> positionType) {
this(protocol, positionType, Type.NBT);
this(protocol, positionType, Type.NAMED_COMPOUND_TAG);
}
public BlockRewriter(Protocol<C, ?, ?, ?> protocol, Type<Position> positionType, Type<CompoundTag> nbtType) {

View File

@ -422,7 +422,7 @@ public abstract class EntityRewriter<C extends ClientboundPacketType, T extends
return wrapper -> {
EntityTracker tracker = tracker(wrapper.user());
CompoundTag registryData = wrapper.get(Type.NBT, nbtIndex);
CompoundTag registryData = wrapper.get(Type.NAMED_COMPOUND_TAG, nbtIndex);
Tag height = registryData.get("height");
if (height instanceof IntTag) {
int blockHeight = ((IntTag) height).asInt();
@ -471,7 +471,7 @@ public abstract class EntityRewriter<C extends ClientboundPacketType, T extends
}
public PacketHandler biomeSizeTracker() {
return wrapper -> trackBiomeSize(wrapper.user(), wrapper.get(Type.NBT, 0));
return wrapper -> trackBiomeSize(wrapper.user(), wrapper.get(Type.NAMED_COMPOUND_TAG, 0));
}
public void trackBiomeSize(final UserConnection connection, final CompoundTag registry) {
@ -481,7 +481,7 @@ public abstract class EntityRewriter<C extends ClientboundPacketType, T extends
}
public PacketHandler dimensionDataHandler() {
return wrapper -> cacheDimensionData(wrapper.user(), wrapper.get(Type.NBT, 0));
return wrapper -> cacheDimensionData(wrapper.user(), wrapper.get(Type.NAMED_COMPOUND_TAG, 0));
}
/**