Jump to content

[1.7.10][SOLVED] Sorting Creative Tab


CactusCoffee

Recommended Posts

It's me again.

 

So I want to sort my mod's creative tab so it isn't a jumbled mess like the vanilla ones, and so I don't have to change item IDs every time I add new stuff to keep the tab neat. I've attempted to follow diesieben07's tutorial on the matter:

http://www.minecraftforge.net/forum/index.php/topic,23782.msg120743.html#msg120743

 

However, I get this error:

com.google.common.collect.Ordering$IncomparableValueException: Cannot compare value: net.minecraft.item.ItemBlock@509e4bc4
at com.google.common.collect.ExplicitOrdering.rank(ExplicitOrdering.java:46)
at com.google.common.collect.ExplicitOrdering.compare(ExplicitOrdering.java:40)
at com.google.common.collect.ByFunctionOrdering.compare(ByFunctionOrdering.java:46)
at java.util.TimSort.countRunAndMakeAscending(Unknown Source)
at java.util.TimSort.sort(Unknown Source)
at java.util.Arrays.sort(Unknown Source)
at java.util.ArrayList.sort(Unknown Source)
at java.util.Collections.sort(Unknown Source)
at com.finneyt.simplymagic.main.SimplyMagicMod$1.displayAllReleventItems(SimplyMagicMod.java:100)
at net.minecraft.client.gui.inventory.GuiContainerCreative.setCurrentCreativeTab(GuiContainerCreative.java:508)
at net.minecraft.client.gui.inventory.GuiContainerCreative.mouseMovedOrUp(GuiContainerCreative.java:482)
at net.minecraft.client.gui.GuiScreen.handleMouseInput(GuiScreen.java:354)
at net.minecraft.client.gui.inventory.GuiContainer.handleMouseInput(GuiContainer.java)
at net.minecraft.client.gui.inventory.GuiContainerCreative.handleMouseInput(GuiContainerCreative.java:598)
at net.minecraft.client.gui.GuiScreen.handleInput(GuiScreen.java:313)
at net.minecraft.client.Minecraft.runTick(Minecraft.java:1720)
at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1028)
at net.minecraft.client.Minecraft.run(Minecraft.java:951)
at net.minecraft.client.main.Main.main(Main.java:164)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source)
at GradleStart.main(Unknown Source)

 

Here's the relevant code:

import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import com.google.common.base.Function;
import com.google.common.collect.Ordering;

public class Mod...
{	

private static Comparator<ItemStack> tabComp;
public static final CreativeTabs tab = new CreativeTabs(MODID + "_" + "tab") 
{
    @Override
    @SideOnly(Side.CLIENT)
    public void displayAllReleventItems(List items) 
    {
    	super.displayAllReleventItems(items);
    	Collections.sort(items, tabComp);
    }
};

@EventHandler
public void preInit(FMLPreInitializationEvent event)
{
	tabComp = Ordering.explicit(ModItems.ITEM_ORDER).onResultOf(new Function<ItemStack, Item>() 
		{
            @Override
            public Item apply(ItemStack i) 
            {
                return i.getItem();
            }
        });
}
}

 

Please let me know what I'm doing wrong, I don't like being incompetent :(

Link to comment
Share on other sites

I thought that was the case. My list currently contains only the items. When I try adding one of the blocks (using Item.getItemFromBlock()), however, I get a nullPointerException:

java.lang.NullPointerException: null key in entry: null=0
at com.google.common.collect.CollectPreconditions.checkEntryNotNull(CollectPreconditions.java:31)
at com.google.common.collect.ImmutableMap.entryOf(ImmutableMap.java:135)
at com.google.common.collect.ImmutableMap$Builder.put(ImmutableMap.java:206)
at com.google.common.collect.ExplicitOrdering.buildRankMap(ExplicitOrdering.java:56)
at com.google.common.collect.ExplicitOrdering.<init>(ExplicitOrdering.java:32)
at com.google.common.collect.Ordering.explicit(Ordering.java:162)
at com.finneyt.simplymagic.main.SimplyMagicMod.preInit(SimplyMagicMod.java:117)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at cpw.mods.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:513)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)
at com.google.common.eventbus.EventBus.post(EventBus.java:275)
at cpw.mods.fml.common.LoadController.sendEventToModContainer(LoadController.java:208)
at cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:187)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)
at com.google.common.eventbus.EventBus.post(EventBus.java:275)
at cpw.mods.fml.common.LoadController.distributeStateMessage(LoadController.java:118)
at cpw.mods.fml.common.Loader.preinitializeMods(Loader.java:513)
at cpw.mods.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:239)
at net.minecraft.client.Minecraft.startGame(Minecraft.java:522)
at net.minecraft.client.Minecraft.run(Minecraft.java:931)
at net.minecraft.client.main.Main.main(Main.java:164)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source)
at GradleStart.main(Unknown Source)

Link to comment
Share on other sites

...Well I'm dumbfounded.

 

Changed it so it got the list from a function instead of a parameter, and added all the blocks. It works just fine. I could swear I tried that before and still got an error. But I guess it doesn't matter, it works.

 

Current status: still incompetent

 

Thanks for your help.

Link to comment
Share on other sites

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.