From 9fe187c0491a5198e0fd63bbd58e8c22bbbe3c54 Mon Sep 17 00:00:00 2001 From: creeper123123321 Date: Tue, 20 Mar 2018 13:46:26 -0300 Subject: [PATCH 1/4] Fix block and item rewriting --- .../packets/InventoryPackets.java | 29 +++++++++---------- .../packets/WorldPackets.java | 2 +- .../providers/blockentities/SkullHandler.java | 1 + 3 files changed, 15 insertions(+), 17 deletions(-) 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 69459eb74..7ebe36580 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 @@ -198,7 +198,7 @@ public class InventoryPackets { public static void toClient(Item item) { if (item == null) return; - int rawId = (item.getId() << 4 | item.getData() & 0xF); + int rawId = (item.getId() << 16 | item.getData() & 0xFFFF); int originalId = rawId; if (!MappingData.oldToNewItems.containsKey(rawId)) { if (MappingData.oldToNewItems.containsKey(item.getId() << 4)) { @@ -219,32 +219,29 @@ public class InventoryPackets { public static void toServer(Item item) { if (item == null) return; - int rawId = -1; if (item.getTag() != null) { CompoundTag tag = item.getTag(); // Check for valid tag if (tag.contains(NBT_TAG_NAME)) { if (tag.get(NBT_TAG_NAME) instanceof IntTag) { - rawId = (int) tag.get(NBT_TAG_NAME).getValue(); + int rawId = (int) tag.get(NBT_TAG_NAME).getValue(); // Remove the tag tag.remove(NBT_TAG_NAME); + item.setId((short) (rawId >> 16)); + item.setData((short) (rawId & 0xFFFF)); + return; } } } - if (rawId == -1){ - int itemID = item.getId(); - for (Map.Entry entry : MappingData.oldToNewItems.entrySet()){ - if (entry.getValue() == itemID){ - rawId = entry.getKey(); - break; - } + int itemID = item.getId(); + for (Map.Entry entry : MappingData.oldToNewItems.entrySet()){ + if (entry.getValue() == itemID){ + int rawId = entry.getKey(); + item.setId((short) (rawId >> 4)); + item.setData((short) (rawId & 0xF)); + return; } } - if (rawId != -1) { - item.setId((short) (rawId >> 4)); - item.setData((short) (rawId & 0xF)); - } else { - System.out.println("FAILED TO GET 1.12 ITEM FOR " + item.getId()); // TODO: Make this nicer etc, perhaps fix issues with mapping :T - } + System.out.println("FAILED TO GET 1.12 ITEM FOR " + item.getId()); // TODO: Make this nicer etc, perhaps fix issues with mapping :T } } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/packets/WorldPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/packets/WorldPackets.java index 3a5b72af2..665eb74ea 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/packets/WorldPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/packets/WorldPackets.java @@ -179,7 +179,7 @@ public class WorldPackets { if (storage.contains(position)) storage.get(position).setReplacement(newId); - chunk.getSections()[y >> 4].setFlatBlock(x & 0xF, y, z & 0xF, newId); + chunk.getSections()[y >> 4].setFlatBlock(x & 0xF, y & 0xF, z & 0xF, newId); } } } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/providers/blockentities/SkullHandler.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/providers/blockentities/SkullHandler.java index 6b42359db..752d739e5 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/providers/blockentities/SkullHandler.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/providers/blockentities/SkullHandler.java @@ -27,6 +27,7 @@ public class SkullHandler implements BlockEntityProvider.BlockEntityHandler { id += (byte) tag.get("SkullType").getValue() * 20 + (byte) tag.get("Rot").getValue(); } else { System.out.println("Why does this block have the skull block entity? :(" + tag); + return -1; } return id; From c102ca7f153a2b034b92bc2bda8b763a4a251b85 Mon Sep 17 00:00:00 2001 From: creeper123123321 Date: Tue, 20 Mar 2018 14:21:37 -0300 Subject: [PATCH 2/4] shield, damageable, map item rewriting --- .../packets/InventoryPackets.java | 91 +++++++++++++++---- 1 file changed, 73 insertions(+), 18 deletions(-) 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 7ebe36580..05366b830 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 @@ -200,6 +200,11 @@ public class InventoryPackets { if (item == null) return; int rawId = (item.getId() << 16 | item.getData() & 0xFFFF); int originalId = rawId; + // Save original id + CompoundTag tag = item.getTag(); + if (tag == null) { + item.setTag(tag = new CompoundTag("tag")); + } if (!MappingData.oldToNewItems.containsKey(rawId)) { if (MappingData.oldToNewItems.containsKey(item.getId() << 4)) { rawId = item.getId() << 4; @@ -208,40 +213,90 @@ public class InventoryPackets { rawId = 16; // Stone } } + if (isDamageable(item.getId())) { + tag.put(new IntTag("Damage", item.getData())); + } + if (item.getId() == 358) { // map + 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()); + } + } + } item.setId(MappingData.oldToNewItems.get(rawId).shortValue()); item.setData((short) 0); - // Save original id - if (item.getTag() == null) { - item.setTag(new CompoundTag("tag")); - } item.getTag().put(new IntTag(NBT_TAG_NAME, originalId)); } public static void toServer(Item item) { if (item == null) return; - if (item.getTag() != null) { - CompoundTag tag = item.getTag(); + Integer rawId = null; + boolean gotRawIdFromTag = false; + CompoundTag tag = item.getTag(); + if (tag != null) { // Check for valid tag if (tag.contains(NBT_TAG_NAME)) { if (tag.get(NBT_TAG_NAME) instanceof IntTag) { - int rawId = (int) tag.get(NBT_TAG_NAME).getValue(); + rawId = (Integer) tag.get(NBT_TAG_NAME).getValue(); // Remove the tag tag.remove(NBT_TAG_NAME); - item.setId((short) (rawId >> 16)); - item.setData((short) (rawId & 0xFFFF)); - return; + gotRawIdFromTag = true; } } } - int itemID = item.getId(); - for (Map.Entry entry : MappingData.oldToNewItems.entrySet()){ - if (entry.getValue() == itemID){ - int rawId = entry.getKey(); - item.setId((short) (rawId >> 4)); - item.setData((short) (rawId & 0xF)); - return; + if (rawId == null) { + for (Map.Entry entry : MappingData.oldToNewItems.entrySet()) { + if (entry.getValue() == item.getId()) { + int oldId = entry.getKey(); + rawId = oldId >> 4 << 16 | oldId & 0xF; + } } } - System.out.println("FAILED TO GET 1.12 ITEM FOR " + item.getId()); // TODO: Make this nicer etc, perhaps fix issues with mapping :T + if (rawId != null) { + item.setId((short) (rawId >> 16)); + item.setData((short) (rawId & 0xFFFF)); + if (!gotRawIdFromTag) { + if (isDamageable(item.getId())) { + if (tag != null && tag.get("Damage") instanceof IntTag) { + item.setData((short) (int) tag.get("Damage").getValue()); + } + } + if (item.getId() == 358) { // map + if (tag != null && tag.get("map") instanceof IntTag) { + item.setData((short) (int) tag.get("map").getValue()); + } + } + } + if (item.getId() == 442) { // shield + if (tag != null && 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()); + } + } + } + } else { + System.out.println("FAILED TO GET 1.12 ITEM FOR " + item.getId()); // TODO: Make this nicer etc, perhaps fix issues with mapping :T + } + } + + public static boolean isDamageable(int id) { + return id >= 256 && id <= 259 // iron shovel, pickaxe, axe, flint and steel + || id == 261 // bow + || id >= 267 && id <= 279 // iron sword, wooden+stone+diamond swords, shovels, pickaxes, axes + || id >= 283 && id <= 286 // gold sword, shovel, pickaxe, axe + || id >= 290 && id <= 294 // hoes + || id >= 298 && id <= 317 // armors + || id == 346 // fishing rod + || id == 359 // shears + || id == 398 // carrot on a stick + || id == 442 // shield + || id == 443; // elytra } } From 39dea80d9c58b6cfddd863c988b08212c9dea1b7 Mon Sep 17 00:00:00 2001 From: creeper123123321 Date: Tue, 20 Mar 2018 14:27:47 -0300 Subject: [PATCH 3/4] todo --- .../protocolsnapshotto1_12_2/packets/InventoryPackets.java | 1 + 1 file changed, 1 insertion(+) 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 05366b830..235d04dd5 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 @@ -228,6 +228,7 @@ public class InventoryPackets { } } } + // todo spawn egg item.setId(MappingData.oldToNewItems.get(rawId).shortValue()); item.setData((short) 0); item.getTag().put(new IntTag(NBT_TAG_NAME, originalId)); From 6571c42c3949f0b88e29a21d33397e9653d0f640 Mon Sep 17 00:00:00 2001 From: creeper123123321 Date: Tue, 20 Mar 2018 14:36:15 -0300 Subject: [PATCH 4/4] shield mapping --- .../src/main/resources/assets/viaversion/data/mapping-1.12.json | 1 + 1 file changed, 1 insertion(+) 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 82b5c9cd7..4d45db38f 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 @@ -2187,6 +2187,7 @@ "6813": "minecraft:magenta_banner", "6814": "minecraft:orange_banner", "6815": "minecraft:white_banner", + "7072": "minecraft:shield", "7088": "minecraft:elytra", "36096": "minecraft:music_disc_13", "36112": "minecraft:music_disc_cat",