Fix NPE for unknown beds & keep original NBT data

This commit is contained in:
Matsv 2017-07-29 13:19:59 +02:00
parent ea2f603cf7
commit dbc92572fd
No known key found for this signature in database
GPG Key ID: 97CEC2A2EA31350F
2 changed files with 13 additions and 2 deletions

View File

@ -52,8 +52,15 @@ public abstract class BlockItemRewriter<T extends BackwardsProtocol> extends Rew
if (i.getTag() == null) if (i.getTag() == null)
i.setTag(new CompoundTag("")); i.setTag(new CompoundTag(""));
// Backup data for toServer
i.getTag().put(createViaNBT(original)); i.getTag().put(createViaNBT(original));
// Keep original data
if (original.getTag() != null)
for (Tag ai : original.getTag())
i.getTag().put(ai);
// Handle colors // Handle colors
if (i.getTag().contains("display")) { if (i.getTag().contains("display")) {
CompoundTag tag = i.getTag().get("display"); CompoundTag tag = i.getTag().get("display");
@ -76,6 +83,8 @@ public abstract class BlockItemRewriter<T extends BackwardsProtocol> extends Rew
data.getItemHandler().handle(i); data.getItemHandler().handle(i);
} }
System.out.println(i);
return i; return i;
} }
@ -146,8 +155,10 @@ public abstract class BlockItemRewriter<T extends BackwardsProtocol> extends Rew
for (int z = 0; z < 16; z++) { for (int z = 0; z < 16; z++) {
int block = section.getBlock(x, y, z); int block = section.getBlock(x, y, z);
int btype = block >> 4; int btype = block >> 4;
int meta = block & 15;
if (containsBlock(btype)) { 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()); section.setBlock(x, y, z, b.getId(), b.getData());
} }
// Entity Tags // Entity Tags

View File

@ -45,6 +45,6 @@ public class BlockColors {
} }
public static String get(Integer key) { public static String get(Integer key) {
return colors.get(key); return colors.getOrDefault(key, "Unknown color");
} }
} }