Jump to content

[Solved] [1.5.1] Subitem names wrong


chupmacabre

Recommended Posts

Hello, I have been having trouble getting unique subitem names for metadata blocks/items all night. New to modding minecraft, and I guess a lot just changed with 1.5 so.. that's just my luck

 

Anyway, I've made a real quick and dirty mod to illustrate my problem. Here are the code files I wrote just now:

 

Test.java

 

package mods.test;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.Mod.PostInit;
import cpw.mods.fml.common.Mod.PreInit;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.item.ItemStack;
import net.minecraft.src.BaseMod;
@Mod(modid="test",name="Test",version="0.0")
@NetworkMod(clientSideRequired=true, serverSideRequired=true)
public class Test extends BaseMod {
public static final Block testBlock = new BlockTest(500, Material.wood);

@Override
public String getVersion() {
// TODO Auto-generated method stub
return "0.0";
}
@Override
public void load() {
// TODO Auto-generated method stub

}
// Says where the client and server 'proxy' code is loaded.
@SidedProxy(clientSide="mods.test.client.ClientProxy", serverSide="mods.test.CommonProxy")
public static CommonProxy proxy;

@PreInit
public void preInit(FMLPreInitializationEvent event) { }

@Init
public void load(FMLInitializationEvent event) {
     int i;
     GameRegistry.registerBlock(testBlock, "test");
    
     for (i=0;i<4;++i){
     LanguageRegistry.addName(
         new ItemStack(testBlock, 1, i),
         BlockTest.subName[i]
         );
     }
}

@PostInit
public void postInit(FMLPostInitializationEvent event) { }

}

 

 

BlockTest.java

 

package mods.test;
import java.util.List;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Icon;
import net.minecraft.world.IBlockAccess;
public class BlockTest extends Block {

public static final String[] subName = {
"Sub-Item A",
"Sub-Item B",
"Sub-Item C",
"Sub-Item D"
};
public BlockTest(int par1, Material par2Material) {
super(par1, par2Material);
this.setCreativeTab(CreativeTabs.tabMisc);
}

/**
     * Determines the damage on the item the block drops. Used in cloth and wood.
     */
public int damageDropped(int metadata)
{
     return metadata;
}
/**
     * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
     */
public void getSubBlocks(int blockID, CreativeTabs creativeTabs, List itemList)
{
     for (int j = 0; j < subName.length; ++j)
     {
         itemList.add(new ItemStack(blockID, 1, j));
     }
}
@SideOnly(Side.CLIENT)
/**
     * When this method is called, your block should register all the icons it needs with the given IconRegister. This
     * is the only chance you get to register icons.
     */
public void registerIcons(IconRegister par1IconRegister)
{
     this.blockIcon = par1IconRegister.registerIcon("dirt");
}
}

 

 

ItemBlockTest.java

 

package mods.test;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
public class ItemBlockTest extends ItemBlock {

public static final String[] subName = {
"subA",
"subB",
"subC",
"subD"
};
public ItemBlockTest(int par1) {
super(par1);
this.setHasSubtypes(true);
this.setUnlocalizedName("test");
this.setCreativeTab(CreativeTabs.tabMisc);
}

@Override
public int getMetadata (int damageValue) {
return damageValue;
}

@Override
public String getItemDisplayName(ItemStack itemStack) {
return this.getUnlocalizedName() + subName[itemStack.getItemDamage()];
}
}

 

 

CommonProxy.java and ClientProxy.java

 

package mods.test;
public class CommonProxy {
}

package mods.test.client;
import mods.test.CommonProxy;
public class ClientProxy extends CommonProxy {
}

 

 

If you run the mod, all 4 blocks show up in the creative section and the inventory as "Sub-item D".

 

What am I missing?

Link to comment
Share on other sites

Thanks for the response. I went ahead and took your suggestion on the above code, and unfortunately I'm getting the same result.

 

This is what I am using now in place of the getItemDisplayName override:

    @Override
    public String getUnlocalizedName(ItemStack itemStack)
    {
    	return this.getUnlocalizedName() + subName[itemStack.getItemDamage()];
    }

Link to comment
Share on other sites

Perfect! Thank you.

 

Here's the updated code for anyone interested:

 

Test.java

 

package mods.test;

import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.Mod.PostInit;
import cpw.mods.fml.common.Mod.PreInit;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.item.ItemStack;

@Mod(modid="test",name="Test",version="0.0")
@NetworkMod(clientSideRequired=true, serverSideRequired=true)
public class Test {

public static final Block testBlock = new BlockTest(500, Material.wood); 

    // Says where the client and server 'proxy' code is loaded.
    @SidedProxy(clientSide="mods.test.client.ClientProxy", serverSide="mods.test.CommonProxy")
    public static CommonProxy proxy;
    
    @PreInit
    public void preInit(FMLPreInitializationEvent event) { }
    
    @Init
    public void load(FMLInitializationEvent event) {
    	int i;

    	GameRegistry.registerBlock(testBlock, ItemBlockTest.class, "test");
    	
    	for (i=0;i<4;++i){
    		LanguageRegistry.addName(
        		new ItemStack(testBlock, 1, i),
        		BlockTest.subName[i]
            );
    	}
    }
    
    @PostInit
    public void postInit(FMLPostInitializationEvent event) { }


}

 

 

ItemBlockTest.java

 

package mods.test;

import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;

public class ItemBlockTest extends ItemBlock {

public static final String[] subName = {
	"subA",
	"subB",
	"subC",
	"subD"
};

public ItemBlockTest(int par1) {
	super(par1);
	this.setHasSubtypes(true);
	this.setUnlocalizedName("test");
	this.setCreativeTab(CreativeTabs.tabMisc);
}

@Override
public int getMetadata (int damageValue) {
	return damageValue;
}

    /**
     * Returns the unlocalized name of this item. This version accepts an ItemStack so different stacks can have
     * different names based on their damage or NBT.
     */
@Override
    public String getUnlocalizedName(ItemStack itemStack)
    {
    	return this.getUnlocalizedName() + subName[itemStack.getItemDamage()];
    }

/*@Override
public String getItemDisplayName(ItemStack itemStack) {
	return this.getUnlocalizedName() + subName[itemStack.getItemDamage()];
}*/

}

 

Link to comment
Share on other sites

  • 3 weeks later...

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.

×
×
  • Create New...

Important Information

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