Newly created MaterialPart throws runtime NullPointerException
Shananiganeer opened this issue ยท 4 comments
After registering a new MaterialPart with Material.registerPart, attempting to get the IItemStack with MaterialPart.getItemStack() throws a NullPointerException. The stack trace shows that the call makes it to the getItemStack() method of the appropriate PartType, but then throws the exception. All other methods of the created MaterialPart work as expected.
What I am trying to do is: create new clusters then change their oreDict to ore:oreNAME, create new ores then change their oreDict to ore:oreBlockNAME, and finally add the cluster as the drop from the ore. I can create the clusters/ores and they show up in game as expected, however, I cannot adjust the oreDict or add the drop as I am unable to get the resulting ItemStack after it has been created. It does work when I hardcode the resulting item's resource ID after checking what ID it got in-game and therefore do not use MaterialPart.getItemStack().
Example code:
import crafttweaker.item.IItemStack;
import mods.contenttweaker.Color;
import mods.contenttweaker.Material;
import mods.contenttweaker.MaterialPart;
import mods.contenttweaker.MaterialSystem;
var material = MaterialSystem.getMaterialBuilder().setName("Test").setColor(10261385).build();
var materialPart = material.registerPart("cluster");
var item = materialPart.getItemStack(); <---- this line throws the runtime error
Don't use that in ContentTweaker Scripts. that method is more for ease of use in CraftTweaker scripts.
Is it possible to programmatically get the appropriate IItemStack from a MaterialPart in a ContentTweaker script through another method?
You shouldn't be messing with IItemStacks in COntentTweaker scripts for the most part. Oredict changes and such, should be done in CraftTweaker's script. If you want you can pop into Discord and explain your scripts and such there, and I can help.