Jump to content

What does the method "getRegisteredItem()" do? (net.minecraft.init.Items)


Recommended Posts

Posted

Hi!

I am trying to find out how to create items with the new (i think its not that new but...) 1.8 version.

 

I didn't find a lot of tutorials for this topic, (I am sure there are a lot but i didn't find a good one)

so i went there and just read the code. I started by reading the "net.minecraft.init.Items" class.

I struggled, because all the items seem to be registered somewhere else. there is just the function:

static
    {
        if (!Bootstrap.isRegistered())
        {
            throw new RuntimeException("Accessed Items before Bootstrap!");
        }
        else
        {
                iron_shovel = getRegisteredItem("iron_shovel");
                // ...

 

I ctrl-clicked the method, but i didn't found anything usefull.

 

Where are the definitions of the Items hidden? (I know that net.minecraft.item is holding some of them, but i can't find any example for a "something_ingot".

Posted

Item.registerItems

instantiates and registers all vanilla items. The static initialiser of

Items

gets the

Item

instances from the item registry and assigns them to the static fields.

 

Item creation and registration hasn't really changed in 1.8, only the model system has.

 

BedrockMiner has a tutorial on creating a basic item in 1.8 here.

 

I register my mod's items using this class. I register my models using this class.

 

This code is for 1.8. Switch to the 1.8.8 branch to see the 1.8.9 code.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

I think it is important to understand that an Item instance is never really useful on its own. You really need an ItemStack or an EntityItem depending on whether it is in an inventory or on the ground. If you only have a single item, you are really holding an ItemStack with quantity 1.

 

I think there are only one main instance of each Item class, and it describes the behavior of items generally. But if you want a specific item of that type to be a bit different then you need to use the ItemStack and a combination of metadata and/or NBT data. So you don't name an Item, you name an ItemStack. You don't damage an Item, you damage an ItemStack.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

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.