Jump to content
  • Home
  • Files
  • Docs
  • Merch
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.11] Creative Tabs
1.13 Update Notes for Mod Creators
Sign in to follow this  
Followers 0
Rohzek

[1.11] Creative Tabs

By Rohzek, January 10, 2017 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

Rohzek    8

Rohzek

Rohzek    8

  • Stone Miner
  • Rohzek
  • Forge Modder
  • 8
  • 77 posts
Posted January 10, 2017

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+

  • Quote

Share this post


Link to post
Share on other sites

Tschipp    3

Tschipp

Tschipp    3

  • Diamond Finder
  • Tschipp
  • Forge Modder
  • 3
  • 302 posts
Posted January 10, 2017

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

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    6671

diesieben07

diesieben07    6671

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6671
  • 45628 posts
Posted January 10, 2017

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

  • Quote

Share this post


Link to post
Share on other sites

Rohzek    8

Rohzek

Rohzek    8

  • Stone Miner
  • Rohzek
  • Forge Modder
  • 8
  • 77 posts
Posted January 11, 2017

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

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    6671

diesieben07

diesieben07    6671

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6671
  • 45628 posts
Posted January 11, 2017

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.

  • Quote

Share this post


Link to post
Share on other sites

Rohzek    8

Rohzek

Rohzek    8

  • Stone Miner
  • Rohzek
  • Forge Modder
  • 8
  • 77 posts
Posted January 11, 2017

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

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    6671

diesieben07

diesieben07    6671

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6671
  • 45628 posts
Posted January 11, 2017

Well, you have a bit of a cyclic dependency there. The tabs creation will reference the static Item/Block fields, which in turn references the Tab, which is not initialized yet at that point, since the initialization of the tab caused the initialization of the Block/Item in the first place.

  • Quote

Share this post


Link to post
Share on other sites

lukas2005    9

lukas2005

lukas2005    9

  • Diamond Finder
  • lukas2005
  • Forge Modder
  • 9
  • 289 posts
Posted January 11, 2017

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

  • Quote

Share this post


Link to post
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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

  • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 0
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • MattNL
      Trouble getting contents of a Chest

      By MattNL · Posted 40 minutes ago

      Oh, I see... well that's useful to know! I'm going to try implementing your JSON-style replacement. Thank you very much!
    • Differentiation
      [1.12.2] Modifying player capabilities for offline players?

      By Differentiation · Posted 53 minutes ago

      Hey!   Is there any way to modify capability values for offline players (where EntityPlayerMP instance is null essentially) without using JSON? Is there like a way to make capabilities for GameProfile?   Any help is appreciated!   Thanks!
    • Draco18s
      Trouble getting contents of a Chest

      By Draco18s · Posted 55 minutes ago

      This event does not fire on 1.14 https://github.com/MinecraftForge/MinecraftForge/pull/6267
    • DaemonUmbra
      Trouble getting contents of a Chest

      By DaemonUmbra · Posted 1 hour ago

      https://mcforge.readthedocs.io/en/1.13.x/concepts/sides/
    • MattNL
      Trouble getting contents of a Chest

      By MattNL · Posted 1 hour ago

      So, I realized I didn't really mention what the problem was, oops. I need to get the contents of broken containers, not just chests, and write that data to an item stack (presumably through net.minecraft.client.Minecraft.storeTEInStack).
  • Topics

    • MattNL
      4
      Trouble getting contents of a Chest

      By MattNL
      Started 1 hour ago

    • Differentiation
      0
      [1.12.2] Modifying player capabilities for offline players?

      By Differentiation
      Started 53 minutes ago

    • inzig0
      1
      Does forge 1.14.-28.1 support openjdk11?

      By inzig0
      Started 1 hour ago

    • hobohogiepro
      5
      1.7.10 libraries won't download

      By hobohogiepro
      Started 1 hour ago

    • millerman19
      1
      java.lang.NoSuchFieldError: world

      By millerman19
      Started 2 hours ago

  • Who's Online (See full list)

    • Atila1091
    • Draco18s
    • J0WAY
    • Differentiation
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.11] Creative Tabs
  • Theme
  • Contact Us
  • Discord

Copyright © 2019 ForgeDevelopment LLC · Ads by Curse Powered by Invision Community