3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-28 09:00:09 +01:00

Merge remote-tracking branch 'origin/master' into dev

Dieser Commit ist enthalten in:
Nassim Jahnke 2021-10-29 17:57:47 +02:00
Commit 82ded0299c
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 6BE3B555EBC5982B

Datei anzeigen

@ -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.MetaType;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata; import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
import com.viaversion.viaversion.api.type.Type;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public abstract class ModernMetaType extends MetaTypeTemplate { public abstract class ModernMetaType extends MetaTypeTemplate {
private static final int END = 255;
@Override @Override
public Metadata read(final ByteBuf buffer) throws Exception { public Metadata read(final ByteBuf buffer) throws Exception {
final short index = buffer.readUnsignedByte(); final short index = buffer.readUnsignedByte();
if (index == 0xff) return null; // End of metadata if (index == END) return null; // End of metadata
final MetaType type = this.getType(buffer.readByte()); final MetaType type = this.getType(Type.VAR_INT.readPrimitive(buffer));
return new Metadata(index, type, type.type().read(buffer)); return new Metadata(index, type, type.type().read(buffer));
} }
@ -40,11 +43,11 @@ public abstract class ModernMetaType extends MetaTypeTemplate {
@Override @Override
public void write(final ByteBuf buffer, final Metadata object) throws Exception { public void write(final ByteBuf buffer, final Metadata object) throws Exception {
if (object == null) { if (object == null) {
buffer.writeByte(0xff); buffer.writeByte(END);
} else { } else {
buffer.writeByte(object.id()); buffer.writeByte(object.id());
final MetaType type = object.metaType(); final MetaType type = object.metaType();
buffer.writeByte(type.typeId()); Type.VAR_INT.writePrimitive(buffer, type.typeId());
type.type().write(buffer, object.getValue()); type.type().write(buffer, object.getValue());
} }
} }