diff --git a/src/main/java/us/myles/ViaVersion/api/PacketWrapper.java b/src/main/java/us/myles/ViaVersion/api/PacketWrapper.java index aabf631ac..943a8f4fa 100644 --- a/src/main/java/us/myles/ViaVersion/api/PacketWrapper.java +++ b/src/main/java/us/myles/ViaVersion/api/PacketWrapper.java @@ -117,7 +117,7 @@ public class PacketWrapper { } } else { Pair read = readableObjects.poll(); - if (read.getKey().equals(type)) { + if (read.getKey().equals(type) || (type.isCompatibleWith(read.getKey()) && type.getOutputClass().equals(read.getKey().getOutputClass()))) { return (T) read.getValue(); } else { if (type == Type.NOTHING) { @@ -173,7 +173,7 @@ public class PacketWrapper { packetValues.addAll(readableObjects); readableObjects.clear(); // If the buffer has readable bytes, copy them. - if(inputBuffer.readableBytes() > 0){ + if (inputBuffer.readableBytes() > 0) { passthrough(Type.REMAINING_BYTES); } } diff --git a/src/main/java/us/myles/ViaVersion/api/type/Type.java b/src/main/java/us/myles/ViaVersion/api/type/Type.java index 7b5e01b7b..ef7833d08 100644 --- a/src/main/java/us/myles/ViaVersion/api/type/Type.java +++ b/src/main/java/us/myles/ViaVersion/api/type/Type.java @@ -10,6 +10,8 @@ import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.type.types.*; import us.myles.ViaVersion.api.type.types.minecraft.*; +import java.util.HashSet; +import java.util.Set; import java.util.UUID; @Getter @@ -68,6 +70,7 @@ public abstract class Type implements ByteBufReader, ByteBufWriter { /* Actual Class */ private final Class outputClass; + private final Set> compatibilities; private final String typeName; public Type(Class outputClass) { @@ -77,6 +80,19 @@ public abstract class Type implements ByteBufReader, ByteBufWriter { public Type(String typeName, Class outputClass) { this.outputClass = outputClass; this.typeName = typeName; + this.compatibilities = new HashSet<>(); + } + + public void addCompatibility(Class claz) { + compatibilities.add(claz); + } + + public void addCompatibility(Type claz) { + addCompatibility(claz.getClass()); + } + + public boolean isCompatibleWith(Type claz) { + return compatibilities.contains(claz.getClass()); } @Override diff --git a/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_9_3/MetaListSnapshotType.java b/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_9_3/MetaListSnapshotType.java index ac81ff271..9fcdb1024 100644 --- a/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_9_3/MetaListSnapshotType.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_9_3/MetaListSnapshotType.java @@ -3,6 +3,7 @@ package us.myles.ViaVersion.protocols.protocolsnapshotto1_9_3; import io.netty.buffer.ByteBuf; import us.myles.ViaVersion.api.minecraft.metadata.Metadata; import us.myles.ViaVersion.api.type.Type; +import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8; import us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata.NewType; import java.util.ArrayList; @@ -11,6 +12,7 @@ import java.util.List; public class MetaListSnapshotType extends Type> { public MetaListSnapshotType() { super(List.class); + addCompatibility(Protocol1_9TO1_8.METADATA_LIST); } @Override diff --git a/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_9_3/MetaSnapshotType.java b/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_9_3/MetaSnapshotType.java index eb833a2ec..47e8f4d03 100644 --- a/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_9_3/MetaSnapshotType.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_9_3/MetaSnapshotType.java @@ -3,11 +3,13 @@ package us.myles.ViaVersion.protocols.protocolsnapshotto1_9_3; import io.netty.buffer.ByteBuf; import us.myles.ViaVersion.api.minecraft.metadata.Metadata; import us.myles.ViaVersion.api.type.Type; +import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8; import us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata.NewType; public class MetaSnapshotType extends Type { public MetaSnapshotType() { super(Metadata.class); + addCompatibility(Protocol1_9TO1_8.METADATA); } @Override