Jump to content

[1.11] Creative Tabs


Rohzek

Recommended Posts

What is the proper way of registering Creative Tabs?

 

Right now, I have them at the top of my main class between declaring the instance, and the preinit event just, like this:

public static final CustomCreativeTabs SP_TAB = new CustomCreativeTabs("myTab", Items.APPLE);

Which works fine if I only have one of them. For some reason, though, If I try to make more than 2, not all of my items and blocks will show up in the last one. If I make 4 or more. no items or blocks show up in the 4th+

Developing the Spiral Power Mod .

こんにちは!お元気ですか?

Link to comment
Share on other sites

I do this, works for me.

public static CreativeTabs buildingBlocks = new CreativeTabs("moreBuildingBlocks"){
	@Override
	public Item getTabIconItem(){
		return Item.getItemFromBlock(BBBlocks.cotswoldBricks);
	}
};

 

Keep in mind this is 1.10.2, in 1.11 I believe you need to return a ItemStack

Link to comment
Share on other sites

Show how you apply your creative tab to your items and how you declared more than one.

 

Right now, I have them all declared at the top of my main class, just like in the op, which probably isn't the correct way to do it.

public static final CustomCreativeTab CUSTOM_TAB = new CustomCreativeTab("myCustomTab", Items.APPLE);
public static final CustomCreativeTab CUSTOM_TAB_ONE = new CustomCreativeTab("myCustomTab1", Items.STICK);
... etc

As for how I "apply" them my items, I have the different types separated by classes (Food, ingots, tools, etc) But in each, I just call setCreativeTab in their constructors, and tell it which tab it belongs in.

public CustomItems(String names)
{
setNames(names);
setCreativeTab(Main.CUSTOM_TAB);
}

private void setNames(String name)
{
setUnlocalizedName(name);
setRegistryName(name);
}

Which works for the first two tabs, but not any more, which is weird. I'm assuming either the items, or the tabs are being initialized in an order that stops one of them from seeing the other. Not sure which way.

 

I do this, works for me.

public static CreativeTabs buildingBlocks = new CreativeTabs("moreBuildingBlocks"){
	@Override
	public Item getTabIconItem(){
		return Item.getItemFromBlock(BBBlocks.cotswoldBricks);
	}
};

 

Keep in mind this is 1.10.2, in 1.11 I believe you need to return a ItemStack

 

Yeah. This is what I have:

public class CustomCreativeTab extends CreativeTabs
{
private ItemStack iconItem;

private ItemSorter itemSorter = new ItemSorter();

public CustomCreativeTab(String label, Item item)
{
	super(label);
	iconItem = new ItemStack(item);
}

@Override
public ItemStack getTabIconItem() 
{
	return iconItem;
}

@Override
public void displayAllRelevantItems(NonNullList<ItemStack> items) 
{
	super.displayAllRelevantItems(items);

	Collections.sort(items, itemSorter);
}

// Sorts items in alphabetical order using their display names, blocks on top
private static class ItemSorter implements Comparator<ItemStack> 
{

	@Override
	public int compare(ItemStack o1, ItemStack o2) 
	{
		Item item1 = o1.getItem();
		Item item2 = o2.getItem();

		// If item1 is a block and item2 isn't, sort item1 before item2
		if (((item1 instanceof ItemBlock)) && (!(item2 instanceof ItemBlock))) 
		{
			return -1;
		}

		// If item2 is a block and item1 isn't, sort item1 after item2
		if (((item2 instanceof ItemBlock)) && (!(item1 instanceof ItemBlock)))
		{
			return 1;
		}

		String displayName1 = o1.getDisplayName();
		String displayName2 = o2.getDisplayName();

		int result = displayName1.compareToIgnoreCase(displayName2);

		return result;
	}
}
}

Developing the Spiral Power Mod .

こんにちは!お元気ですか?

Link to comment
Share on other sites

You say it works for two tabs, but not more. Then you still have not shown the problematic code, you have shown only two tabs.

 

But that's just it. That's why this is getting even more confusing, since all of the creative tabs, are created exactly the same as the others. Literally the only thing that I've changed is the tab chosen in this line, in every class:

 

setCreativeTab(Main.CUSTOM_TAB);

 

At first it was set to all the individual tabs, where food items were going to my "Main.FOOD_TAB," and blocks into "Main.BLOCKS_TAB" etc, etc, and only the first two tabs I added worked.

 

Then I commented out all but one while testing after submitting this, and changed all of the item classes' 'setCreativeTabs()' calls to list into the one that was left, and it worked fine; every item appeared like it should.

 

And now, to make it worse, I've un-commented them all, and set them all back to the way it originally was, and even less of them are working, now.

 

It has to be the order they're being loaded (in the main class) vs the item classes (through a registered as @Mod.EventBusSubscriber), or something. This literally makes no sense.

 

Project on Github:

Main (Creative Tab's Init)

Custom Creative Tabs

Example Food

Example Item

Example Tool

Example Tool Registration

Developing the Spiral Power Mod .

こんにちは!お元気ですか?

Link to comment
Share on other sites

i also was confused about this the only way that registering creative tabs works right for me is

 

public static CreativeTabs testtab = new CreativeTabs("testtab"){
	@Override
	public Item getTabIconItem(){
		return MyModItems.Test;
	}
};

 

in main mod class at the end

i dont know if in 1.11 something changed

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.