Can I first start off by saying jumping code from 1.5.2 straight to 1.7.2/1.7.10... not fun. Basically re-writing the entire thing.
Anyway, after several hours of searching for a solution I've decided to make a post here.
I have an item (a few items, actually) that is subtyped via metadata and using /give works and appears to be coded and localized correctly.
However, when viewing the tab in the creative menu only the first subtype is shown and can be spawned.
(Yes, the dust/ingot textures are from TherrmalExpansion. These are only temp. textures.)
ItemMod.java
package com.tehseph.sephsmod.item;
import com.tehseph.sephsmod.core.Globals;
import com.tehseph.sephsmod.core.ModCreativeTab;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
public class ItemMod extends Item {
public ItemMod() {
super();
this.setCreativeTab(ModCreativeTab.tabSephsMod);
this.setMaxStackSize(1);
this.setNoRepair();
}
@Override
public String getUnlocalizedName() {
return String.format("item.%s:%s", Globals.MODID.toLowerCase(), getUnwrappedName());
}
@Override
public String getUnlocalizedName(ItemStack itemStack) {
return String.format("item.%s:%s", Globals.MODID.toLowerCase(), getUnwrappedName());
}
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IIconRegister iconRegister) {
itemIcon = iconRegister.registerIcon(this.getUnlocalizedName().substring(this.getUnlocalizedName().indexOf(".") + 1));
}
protected String getUnwrappedName() {
return super.getUnlocalizedName().substring(super.getUnlocalizedName().indexOf(".") + 1);
}
}
ItemModMeta.java
package com.tehseph.sephsmod.item;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import java.util.List;
public class ItemModMeta extends ItemMod {
protected String[] metaNames;
protected IIcon[] metaIcons;
public ItemModMeta() {
super();
this.setHasSubtypes(true);
}
@Override
public String getUnlocalizedName(ItemStack itemStack) {
return (super.getUnlocalizedName() + "_" + this.metaNames[itemStack.getItemDamage()]);
}
@SideOnly(Side.CLIENT)
public String getUnlocalizedName(int metadata) {
return (super.getUnlocalizedName() + "_" + this.metaNames[metadata]);
}
@Override
@SideOnly(Side.CLIENT)
public IIcon getIconFromDamage(int metadata) {
return this.metaIcons[metadata];
}
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IIconRegister iconRegister) {
itemIcon = iconRegister.registerIcon(this.getUnlocalizedName(0).substring(this.getUnlocalizedName(0).indexOf(".") + 1));
for (int i = 0; i < metaIcons.length; i++) {
metaIcons[i] = iconRegister.registerIcon(this.getUnlocalizedName(i).substring(this.getUnlocalizedName(i).indexOf(".") + 1));
}
}
@SideOnly(Side.CLIENT)
public void getSubItems(int itemID, CreativeTabs cTab, List itemList) {
for (int i = 0; i < this.metaNames.length; ++i) {
itemList.add(new ItemStack(this, 1, i));
}
}
}
ItemOreDusts.java
package com.tehseph.sephsmod.item;
import net.minecraft.util.IIcon;
public class ItemOreDusts extends ItemModMeta {
private String[] dustNames = {"Copper", "Gold", "Iron", "Tin" };
public ItemOreDusts() {
super();
this.metaNames = this.dustNames;
this.metaIcons = new IIcon[this.dustNames.length];
this.setUnlocalizedName("oreDusts");
}
}
ModItems.java
package com.tehseph.sephsmod.core;
import com.tehseph.sephsmod.item.*;
import cpw.mods.fml.common.registry.GameRegistry;
@GameRegistry.ObjectHolder(Globals.MODID)
public class ModItems {
public static final ItemMod grindstone = new ItemGrindstone();
public static final ItemMod infernalStone = new ItemInfernalStone();
public static final ItemMod oreDusts = new ItemOreDusts();
public static final ItemMod oreIngots = new ItemOreIngots();
public static void init() {
GameRegistry.registerItem(grindstone, "grindstone");
GameRegistry.registerItem(infernalStone, "infernalStone");
GameRegistry.registerItem(oreDusts, "oreDusts");
GameRegistry.registerCustomItemStack("dustCopper", new ItemStack(oreDusts, 1, 0));
GameRegistry.registerCustomItemStack("dustGold", new ItemStack(oreDusts, 1, 1));
GameRegistry.registerCustomItemStack("dustIron", new ItemStack(oreDusts, 1, 2));
GameRegistry.registerCustomItemStack("dustTin", new ItemStack(oreDusts, 1, 3));
GameRegistry.registerItem(oreIngots, "oreIngots");
GameRegistry.registerCustomItemStack("ingotCopper", new ItemStack(oreIngots, 1, 0));
GameRegistry.registerCustomItemStack("ingotTin", new ItemStack(oreIngots, 1, 1));
}
}