Jump to content

Recommended Posts

Posted

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.

 

Posted (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 by xanderindalzone
Posted
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);
    }
    
    
}

 

Posted
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

3a028db0777a4277d6ab55f177869b8d.png

 

Quote

75598a07f23ccbd5e38e3028f07e601b.png

 

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

a913bf851bceb50e9f929027363a1a8a.png

 

Posted
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);
    }

 

Posted

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()
        ); 
    }

 

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.

Posted
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(

 

Posted
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

f3c992a691e5935c4900a8dcb335a792.png

 

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.