diff --git a/bukkit/pom.xml b/bukkit/pom.xml index 592e87676..b77f6ea56 100644 --- a/bukkit/pom.xml +++ b/bukkit/pom.xml @@ -5,7 +5,7 @@ viaversion-parent us.myles - 1.4.0-1.13-pre9 + 1.4.0-1.13-pre10 4.0.0 diff --git a/bungee/pom.xml b/bungee/pom.xml index 52b38a35c..15aa94fef 100644 --- a/bungee/pom.xml +++ b/bungee/pom.xml @@ -5,7 +5,7 @@ viaversion-parent us.myles - 1.4.0-1.13-pre9 + 1.4.0-1.13-pre10 4.0.0 diff --git a/common/pom.xml b/common/pom.xml index 02a158aff..8eb581109 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -5,7 +5,7 @@ viaversion-parent us.myles - 1.4.0-1.13-pre9 + 1.4.0-1.13-pre10 4.0.0 diff --git a/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolVersion.java b/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolVersion.java index 6fb3db92c..855eff31c 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolVersion.java +++ b/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolVersion.java @@ -62,7 +62,7 @@ public class ProtocolVersion { register(v1_12 = new ProtocolVersion(335, "1.12")); register(v1_12_1 = new ProtocolVersion(338, "1.12.1")); register(v1_12_2 = new ProtocolVersion(340, "1.12.2")); - register(v1_13 = new ProtocolVersion(391, "1.13-pre9")); + register(v1_13 = new ProtocolVersion(392, "1.13-pre10")); register(unknown = new ProtocolVersion(-1, "UNKNOWN")); } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/ProtocolSnapshotTo1_12_2.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/ProtocolSnapshotTo1_12_2.java index d6b2923c5..a5934fc5a 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/ProtocolSnapshotTo1_12_2.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/ProtocolSnapshotTo1_12_2.java @@ -49,6 +49,56 @@ public class ProtocolSnapshotTo1_12_2 extends Protocol { } }; + public static final PacketHandler SEND_DECLARE_COMMANDS_AND_TAGS = new PacketHandler() { // *insert here a good name* + @Override + public void handle(PacketWrapper w) throws Exception { + // Send fake declare commands + w.create(0x11, new ValueCreator() { + @Override + public void write(PacketWrapper wrapper) { + wrapper.write(Type.VAR_INT, 2); // Size + // Write root node + wrapper.write(Type.VAR_INT, 0); // Mark as command + wrapper.write(Type.VAR_INT, 1); // 1 child + wrapper.write(Type.VAR_INT, 1); // Child is at 1 + + // Write arg node + wrapper.write(Type.VAR_INT, 0x02 | 0x04 | 0x10); // Mark as command + wrapper.write(Type.VAR_INT, 0); // No children + // Extra data + wrapper.write(Type.STRING, "args"); // Arg name + wrapper.write(Type.STRING, "brigadier:string"); + wrapper.write(Type.VAR_INT, 2); // Greedy + wrapper.write(Type.STRING, "minecraft:ask_server"); // Ask server + + wrapper.write(Type.VAR_INT, 0); // Root node index + } + }).send(ProtocolSnapshotTo1_12_2.class); + + // Send tags packet + w.create(0x55, new ValueCreator() { + @Override + public void write(PacketWrapper wrapper) throws Exception { + wrapper.write(Type.VAR_INT, MappingData.blockTags.size()); // block tags + for (Map.Entry tag : MappingData.blockTags.entrySet()) { + wrapper.write(Type.STRING, tag.getKey()); + wrapper.write(Type.VAR_INT_ARRAY, tag.getValue().clone()); + } + wrapper.write(Type.VAR_INT, MappingData.itemTags.size()); // item tags + for (Map.Entry tag : MappingData.itemTags.entrySet()) { + wrapper.write(Type.STRING, tag.getKey()); + wrapper.write(Type.VAR_INT_ARRAY, tag.getValue().clone()); + } + wrapper.write(Type.VAR_INT, MappingData.fluidTags.size()); // fluid tags + for (Map.Entry tag : MappingData.fluidTags.entrySet()) { + wrapper.write(Type.STRING, tag.getKey()); + wrapper.write(Type.VAR_INT_ARRAY, tag.getValue().clone()); + } + } + }).send(ProtocolSnapshotTo1_12_2.class); + } + }; + static { MappingData.init(); } @@ -165,53 +215,9 @@ public class ProtocolSnapshotTo1_12_2 extends Protocol { ClientWorld clientChunks = wrapper.user().get(ClientWorld.class); int dimensionId = wrapper.get(Type.INT, 1); clientChunks.setEnvironment(dimensionId); - - // Send fake declare commands - wrapper.create(0x11, new ValueCreator() { - @Override - public void write(PacketWrapper wrapper) { - wrapper.write(Type.VAR_INT, 2); // Size - // Write root node - wrapper.write(Type.VAR_INT, 0); // Mark as command - wrapper.write(Type.VAR_INT, 1); // 1 child - wrapper.write(Type.VAR_INT, 1); // Child is at 1 - - // Write arg node - wrapper.write(Type.VAR_INT, 0x02 | 0x04 | 0x10); // Mark as command - wrapper.write(Type.VAR_INT, 0); // No children - // Extra data - wrapper.write(Type.STRING, "args"); // Arg name - wrapper.write(Type.STRING, "brigadier:string"); - wrapper.write(Type.VAR_INT, 2); // Greedy - wrapper.write(Type.STRING, "minecraft:ask_server"); // Ask server - - wrapper.write(Type.VAR_INT, 0); // Root node index - } - }).send(ProtocolSnapshotTo1_12_2.class); - - // Send tags packet - wrapper.create(0x55, new ValueCreator() { - @Override - public void write(PacketWrapper wrapper) throws Exception { - wrapper.write(Type.VAR_INT, MappingData.blockTags.size()); // block tags - for (Map.Entry tag : MappingData.blockTags.entrySet()) { - wrapper.write(Type.STRING, tag.getKey()); - wrapper.write(Type.VAR_INT_ARRAY, tag.getValue().clone()); - } - wrapper.write(Type.VAR_INT, MappingData.itemTags.size()); // item tags - for (Map.Entry tag : MappingData.itemTags.entrySet()) { - wrapper.write(Type.STRING, tag.getKey()); - wrapper.write(Type.VAR_INT_ARRAY, tag.getValue().clone()); - } - wrapper.write(Type.VAR_INT, MappingData.fluidTags.size()); // fluid tags - for (Map.Entry tag : MappingData.fluidTags.entrySet()) { - wrapper.write(Type.STRING, tag.getKey()); - wrapper.write(Type.VAR_INT_ARRAY, tag.getValue().clone()); - } - } - }).send(ProtocolSnapshotTo1_12_2.class); } }); + handler(SEND_DECLARE_COMMANDS_AND_TAGS); } }); @@ -296,6 +302,7 @@ public class ProtocolSnapshotTo1_12_2 extends Protocol { clientWorld.setEnvironment(dimensionId); } }); + handler(SEND_DECLARE_COMMANDS_AND_TAGS); } }); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/data/MappingData.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/data/MappingData.java index 712d2096e..53a134aca 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/data/MappingData.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/data/MappingData.java @@ -15,8 +15,7 @@ import java.util.Map; public class MappingData { public static Map oldToNewBlocks = new HashMap<>(); - public static Map oldToNewItems = new HashMap<>(); - public static Map newToOldItems = new HashMap<>(); + public static BiMap oldToNewItems = HashBiMap.create(); public static Map blockTags = new HashMap<>(); public static Map itemTags = new HashMap<>(); public static Map fluidTags = new HashMap<>(); @@ -32,8 +31,6 @@ public class MappingData { mapIdentifiers(oldToNewBlocks, mapping1_12.getAsJsonObject("blocks"), mapping1_13.getAsJsonObject("blocks")); System.out.println("Loading item mapping..."); mapIdentifiers(oldToNewItems, mapping1_12.getAsJsonObject("items"), mapping1_13.getAsJsonObject("items")); - System.out.println("Loading new to old item mapping..."); - mapIdentifiers(newToOldItems, mapping1_13.getAsJsonObject("items"), mapping1_12.getAsJsonObject("items")); System.out.println("Loading new tags..."); loadTags(blockTags, mapping1_13.getAsJsonObject("block_tags")); loadTags(itemTags, mapping1_13.getAsJsonObject("item_tags")); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/packets/InventoryPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/packets/InventoryPackets.java index 9bf5766cd..0c2eec81a 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/packets/InventoryPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/packets/InventoryPackets.java @@ -263,66 +263,63 @@ public class InventoryPackets { // TODO Rewrite identifiers public static void toClient(Item item) { if (item == null) return; - - // create tag CompoundTag tag = item.getTag(); - if (tag == null) { - item.setTag(tag = new CompoundTag("tag")); - } // Save original id int originalId = (item.getId() << 16 | item.getData() & 0xFFFF); - tag.put(new IntTag(NBT_TAG_NAME, originalId)); - // NBT changes + // NBT Additions if (isDamageable(item.getId())) { + if (tag == null) item.setTag(tag = new CompoundTag("tag")); tag.put(new IntTag("Damage", item.getData())); } - if (item.getId() == 358) { // map + if (tag == null) item.setTag(tag = new CompoundTag("tag")); tag.put(new IntTag("map", item.getData())); } - if (item.getId() == 442) { // shield - if (tag.get("BlockEntityTag") instanceof CompoundTag) { - CompoundTag blockEntityTag = tag.get("BlockEntityTag"); - if (blockEntityTag.get("Base") instanceof IntTag) { - IntTag base = blockEntityTag.get("Base"); - base.setValue(15 - base.getValue()); // invert color id + // NBT Changes + if (tag != null) { + // Invert shield color id + if (item.getId() == 442) { + if (tag.get("BlockEntityTag") instanceof CompoundTag) { + CompoundTag blockEntityTag = tag.get("BlockEntityTag"); + if (blockEntityTag.get("Base") instanceof IntTag) { + IntTag base = blockEntityTag.get("Base"); + base.setValue(15 - base.getValue()); + } } } - } - - // Display Name now uses JSON - if (tag.get("display") instanceof CompoundTag) { - if (((CompoundTag) tag.get("display")).get("Name") instanceof StringTag) { - StringTag name = ((CompoundTag) tag.get("display")).get("Name"); - name.setValue( - ProtocolSnapshotTo1_12_2.legacyTextToJson( - name.getValue() - ) - ); - } - } - - // ench is now Enchantments and now uses identifiers - if (tag.get("ench") instanceof ListTag) { - ListTag ench = tag.get("ench"); - ListTag enchantments = new ListTag("Enchantments", CompoundTag.class); - for (Tag enchEntry : ench) { - if (enchEntry instanceof CompoundTag) { - CompoundTag enchantmentEntry = new CompoundTag(""); - enchantmentEntry.put(new StringTag("id", - MappingData.oldEnchantmentsIds.get( - (Short) ((CompoundTag) enchEntry).get("id").getValue() + // Display Name now uses JSON + if (tag.get("display") instanceof CompoundTag) { + if (((CompoundTag) tag.get("display")).get("Name") instanceof StringTag) { + StringTag name = ((CompoundTag) tag.get("display")).get("Name"); + name.setValue( + ProtocolSnapshotTo1_12_2.legacyTextToJson( + name.getValue() ) - )); - enchantmentEntry.put(new ShortTag("lvl", (Short) ((CompoundTag) enchEntry).get("lvl").getValue())); - enchantments.add(enchantmentEntry); + ); } } - tag.remove("ench"); - tag.put(enchantments); + // ench is now Enchantments and now uses identifiers + if (tag.get("ench") instanceof ListTag) { + ListTag ench = tag.get("ench"); + ListTag enchantments = new ListTag("Enchantments", CompoundTag.class); + for (Tag enchEntry : ench) { + if (enchEntry instanceof CompoundTag) { + CompoundTag enchantmentEntry = new CompoundTag(""); + enchantmentEntry.put(new StringTag("id", + MappingData.oldEnchantmentsIds.get( + (short) ((CompoundTag) enchEntry).get("id").getValue() + ) + )); + enchantmentEntry.put(new ShortTag("lvl", (Short) ((CompoundTag) enchEntry).get("lvl").getValue())); + enchantments.add(enchantmentEntry); + } + } + tag.remove("ench"); + tag.put(enchantments); + } } int rawId = (item.getId() << 4 | item.getData() & 0xF); @@ -345,7 +342,13 @@ public class InventoryPackets { } if (!MappingData.oldToNewItems.containsKey(rawId)) { - if (MappingData.oldToNewItems.containsKey(rawId & ~0xF)) { + if (!isDamageable(item.getId()) && item.getId() != 358) { // Map + if (tag == null) item.setTag(tag = new CompoundTag("tag")); + tag.put(new IntTag(NBT_TAG_NAME, originalId)); // Data will be lost, saving original id + } + if (item.getId() == 31 && item.getData() == 0) { // Shrub was removed + rawId = 32 << 4; // Dead Bush + } else if (MappingData.oldToNewItems.containsKey(rawId & ~0xF)) { rawId &= ~0xF; // Remove data } else { System.out.println("FAILED TO GET 1.13 ITEM FOR " + item.getId()); // TODO: Make this nicer etc, perhaps fix issues with mapping :T @@ -378,7 +381,7 @@ public class InventoryPackets { } if (rawId == null) { - Integer oldId = MappingData.newToOldItems.get((int) item.getId()); + Integer oldId = MappingData.oldToNewItems.inverse().get((int) item.getId()); if (oldId != null) { // Handle spawn eggs Optional eggEntityId = SpawnEggRewriter.getEntityId(oldId); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/providers/BlockEntityProvider.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/providers/BlockEntityProvider.java index c495721c1..8256294f0 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/providers/BlockEntityProvider.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/providers/BlockEntityProvider.java @@ -42,7 +42,7 @@ public class BlockEntityProvider implements Provider { String id = (String) tag.get("id").getValue(); if (!handlers.containsKey(id)) { - System.out.println("Unhandled BlockEntity " + id + " full tag: " + tag); + //System.out.println("Unhandled BlockEntity " + id + " full tag: " + tag); return -1; } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/providers/blockentities/FlowerPotHandler.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/providers/blockentities/FlowerPotHandler.java index fa740b7dc..79ac4807d 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/providers/blockentities/FlowerPotHandler.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/providers/blockentities/FlowerPotHandler.java @@ -9,47 +9,53 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; public class FlowerPotHandler implements BlockEntityProvider.BlockEntityHandler { - private static final Map, Integer> flowers = new ConcurrentHashMap<>(); + private static final Map, Integer> flowers = new ConcurrentHashMap<>(); + private static final Map, Integer> flowersNumberId = new ConcurrentHashMap<>(); static { - register("minecraft:air", 0, 5265); - register("minecraft:sapling", 0, 5266); - register("minecraft:sapling", 1, 5267); - register("minecraft:sapling", 2, 5268); - register("minecraft:sapling", 3, 5269); - register("minecraft:sapling", 4, 5270); - register("minecraft:sapling", 5, 5271); - register("minecraft:tallgrass", 2, 5272); - register("minecraft:yellow_flower", 0, 5273); - register("minecraft:red_flower", 0, 5274); - register("minecraft:red_flower", 1, 5275); - register("minecraft:red_flower", 2, 5276); - register("minecraft:red_flower", 3, 5277); - register("minecraft:red_flower", 4, 5278); - register("minecraft:red_flower", 5, 5279); - register("minecraft:red_flower", 6, 5280); - register("minecraft:red_flower", 7, 5281); - register("minecraft:red_flower", 8, 5282); - register("minecraft:red_mushroom", 0, 5283); - register("minecraft:brown_mushroom", 0, 5284); - register("minecraft:deadbush", 0, 5285); - register("minecraft:cactus", 0, 5286); + register("minecraft:air", (byte) 0, (byte) 0, 5265); + register("minecraft:sapling", (byte) 6, (byte) 0, 5266); + register("minecraft:sapling", (byte) 6, (byte) 1, 5267); + register("minecraft:sapling", (byte) 6, (byte) 2, 5268); + register("minecraft:sapling", (byte) 6, (byte) 3, 5269); + register("minecraft:sapling", (byte) 6, (byte) 4, 5270); + register("minecraft:sapling", (byte) 6, (byte) 5, 5271); + register("minecraft:tallgrass", (byte) 31, (byte) 2, 5272); + register("minecraft:yellow_flower", (byte) 37, (byte) 0, 5273); + register("minecraft:red_flower", (byte) 38, (byte) 0, 5274); + register("minecraft:red_flower", (byte) 38, (byte) 1, 5275); + register("minecraft:red_flower", (byte) 38, (byte) 2, 5276); + register("minecraft:red_flower", (byte) 38, (byte) 3, 5277); + register("minecraft:red_flower", (byte) 38, (byte) 4, 5278); + register("minecraft:red_flower", (byte) 38, (byte) 5, 5279); + register("minecraft:red_flower", (byte) 38, (byte) 6, 5280); + register("minecraft:red_flower", (byte) 38, (byte) 7, 5281); + register("minecraft:red_flower", (byte) 38, (byte) 8, 5282); + register("minecraft:red_mushroom", (byte) 40, (byte) 0, 5283); + register("minecraft:brown_mushroom", (byte) 39, (byte) 0, 5284); + register("minecraft:deadbush", (byte) 32, (byte) 0, 5285); + register("minecraft:cactus", (byte) 81, (byte) 0, 5286); } - public static void register(String identifier, int blockData, int newId) { + public static void register(String identifier, byte numbericBlockId, byte blockData, int newId) { flowers.put(new Pair<>(identifier, blockData), newId); + flowersNumberId.put(new Pair<>(numbericBlockId, blockData), newId); } @Override public int transform(UserConnection user, CompoundTag tag) { - String item = (String) tag.get("Item").getValue(); - int data = (int) tag.get("Data").getValue(); + Object item = tag.get("Item").getValue(); + byte data = ((Number) tag.get("Data").getValue()).byteValue(); - Pair pair = new Pair<>(item, data); + Pair pair = item instanceof Number + ? new Pair<>(((Number) item).byteValue(), data) + : new Pair<>((String) item, data); if (flowers.containsKey(pair)) { return flowers.get(pair); + } else if (flowersNumberId.containsKey(pair)) { + return flowersNumberId.get(pair); } else { System.out.println("Could not find flowerpot content " + item + " for " + tag); } diff --git a/common/src/main/resources/assets/viaversion/data/mapping-1.12.json b/common/src/main/resources/assets/viaversion/data/mapping-1.12.json index 29822180c..f923bb0c2 100644 --- a/common/src/main/resources/assets/viaversion/data/mapping-1.12.json +++ b/common/src/main/resources/assets/viaversion/data/mapping-1.12.json @@ -1743,7 +1743,7 @@ "448": "minecraft:detector_rail", "464": "minecraft:sticky_piston", "480": "minecraft:cobweb", - "496": "minecraft:dead_bush", + //"496": "minecraft:dead_bush", "497": "minecraft:grass", "498": "minecraft:fern", "512": "minecraft:dead_bush", diff --git a/jar/pom.xml b/jar/pom.xml index 5d8f89d98..6d57b8b20 100644 --- a/jar/pom.xml +++ b/jar/pom.xml @@ -5,7 +5,7 @@ viaversion-parent us.myles - 1.4.0-1.13-pre9 + 1.4.0-1.13-pre10 4.0.0 viaversion-jar diff --git a/pom.xml b/pom.xml index 3d09f4fcb..d6fc8f267 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ us.myles viaversion-parent - 1.4.0-1.13-pre9 + 1.4.0-1.13-pre10 pom viaversion-parent diff --git a/sponge-legacy/pom.xml b/sponge-legacy/pom.xml index 8cda8f1bc..ab1ab0284 100644 --- a/sponge-legacy/pom.xml +++ b/sponge-legacy/pom.xml @@ -5,7 +5,7 @@ viaversion-parent us.myles - 1.4.0-1.13-pre9 + 1.4.0-1.13-pre10 4.0.0 diff --git a/sponge/pom.xml b/sponge/pom.xml index 7e862548e..c9e2d0040 100644 --- a/sponge/pom.xml +++ b/sponge/pom.xml @@ -5,7 +5,7 @@ viaversion-parent us.myles - 1.4.0-1.13-pre9 + 1.4.0-1.13-pre10 4.0.0