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.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • LAYANAN DAFTAR TRANSTOGEL ! WA : 082213952901 SEARCH GOOGLE > TRANSTOGEL  
    • If you’ve ever experienced the sinking feeling of losing funds online, you’re not alone. Enter recovery services like ADWARE RECOVERY SPECIALIST, the heroes of the digital age who help individuals track down and retrieve lost funds. These services act as modern-day sheriffs in the Wild West of the internet, bringing justice to those who have fallen victim to online scams and fraud. In a world where online transactions are as common as selfies, the need for recovery services is more pressing than ever. Individuals worldwide are vulnerable to various online schemes, from investment fraud to phishing scams. Recovery services provide a glimmer of hope for those who have lost money, offering a chance to recover what's rightfully theirs and restore faith in the digital realm. The beauty of recovery services like ADWARE RECOVERY SPECIALIST lies in their global reach. Email: Adwarerecoveryspecialist@auctioneer. net  Regardless of where individuals are located worldwide, these services extend their virtual arms to help victims of online fraud. From bustling metropolises to remote villages, no corner of the world is beyond the grasp of these modern-day Robin Hoods. Thanks to the wonders of globalization, recovery services have transcended geographical boundaries to serve individuals worldwide. The interconnected nature of the digital world means that help is just a click away, bridging gaps between nations and bringing relief to those in need. In a world where borders are becoming increasingly blurred, recovery services stand as beacons of accessibility and assistance. When a broker stole from me and withheld access from me for five months, I had no idea that I would be able to recover my trading money back. I'm relieved that I was able to get my money returned without any issues. The impact of recovery services like ADWARE RECOVERY SPECIALIST extends far beyond individual wallets. Communities worldwide have experienced a renewed sense of trust and security, knowing that there are dedicated professionals working tirelessly to recover their lost assets. These services not only bring financial relief but also restore faith in the integrity of the digital world. Trust is the cornerstone of any successful recovery service, and building credibility in a global market can pose unique challenges. ADWARE RECOVERY SPECIALIST strives to maintain transparency and reliability in all its interactions, earning the trust of clients worldwide. ADWARE RECOVERY SPECIALIST can be talked to through:  Website: www.adwarerecoveryspecialist.expert  Telegram: @ADWARE_RECOVERY_SPECIALIST
    • The game wont start and keeps crashing everytime I hit play "The game crashed whilst rendering overlay Error: java.lang.IllegalAccessError: failed to access class com.mojang.blaze3d.platform.GlStateManager$TextureState from class net.coderbot.iris.gl.IrisRenderSystem$DSAARB (com.mojang.blaze3d.platform.GlStateManager$TextureState is in module minecraft@1.18.2 of loader 'TRANSFORMER' @724b939e; net.coderbot.iris.gl.IrisRenderSystem$DSAARB is in module oculus@1.6.4 of loader 'TRANSFORMER' @724b939e)" How do I get it to stop? Log error here: https://pastebin.com/byv1dR54
    • In case anyone happens on this with the same issue, I was able to overcome it. After re-reading @Paint_Ninja's last post numerous time, it finally dawned on me that he was referring wholly to the forge installer, which has nothing to do with the packaged modpack installer. As such, I downloaded the new copy of the forge installer and copied it to my linux host, then opened a second ssh session and prepared a cp command to move the new (correct) installer over to the install directory where I was installing the modpack. After the modpack installer had just about finished retrieving files, I overwrote the installer.jar file with the correct one in a seperate ssh session. The modpack (packaged) installer then used that jar to install forge with the included files, and the install finished as I would have expected. Thanks all!
  • Topics

×
×
  • Create New...

Important Information

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