diff --git a/item-nbt-api/src/main/java/de/tr7zw/changeme/nbtapi/NBTReflectionUtil.java b/item-nbt-api/src/main/java/de/tr7zw/changeme/nbtapi/NBTReflectionUtil.java index 5c50ac154..733f2d303 100644 --- a/item-nbt-api/src/main/java/de/tr7zw/changeme/nbtapi/NBTReflectionUtil.java +++ b/item-nbt-api/src/main/java/de/tr7zw/changeme/nbtapi/NBTReflectionUtil.java @@ -213,8 +213,9 @@ public static Object convertNBTCompoundtoNMSItem(NBTCompound nbtcompound) { try { Object nmsComp = getToCompount(nbtcompound.getCompound(), nbtcompound); if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_20_R4)) { - if(nbtcompound.hasTag("tag")) { - nmsComp = DataFixerUtil.fixUpRawItemData(nmsComp, DataFixerUtil.VERSION1_20_4, DataFixerUtil.getCurrentVersion()); + if (nbtcompound.hasTag("tag")) { + nmsComp = DataFixerUtil.fixUpRawItemData(nmsComp, DataFixerUtil.VERSION1_20_4, + DataFixerUtil.getCurrentVersion()); } return ReflectionMethod.NMSITEM_LOAD.run(null, registry_access, nmsComp); } else if (MinecraftVersion.getVersion().getVersionId() >= MinecraftVersion.MC1_11_R1.getVersionId()) { @@ -316,6 +317,11 @@ public static Object getTileEntityNBTTagCompound(BlockState tile) { o = ReflectionMethod.NMS_WORLD_GET_TILEENTITY.run(nmsworld, pos); } + if (o == null) { + throw new NbtApiException("The passed BlockState(" + tile.getType() + + ") doesn't point to a BlockEntity. Only BlockEntities like Chest/Signs/Furnance/etc have NBT."); + } + Object answer = null; if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_20_R4)) { answer = ReflectionMethod.TILEENTITY_GET_NBT_1205.run(o, registry_access);