Jump to content

[1.7.10] Retaining ItemStack Damage During Crafting


TLHPoE

Recommended Posts

Hello, how would I make an item retain its damage after being crafted with something else?

 

Item:

package tf2crates.item;

import java.util.List;

import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.IIcon;
import net.minecraft.util.StatCollector;
import tf2crates.ReferenceTC;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class ItemPaint extends Item {
public static final String[] TYPES = { "black", "red", "green", "brown", "blue", "purple", "cyan", "silver", "gray", "pink", "lime", "yellow", "lightBlue", "magenta", "orange", "white" };
public IIcon[] textures;

public ItemPaint() {
	super();

	this.setUnlocalizedName("paint");
	this.setMaxStackSize(1);

	this.hasSubtypes = true;

	this.setContainerItem(this);
}

@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IIconRegister iconRegister) {
	textures = new IIcon[TYPES.length];

	for(int i = 0; i < TYPES.length; i++) {
		textures[i] = iconRegister.registerIcon(ReferenceTC.ID + ":paint/" + TYPES[i]);
	}
}

@Override
public String getItemStackDisplayName(ItemStack itemStack) {
	String res = StatCollector.translateToLocal("paint." + TYPES[itemStack.getItemDamage()] + ".name");
	return res;
}

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

@Override
public EnumRarity getRarity(ItemStack itemStack) {
	return EnumRarity.rare;
}

@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack itemStack, EntityPlayer player, List info, boolean f) {
	info.add(EnumChatFormatting.YELLOW + "Combine this with the helmet of your choice!");
}

@Override
@SideOnly(Side.CLIENT)
public IIcon getIconFromDamage(int dmg) {
	return textures[dmg];
}

@Override
public boolean doesContainerItemLeaveCraftingGrid(ItemStack itemStack) {
	return false;
}
}

 

Recipe:

public boolean doesContainerItemLeaveCraftingGrid(ItemStack p_77630_1_)

 

I was able to make the item persist through crafting, but it resets its damage. I've seen some people recommend using a recipe handler (IRecipe), but it doesn't seem like there's anything to help with achieving this.

Kain

Link to comment
Share on other sites

If your paint is like dye, then I think you need a separate recipe for each color (use a loop with a var incrementing 0-15 which gets applied to the itemStacks in your recipe statement). Unfortunately, I can't see your recipe in the box labeled "recipe", so I can't see what you're trying to do.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Link to comment
Share on other sites

Oh, I must've not copy and pasted the right code segment haha

 

I was able to get the recipes working:

for(i = 0; i < 16; i++) {
   GameRegistry.addShapelessRecipe(new ItemStack(Blocks.wool, 1, BlockColored.func_150031_c(i)), new ItemStack(paint, 1, i), new ItemStack(Blocks.wool, 1, 0));
}

Kain

Link to comment
Share on other sites

With that set of recipes, you can paint white wool into any color wool. If you want to paint from color to color, I think you can replace the white wool's zero "damage" with a wildcard value.

 

If you wanted to, you might also play with the stack sizes so that one paint could color several wool blocks (e.g. 4 wool in and 4 wool out for each paint used).

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

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



×
×
  • Create New...

Important Information

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