Jump to content

Create sub-items (like dyes)


thib92

Recommended Posts

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 !

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 !

Link to comment
Share on other sites

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.

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

    • Add crash-reports with sites like https://paste.ee/ Maybe an issue with blur, essentials or cumulus_menus
    • Add the crash-report or latest.log (logs-folder) with sites like https://paste.ee/ and paste the link to it here  
    • I have a problem, I am trying to put two different effects to two different armors but when I run it only the emerald armor effect works. This is the code public class ModArmorItem extends ArmorItem{ private static final Map<ArmorMaterial, MobEffectInstance> MATERIAL_TO_EFFECT_MAP = (new ImmutableMap.Builder<ArmorMaterial, MobEffectInstance>()) .put(ModArmorMaterials.EMERALD, new MobEffectInstance(MobEffects.HERO_OF_THE_VILLAGE,200, 1,false,false, true)) .put(ModArmorMaterials.OBSIDIAN, new MobEffectInstance(MobEffects.FIRE_RESISTANCE,200, 1,false,false, true)).build(); public ModArmorItem(ArmorMaterial pMaterial, Type pType, Properties pProperties) { super(pMaterial, pType, pProperties); } @Override public void onArmorTick(ItemStack stack, Level world, Player player){ if (!world.isClientSide()) { if (hasFullSuitOfArmorOn(player)) { evaluateArmorEffects(player); } } } private void evaluateArmorEffects(Player player) { for (Map.Entry<ArmorMaterial,MobEffectInstance> entry : MATERIAL_TO_EFFECT_MAP.entrySet()){ ArmorMaterial mapArmorMaterial = entry.getKey(); MobEffectInstance mapStatusEffect = entry.getValue(); if (hasCorrectArmorOn(mapArmorMaterial, player)) { addStatusEffectForMaterial(player, mapArmorMaterial, mapStatusEffect); } } } private void addStatusEffectForMaterial(Player player, ArmorMaterial mapArmorMaterial, MobEffectInstance mapStatusEffect) { boolean hasPlayerEffect = player.hasEffect(mapStatusEffect.getEffect()); if (hasCorrectArmorOn(mapArmorMaterial, player) && !hasPlayerEffect) { player.addEffect(new MobEffectInstance(mapStatusEffect)); } } private boolean hasCorrectArmorOn(ArmorMaterial material, Player player) { for (ItemStack armorStack : player.getInventory().armor){ if (!(armorStack.getItem() instanceof ArmorItem)) { return false; } } ArmorItem helmet = ((ArmorItem)player.getInventory().getArmor(3).getItem()); ArmorItem breastplace = ((ArmorItem)player.getInventory().getArmor(2).getItem()); ArmorItem leggins = ((ArmorItem)player.getInventory().getArmor(1).getItem()); ArmorItem boots = ((ArmorItem)player.getInventory().getArmor(0).getItem()); return helmet.getMaterial() == material && breastplace.getMaterial() == material && leggins.getMaterial() == material && boots.getMaterial() == material; } private boolean hasFullSuitOfArmorOn(Player player){ ItemStack helmet = player.getInventory().getArmor(3); ItemStack breastplace = player.getInventory().getArmor(2); ItemStack leggins = player.getInventory().getArmor(1); ItemStack boots = player.getInventory().getArmor(0); return !helmet.isEmpty() && !breastplace.isEmpty() && !leggins.isEmpty() && !boots.isEmpty(); } } Also when I place two effects on the same armor, the game crashes. Here is the crash file. The code is the same, only this part is different   private static final Map<ArmorMaterial, MobEffectInstance> MATERIAL_TO_EFFECT_MAP = (new ImmutableMap.Builder<ArmorMaterial, MobEffectInstance>()) .put(ModArmorMaterials.EMERALD, new MobEffectInstance(MobEffects.HERO_OF_THE_VILLAGE,200, 1,false,false, true)) .put(ModArmorMaterials.EMERALD, new MobEffectInstance(MobEffects.FIRE_RESISTANCE,200, 1,false,false, true)).build(); I hope you guys can help me. Thanks.
  • Topics

×
×
  • Create New...

Important Information

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