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
  On 8/7/2020 at 11:06 AM, diesieben07 said:

Old tutorial, but with some changes to the method names it still applies:

 

Expand  

thx for the guide...

 

  On 8/7/2020 at 12:29 PM, poopoodice said:

probably fill() (not so sure)

Expand  

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

Expand  

 

 

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

Expand  

 

Posted
  On 8/7/2020 at 1:28 PM, 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.

Expand  

Can I return the list from a static method instead, like this? this static variable is in the Mod's class

  Quote

3a028db0777a4277d6ab55f177869b8d.png

Expand  

 

  Quote

75598a07f23ccbd5e38e3028f07e601b.png

Expand  

 

if its not posible, how do I deal with this error changing the List<Item> to List<RegistryObject>? like you said here

  On 8/7/2020 at 1:28 PM, diesieben07 said:

Store the RegistryObject itself instead.

Expand  
  Quote

a913bf851bceb50e9f929027363a1a8a.png

Expand  

 

Posted
  On 8/7/2020 at 3:22 PM, 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.

Expand  

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

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

Expand  

 

 

Overriden method in the ItemGroup class:

  Quote

    @Override
    public void fill(NonNullList<ItemStack> items) {
        super.fill(items);
        items.sort(CustomGunsMod.instance.tabSorter);
    }

Expand  

 

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.

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.