Block registration requires the ability to register an ItemGroup
Closed this issue · 2 comments
Either simpleItem
needs to have an ItemGroup parameter, of the builder itself needs to have some sort of function which accepts an ItemGroup.
Without this, there's a series of obscure errors occurs when you attempt to register recipes for blocks:
public static RegistryObject<Block> BRICKS = REGISTRATE.object("polished_andesite_bricks")
.block(Block::new)
.properties(STONE_PROPS)
.simpleItem()
.recipe(ctx -> {
ShapedRecipeBuilder.shapedRecipe(ctx.getEntry(), 4)
.patternLine("XX")
.patternLine("XX")
.key('X', Items.POLISHED_ANDESITE)
.addCriterion("has_andesite", ctx.getProvider().hasItem(Items.POLISHED_ANDESITE))
.build(ctx.getProvider());
SingleItemRecipeBuilder.stonecuttingRecipe(Ingredient.fromItems(Items.POLISHED_ANDESITE), ctx.getEntry())
.addCriterion("has_andesite", ctx.getProvider().hasItem(Items.POLISHED_ANDESITE))
.build(ctx.getProvider(), new ResourceLocation(Glimmering.MODID, "polished_andesite_bricks_from_stonecutting"));
})
.register();
Results in the following error, pointing to the first .build
line:
[19:02:00] [main/INFO] [STDERR/]: [java.lang.Throwable:printStackTrace:643]: Caused by: java.lang.NullPointerException
[19:02:00] [main/INFO] [STDERR/]: [java.lang.Throwable:printStackTrace:643]: at net.minecraft.data.ShapedRecipeBuilder.build(SourceFile:108)
[19:02:00] [main/INFO] [STDERR/]: [java.lang.Throwable:printStackTrace:643]: at net.minecraft.data.ShapedRecipeBuilder.build(SourceFile:90)
[19:02:00] [main/INFO] [STDERR/]: [java.lang.Throwable:printStackTrace:643]: at noobanidus.mods.glimmering.init.ModBlocks.lambda$static$4(ModBlocks.java:58)
It took me a little time to track this down, but I eventually realised that the breakpoint actually gets considerably past this point where the supposed NullPointerException happens:
p_200467_1_.accept(new ShapedRecipeBuilder.Result(p_200467_2_, this.result, this.count, this.group == null ? "" : this.group, this.pattern, this.key, this.advancementBuilder, new ResourceLocation(p_200467_2_.getNamespace(), "recipes/" + --> this.result.getGroup().getPath() <-- + "/" + p_200467_2_.getPath())));
(Line 110 of ShapedRecipeBuilder)
The result of the recipe doesn't have an itemGroup (null), hence the .getPath
call fails.
My current solution to this was:
.item()
.properties((o) -> o.group(Glimmering.ITEM_GROUP))
.build()
.recipe(ctx -> {
which could be easily simplified.
Yeah, that's a tricky one. I don't really want the block builder to care about itemgroups. I think having simpleItem accept the ItemGroup makes the most sense, in addition to more helpers in that department in general.
REGISTRATE.itemGroup(() -> Glimmering.ITEM_GROUP);
or
.item().group(() -> Glimmering.ITEM_GROUP).build()
I opted not to modify BlockBuilder as accepting a group there would double the method count and require me to duplicate some logic, for not much gain. If you see a good reason for that feature, feel free to open another issue.