ContentTweaker

ContentTweaker

27M Downloads

Newly created MaterialPart throws runtime NullPointerException

Shananiganeer opened this issue ยท 4 comments

commented

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
commented

Don't use that in ContentTweaker Scripts. that method is more for ease of use in CraftTweaker scripts.

commented

Is it possible to programmatically get the appropriate IItemStack from a MaterialPart in a ContentTweaker script through another method?

commented

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.

commented

In that case, I think I understand what I need to do. I hopped in discord and am waiting on the 10m to type. I'll take another crack at this a little later (when I get a free moment at work XD) and reach out on discord for help.