Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

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.

  • Author

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

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.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.