Jump to content

Recommended Posts

Posted

Hi everyone,

I'd like to know how to make a sub-item, like dyes (for instance the Id of an item is 6549, another is 6549:1, another is 6549:2 etc...)

 

Please reply,

- Thib92

Posted

Study that file. Metadata is extra data that is saved to other data. For example, the data value for dyes is 351. They contain extra data, such as 0, 1, 2, . . ., 15.

Posted

Sorry but I'm really really bad !! I started 3 days ago, so I don't know what you're talking about !

 

Could you be more precise please ? I don't have enough level yet to study that kind of file, I managed to study some easy ones but this one is really complicated !

Posted

I was going to refer you to the wiki page on it but apparently that page got deleted. So, I can explain it to you i guess.

 

I will assume you are looking at the ItemDye class

Basically, you need a table of all the sub items you want and their unlocalized names. (Line 33)

Then, you need a table of all their icons (Line 37)

You need to let Minecraft know that this item has subtypes by using the this.setHasSubtypes(true) function in the constructor (Line 42)

You then have to make sure the item cannot be damaged by using the item.setItemDamage() function (Line 43)

After that, you need to get the item Icon. (Line 54 and 55)

You also need to give each sub item a unique name. (Line 64 and 65)

On Line 378, the method getSubItems() gets all the sub items from that particular item. VERY IMPORTANT: Replace the 16 on line 380 with whatever amount of items you have. Example: If I had 3 sub items, i would replace 16 with 3

 

Finally, the registerIcons function on line 387 set the texture of each individual item.

 

If I had 5 items the code would look like this

for (int i = 0; i < ARRAY_WITH_ITEM_NAMES.legnth(); i++){
    this.ICON_ARRAY[i] = par1IconRegister.registerIcon("MAIN_ITEM_NAME_" + ARRAY_WITH_ITEM_NAMES[i]);
}

 

100% Working example file: http://pastebin.com/P2eZaYsd

Posted

Look at the important parts:

 

In the constructor:

this.setHasSubtypes(true);

This should indicate the obvious.

 

This method:

public String getUnlocalizedName(ItemStack par1ItemStack)
    {
        int i = MathHelper.clamp_int(par1ItemStack.getItemDamage(), 0, 15);
        return super.getUnlocalizedName() + "." + dyeColorNames[i];
    }

This is necessary if you want your sub-items to have different names. dyeColorNames is just a String array with different unlocalized names to append to the return String for that method.

 

These methods:

public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List par3List)
    {
        for (int j = 0; j < 16; ++j)
        {
            par3List.add(new ItemStack(par1, 1, j));
        }
    }

    @SideOnly(Side.CLIENT)
    public void registerIcons(IconRegister par1IconRegister)
    {
        this.field_94594_d = new Icon[field_94595_b.length];

        for (int i = 0; i < field_94595_b.length; ++i)
        {
            this.field_94594_d[i] = par1IconRegister.registerIcon(this.func_111208_A() + "_" + field_94595_b[i]);
        }
    }

The first will compile all of the different items that should be displayed on the creative tab, in other words damage values 0 through 15 (all 16 dye colors). The second will register the individual icons for each dye. These icons are retrieved in getIconFromDamage() when rendering.

 

All of the other methods are for applying dyes to sheep and fertilizing plants, which is something your item probably will not even do.

 

You should easily be able to basically copy everything I just gave you, put it where it needs to go, and make a new item with damage values by adapting the information to fit your needs.

Posted

okay, thank you very muuch ! And after this, how do I get my sub-items as a variable ?

new ItemStack(item, 1, dmgValue) will give an ItemStack of the specified Item having the specific damage value.

Posted

By damage value I mean the metadata value that the sub-item is identified by. IE, bonemeal is identified by 351:15, whereas ink sac is identified by 351:0.

Posted

Okay, here is my code :

package thib92.theusefulmod;

import java.util.List;

import cpw.mods.fml.common.registry.LanguageRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumArmorMaterial;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Icon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;


public class RedstoneHelmet extends ItemArmor
{

public final static String[] subitemsNames = new String[] {"respiration1", "respiration2", "respiration3", "nightvision"};
private Icon[] iconList;

public RedstoneHelmet(int par1, EnumArmorMaterial par2EnumArmorMaterial, int par3, int par4)
{
	super(par1, par2EnumArmorMaterial, par3, par4);
	this.setHasSubtypes(true);
	this.setMaxDamage(0);
	this.setCreativeTab(CreativeTabs.tabCombat);

	for(int i = 0; i < subitemsNames.length; i++){
            LanguageRegistry.addName(new ItemStack(this,1,i), subitemsNames[i]);
	}

}

@Override
    @SideOnly(Side.CLIENT)
    public Icon getIconFromDamage(int par1) {
            int i = MathHelper.clamp_int(par1, 0, 3);
            return this.iconList[i];
    }

@Override
    @SideOnly(Side.CLIENT)
    public void registerIcons(IconRegister par1IconRegister) {
            this.iconList = new Icon[subitemsNames.length];
           
            for(int i = 0; i < subitemsNames.length; i++){
                    this.iconList[i] = par1IconRegister.registerIcon("theusefulmod:redstoneHelmet");
            }
    }

@Override
    @SideOnly(Side.CLIENT)
    public void getSubItems(int itemID, CreativeTabs tab,
                    List itemList) {
            for(int i = 0; i < subitemsNames.length; i++){
                    itemList.add(new ItemStack(itemID,1,i));
            }
    }

@Override
    public String getUnlocalizedName(ItemStack item) {
            return this.getUnlocalizedName() + "." + subitemsNames[item.getItemDamage()];
    }

public String getArmorTexture(ItemStack stack, Entity entity, int slot, int layer)
{
         if (itemID == TheUsefulMod.redstoneHelmet.itemID || stack.itemID == TheUsefulMod.redstoneChestplate.itemID || stack.itemID == TheUsefulMod.redstoneBoots.itemID) {
                         return "TheUsefulMod:textures/armor/redstone_1.png";
         }
         if(itemID== TheUsefulMod.redstoneLeggings.itemID) {
                         return "TheUsefulMod:textures/armor/redstone_2.png";
         }
         return "TheUsefulMod:textures/armor/redstone_2.png";
}
}

 

When I open my inventory, I have no problem, but if I hover the item with my mouse, then... the game just ends !

Posted

You're not going to be able to use metadata for items that take damage such as armor, tools, sword, etc. They need the damage values for the damaged versions of themselves, so this won't even work for your Redstone Helmet.

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • When I first heard about Bitcoin back in 2018, I was skeptical. The idea of a decentralized, digital currency seemed too good to be true. But I was intrigued as I learned more about the technology behind it and its potential. I started small, investing just a few hundred dollars, dipping my toes into the cryptocurrency waters. At first, it was exhilarating to watch the value of my investment grow exponentially. I felt like I was part of the future, an early adopter of this revolutionary new asset. But that euphoria was short-lived. One day, I logged into my digital wallet only to find it empty - my Bitcoin had vanished without a trace. It turned out that the online exchange I had trusted had been hacked, and my funds were stolen. I was devastated, both financially and emotionally. All the potential I had seen in Bitcoin was tainted by the harsh reality that with decentralization came a lack of regulation and oversight. My hard-earned money was gone, lost to the ether of the digital world. This experience taught me a painful lesson about the price of trust in the uncharted territory of cryptocurrency. While the technology holds incredible promise, the risks can be catastrophic if you don't approach it with extreme caution. My Bitcoin investment gamble had failed, and I was left to pick up the pieces, wiser but poorer for having placed my faith in the wrong hands. My sincere appreciation goes to MUYERN TRUST HACKER. You are my hero in recovering my lost funds. Send a direct m a i l ( muyerntrusted ( @ ) mail-me ( . )c o m ) or message on whats app : + 1 ( 4-4-0 ) ( 3 -3 -5 ) ( 0-2-0-5 )
    • You could try posting a log (if there is no log at all, it may be the launcher you are using, the FAQ may have info on how to enable the log) as described in the FAQ, however this will probably need to be reported to/remedied by the mod author.
    • So me and a couple of friends are playing with a shitpost mod pack and one of the mods in the pack is corail tombstone and for some reason there is a problem with it, where on death to fire the player will get kicked out of the server and the tombstone will not spawn basically deleting an entire inventory, it doesn't matter what type of fire it is, whether it's from vanilla fire/lava, or from modded fire like ice&fire/lycanites and it's common enough to where everyone on the server has experienced at least once or twice and it doesn't give any crash log. a solution to this would be much appreciated thank you!
    • It is 1.12.2 - I have no idea if there is a 1.12 pack
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.