xanderindalzone Posted August 7, 2020 Posted August 7, 2020 Hi, I was wondering, is there a way to fix/update the order of mod items in the world, without having to create a new world? Because everytime I add a new item and I re-sort the item order when they register, the world doesnt follow the current order in code. Quote
xanderindalzone Posted August 7, 2020 Author Posted August 7, 2020 (edited) 1 hour ago, diesieben07 said: Old tutorial, but with some changes to the method names it still applies: what is the equivalent in 1.15.2 to the method "displayAllRelevantItems" from ItemGroup? Edited August 7, 2020 by xanderindalzone Quote
poopoodice Posted August 7, 2020 Posted August 7, 2020 (edited) probably fill() (not so sure) Edited August 7, 2020 by poopoodice Quote
xanderindalzone Posted August 7, 2020 Author Posted August 7, 2020 1 hour ago, diesieben07 said: Old tutorial, but with some changes to the method names it still applies: thx for the guide... 33 minutes ago, poopoodice said: probably fill() (not so sure) and thx for the update... its working For anyone interesed on the end result, here it is: 1.I made a class to store the static comparator with a static list with all the items in the order I want Quote public class SortedItemList { private static List<Item> sortedItemList = Arrays.asList( InitItems.PISTOL_CAL_45_PROTOTYPE_BASIC.get(), InitItems.BARREL_CAL_45_LIGHT.get(), InitItems.BARREL_CAL_45_MEDIUM.get(), InitItems.BARREL_CAL_45_HEAVY.get(), InitItems.MAG_CAL_45_SMALL.get(), InitItems.MAG_CAL_45_BIG.get(), InitItems.MAG_CAL_45_DRUM.get(), InitItems.MAG_CAL_45_BOX.get(), InitItems.GUN_BODY_LIGHT.get(), InitItems.GUN_BODY_MEDIUM.get(), InitItems.GUN_BODY_HEAVY.get(), InitItems.PIPE_CAL_45.get(), InitItems.GUN_GRIP.get(), InitItems.GUN_BUTT.get()); public static Comparator<ItemStack> tabSorter = Ordering.explicit(sortedItemList).onResultOf(ItemStack::getItem); } 2. I overriden the fill() method in the CustomTab class that I wanted to sort, sorting the item list after calling super: Quote public class GunPartsGroup extends ItemGroup { public GunPartsGroup(String label) { super(label); } @Override public ItemStack createIcon() { return new ItemStack(InitItems.BARREL_CAL_45_LIGHT.get()); } @Override public void fill(NonNullList<ItemStack> items) { super.fill(items); items.sort(SortedItemList.tabSorter); } } Quote
xanderindalzone Posted August 7, 2020 Author Posted August 7, 2020 19 minutes ago, diesieben07 said: Do not call RegistryObject#get in a static initializer, it defeats the purpose and can cause initialization-order problems. Store the RegistryObject itself instead. Can I return the list from a static method instead, like this? this static variable is in the Mod's class Quote Quote if its not posible, how do I deal with this error changing the List<Item> to List<RegistryObject>? like you said here 22 minutes ago, diesieben07 said: Store the RegistryObject itself instead. Quote Quote
xanderindalzone Posted August 7, 2020 Author Posted August 7, 2020 6 hours ago, diesieben07 said: The best way I can think of to do this is to just not do this in a static initializer, but in e.g. FMLCommonSetupEvent. is this ok now? I'm using the first List I had, List<Item>, because you said the issue was in the "static" initializing thing. I'm creating a new SortedItemList object in CommonSetup so I can get the predifined List for the Comparator, then I use the Mod Class instance field to access that mod object's Comparator field. its still working as expected ingame at least 😅 Quote public class SortedItemList { public List<Item> sortedList = Arrays.asList( //Guns InitItems.PISTOL_COLT_1911.get(), //Bullets InitItems.BULLET_CAL_45.get(), //GunParts InitItems.PISTOL_CAL_45_PROTOTYPE_BASIC.get(), InitItems.BARREL_CAL_45_LIGHT.get(), InitItems.BARREL_CAL_45_MEDIUM.get(), InitItems.BARREL_CAL_45_HEAVY.get(), InitItems.MAG_CAL_45_SMALL.get(), InitItems.MAG_CAL_45_BIG.get(), InitItems.MAG_CAL_45_DRUM.get(), InitItems.MAG_CAL_45_BOX.get(), InitItems.GUN_BODY_LIGHT.get(), InitItems.GUN_BODY_MEDIUM.get(), InitItems.GUN_BODY_HEAVY.get(), InitItems.PIPE_CAL_45.get(), InitItems.GUN_GRIP.get(), InitItems.GUN_BUTT.get(), //Blocks InitItems.ARMORED_GLASS_ITEM_BLOCK.get() ); ............................................... Quote /*===================*/ /*CREATIVE TAB SORTER*/ /*===================*/ public Comparator<ItemStack> tabSorter; private void setup(final FMLCommonSetupEvent event) { PacketHandler.registerPackets(); InitCapabilities.registerCapabilities(); tabSorter = Ordering.explicit(new SortedItemList().sortedList).onResultOf(ItemStack::getItem); } Overriden method in the ItemGroup class: Quote @Override public void fill(NonNullList<ItemStack> items) { super.fill(items); items.sort(CustomGunsMod.instance.tabSorter); } Quote
Draco18s Posted August 7, 2020 Posted August 7, 2020 The fuck is wrong with: public void fill(NonNullList<ItemStack> items) { items.add( InitItems.PISTOL_COLT_1911.get(), InitItems.BULLET_CAL_45.get(), InitItems.PISTOL_CAL_45_PROTOTYPE_BASIC.get(), InitItems.BARREL_CAL_45_LIGHT.get(), InitItems.BARREL_CAL_45_MEDIUM.get(), InitItems.BARREL_CAL_45_HEAVY.get(), InitItems.MAG_CAL_45_SMALL.get(), InitItems.MAG_CAL_45_BIG.get(), InitItems.MAG_CAL_45_DRUM.get(), InitItems.MAG_CAL_45_BOX.get(), InitItems.GUN_BODY_LIGHT.get(), InitItems.GUN_BODY_MEDIUM.get(), InitItems.GUN_BODY_HEAVY.get(), InitItems.PIPE_CAL_45.get(), InitItems.GUN_GRIP.get(), InitItems.GUN_BUTT.get(), InitItems.ARMORED_GLASS_ITEM_BLOCK.get() ); } Quote 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.
xanderindalzone Posted August 8, 2020 Author Posted August 8, 2020 2 hours ago, diesieben07 said: 11 hours ago, xanderindalzone said: public List<Item> sortedList = Arrays.asList( Still a static initializer. ohhh you mean this method? if it isnt, please, tell me where's the "static" issue because thats the only static I see 😅 Quote https://gyazo.com/d0432f35abffee2576741ce541c61e9c Quote
xanderindalzone Posted August 8, 2020 Author Posted August 8, 2020 40 minutes ago, diesieben07 said: The issue is the static initializer, because you cannot guarantee when exactly it runs. are you saying this because "Array.asList();" may run before the items are initialized? 47 minutes ago, xanderindalzone said: public List<Item> sortedList = Arrays.asList( Quote
xanderindalzone Posted August 8, 2020 Author Posted August 8, 2020 6 minutes ago, diesieben07 said: Correct. soooo, is it ok if I declare all the items and then, initializing them in Common first, and then calling the sorted list initializing the list? But, is fill() method from ItemGroup called after Common? Quote Quote
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.