From db935b454f67b2a0f255bb1d62aca4cc32b75351 Mon Sep 17 00:00:00 2001 From: Matsv Date: Mon, 11 Jul 2016 13:48:48 +0200 Subject: [PATCH] Make the Metadata types version based and remove the NoGravity tag init since it doesn't seem needed. --- .../Protocol1_10To1_9_3_4.java | 27 +++++++++++++------ ...eta1_10Type.java => Meta1_9_1_10Type.java} | 2 +- ..._10Type.java => MetaList1_9_1_10Type.java} | 11 ++------ .../protocol1_9to1_8/Protocol1_9TO1_8.java | 8 +++--- .../packets/EntityPackets.java | 9 ++++--- .../packets/SpawnPackets.java | 15 ++++++----- .../storage/EntityTracker.java | 3 ++- ...MetadataType.java => Metadata1_8Type.java} | 10 ++----- ...ListType.java => MetadataList1_8Type.java} | 8 ++---- 9 files changed, 45 insertions(+), 48 deletions(-) rename src/main/java/us/myles/ViaVersion/protocols/protocol1_10to1_9_3/types/{Meta1_10Type.java => Meta1_9_1_10Type.java} (94%) rename src/main/java/us/myles/ViaVersion/protocols/protocol1_10to1_9_3/types/{MetaList1_10Type.java => MetaList1_9_1_10Type.java} (67%) rename src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/types/{MetadataType.java => Metadata1_8Type.java} (72%) rename src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/types/{MetadataListType.java => MetadataList1_8Type.java} (76%) diff --git a/src/main/java/us/myles/ViaVersion/protocols/protocol1_10to1_9_3/Protocol1_10To1_9_3_4.java b/src/main/java/us/myles/ViaVersion/protocols/protocol1_10to1_9_3/Protocol1_10To1_9_3_4.java index 3363c6847..23abc46ad 100644 --- a/src/main/java/us/myles/ViaVersion/protocols/protocol1_10to1_9_3/Protocol1_10To1_9_3_4.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocol1_10to1_9_3/Protocol1_10To1_9_3_4.java @@ -10,19 +10,30 @@ import us.myles.ViaVersion.api.remapper.ValueTransformer; import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.packets.State; import us.myles.ViaVersion.protocols.protocol1_10to1_9_3.storage.ResourcePackTracker; -import us.myles.ViaVersion.protocols.protocol1_10to1_9_3.types.Meta1_10Type; -import us.myles.ViaVersion.protocols.protocol1_10to1_9_3.types.MetaList1_10Type; +import us.myles.ViaVersion.protocols.protocol1_10to1_9_3.types.Meta1_9_1_10Type; +import us.myles.ViaVersion.protocols.protocol1_10to1_9_3.types.MetaList1_9_1_10Type; import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; public class Protocol1_10To1_9_3_4 extends Protocol { - public static final Type> METADATA_LIST = new MetaList1_10Type(); - public static final Type METADATA = new Meta1_10Type(); + public static final Type> METADATA_LIST = new MetaList1_9_1_10Type(); + public static final Type METADATA = new Meta1_9_1_10Type(); public static ValueTransformer toNewPitch = new ValueTransformer(Type.FLOAT) { @Override public Float transform(PacketWrapper wrapper, Short inputValue) throws Exception { return inputValue / 63.5F; - + } + }; + public static ValueTransformer, List> transformMetadata = new ValueTransformer, List>(METADATA_LIST) { + @Override + public List transform(PacketWrapper wrapper, List inputValue) throws Exception { + List metaList = new CopyOnWriteArrayList<>(inputValue); + for (Metadata m : metaList) { + if (m.getId() >= 5) + m.setId(m.getId() + 1); + } + return metaList; } }; @@ -69,7 +80,7 @@ public class Protocol1_10To1_9_3_4 extends Protocol { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity ID - map(METADATA_LIST); // 1 - Metadata list + map(METADATA_LIST, transformMetadata); // 1 - Metadata list } }); @@ -89,7 +100,7 @@ public class Protocol1_10To1_9_3_4 extends Protocol { map(Type.SHORT); // 9 - Velocity X map(Type.SHORT); // 10 - Velocity Y map(Type.SHORT); // 11 - Velocity Z - map(METADATA_LIST); // 12 - Metadata + map(METADATA_LIST, transformMetadata); // 12 - Metadata } }); @@ -104,7 +115,7 @@ public class Protocol1_10To1_9_3_4 extends Protocol { map(Type.DOUBLE); // 4 - Z map(Type.BYTE); // 5 - Yaw map(Type.BYTE); // 6 - Pitch - map(METADATA_LIST); // 7 - Metadata list + map(METADATA_LIST, transformMetadata); // 7 - Metadata list } }); diff --git a/src/main/java/us/myles/ViaVersion/protocols/protocol1_10to1_9_3/types/Meta1_10Type.java b/src/main/java/us/myles/ViaVersion/protocols/protocol1_10to1_9_3/types/Meta1_9_1_10Type.java similarity index 94% rename from src/main/java/us/myles/ViaVersion/protocols/protocol1_10to1_9_3/types/Meta1_10Type.java rename to src/main/java/us/myles/ViaVersion/protocols/protocol1_10to1_9_3/types/Meta1_9_1_10Type.java index 8dbdfe846..292face5e 100644 --- a/src/main/java/us/myles/ViaVersion/protocols/protocol1_10to1_9_3/types/Meta1_10Type.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocol1_10to1_9_3/types/Meta1_9_1_10Type.java @@ -5,7 +5,7 @@ import us.myles.ViaVersion.api.minecraft.metadata.Metadata; import us.myles.ViaVersion.api.type.types.minecraft.MetaTypeTemplate; import us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata.NewType; -public class Meta1_10Type extends MetaTypeTemplate { +public class Meta1_9_1_10Type extends MetaTypeTemplate { @Override public Metadata read(ByteBuf buffer) throws Exception { diff --git a/src/main/java/us/myles/ViaVersion/protocols/protocol1_10to1_9_3/types/MetaList1_10Type.java b/src/main/java/us/myles/ViaVersion/protocols/protocol1_10to1_9_3/types/MetaList1_9_1_10Type.java similarity index 67% rename from src/main/java/us/myles/ViaVersion/protocols/protocol1_10to1_9_3/types/MetaList1_10Type.java rename to src/main/java/us/myles/ViaVersion/protocols/protocol1_10to1_9_3/types/MetaList1_9_1_10Type.java index dfaa80c99..9f52af337 100644 --- a/src/main/java/us/myles/ViaVersion/protocols/protocol1_10to1_9_3/types/MetaList1_10Type.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocol1_10to1_9_3/types/MetaList1_9_1_10Type.java @@ -2,15 +2,13 @@ package us.myles.ViaVersion.protocols.protocol1_10to1_9_3.types; import io.netty.buffer.ByteBuf; import us.myles.ViaVersion.api.minecraft.metadata.Metadata; -import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.types.minecraft.MetaListTypeTemplate; import us.myles.ViaVersion.protocols.protocol1_10to1_9_3.Protocol1_10To1_9_3_4; -import us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata.NewType; import java.util.ArrayList; import java.util.List; -public class MetaList1_10Type extends MetaListTypeTemplate { +public class MetaList1_9_1_10Type extends MetaListTypeTemplate { @Override public List read(ByteBuf buffer) throws Exception { @@ -27,13 +25,8 @@ public class MetaList1_10Type extends MetaListTypeTemplate { @Override public void write(ByteBuf buffer, List object) throws Exception { - for (Metadata m : object) { - if (m.getId() >= 5) - m.setId(m.getId() + 1); - if (m.getId() == 4) - Protocol1_10To1_9_3_4.METADATA.write(buffer, new Metadata(5, NewType.Boolean.getTypeID(), Type.BOOLEAN, false)); // No gravity metadata + for (Metadata m : object) Protocol1_10To1_9_3_4.METADATA.write(buffer, m); - } // Write end of list Protocol1_10To1_9_3_4.METADATA.write(buffer, null); diff --git a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/Protocol1_9TO1_8.java b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/Protocol1_9TO1_8.java index ac019978b..267fd85a7 100644 --- a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/Protocol1_9TO1_8.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/Protocol1_9TO1_8.java @@ -17,8 +17,8 @@ import us.myles.ViaVersion.protocols.base.ProtocolInfo; import us.myles.ViaVersion.protocols.protocol1_9to1_8.listeners.*; import us.myles.ViaVersion.protocols.protocol1_9to1_8.packets.*; import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.*; -import us.myles.ViaVersion.protocols.protocol1_9to1_8.types.MetadataListType; -import us.myles.ViaVersion.protocols.protocol1_9to1_8.types.MetadataType; +import us.myles.ViaVersion.protocols.protocol1_9to1_8.types.Metadata1_8Type; +import us.myles.ViaVersion.protocols.protocol1_9to1_8.types.MetadataList1_8Type; import java.util.List; import java.util.UUID; @@ -26,8 +26,8 @@ import java.util.concurrent.Callable; import java.util.concurrent.TimeUnit; public class Protocol1_9TO1_8 extends Protocol { - public static Type> METADATA_LIST = new MetadataListType(); - public static Type METADATA = new MetadataType(); + public static Type> METADATA_LIST = new MetadataList1_8Type(); + public static Type METADATA = new Metadata1_8Type(); private static Gson gson = new GsonBuilder().create(); public static ValueTransformer FIX_JSON = new ValueTransformer(Type.STRING) { @Override diff --git a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/EntityPackets.java b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/EntityPackets.java index f9e417810..43faa4c5d 100644 --- a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/EntityPackets.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/EntityPackets.java @@ -11,6 +11,7 @@ import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.remapper.ValueTransformer; import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.packets.State; +import us.myles.ViaVersion.protocols.protocol1_10to1_9_3.Protocol1_10To1_9_3_4; import us.myles.ViaVersion.protocols.protocol1_9to1_8.ItemRewriter; import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8; import us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata.MetadataRewriter; @@ -175,11 +176,11 @@ public class EntityPackets { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity ID - map(Protocol1_9TO1_8.METADATA_LIST); // 1 - Metadata List + map(Protocol1_9TO1_8.METADATA_LIST, Protocol1_10To1_9_3_4.METADATA_LIST); // 1 - Metadata List handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { - List metadataList = wrapper.get(Protocol1_9TO1_8.METADATA_LIST, 0); + List metadataList = wrapper.get(Protocol1_10To1_9_3_4.METADATA_LIST, 0); int entityID = wrapper.get(Type.VAR_INT, 0); EntityTracker tracker = wrapper.user().get(EntityTracker.class); if (tracker.getClientEntityTypes().containsKey(entityID)) { @@ -196,7 +197,7 @@ public class EntityPackets { handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { - List metadataList = wrapper.get(Protocol1_9TO1_8.METADATA_LIST, 0); + List metadataList = wrapper.get(Protocol1_10To1_9_3_4.METADATA_LIST, 0); int entityID = wrapper.get(Type.VAR_INT, 0); EntityTracker tracker = wrapper.user().get(EntityTracker.class); tracker.handleMetadata(entityID, metadataList); @@ -207,7 +208,7 @@ public class EntityPackets { handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { - List metadataList = wrapper.get(Protocol1_9TO1_8.METADATA_LIST, 0); + List metadataList = wrapper.get(Protocol1_10To1_9_3_4.METADATA_LIST, 0); if (metadataList.size() == 0) { wrapper.cancel(); } diff --git a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/SpawnPackets.java b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/SpawnPackets.java index 789514c0a..3763d8349 100644 --- a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/SpawnPackets.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/SpawnPackets.java @@ -12,6 +12,7 @@ import us.myles.ViaVersion.api.remapper.ValueCreator; import us.myles.ViaVersion.api.remapper.ValueTransformer; import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.packets.State; +import us.myles.ViaVersion.protocols.protocol1_10to1_9_3.Protocol1_10To1_9_3_4; import us.myles.ViaVersion.protocols.protocol1_9to1_8.ItemRewriter; import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8; import us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata.MetadataRewriter; @@ -107,7 +108,7 @@ public class SpawnPackets { // TEMP FIX FOR POTIONS UNTIL WE FIGURE OUT HOW TO TRANSFORM SENT PACKETS Metadata potion = new Metadata(5, NewType.Slot.getTypeID(), Type.ITEM, item); meta.add(potion); - wrapper.write(Protocol1_9TO1_8.METADATA_LIST, meta); + wrapper.write(Protocol1_10To1_9_3_4.METADATA_LIST, meta); } }); metaPacket.send(Protocol1_9TO1_8.class); @@ -206,11 +207,11 @@ public class SpawnPackets { map(Type.SHORT); // 10 - Velocity Y map(Type.SHORT); // 11 - Velocity Z - map(Protocol1_9TO1_8.METADATA_LIST); + map(Protocol1_9TO1_8.METADATA_LIST, Protocol1_10To1_9_3_4.METADATA_LIST); handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { - List metadataList = wrapper.get(Protocol1_9TO1_8.METADATA_LIST, 0); + List metadataList = wrapper.get(Protocol1_10To1_9_3_4.METADATA_LIST, 0); int entityID = wrapper.get(Type.VAR_INT, 0); EntityTracker tracker = wrapper.user().get(EntityTracker.class); if (tracker.getClientEntityTypes().containsKey(entityID)) { @@ -225,7 +226,7 @@ public class SpawnPackets { handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { - List metadataList = wrapper.get(Protocol1_9TO1_8.METADATA_LIST, 0); + List metadataList = wrapper.get(Protocol1_10To1_9_3_4.METADATA_LIST, 0); int entityID = wrapper.get(Type.VAR_INT, 0); EntityTracker tracker = wrapper.user().get(EntityTracker.class); tracker.handleMetadata(entityID, metadataList); @@ -311,12 +312,12 @@ public class SpawnPackets { } }); - map(Protocol1_9TO1_8.METADATA_LIST); + map(Protocol1_9TO1_8.METADATA_LIST, Protocol1_10To1_9_3_4.METADATA_LIST); handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { - List metadataList = wrapper.get(Protocol1_9TO1_8.METADATA_LIST, 0); + List metadataList = wrapper.get(Protocol1_10To1_9_3_4.METADATA_LIST, 0); int entityID = wrapper.get(Type.VAR_INT, 0); EntityTracker tracker = wrapper.user().get(EntityTracker.class); if (tracker.getClientEntityTypes().containsKey(entityID)) { @@ -332,7 +333,7 @@ public class SpawnPackets { handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { - List metadataList = wrapper.get(Protocol1_9TO1_8.METADATA_LIST, 0); + List metadataList = wrapper.get(Protocol1_10To1_9_3_4.METADATA_LIST, 0); int entityID = wrapper.get(Type.VAR_INT, 0); EntityTracker tracker = wrapper.user().get(EntityTracker.class); tracker.handleMetadata(entityID, metadataList); diff --git a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/EntityTracker.java b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/EntityTracker.java index 586e178e5..f5be00076 100644 --- a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/EntityTracker.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/EntityTracker.java @@ -20,6 +20,7 @@ import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.minecraft.metadata.Metadata; import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.protocols.base.ProtocolInfo; +import us.myles.ViaVersion.protocols.protocol1_10to1_9_3.Protocol1_10To1_9_3_4; import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8; import us.myles.ViaVersion.protocols.protocol1_9to1_8.chat.GameMode; import us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata.MetadataRewriter; @@ -274,7 +275,7 @@ public class EntityTracker extends StoredObject { if (metadataBuffer.containsKey(entityID)) { PacketWrapper wrapper = new PacketWrapper(0x39, null, getUser()); wrapper.write(Type.VAR_INT, entityID); - wrapper.write(Protocol1_9TO1_8.METADATA_LIST, metadataBuffer.get(entityID)); + wrapper.write(Protocol1_10To1_9_3_4.METADATA_LIST, metadataBuffer.get(entityID)); MetadataRewriter.transform(getClientEntityTypes().get(entityID), metadataBuffer.get(entityID)); handleMetadata(entityID, metadataBuffer.get(entityID)); if (metadataBuffer.get(entityID).size() > 0) { diff --git a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/types/MetadataType.java b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/types/Metadata1_8Type.java similarity index 72% rename from src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/types/MetadataType.java rename to src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/types/Metadata1_8Type.java index 8e6760aeb..e02b24194 100644 --- a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/types/MetadataType.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/types/Metadata1_8Type.java @@ -6,7 +6,7 @@ import us.myles.ViaVersion.api.minecraft.metadata.Metadata; import us.myles.ViaVersion.api.type.types.minecraft.MetaTypeTemplate; import us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata.MetadataTypes; -public class MetadataType extends MetaTypeTemplate { +public class Metadata1_8Type extends MetaTypeTemplate { @Override public Metadata read(ByteBuf buffer) throws Exception { @@ -20,12 +20,6 @@ public class MetadataType extends MetaTypeTemplate { @Override public void write(ByteBuf buffer, Metadata object) throws Exception { - if (object == null) { - buffer.writeByte(255); - } else { - buffer.writeByte(object.getId()); - buffer.writeByte(object.getTypeID()); - object.getType().write(buffer, object.getValue()); - } + throw new UnsupportedOperationException("1.8 Metadata writing is not implemented!"); } } diff --git a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/types/MetadataListType.java b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/types/MetadataList1_8Type.java similarity index 76% rename from src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/types/MetadataListType.java rename to src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/types/MetadataList1_8Type.java index 4e3918f50..8c6622ef9 100644 --- a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/types/MetadataListType.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/types/MetadataList1_8Type.java @@ -8,7 +8,7 @@ import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8; import java.util.ArrayList; import java.util.List; -public class MetadataListType extends MetaListTypeTemplate { +public class MetadataList1_8Type extends MetaListTypeTemplate { @Override public List read(ByteBuf buffer) throws Exception { @@ -26,10 +26,6 @@ public class MetadataListType extends MetaListTypeTemplate { @Override public void write(ByteBuf buffer, List object) throws Exception { - for (Metadata m : object) { - Protocol1_9TO1_8.METADATA.write(buffer, m); - } - // Write end of list - Protocol1_9TO1_8.METADATA.write(buffer, null); + throw new UnsupportedOperationException("1.8 MetadataList writing is not implemented"); } }