Jump to content

Recommended Posts

Posted

I was wondering what is the best way to make an item with subsets (ItemMana is composed of Mana Crystal, Mana Shard, Mana Foci)

 

Right now Im using the item's damage to make the subsets, but then I ran into the issue of "How do I name each one differently?"

 

So, what is the proper way of doing this? And also if using ItemDamage can I check that for crafting recipes that's another big concern because I want 4 shard = 1 crystal, and 4 crystals + 4 diamond = foci.

 

I would ask about blocks but I googled (and searched this forum) and found this http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-mods/modification-development/1437838-1-7-2-forge-metadata-blocks-and-items so I figure I can use that as my starter for blocks.

 

Edit: to add the current class

 

public class ItemMana extends Item
{
public ItemMana()
{
	setMaxStackSize(1);
}
IIcon full;
IIcon shard;

@Override
public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World,
		EntityPlayer par3EntityPlayer) {
	System.out.println(par1ItemStack.getItemDamage());
	return super.onItemRightClick(par1ItemStack, par2World, par3EntityPlayer);
}

@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IIconRegister ir) 
{
	full = ir.registerIcon(Rot.MODID.toLowerCase()+":"+"manaCrystal");
	shard = ir.registerIcon(Rot.MODID.toLowerCase()+":"+"manaShard");
}

@Override
@SideOnly(Side.CLIENT)
public IIcon getIconFromDamage(int par1) 
{
	if (par1 == 0)return full;
	else return shard;
}

@Override
@SideOnly(Side.CLIENT)
public void getSubItems(Item item, CreativeTabs tab, List list) 
{
	list.add(new ItemStack(item, 1, 0));
	list.add(new ItemStack(item, 1, 1));
}	
}

 

Posted

Seemed to work fine without "hasSubtypes(true) and setMaxDamage(0)" but I added them in for the sake of suggestion(and proper use)

 

@TheGreyGhost

Didn't know I could use itemStacks in the crafting prams, got that working fine and dandy now thanks. However following ItemColored I get a crash when I hover over my item now.

 

The crash report is a stackoverflow (oh no!) and it is caused on the line that returns the unlocalized name. Is it because ItemColored is ItemBlock and not Item?

 

my Code:

 

public class ItemMana extends Item
{
public ItemMana()
{
	this.setMaxDamage(0);
	setMaxStackSize(1);
	setHasSubtypes(true);
}
private IIcon full;
private IIcon shard;
private String[] names = new String[]{"manaCrystal", "manaShard","manaFoci"};

@Override
public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World,
		EntityPlayer par3EntityPlayer) {
	System.out.println(par1ItemStack.getItemDamage());
	return super.onItemRightClick(par1ItemStack, par2World, par3EntityPlayer);
}

@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IIconRegister ir) 
{
	full = ir.registerIcon(Rot.MODID.toLowerCase()+":"+"manaCrystal");
	shard = ir.registerIcon(Rot.MODID.toLowerCase()+":"+"manaShard");
}

@Override
@SideOnly(Side.CLIENT)
public IIcon getIconFromDamage(int par1) 
{
	if (par1 == 0)return full;
	else return shard;
}

@Override
@SideOnly(Side.CLIENT)
public void getSubItems(Item item, CreativeTabs tab, List list) 
{
	list.add(new ItemStack(item, 1, 0));
	list.add(new ItemStack(item, 1, 1));
}	

@Override
public String getUnlocalizedName(ItemStack item) 
{
	try
	{
		System.out.println(getUnlocalizedName(item) + "." + names[getDamage(item)]);
		return getUnlocalizedName(item) + "." + names[getDamage(item)];
	}
	catch(Exception e)
	{
		return getUnlocalizedName(item);
	}

}
}

 

 

ItemColored Code:

 

public class ItemColored extends ItemBlock
{
    private final Block field_150944_b;
    private String[] field_150945_c;
    private static final String __OBFID = "CL_00000003";

    public ItemColored(Block p_i45332_1_, boolean p_i45332_2_)
    {
        super(p_i45332_1_);
        this.field_150944_b = p_i45332_1_;

        if (p_i45332_2_)
        {
            this.setMaxDamage(0);
            this.setHasSubtypes(true);
        }
    }

    @SideOnly(Side.CLIENT)
    public int getColorFromItemStack(ItemStack par1ItemStack, int par2)
    {
        return this.field_150944_b.getRenderColor(par1ItemStack.getItemDamage());
    }

    /**
     * Returns the metadata of the block which this Item (ItemBlock) can place
     */
    public int getMetadata(int par1)
    {
        return par1;
    }

    public ItemColored func_150943_a(String[] p_150943_1_)
    {
        this.field_150945_c = p_150943_1_;
        return this;
    }

    /**
     * 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.
     */
    public String getUnlocalizedName(ItemStack par1ItemStack)
    {
        if (this.field_150945_c == null)
        {
            return super.getUnlocalizedName(par1ItemStack);
        }
        else
        {
            int i = par1ItemStack.getItemDamage();
            return i >= 0 && i < this.field_150945_c.length ? super.getUnlocalizedName(par1ItemStack) + "." + this.field_150945_c[i] : super.getUnlocalizedName(par1ItemStack);
        }
    }

    /**
     * Gets an icon index based on an item's damage value
     */
    @SideOnly(Side.CLIENT)
    public IIcon getIconFromDamage(int par1)
    {
        return this.field_150944_b.getIcon(0, par1);
    }
}

 

 

Having the crafting work and having that bit of info that I can use Itemstacks is great. So that's one of my problems down (1 of many) now I just need the naming.

 

Edit:

oh and how can I have them stack with only the same damaged subset? I know I forced the stackSize to 1 only because I when I picked up one of them theyd merged and become the same as the first one in inventory (have crystal in first slot, pick up shard, now have two crystals) what is the way to get around this? or is single stacks the way to go?

Posted

StackOverflow happens in recursion, i.e. when you call a method from itself. StackOverflow happens when you keep calling the same method again without stop, which is what happens in your getUnlocalizedName() method.

 

oh and how can I have them stack with only the same damaged subset? I know I forced the stackSize to 1 only because I when I picked up one of them theyd merged and become the same as the first one in inventory (have crystal in first slot, pick up shard, now have two crystals) what is the way to get around this? or is single stacks the way to go?

 

Well, that's what hasSubtypes(true) and setMaxDamage(0) are for.

Posted

Ok got multi texturedm subset blocks working, but I noticed with my mana items the names show up, but have a ".name" on them in game. How do I remove that? I have a lang file which I believe is working, but why does looking at the item give me "Mana Crystal.name"?

 

ItemMana

 

public class ItemMana extends Item
{
public ItemMana()
{
	this.setMaxDamage(0);
	//setMaxStackSize(1);
	setHasSubtypes(true);
}
private IIcon[] icons = new IIcon[3];
private String[] names = new String[]{"manaCrystal", "manaShard","manaFoci"};

@Override
public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World,
		EntityPlayer par3EntityPlayer) {
	System.out.println(par1ItemStack.getItemDamage());
	return super.onItemRightClick(par1ItemStack, par2World, par3EntityPlayer);
}

@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IIconRegister ir) 
{
	icons[0] = ir.registerIcon(Rot.MODID.toLowerCase()+":"+"manaCrystal");
	icons[1] = ir.registerIcon(Rot.MODID.toLowerCase()+":"+"manaShard");
	icons[2] = ir.registerIcon(Rot.MODID.toLowerCase()+":"+"manaFoci");
}

@Override
@SideOnly(Side.CLIENT)
public IIcon getIconFromDamage(int par1) 
{
	switch (par1)
	{
		case 0:return icons[0];
		case 1:return icons[1];
		case 2:return icons[2];
		default:return icons[0];
	}
}

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

@Override
public String getUnlocalizedName(ItemStack item) 
{		
	//System.out.println(getUnlocalizedName() + "." + names[getDamage(item)]);
	return getUnlocalizedName() + "." + names[getDamage(item)];		
}

 

 

Lang File

tile.testBlock.name=Test

item.manaConverter.name=Mana Converter
item.relicRepair.name=Key of Mending
item.gunpowderInfuser.name=Gunpowder Infuser
item.relicHeal.name=Locket of Life
item.relicLife.name=Brooch of the Scarab
item.manaCrystal.manaCrystal=Mana Crystal
item.manaCrystal.manaShard=Mana Shard
item.manaCrystal.manaFoci=Mana Focus

itemGroup.RoT=Rise of Tristram

 

Also I don't know if I should make a new thread or I can ask here. But I have the PacketPipeLine setup using AbstractPackets which I used for this tutorial Event Handlers and IExtendedProperties for mana but it goes off and uses the DataWatcher (which of course is better) but I don't know where to go to find out how to use packets, and use them properly. I have some ideas for tileEntities but I need to send data from a Gui to them, and thus idk how to use a packet to do that. A simple tutorial or a exsisting thread explaining/showing this would be nice, or explain it here for me would be great. PS. The tileEntities are not a simple inventory one, else i'd be fine with the current Container transfer of itemStacks.

Posted

item.manaCrystal.manaCrystal=Mana Crystal
item.manaCrystal.manaShard=Mana Shard
item.manaCrystal.manaFoci=Mana Focus

 

it should be:

item.manaCrystal.manaCrystal.name=Mana Crystal
item.manaCrystal.manaShard.name=Mana Shard
item.manaCrystal.manaFoci.name=Mana Focus

 

For the packet thing, I barely could handle my problems in it, I would've answered if I've known  :-\

Posted

Thanks, can't believe I was that Dense >.> by that I mean not adding a .name to see if it would clear it up.

 

And I guess I have to wait or make a new thread about packets. I know the tutorials subboard has something about IMessages and that they "could" be used to send info from the player to tileEntity. But that is with a different packet thingy, so hopefully someone can tell me the correct way of doing so or lead me to the right direction.

 

Thanks for your help. Much appreciated.

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



×
×
  • Create New...

Important Information

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