MostafaSabry55 Posted October 18, 2020 Share Posted October 18, 2020 (edited) So basically I want to make lots of recipes, so public class Recipes extends RecipeProvider { public Recipes(DataGenerator generatorIn) { super(generatorIn); } @Override protected void registerRecipes(Consumer<IFinishedRecipe> consumer) { for (EnumMaterials material : EnumMaterials.values()) { for (int i = 0; i < 2; i++) { if (i == 0) { //final RegistryObject<Item> Plate = RegistryObject.of(new ResourceLocation(MorePlates.MODID, material.toString() + "_plate"), ForgeRegistries.ITEMS); final RegistryObject<Item> Ingot = RegistryObject.of(material.getTag(), ForgeRegistries.ITEMS); //TODO set back to Plate.get() ShapelessRecipeBuilder.shapelessRecipe(Ingot.get()) .addIngredient(Ingot.get(), 2) .addIngredient(ModItems.HAMMER.get()) .build(consumer); } else { final RegistryObject<Item> Gear = RegistryObject.of(new ResourceLocation(MorePlates.MODID, material.toString() + "_gear"), () -> Item.class); final RegistryObject<Item> Ingot = RegistryObject.of(material.getTag(), ForgeRegistries.ITEMS); ShapedRecipeBuilder.shapedRecipe(Gear.get()) .patternLine(" x ") .patternLine("x#x") .patternLine(" x ") .key('x', Ingot.get()) .key('#', Tags.Items.INGOTS_IRON) .build(consumer); } } } } So Plate.get() was erroring saying : [m[32m[20:36:27] [main/INFO] [STDERR/]: [java.lang.Throwable:printStackTrace:643]: Caused by: java.lang.NullPointerException: Registry Object not present: moreplates:brick_plate So I commented it out, checked if normal materials do work, but the problem is still present : [m[32m[20:36:27] [main/INFO] [STDERR/]: [java.lang.Throwable:printStackTrace:643]: Caused by: java.lang.NullPointerException: Registry Object not present: minecraft:brick This got me very confused, how am I supposed to DYNIMACALLY call RegistryObjects?? Some examples of what I set them to can be found in this part of my enum BRICK(new ResourceLocation("brick")), CHARCOAL(new ResourceLocation("charcoal")), COAL(new ResourceLocation("coal")), ALLTHEMODIUM(new ResourceLocation("allthemodium", "allthemodium")), ; EnumMaterials(ResourceLocation tag) { this.tag = tag; } @Override public String toString() { return name().toLowerCase(Locale.ENGLISH); } public ResourceLocation getTag() { return tag; } Any help is appreciated, thanks Edited October 18, 2020 by MostafaSabry55 Quote Link to comment Share on other sites More sharing options...
ChampionAsh5357 Posted October 18, 2020 Share Posted October 18, 2020 Why are you using a registry object if you just plan on grabbing the entry directly from the registry itself? For reference, the constructor only adds a handler to the object to populate the objects whenever they are frozen. However, since you are constructing after the snapshot occurs, they will never be populated. This can be circumvented by calling RegistryObject#updateReference, but there is simply no point as you can just grab the instance from the registry itself directly via ForgeRegistries. Quote Link to comment Share on other sites More sharing options...
MostafaSabry55 Posted October 18, 2020 Author Share Posted October 18, 2020 Iam completely sure I misunderstood what you said, please bear with me Item Plate = ForgeRegistries.ITEMS.getValue(new ResourceLocation(MorePlates.MODID, material.toString() + "_plate")); Item Ingot = ForgeRegistries.ITEMS.getValue(material.getTag()); ShapelessRecipeBuilder.shapelessRecipe(Plate) .addIngredient(Ingot, 2) .addIngredient(ItemTags.createOptional(new ResourceLocation(MorePlates.MODID, "hammer"))) .build(consumer); now that error is gone but it errors with the following [m[32m[21:16:39] [main/INFO] [STDERR/]: [java.lang.Throwable:printStackTrace:643]: Caused by: java.lang.IllegalStateException: No way of obtaining recipe moreplates:brick_plate Quote Link to comment Share on other sites More sharing options...
MostafaSabry55 Posted October 18, 2020 Author Share Posted October 18, 2020 I think I found the problem, I checked ShapelessRecipeBuilder.java:141 and it turns out if (this.advancementBuilder.getCriteria().isEmpty()) { throw new IllegalStateException("No way of obtaining recipe " + id); } is true, now there's this #addCriteria for recipe building, why do I need it and how do I use it? Quote Link to comment Share on other sites More sharing options...
MostafaSabry55 Posted October 18, 2020 Author Share Posted October 18, 2020 I fixed the error above but, After some even more painful investegating, I found out that my item's ItemGroup is null which is causing ShapelessRecipeBuilder.java:133 to error consumerIn.accept(new ShapelessRecipeBuilder.Result(id, this.result, this.count, this.group == null ? "" : this.group, this.ingredients, this.advancementBuilder, new ResourceLocation(id.getNamespace(), "recipes/" + this.result.getGroup().getPath() + "/" + id.getPath()))); the bit that errors is this new ResourceLocation( Registry.ITEM.getKey(Plate).getPath(), /* This line */ "recipes/" + Plate.getGroup().getPath() + "/" + Registry.ITEM.getKey(Plate).getPath()); Now I'm sure Iam setting an ItemGroup to it, as seen here public static RegistryObject<Item> register(String name) { return ITEMS.register(name, () -> new BaseItem( new Item.Properties().group(MorePlates.ITEMGROUP)) //This should work tho?? ); } I am in need of help, please Quote Link to comment Share on other sites More sharing options...
ChampionAsh5357 Posted October 18, 2020 Share Posted October 18, 2020 46 minutes ago, MostafaSabry55 said: I am in need of help, please Can you please show the entire code block including that of your ItemGroup. To me, some of this code just seems a bit out context. For example: 47 minutes ago, MostafaSabry55 said: Registry.ITEM.getKey(Plate).getPath() Why is this used as the namespace when you already have an instance of the namespace itself? Quote Link to comment Share on other sites More sharing options...
MostafaSabry55 Posted October 19, 2020 Author Share Posted October 19, 2020 9 hours ago, ChampionAsh5357 said: Can you please show the entire code block including that of your ItemGroup Sure thing : public class MorePlatesItemGroup extends ItemGroup { public MorePlatesItemGroup() { super(MorePlates.MODID); } @Override public ItemStack createIcon() { return new ItemStack(ModItems.HAMMER.get()); } } public class RegistryHandler { public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MorePlates.MODID); public static void init() { ITEMS.register(FMLJavaModLoadingContext.get().getModEventBus()); } public static RegistryObject<Item> register(String name) { return ITEMS.register(name, () -> new Item( new Item.Properties().group(MorePlates.ITEMGROUP) ) ); } } 10 hours ago, ChampionAsh5357 said: To me, some of this code just seems a bit out context. For example: Why is this used as the namespace when you already have an instance of the namespace itself? No no no no no, let me explain what I meant there, basically public class Recipes extends RecipeProvider { public Recipes(DataGenerator generatorIn) { super(generatorIn); } @Override protected void registerRecipes(Consumer<IFinishedRecipe> consumer) { for (EnumMaterials material : EnumMaterials.values()) { for (int i = 0; i < 2; i++) { if (i == 0) { Item Plate = ForgeRegistries.ITEMS.getValue(new ResourceLocation(MorePlates.MODID, material.toString() + "_plate")); Item Ingot = ForgeRegistries.ITEMS.getValue(material.getTag()); ShapelessRecipeBuilder.shapelessRecipe(Plate) .addIngredient(Ingot, 2) .addIngredient(ForgeRegistries.ITEMS.getValue(new ResourceLocation(MorePlates.MODID, "hammer"))) .setGroup(material.toString()) .addCriterion("has_item", hasItem(Ingot)) .build(consumer); } else { Item Gear = ForgeRegistries.ITEMS.getValue(new ResourceLocation(MorePlates.MODID, material.toString() + "_gear")); Item Ingot = ForgeRegistries.ITEMS.getValue(material.getTag()); ShapedRecipeBuilder.shapedRecipe(Gear) .patternLine(" x ") .patternLine("x#x") .patternLine(" x ") .key('x', Ingot) .key('#', Tags.Items.INGOTS_IRON) .setGroup(material.toString()) .addCriterion("has_item", hasItem(Ingot)) .build(consumer); } } } } } Now when I build my recipe " .build(consumer) ", it errors with a null pointer exception [m[32m[09:11:44] [main/INFO] [STDERR/]: [java.lang.Throwable:printStackTrace:643]: Caused by: java.lang.NullPointerException [m[32m[09:11:44] [main/INFO] [STDERR/]: [java.lang.Throwable:printStackTrace:643]: at net.minecraft.data.ShapelessRecipeBuilder.build(ShapelessRecipeBuilder.java:133) [m[32m[09:11:44] [main/INFO] [STDERR/]: [java.lang.Throwable:printStackTrace:643]: at net.minecraft.data.ShapelessRecipeBuilder.build(ShapelessRecipeBuilder.java:111) at the line that I just posted consumerIn.accept(new ShapelessRecipeBuilder.Result(id, this.result, this.count, this.group == null ? "" : this.group, this.ingredients, this.advancementBuilder, new ResourceLocation(id.getNamespace(), "recipes/" + this.result.getGroup().getPath() + "/" + id.getPath()))); Now in THIS LINE in ShapelessRecipeBuilder, I noticed that the last parameter was the cause which is : new ResourceLocation(id.getNamespace(), "recipes/" + this.result.getGroup().getPath() + "/" + id.getPath()) was the cause, sorry for me changing them to my items, I was testing and I was also unclear, now I dunno what I'm doing wrong Quote Link to comment Share on other sites More sharing options...
MostafaSabry55 Posted October 19, 2020 Author Share Posted October 19, 2020 WHOOPS. I forgot to auto register a few materials (they're divided into seperate plugins, normal classes), printing is so useful Problem fixed, sorry for wasting your time Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.