From 4e2156bd2bbf69cb036a1c26a71f52ce7e01d606 Mon Sep 17 00:00:00 2001 From: creeper123123321 Date: Fri, 20 Jul 2018 07:14:51 -0300 Subject: [PATCH 1/3] Remove redundant tags --- .../data/SpawnEggRewriter.java | 3 +- .../packets/InventoryPackets.java | 37 ++++++++++++------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/SpawnEggRewriter.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/SpawnEggRewriter.java index 80ce89112..d4ff6564c 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/SpawnEggRewriter.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/SpawnEggRewriter.java @@ -64,7 +64,8 @@ public class SpawnEggRewriter { public static int getSpawnEggId(String entityIdentifier) { // Fallback to bat if (!spawnEggs.containsKey(entityIdentifier)) - return 25100288; + //return 25100288; + return -1; return (383 << 16 | (spawnEggs.get(entityIdentifier) & 0xFFFF)); } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java index c6d4d4429..1025771f7 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java @@ -265,6 +265,8 @@ public class InventoryPackets { // Save original id int originalId = (item.getId() << 16 | item.getData() & 0xFFFF); + int rawId = (item.getId() << 4 | item.getData() & 0xF); + // NBT Additions if (isDamageable(item.getId())) { if (tag == null) item.setTag(tag = new CompoundTag("tag")); @@ -343,24 +345,31 @@ public class InventoryPackets { tag.remove("StoredEnchantments"); tag.put(newStoredEnch); } - } - - int rawId = (item.getId() << 4 | item.getData() & 0xF); - - // Handle SpawnEggs - if (item.getId() == 383) { - if (tag != null && tag.get("EntityTag") instanceof CompoundTag) { - CompoundTag entityTag = tag.get("EntityTag"); - if (entityTag.get("id") instanceof StringTag) { - StringTag identifier = entityTag.get("id"); - rawId = SpawnEggRewriter.getSpawnEggId(identifier.getValue()); + // Handle SpawnEggs + if (item.getId() == 383) { + if (tag.get("EntityTag") instanceof CompoundTag) { + CompoundTag entityTag = tag.get("EntityTag"); + if (entityTag.get("id") instanceof StringTag) { + StringTag identifier = entityTag.get("id"); + rawId = SpawnEggRewriter.getSpawnEggId(identifier.getValue()); + if (rawId == -1) { + rawId = 25100288; // Bat fallback + } else { + entityTag.remove("id"); + if (entityTag.isEmpty()) + tag.remove("EntityTag"); + } + } else { + // Fallback to bat + rawId = 25100288; + } } else { // Fallback to bat rawId = 25100288; } - } else { - // Fallback to bat - rawId = 25100288; + } + if (tag.isEmpty()) { + item.setTag(tag = null); } } From 78b9e5d8330486e4a75b9027a922023319efcf5b Mon Sep 17 00:00:00 2001 From: creeper123123321 Date: Fri, 20 Jul 2018 10:26:56 -0300 Subject: [PATCH 2/3] Fix biomes --- .../protocol1_13to1_12_2/packets/WorldPackets.java | 9 +++++++++ .../protocol1_13to1_12_2/types/Chunk1_13Type.java | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java index 055957a56..32468ab5e 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java @@ -171,6 +171,15 @@ public class WorldPackets { } } + // Rewrite biome id 255 to plains + if (chunk.isBiomeData()) { + for (int i = 0; i < 256; i++) { + int data = chunk.getBiomeData()[i] & 0xFF; + if (data == 255) + chunk.getBiomeData()[i] = 1; + } + } + // Rewrite BlockEntities to normal blocks BlockEntityProvider provider = Via.getManager().getProviders().get(BlockEntityProvider.class); for (CompoundTag tag : chunk.getBlockEntities()) { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/types/Chunk1_13Type.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/types/Chunk1_13Type.java index c7c5d93c2..f5941f5be 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/types/Chunk1_13Type.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/types/Chunk1_13Type.java @@ -101,7 +101,7 @@ public class Chunk1_13Type extends PartialType { // Write biome data if (chunk.isBiomeData()) { for (byte value : chunk.getBiomeData()) { - output.writeInt(0); // This is a temporary workaround, we'll look into fixing this soon :) + output.writeInt(value & 0xFF); // This is a temporary workaround, we'll look into fixing this soon :) } } From a2fce6f4a5279d7071a488cbfecddebf1d9882cb Mon Sep 17 00:00:00 2001 From: creeper123123321 Date: Fri, 20 Jul 2018 10:29:51 -0300 Subject: [PATCH 3/3] Update WorldPackets.java --- .../protocols/protocol1_13to1_12_2/packets/WorldPackets.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java index 32468ab5e..fcf898dca 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java @@ -174,8 +174,7 @@ public class WorldPackets { // Rewrite biome id 255 to plains if (chunk.isBiomeData()) { for (int i = 0; i < 256; i++) { - int data = chunk.getBiomeData()[i] & 0xFF; - if (data == 255) + if (chunk.getBiomeData()[i] == -1) chunk.getBiomeData()[i] = 1; } }