Skip to content

Commit

Permalink
Improve error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
mezz committed Jun 9, 2016
1 parent ab8bb32 commit 1d7a7cc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
19 changes: 16 additions & 3 deletions src/main/java/mezz/jei/util/ErrorUtil.java
Expand Up @@ -8,6 +8,7 @@
import mezz.jei.Internal;
import mezz.jei.api.recipe.IRecipeHandler;
import mezz.jei.api.recipe.IRecipeWrapper;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
Expand Down Expand Up @@ -106,15 +107,27 @@ public static String getItemStackInfo(@Nonnull ItemStack itemStack) {
if (registryName != null) {
itemName = registryName.toString();
} else if (item instanceof ItemBlock) {
itemName = "ItemBlock(" + ((ItemBlock) item).getBlock() + ")";
final String blockName;
Block block = ((ItemBlock) item).getBlock();
if (block == null) {
blockName = "null";
} else {
ResourceLocation blockRegistryName = block.getRegistryName();
if (blockRegistryName != null) {
blockName = blockRegistryName.toString();
} else {
blockName = block.getClass().getName();
}
}
itemName = "ItemBlock(" + blockName + ")";
} else {
itemName = item.getClass().getName();
}

NBTTagCompound nbt = itemStack.getTagCompound();
if (nbt != null) {
return itemStack.toString() + " " + itemName + " nbt:" + nbt;
return itemStack + " " + itemName + " nbt:" + nbt;
}
return itemStack.toString() + " " + itemName;
return itemStack + " " + itemName;
}
}
3 changes: 2 additions & 1 deletion src/main/java/mezz/jei/util/ItemStackElement.java
Expand Up @@ -65,7 +65,8 @@ private ItemStackElement(@Nonnull ItemStack itemStack) {

String displayName = itemStack.getDisplayName();
if (displayName == null) {
throw new NullPointerException("No display name for item. " + itemResourceLocation + ' ' + item.getClass());
String stackInfo = ErrorUtil.getItemStackInfo(itemStack);
throw new NullPointerException("No display name for item. " + stackInfo);
}
displayName = displayName.toLowerCase();

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/mezz/jei/util/StackHelper.java
Expand Up @@ -347,7 +347,8 @@ public String getUniqueIdentifierForStack(@Nonnull ItemStack stack, @Nonnull Uid

ResourceLocation itemName = Item.REGISTRY.getNameForObject(item);
if (itemName == null) {
throw new NullPointerException("Item.itemRegistry.getNameForObject returned null for: " + item.getClass());
String stackInfo = ErrorUtil.getItemStackInfo(stack);
throw new NullPointerException("Item is not registered. Item.REGISTRY.getNameForObject returned null for: " + stackInfo);
}

String itemNameString = itemName.toString();
Expand Down

0 comments on commit 1d7a7cc

Please sign in to comment.