Skip to content

Commit

Permalink
Improve error when trying to get NBT from non BlockEntity BlockStates.
Browse files Browse the repository at this point in the history
…Fix #276
  • Loading branch information
tr7zw committed May 18, 2024
1 parent 30f75e0 commit 8570c6f
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 8570c6f

Please sign in to comment.