Posted September 25, 20204 yr Hey y'all, I'm currently working on a mod that adds a bunch of equipable accessories to the game. I've put them all in their own creative tab, which works fine. The only thing I'm stuck on is the icon. I'd like it to be one of the accessories, but this creates a reference loop. I need to supply the custom ItemGroup to the Item when I register it: public static final RegistryObject<Item> SHACKLE = ITEMS.register("shackle", () -> new Item(new Item.Properties().group(ModItemGroup.ACCESSORIES))); But at the same time I need to supply the Item to the custom ItemGroup when I create it: public static final ItemGroup ACCESSORIES = new ItemGroup("accessories") { @Override public ItemStack createIcon() { return new ItemStack(ModItems.SHACKLE.get(); } }; How do I work around this issue? I've tried registering the Shackle without an ItemGroup first, then creating the ItemGroup, and then setting the Shackle's ItemGroup with SHACKLE.get().getCreativeTabs().add(), but this doesn't work either. I'm probably overlooking something really simple, but my brain has just been refusing to work lately. Thanks in advance for any help!
September 25, 20204 yr You need to use a Supplier<ItemStack>...this way you avoid a direct call to an object that has not been registered yet. Then your createIcon method would need to return iconSupplier.get()..where iconSupplier is whatever name you will give to the supplier Check out the port of the BetterEnd fabric mod (WIP): https://www.curseforge.com/minecraft/mc-mods/betterend-forge-port
September 25, 20204 yr You can see how I handled it in 1.14: https://github.com/Draco18s/ReasonableRealism/blob/1.14.4/src/main/java/com/draco18s/hardlib/api/internal/ModItemGroup.java https://github.com/Draco18s/ReasonableRealism/blob/1.14.4/src/main/java/com/draco18s/industry/ExpandedIndustry.java#L59 (IItemProvider is approximately equal to a Supplier<ItemStack>, pretty sure the latter replaced the former, but the end result is pretty much the same) Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
September 26, 20204 yr Author Thanks everyone! I got things working with ease thanks to your help. Here's what my ModItemGroup class looks like now for future reference: public class ModItemGroup extends ItemGroup { private Supplier<ItemStack> displayStack; public static final ModItemGroup ACCESSORIES = new ModItemGroup("accessories", () -> new ItemStack(ModItems.SHACKLE.get())); private ModItemGroup(String label, Supplier<ItemStack> displayStack) { super(label); this.displayStack = displayStack; } @Override public ItemStack createIcon() { return displayStack.get(); } }
January 26, 20214 yr I just want to say that this thread has been massively helpful to me! Thank you to all who have contributed.
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.