Why can't the exception be caught
joe-vettek opened this issue ยท 2 comments
Describe the feature you'd like
Many methods return errors instead of null (such as BracketHandlers.getItem), but CRT cannot handle exceptions. I think this is a super flaw.
Describe alternatives you've considered
No response
Additional context
No response
Minecraft version
1.16
Uh, I think you greatly misunderstand what is going on.
CraftTweaker is the one throwing those errors because scripters are making mistakes.
There is no such thing as a null ItemStack, we throw the errors because getting an ItemStack that doesn't exist is something that is very important for a scripter to know so they can fix it.
If we returned null, that would cause a plethora of other issues, we now need to handle null ItemStacks everywhere, you the scripter will never know that you had the wrong name and will now need to figure out why your recipe isn't working, or why the recipe asks for an empty slot even though you used the <item:minecraft:apples>
item (which is not a valid item.
Please elaborate on what you mean by:
CRT cannot handle exceptions
It seems to work perfectly fine for me:
Granted it does have the error message twice, which is something that needs fixing, but the error is very much there.
#debug
import crafttweaker.api.item.IItemStack;
import crafttweaker.api.BracketHandlers;
import stdlib.IllegalArgumentException;
public function isItemExists(name as string) as bool {
var result = false;
try {
BracketHandlers.getItem(name);
result = true;
} catch e as IllegalArgumentException {
result = false;
}
return result;
}
print(isItemExists("minecraft:apple"));
print(isItemExists("minecraft:apple_pen"));