Amazon Ad

Tuesday, May 23, 2017

Blocks, Items, Creative tabs, and all review

In the last tutorial, we created a util class that handles the registry and rendering of all of our blocks and items. Now we need to create our blocks and items. First we need to create a package in our main com.[your_domain].tut package and call it init and put two classes in there and called them Blocks and Items. Let's create a block and an item.

First the block in our Blocks class:


Now we create BlockTutBlock in a package called com.[your_domain].tut.blocks.


As I have said before, you do not have to format your code the way you see it here.

Now we have to make a class called BlockBase and put all of our templates.



Now you can create a block and initialize it all in it's constructor, whether you want to give it a light level, a harvest level, or make it just a basic block. Lastly, we now need to register and render it in our RegisterUtil class.


Now we need to create an item.


Then we create the item class and inherit from ItemBase



But wait, what if we don't wanna put our blocks and items into the vanilla creative tabs? Well, we should create a class called CreativeTabsHandler in our com.[your_domain].tut.handlers and put our new creative tab in their.


This creates a new creative tab with an unlocalized name of "tutTab" and we are setting the tab icon to be our newly created tut item.

Now we need to do the JSON's for our block and item. We can just copy from coal_ore and coal JSON's.

The way that IntelliJ creates directories is kinda weird so we will have to go into the actual folder and create the assets.tut.blockstates and assets.tut.models.item, assets.tut.models.block directories. If we go into the external libraries and open the forgeSrc and locate the assets then we can find the JSON files of coal_ore and coal. You can reference earlier tutorials for creating JSON files for blocks and items, nothing have changed. I will provide images for you if you do not know how to make images. I actually have a small Paint.NET tutorial here if you would like to learn how to make basic textures for items and blocks. You'd have to research or find ways into making higher quality textures though. Here is the link to a couple of textures, one of the block, and one of the item. Once you place them in the right directories, and run the mod, then it should work. I have already tested it.

If you have any questions, please feel free to ask in the comments!

29 comments:

  1. Great Tutorials so far. But I've got a question:
    How do you actually get the CreativeTab into the game? It is going to be initialized at some point, isn't it?

    ReplyDelete
    Replies
    1. Ah right. In the "setCreativeTab(tab)" part of our item and blocks, Minecraft initializes any instances of CreativeTabs into the creative inventory menu.

      Delete
  2. The directory situation here has gotten quite confusing, especially with the manual creation of directories here. Could you include a screenshot of what the project file structure should look like?

    ReplyDelete
    Replies
    1. Sorry about that! The set up that I am doing follows the package naming convention of com.cdc.tut, cdc being my domain, so [your_domain] would be maybe your name or your website if you have one. Mojang's is net.mojang.minecraft, as an external example. Another external example is java.lang.String for strings.

      Delete
  3. This comment has been removed by the author.

    ReplyDelete
  4. Hey, both textures will not load for me and I'm getting these errors, https://pastebin.com/MeGPAQHx , my mod id is tm. I have added what all my json files contain at the bottom of the pastebin.

    ReplyDelete
    Replies
    1. Haha sometimes things are right in front of you and you're just oblivious, sorry about that

      Delete
  5. This comment has been removed by the author.

    ReplyDelete
  6. I dont understand the folder setup for the assets, could you explain more? Is the folder setup like this

    assets
    domain
    mod

    or just
    assets.domain.mod?

    ReplyDelete
  7. okay im having some trouble, i have everything exactly how you have it, but for some reason when it tries to get the texture it is looking in the wrong directory, it is looking in the minecraft resource folder instead of my resource folder, but my block is rendering just fine.

    ReplyDelete
    Replies
    1. Mod ID's!! Always put your Mod ID's!!

      Delete
    2. okay i went back and looked at your json tutorial and found out where i was supposed to put the modid in the item json, i was confused because i didnt need it for the block json

      Delete
    3. i did put it in the block json but the one in blockstates not the one in models, so i screwed myself

      Delete
    4. Interesting...Did you try putting your modid into your block resource location as well?

      Delete
  8. Hey, getTabIconItem()'s return type is now Item, not ItemStack. Please change!

    ReplyDelete
    Replies
    1. This is still only 1.11.2, not 1.12. It may be like that in 1.12 but this tutorial is for 1.11.2, I will be updating this summer though, thanks for the look out!

      Delete
  9. i don't understand adding items part, when i follow that part, its said Itemtutitem cannot be resolved to a type.

    do i need to make another class for that item?
    and what do i need to put in?

    ReplyDelete
    Replies
    1. You should go to my original Items tutorial which will take you through the step-by-step process of creating an item.

      Delete
    2. but mixing with these two tut, i am very confuse what to do.

      original tutorial's ItemHandler seems like doing the same thing with registerUtil, and ModItem doing the ItemBase thing.

      but the old one in myitemclass is extends to ModItems, so in the new way should i in myitemclass extends to Itembase for register?

      but then public static final Item myitem = new ItemMyitem("my_item", CreativeTabs.MISC); where do i put to create item?

      and this new tut on CreativeTabHandler, you just return the sigle item, but how can i set to each time if i have something added it will auto register to which tab i want to place?

      Delete
  10. What is the significance in creating BlockTutBlock class?
    The constructor is the same in BlockBase, so BlockTutBlock is not necessary.

    ReplyDelete
  11. This comment has been removed by the author.

    ReplyDelete
  12. This comment has been removed by the author.

    ReplyDelete
  13. i did everything in this tut but mc cant seem to know my item/block exists, or even my entire mod, it says it works but then it says it runs but it feels like it doesnt, it was working before this tho, any help?

    ReplyDelete