Jump to content

Recommended Posts

Posted (edited)

Hello

 

I registered a bunch of entities with their spawn-eggs.

Why the eggs are in the creative-inventory not in the same order like in my registration-list:

    public static void registerEntitySpawnEggs(final RegistryEvent.Register<Item>event)
    {
        event.getRegistry().registerAll(AngryBirdsItems.red_egg = registerEntitySpawnEgg(RED, 0xdf0000, 0xdfbf9f, "red_egg"),
                                        AngryBirdsItems.chuck_egg = registerEntitySpawnEgg(CHUCK, 0xffff00, 0xffffff, "chuck_egg"),
                                        AngryBirdsItems.blues_egg = registerEntitySpawnEgg(BLUES, 0x007fff, 0xff0000, "blues_egg"),
                                        AngryBirdsItems.bomb_egg = registerEntitySpawnEgg(BOMB, 0x3f3f3f, 0x7f7f7f, "bomb_egg"),
                                        AngryBirdsItems.mathilda_egg = registerEntitySpawnEgg(MATHILDA, 0xffffff, 0xffbfbf, "mathilda_egg"),
                                        AngryBirdsItems.terence_egg = registerEntitySpawnEgg(TERENCE, 0xbf002f, 0xbf9f7f, "terence_egg"),
                                        AngryBirdsItems.silver_egg = registerEntitySpawnEgg(SILVER, 0xbfbfbf, 0xffffff, "silver_egg"),
                                        AngryBirdsItems.bubbles_egg = registerEntitySpawnEgg(BUBBLES, 0xff7f00, 0x000000, "bubbles_egg"),
                                        AngryBirdsItems.hal_egg = registerEntitySpawnEgg(HAL, 0x00bf00, 0xffffff, "hal_egg"),
                                        AngryBirdsItems.stella_egg = registerEntitySpawnEgg(STELLA, 0xffadb7, 0xffd7dc, "stella_egg"),
                                        AngryBirdsItems.poppy_egg = registerEntitySpawnEgg(POPPY, 0xffff3f, 0xffffbf, "poppy_egg"),
                                        AngryBirdsItems.willow_egg = registerEntitySpawnEgg(WILLOW, 0x3f9fff, 0x7fbfff, "willow_egg"),
                                        AngryBirdsItems.dahlia_egg = registerEntitySpawnEgg(DAHLIA, 0xbf7f3f, 0xffdfbf, "dahlia_egg"),
                                        AngryBirdsItems.luca_egg = registerEntitySpawnEgg(LUCA, 0x7fbfff, 0xffffbf, "luca_egg"),
                                        AngryBirdsItems.ice_bird_egg = registerEntitySpawnEgg(ICE_BIRD, 0x7fbfff, 0x007fff, "ice_bird_egg"));	    
    }

Any idea?

Edited by Drachenbauer
Posted

Now i have this:

package drachenbauer32.angrybirdsmod.util;

import drachenbauer32.angrybirdsmod.init.AngryBirdsItems;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;

public class AngryBirdsItemGroup extends ItemGroup
{
    public AngryBirdsItemGroup()
    {
        super("AngryBirds");
    }
    
    @Override
    public ItemStack createIcon()
    {
        return new ItemStack(AngryBirdsItems.nest_block);
    }
    
    /*public void displayAllRelevantItems(NonNullList<ItemStack> items)
    {
        super.displayAllRelevantItems(items);
        items.sort(tabSorter);
    }*/
}

What is the right thing to replace "displayAllRelevantItems"?

Posted (edited)

i tryed strg and space to show a list of all methods, i can override there and found nothing, that may mean the same.

 

oh, is it now "fill"?

it has the same content in it´s brackets.

 

Now i have another problem:

    void preInit()
    {
        List<Item> order = Arrays.asList(AngryBirdsItems.red_egg,
                                         AngryBirdsItems.chuck_egg,
                                         AngryBirdsItems.blues_egg,
                                         AngryBirdsItems.bomb_egg,
                                         AngryBirdsItems.mathilda_egg,
                                         AngryBirdsItems.terence_egg,
                                         AngryBirdsItems.silver_egg,
                                         AngryBirdsItems.bubbles_egg,
                                         AngryBirdsItems.hal_egg,
                                         AngryBirdsItems.stella_egg,
                                         AngryBirdsItems.poppy_egg,
                                         AngryBirdsItems.willow_egg,
                                         AngryBirdsItems.dahlia_egg,
                                         AngryBirdsItems.luca_egg,
                                         AngryBirdsItems.ice_bird_egg,
                                         AngryBirdsItems.balloon_block,
                                         AngryBirdsItems.egg_block,
                                         AngryBirdsItems.nest_block,
                                         AngryBirdsItems.slingshot_block,
                                         AngryBirdsItems.slingshot2_block);
        
        //tabSorter = Ordering.explicit(order).onResultOf(ItemStack::getItem);
    }

it seams like ItemStack::getItem does not work any more.

Edited by Drachenbauer
  • 3 weeks later...
Posted (edited)
public static Comparator<? super ItemStack> tabSorter;
tabSorter = Ordering.explicit(order).onResultOf(ItemStack::getItem);

"getItem" cannot more be used this way there.

How must i modify this comperator for sorting items to make it work in 1.14?

Edited by Drachenbauer
Posted (edited)

Now i found some texts about lambda, but there i found no way to use lambda to call a non static method ("getItem") without creating an instance of it´s class ("ItemStack").

 

in some forums, i found on the web, thay say, this style is already lambda:

ItemStack::getItem

but ot makes the error:

The type ItemStack does not define getItem(F) that is applicable here

Edited by Drachenbauer
Posted (edited)

As i found no solution for the original setup of the comperator, i tried this now:

        List<ItemStack> order = null;
        
        for (Item item : items)
        {
            order.add(new ItemStack(item));
        }
        
        itemSorter = Ordering.explicit(order);

I thaught, maybe i can create a list of itemstacks and fill it with itemstacks of the items of the first list, and than just order by this seccond list, without using the

.onResultOf(ItemStack::getItem);

part of the comperator.

but it gives this error:

Quote

java.lang.ClassCastException: net.minecraft.item.ItemStack cannot be cast to java.lang.Comparable

I thaught, the comperator has to sort itemstacks, so it needs a list of itemstacks to get the right order.

So i thaught, i can create a list of itemstacks and use it directly for the comperator.

It seams like it cannot compare ItemStacks directly.

Edited by Drachenbauer
Posted (edited)

Because i found no way to get the comperator to work, i tryed around without it, directly in the method "fill" in my ItemGroup-class.

So finally i got this:

    Override
    public void fill(NonNullList<ItemStack> itemStacks)
    {
        List<Item> items = Arrays.asList(AngryBirdsItems.red_egg,
                                         AngryBirdsItems.chuck_egg,
                                         AngryBirdsItems.blues_egg,
                                         AngryBirdsItems.bomb_egg,
                                         AngryBirdsItems.mathilda_egg,
                                         AngryBirdsItems.terence_egg,
                                         AngryBirdsItems.silver_egg,
                                         AngryBirdsItems.bubbles_egg,
                                         AngryBirdsItems.hal_egg,
                                         AngryBirdsItems.stella_egg,
                                         AngryBirdsItems.poppy_egg,
                                         AngryBirdsItems.willow_egg,
                                         AngryBirdsItems.dahlia_egg,
                                         AngryBirdsItems.luca_egg,
                                         AngryBirdsItems.ice_bird_egg,
                                         
                                         AngryBirdsItems.slingshot,
                                         AngryBirdsItems.red_shot,
                                         AngryBirdsItems.chuck_shot,
                                         AngryBirdsItems.blues_shot,
                                         AngryBirdsItems.bomb_shot,
                                         AngryBirdsItems.mathilda_shot,
                                         AngryBirdsItems.terence_shot,
                                         AngryBirdsItems.silver_shot,
                                         AngryBirdsItems.bubbles_shot,
                                         AngryBirdsItems.hal_shot,
                                         AngryBirdsItems.stella_shot,
                                         AngryBirdsItems.poppy_shot,
                                         AngryBirdsItems.willow_shot,
                                         AngryBirdsItems.dahlia_shot,
                                         AngryBirdsItems.luca_shot,
                                         AngryBirdsItems.ice_bird_shot,
                                           
                                         AngryBirdsItems.balloon_block,
                                         AngryBirdsItems.egg_block,
                                         AngryBirdsItems.nest_block,
                                         AngryBirdsItems.slingshot_acacia_block,
                                         AngryBirdsItems.slingshot_acacia_2_block,
                                         AngryBirdsItems.slingshot_birch_block,
                                         AngryBirdsItems.slingshot_birch_2_block,
                                         AngryBirdsItems.slingshot_dark_oak_block,
                                         AngryBirdsItems.slingshot_dark_oak_2_block,
                                         AngryBirdsItems.slingshot_jungle_block,
                                         AngryBirdsItems.slingshot_jungle_2_block,
                                         AngryBirdsItems.slingshot_oak_block,
                                         AngryBirdsItems.slingshot_oak_2_block,
                                         AngryBirdsItems.slingshot_spruce_block,
                                         AngryBirdsItems.slingshot_spruce_2_block,
                                         AngryBirdsItems.acacia_planks_frame_block,
                                         AngryBirdsItems.birch_planks_frame_block,
                                         AngryBirdsItems.dark_oak_planks_frame_block,
                                         AngryBirdsItems.jungle_planks_frame_block,
                                         AngryBirdsItems.oak_planks_frame_block,
                                         AngryBirdsItems.spruce_planks_frame_block,
                                         AngryBirdsItems.stone_frame_block,
                                         AngryBirdsItems.blue_ice_frame_block);
        
        itemStacks.clear();
        
        for (Item item : items)
        {
            if(item.getCreativeTabs().contains(AngryBirds.RegistryEvents.ANGRY_BIRDS))
            {
                itemStacks.add(new ItemStack(item));
            }
        }
    }

This makes the items appear in the order, i want to have them.

Edited by Drachenbauer
Posted

I wonder, why you say, i have to use lambda in the comperator.

 

The comperator includes:

ItemStack::getItem

This is already lambda, but it does not work.

 

So there must be any other reason, why the existing comperator does not work.

Posted (edited)

Now i placed your comperator in my mod again, like it looks in your tutorial, and now there are no more errors at

ItemStack::getItem

I noticed, that there are two imports for

Ordering

Now i used the "import com.google.common.collect.Ordering;"-one.

maybe i used the other one at the first try.

 

But it gives an error, if i try to open my creative tab in a test-run:

Quote

net.minecraft.item.ItemStack cannot be cast to java.lang.Comparable

Was ItemStack comparable earlyer and is not more now?

Edited by Drachenbauer
Posted (edited)

This initializes the comperator in the main-class

public static Comparator<ItemStack> itemSorter;

 

This is in preInit:

List<Item> items = Arrays.asList(AngryBirdsItems.red_egg,
                                         AngryBirdsItems.chuck_egg,
                                         AngryBirdsItems.blues_egg,
                                         AngryBirdsItems.bomb_egg,
                                         AngryBirdsItems.mathilda_egg,
                                         AngryBirdsItems.terence_egg,
                                         AngryBirdsItems.silver_egg,
                                         AngryBirdsItems.bubbles_egg,
                                         AngryBirdsItems.hal_egg,
                                         AngryBirdsItems.stella_egg,
                                         AngryBirdsItems.poppy_egg,
                                         AngryBirdsItems.willow_egg,
                                         AngryBirdsItems.dahlia_egg,
                                         AngryBirdsItems.luca_egg,
                                         AngryBirdsItems.ice_bird_egg,
                                         
                                         AngryBirdsItems.red_shot,
                                         AngryBirdsItems.chuck_shot,
                                         AngryBirdsItems.blues_shot,
                                         AngryBirdsItems.bomb_shot,
                                         AngryBirdsItems.mathilda_shot,
                                         AngryBirdsItems.terence_shot,
                                         AngryBirdsItems.silver_shot,
                                         AngryBirdsItems.bubbles_shot,
                                         AngryBirdsItems.hal_shot,
                                         AngryBirdsItems.stella_shot,
                                         AngryBirdsItems.poppy_shot,
                                         AngryBirdsItems.willow_shot,
                                         AngryBirdsItems.dahlia_shot,
                                         AngryBirdsItems.luca_shot,
                                         AngryBirdsItems.ice_bird_shot,
                                         AngryBirdsItems.slingshot,
                                           
                                         AngryBirdsItems.balloon_block,
                                         AngryBirdsItems.egg_block,
                                         AngryBirdsItems.nest_block,
                                         AngryBirdsItems.slingshot_acacia_block,
                                         AngryBirdsItems.slingshot_acacia_2_block,
                                         AngryBirdsItems.slingshot_birch_block,
                                         AngryBirdsItems.slingshot_birch_2_block,
                                         AngryBirdsItems.slingshot_dark_oak_block,
                                         AngryBirdsItems.slingshot_dark_oak_2_block,
                                         AngryBirdsItems.slingshot_jungle_block,
                                         AngryBirdsItems.slingshot_jungle_2_block,
                                         AngryBirdsItems.slingshot_oak_block,
                                         AngryBirdsItems.slingshot_oak_2_block,
                                         AngryBirdsItems.slingshot_spruce_block,
                                         AngryBirdsItems.slingshot_spruce_2_block,
                                         AngryBirdsItems.acacia_planks_frame_block,
                                         AngryBirdsItems.birch_planks_frame_block,
                                         AngryBirdsItems.dark_oak_planks_frame_block,
                                         AngryBirdsItems.jungle_planks_frame_block,
                                         AngryBirdsItems.oak_planks_frame_block,
                                         AngryBirdsItems.spruce_planks_frame_block,
                                         AngryBirdsItems.stone_frame_block,
                                         AngryBirdsItems.blue_ice_frame_block);
        
        itemSorter = Ordering.explicit(items).onResultOf(ItemStack::getItem);

 

and this is in my creative-tab-class:

public void fill(NonNullList<ItemStack> itemStacks)
    {
        super.fill(itemStacks);
        itemStacks.sort(AngryBirds.itemSorter);
    }

 

In your tutorial you use "ItemStack" in the same locations in your code.

Edited by Drachenbauer
Posted (edited)

there you have the comperator in the preInit-method of the main-class to make it usable in  multiple different situations.

Quote
Finishing up

The Comparator you've created can be reused, you only need to create it once. Then store it in a static field in your Main mod class and use it from your CreativeTabs class. 

Quote

void preInit() {
        // create items, blocks, etc.
        List<Item> order = Arrays.asList(myItemA, myItemB, Item.getItemFromBlock(myBlockA), ...);
        tabSorter = Ordering.explicit(order).onResultOf(ItemStack::getItem);
    }

 

 

But maybe in 1.14 there is no more preinit in the main-class.

 

As i now placed the comperator directly into the fill-method of my creativetab-class, it works.

 

So what is the right way to have the comperator in the main-class now?

Edited by Drachenbauer
Posted (edited)

I have a method "setup" with this event in the round brackets.

I think, that should be the right one.

 

Test on this method is successfull.

 

So no more questions here.

Edited by Drachenbauer

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Reach Out To Rapid Digital: What sapp Info: +1 41 4 80 7 14 85 Email INFO: rap iddi gita lrecov ery @ exe cs. com Hello, my name is Jayson, and I’m 35 years old from the United Kingdom. My family and I recently endured an incredibly challenging experience that I wouldn’t wish on anyone. We became victims of a cryptocurrency investment fraud scheme that saw us lose a staggering $807,000 in USDT and Bitcoins. The fraudsters had created a convincing facade, and we were lured into investing, only to discover later that the platform was a complete scam. We were left devastated, not just financially, but emotionally, as we had trusted these people and believed in the legitimacy of the investment. After the initial shock wore off, we desperately searched for ways to recover the lost funds. It seemed like an impossible task, and we felt as though there was no hope. That’s when, by sheer luck, we stumbled across a post about Rapid Digital Recovery, a cryptocurrency and funds recovery organization with a proven track record in cybersecurity and fraud recovery. We decided to reach out to them, and from the first interaction, we were impressed with their professionalism and transparency. They explained the recovery process in detail and reassured us that they had the skills and expertise to track down the perpetrators and recover our funds. This gave us a renewed sense of hope, something we hadn’t felt in months. What truly stood out during our experience with Rapid Digital Recovery was their dedication to the recovery process. The team went above and beyond, using sophisticated tracking tools and cyber forensics to gather critical information. Within a matter of weeks, they had successfully located the funds and traced the scam back to the fraudsters responsible. They worked with the authorities to ensure the criminals were held accountable for their actions. To our relief, the team at Rapid Digital Recovery was able to recover every single penny we had lost. The funds were returned in full, and the sense of closure we felt was invaluable. We couldn’t have imagined such a positive outcome in the early stages of our recovery journey, and we are deeply grateful for the work they did. If you ever find yourself in a similar situation, I highly recommend contacting Rapid Digital Recovery. Their expertise, transparency, and dedication to their clients make them the go-to choice for anyone seeking to recover lost cryptocurrency or funds. They truly gave us back our financial future.  
    • This is my first time modding anything, so maybe just skill issue. I'm using Forge 54.0.12 and Temurin 21.0.5+11-LTS I wanted to create a custom keybind and to check whether it works I'd like to send a chat message. I tried using Minecraft.getInstance().player.sendSystemMessage(Component.literal("test")); but IntelliJ couldnt resolve sendSystemMessage(...). Since I saw people using it in earlier versions, I tried the same thing with 1.20.6(- 50.1.0), where it works fine, now I can't figure out if this is intentional and whether there are other options for sending chat messages. On that note, is there more documentation than https://docs.minecraftforge.net/en/1.21.x/? It seems very incomplete compared to something like the Oracle Java docs
    • Hi, i'm having this error and I wanna fix it. we try: -Reload drivers -Eliminate .minecraft -Eliminate Java -Restart launcher -Verify if minecraft is using gpu -Mods  in .minecraft is empty -Install the latest and recomended version of forge idk what i have to do, help me pls. the lastest log is: https://mclo.gs/WAMao8x  
    • Read the FAQ, Rule #2. (https://forums.minecraftforge.net/topic/125488-rules-and-frequently-asked-questions-faq/)  
  • Topics

×
×
  • Create New...

Important Information

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