Amazon Ad

Thursday, February 2, 2017

Creative Tabs and en_US.lang

Hello, my name is Alex and I am going to show you how to create a mod for minecraft forge 1.11.2. There's not a lot of tutorials on 1.11 so I am creating one for those that want to get started.

WARNING: IF YOU DO NOT KNOW ANYTHING ABOUT JAVA, PLEASE LEARN THE BASICS BEFORE ATTEMPTING TO FOLLOW ANY MODDING TUTORIALS!!!!!


In this tutorial, we will be looking at putting all of our items and blocks into their own creative tabs. Creative tabs do not have a separate registries, it's just using it in your mod that makes it appear. CreativeTabs is an abstract class, and for a good reason, too. If you don't know what an abstract class is, it is basically a class that cannot be instantiated. This way, you actually set the properties by calling the methods within the initialization. You'll see what I mean in a moment.

Let's start off by creating a class in our handlers package, called CreativeTabHandler. This is where we are going to put all of our Creative Tabs. We need a static field of the type CreativeTabs with a name in the form of tab<yourtabname>. Of course, you can always name this whatever, but it's good practice to give a convention to your fields. The first creative tab we will make will store all of our blocks. We will call this tabBlocks.

This will initiate to a new CreativeTabs with a given name, set as a parameter, but instead of ending it off, we need to treat it like a method, and add the unimplemented method, being getTabIconItem.

1
2
3
4
5
6
 public static CreativeTabs tabBlocks = new CreativeTabs("tut_blocks"){

  public ItemStack getTabIconItem() {
   return null;
  }
 };

getTabIconItem is how we set the tab icon and what block or item it should display. We give it the name "tut_blocks". We need to give this tab a tab icon. We will make it our block, created in the blocks tutorial.

1
return new ItemStack(Item.getItemFromBlock(BlockHandler.tutBlock));

It returns a new ItemStack, I don't know why but I am guessing because it is handled easier than just an item, but I personally see no reason to return an ItemStack. We need to convert our block to an item, so we get the ItemBlock from our block.

Next is actually using it, so go on over to your BlockHandler class and change the creative tab argument to our newly created tab.


1
tutBlock = new BlockTutBlock(Material.ROCK, "tut_block", CreativeTabHandler.tabBlocks, 5F, 15F, 3, "pickaxe");

This will allow us to place our block in the creative tab we created. If we run the game, it should be there for us, as shown below.


===========================================Bonus=============================================

Let's make a couple more, shall we? Make three more tabs, one for items, one for tools, and one for weapons. Make the item tab have the tab icon of our tut item. For now, just leave the tab icons for the last two null, and don't use them until the tools tutorial.

We need to give everything names, like, proper names, that are readable. So we shall go into our resources folder and create a package called "assets.tut.lang". This is where we will put a file rightly called "en_US.lang". Make this file and in it we will name all of our components.

The convention of a .lang file is this:

Blocks: tile.<unlocalizedName>.name=Your Block Name
Items: item.<unlocalizedName>.name=Your Item Name
Creative Tabs: itemGroup.<unlocalizedName>=Your Tab Name

Here is what mine looks like:


1
2
3
tile.tut_block.name=Tutorial Ore
item.tut_item.name=Tutorial Item
itemGroup.tut_blocks=Mod Blocks

Run the game and you should be good to go!

7 comments:

  1. How do you include a vanila item into the new tab?

    ReplyDelete
    Replies
    1. Why do you need to do that? There's no reason to do so.

      Delete
    2. You need to add the item into the creative tabs. I had like moditems, and items.stone is the vanilla item and moditems.stonedagger is the one you use for tabs.

      Delete
  2. My game crashes if I return null for a tab's icon, so I just have a temp icon instead.

    ReplyDelete
  3. its nice and all, but how do I make my class CreativeTabHandler run if im never importing it anywhere?

    ReplyDelete
  4. my en_US.lang is not working but i did everything just like you

    ReplyDelete
  5. Nice game, thanks for taking your time to write about it. Very cool graphics, the screenshots provided looks very good. I have a blog about games too, you can visit it at:

    > Minecraft GAMES FREE DOWNLOAD <

    ReplyDelete