From ab7cd4955b5b557cc9e633f79ee546084d738832 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Fri, 29 Oct 2021 17:57:23 +0200 Subject: [PATCH] Metadata type should be written as var int --- .../api/type/types/minecraft/ModernMetaType.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/minecraft/ModernMetaType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/minecraft/ModernMetaType.java index 7fff1a117..a3894eaab 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/minecraft/ModernMetaType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/minecraft/ModernMetaType.java @@ -24,14 +24,17 @@ package com.viaversion.viaversion.api.type.types.minecraft; import com.viaversion.viaversion.api.minecraft.metadata.MetaType; import com.viaversion.viaversion.api.minecraft.metadata.Metadata; +import com.viaversion.viaversion.api.type.Type; import io.netty.buffer.ByteBuf; public abstract class ModernMetaType extends MetaTypeTemplate { + private static final int END = 255; + @Override public Metadata read(final ByteBuf buffer) throws Exception { final short index = buffer.readUnsignedByte(); - if (index == 0xff) return null; // End of metadata - final MetaType type = this.getType(buffer.readByte()); + if (index == END) return null; // End of metadata + final MetaType type = this.getType(Type.VAR_INT.readPrimitive(buffer)); return new Metadata(index, type, type.type().read(buffer)); } @@ -40,11 +43,11 @@ public abstract class ModernMetaType extends MetaTypeTemplate { @Override public void write(final ByteBuf buffer, final Metadata object) throws Exception { if (object == null) { - buffer.writeByte(0xff); + buffer.writeByte(END); } else { buffer.writeByte(object.id()); final MetaType type = object.metaType(); - buffer.writeByte(type.typeId()); + Type.VAR_INT.writePrimitive(buffer, type.typeId()); type.type().write(buffer, object.getValue()); } }