From dbc92572fd3e70222df4c458b7537682b3215bfc Mon Sep 17 00:00:00 2001 From: Matsv Date: Sat, 29 Jul 2017 13:19:59 +0200 Subject: [PATCH] Fix NPE for unknown beds & keep original NBT data --- .../api/rewriters/BlockItemRewriter.java | 13 ++++++++++++- .../protocol1_12to1_11_1/data/BlockColors.java | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/nl/matsv/viabackwards/api/rewriters/BlockItemRewriter.java b/core/src/main/java/nl/matsv/viabackwards/api/rewriters/BlockItemRewriter.java index acf76fdb..fc0fd4b2 100644 --- a/core/src/main/java/nl/matsv/viabackwards/api/rewriters/BlockItemRewriter.java +++ b/core/src/main/java/nl/matsv/viabackwards/api/rewriters/BlockItemRewriter.java @@ -52,8 +52,15 @@ public abstract class BlockItemRewriter extends Rew if (i.getTag() == null) i.setTag(new CompoundTag("")); + + // Backup data for toServer i.getTag().put(createViaNBT(original)); + // Keep original data + if (original.getTag() != null) + for (Tag ai : original.getTag()) + i.getTag().put(ai); + // Handle colors if (i.getTag().contains("display")) { CompoundTag tag = i.getTag().get("display"); @@ -76,6 +83,8 @@ public abstract class BlockItemRewriter extends Rew data.getItemHandler().handle(i); } + System.out.println(i); + return i; } @@ -146,8 +155,10 @@ public abstract class BlockItemRewriter extends Rew for (int z = 0; z < 16; z++) { int block = section.getBlock(x, y, z); int btype = block >> 4; + int meta = block & 15; + if (containsBlock(btype)) { - Block b = handleBlock(btype, block & 15); // Type / data + Block b = handleBlock(btype, meta); // Type / data section.setBlock(x, y, z, b.getId(), b.getData()); } // Entity Tags diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12to1_11_1/data/BlockColors.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12to1_11_1/data/BlockColors.java index 0d53d99f..40666a5e 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12to1_11_1/data/BlockColors.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12to1_11_1/data/BlockColors.java @@ -45,6 +45,6 @@ public class BlockColors { } public static String get(Integer key) { - return colors.get(key); + return colors.getOrDefault(key, "Unknown color"); } }