Fixed NbtDataImpl not working in creative mode

This commit is contained in:
themode 2020-11-11 00:29:06 +01:00
parent 78bf5dda05
commit 99d27b78c4
2 changed files with 6 additions and 5 deletions

View File

@ -45,7 +45,8 @@ public class NbtDataImpl extends DataImpl {
Check.notNull(nbt, Check.notNull(nbt,
"The type '" + type + "' is not supported within NbtDataImpl, if you wish to use a custom type you can encode the value into a byte array using a DataType"); "The type '" + type + "' is not supported within NbtDataImpl, if you wish to use a custom type you can encode the value into a byte array using a DataType");
nbtCompound.set(KEY_PREFIX + key, nbt); final String finalKey = KEY_PREFIX + key;
nbtCompound.set(finalKey, nbt);
} }
} }

View File

@ -188,21 +188,21 @@ public final class NBTUtils {
// Meta specific field // Meta specific field
final ItemMeta itemMeta = item.getItemMeta(); final ItemMeta itemMeta = item.getItemMeta();
if (itemMeta == null) if (itemMeta != null) {
return; itemMeta.read(nbt);
itemMeta.read(nbt); }
NbtDataImpl customData = null; NbtDataImpl customData = null;
for (String key : nbt.getKeys()) { for (String key : nbt.getKeys()) {
if (key.startsWith(NbtDataImpl.KEY_PREFIX)) { if (key.startsWith(NbtDataImpl.KEY_PREFIX)) {
if (customData == null) { if (customData == null) {
customData = new NbtDataImpl(); customData = new NbtDataImpl();
item.setData(customData);
} }
final NBT keyNbt = nbt.get(key); final NBT keyNbt = nbt.get(key);
final String dataKey = key.replaceFirst(NbtDataImpl.KEY_PREFIX, ""); final String dataKey = key.replaceFirst(NbtDataImpl.KEY_PREFIX, "");
final Object dataValue = fromNBT(keyNbt); final Object dataValue = fromNBT(keyNbt);
customData.set(dataKey, dataValue); customData.set(dataKey, dataValue);
} }
} }