Drachenbauer Posted July 15, 2019 Posted July 15, 2019 (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 July 15, 2019 by Drachenbauer Quote
Drachenbauer Posted July 16, 2019 Author Posted July 16, 2019 for wich version is your tutorial? I cannot import "CreativeTabs" to extend my own creativetab-class... Quote
Drachenbauer Posted July 16, 2019 Author Posted July 16, 2019 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"? Quote
Drachenbauer Posted July 16, 2019 Author Posted July 16, 2019 (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 July 16, 2019 by Drachenbauer Quote
Drachenbauer Posted August 6, 2019 Author Posted August 6, 2019 (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 August 6, 2019 by Drachenbauer Quote
Drachenbauer Posted August 7, 2019 Author Posted August 7, 2019 (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 August 8, 2019 by Drachenbauer Quote
Drachenbauer Posted August 7, 2019 Author Posted August 7, 2019 (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 August 7, 2019 by Drachenbauer Quote
Drachenbauer Posted August 7, 2019 Author Posted August 7, 2019 (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 August 7, 2019 by Drachenbauer Quote
Drachenbauer Posted August 8, 2019 Author Posted August 8, 2019 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. Quote
Drachenbauer Posted August 8, 2019 Author Posted August 8, 2019 (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 August 8, 2019 by Drachenbauer Quote
Drachenbauer Posted August 8, 2019 Author Posted August 8, 2019 (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 August 8, 2019 by Drachenbauer Quote
Drachenbauer Posted August 8, 2019 Author Posted August 8, 2019 I made it like it looks in the last piece of tutorial. there is the same stuff in the main-class and in the item-tab-class, like i have. Quote
Drachenbauer Posted August 8, 2019 Author Posted August 8, 2019 (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 August 8, 2019 by Drachenbauer Quote
Drachenbauer Posted August 8, 2019 Author Posted August 8, 2019 (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 August 8, 2019 by Drachenbauer 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.