I have a fix. I started learning full java about a week ago, and can now understand how it works, so I made a pretty decent fix.
All it is, is that when you use the loop, it will continue to damage the item, it is never told when to stop doing so, or at what damage value. SO it will go on and on, so you just stick an if statement in there, and if the value is less than the damage value you want it to stop looping at, move on. If not, then return any item with a stack of 0. Example:
Then, anywhere you define the damageable item in a recipe, instead of just using ItemNameHere, use new ItemStack(ItemNameHere, 1, -1). The -1 allows the recipe to work no matter what the damage value of the item is.
Thank you so much. I have been looking for the -1 ALL DAY LONG (Well, practically)!!! Thank you, man! Genius! This also helps with my modding because of the other stuff, but that -1 saved my day.
Ya, I'm trying to get this to run with forge 1.3.2 and I can not for the life of me figure it out =/ every time it just eats the item, doesn't return it to me or anything.
EDIT 2:
Alright, got it to work perfectly. What I had to add was an if statement, like I saw someone do earlier. My code now is:
The new piece of code is the if(j.getItemDamage() < j.getMaxDamage()) right before the last if.
This checks to see if the Item damage is less than max damage. If the item damage is greater than max damage, it will not create a second item.
For some reason, my item's damage bar isn't showing up.
It's clearly working, because the item stays in the crafting bench.
I just can't get the bar to show up.
i seriously cannot get this to work, my Mallet just stays in the crafting grid without losing uses, and the bar doesnt even pop up
package net.minecraft.src;
public class mod_ironmallet extends BaseMod
{
public static final Item ironMallet = (new ItemSword(8111, EnumToolMaterial.IRON)).setMaxDamage(250).setItemName("ironMallet");
public void load()
{
ironMallet.iconIndex = ModLoader.addOverride("/gui/items.png", "/textures/iron_mallet.png");
ModLoader.addRecipe(new ItemStack(mod_ironmallet.ironMallet, 1), new Object []
{
"###",
"###",
" X ", Character.valueOf('#'), Item.ingotIron, Character.valueOf('X'), mod_stonestick.stoneStick});
ModLoader.addName(ironMallet, "Iron Mallet");
}
@Override
public void takenFromCrafting(EntityPlayer player, ItemStack item, IInventory matrix)
{
for(int i=0; i<matrix.getSizeInventory(); i++)
{
if(matrix.getStackInSlot(i) != null)
{
ItemStack itemnew = matrix.getStackInSlot(i);
if(itemnew != null && itemnew.getItem() == mod_ironmallet.ironMallet)
{
ItemStack k = new ItemStack(mod_ironmallet.ironMallet, 2);
{
k.damageItem(itemnew.getItemDamage() + 1, player);
matrix.setInventorySlotContents(i, k);
}
}
}
}
}
public String getVersion()
{
return "For: v1.4.5, Mod: v1.0";
}
}
package net.minecraft.src;
import java.util.Random;
public class mod_gravatitegem extends BaseMod
{
public static final Item gravatiteGem = new Item(5503).setItemName("gravatiteGem").setCreativeTab(CreativeTabs.tabMaterials);
public void load()
{
gravatiteGem.iconIndex = ModLoader.addOverride("/gui/items.png", "/textures/gravatite_gem.png");
ModLoader.addName(gravatiteGem, "§5Gravatite Gem");
ModLoader.addRecipe(new ItemStack(mod_gravatitedust.gravatiteDust, 1), new Object[]
{" + ", " # ", " # ", Character.valueOf('#'), gravatiteGem, Character.valueOf('+'), new ItemStack(mod_ironmallet.ironMallet, 1, -1)});
}
public String getVersion()
{
return "1.4.5";
}
}
so yeah i have no idea what's wrong with it but wut im trying to do is take an iron mallet and use them on the gems to create dust, the higher tier mallet you use the more dust u get from the gems. this is a crucial component in my mod because it allows you to get the highest tier tools.
I attempted to implement this in FML for 1.4.6. I got it sort-of working... it works the first time, but not the second and beyond. By this I mean it will work in the recipe but will not continue to take damage. Just the first time.
Code:
public class CraftingHandlerCC implements ICraftingHandler {
@Override
public void onCrafting(EntityPlayer player, ItemStack item, IInventory matrix) {
// TODO Auto-generated method stub
for(int i=0; i<matrix.getSizeInventory(); i++)
{
if(matrix.getStackInSlot(i) != null)
{
ItemStack itemnew = matrix.getStackInSlot(i);
if(itemnew != null)
{
if (itemnew.getItem() == ToolsCC.axeBronze){
ItemStack k = new ItemStack(ToolsCC.axeBronze, 2);
giveDamage(player, item, matrix, i, k);
}
else if (itemnew.getItem() == ToolsCC.axeCarbide){
ItemStack k = new ItemStack(ToolsCC.axeCarbide, 2);
giveDamage(player, item, matrix, i, k);
}
else if (itemnew.getItem() == ToolsCC.axeCopper){
ItemStack k = new ItemStack(ToolsCC.axeCopper, 2);
giveDamage(player, item, matrix, i, k);
}
else if (itemnew.getItem() == ToolsCC.axeDiamondCarbide){
ItemStack k = new ItemStack(ToolsCC.axeDiamondCarbide, 2);
giveDamage(player, item, matrix, i, k);
}
else if (itemnew.getItem() == ToolsCC.axeDUranium){
ItemStack k = new ItemStack(ToolsCC.axeDUranium, 2);
giveDamage(player, item, matrix, i, k);
}
else if (itemnew.getItem() == ToolsCC.axeFlint){
ItemStack k = new ItemStack(ToolsCC.axeFlint, 2);
giveDamage(player, item, matrix, i, k);
}
else if (itemnew.getItem() == ToolsCC.axeSteel){
ItemStack k = new ItemStack(ToolsCC.axeSteel, 2);
giveDamage(player, item, matrix, i, k);
}
else if (itemnew.getItem() == ToolsCC.axeTitanium){
ItemStack k = new ItemStack(ToolsCC.axeTitanium, 2);
giveDamage(player, item, matrix, i, k);
}
}
}
}
}
public void giveDamage(EntityPlayer player, ItemStack item, IInventory matrix, int i, ItemStack k){
Is there any way to make it so that when crafting a certain item the item that gets damaged is destroyed instantly?
Basically i'm trying to make a mod that will have an item that get's damaged in crafting and what is supposed to happen is when you upgrade it, the original get's destroyed and you get an upgraded one. What is happening is that I get both the upgraded one and original one. I looked through many class files to try to make it work, but I can't find anything that will help. I am using 1.4.7 right now since all of the mods I use normally have not been updated. Could you help me out with this?
mine just disapers in crafting table
LapisGuy: Lol, Saw your location, and noticed I'm wearing a Portal 2 shirt
http://www.minecraftforum.net/topic/1398395-125sspmodloaderminecraft-overloaded-101/#entry17015140
http://www.minecraftforum.net/topic/1398395-125sspmodloaderminecraft-overloaded-101/#entry17015140
Thank you so much. I have been looking for the -1 ALL DAY LONG (Well, practically)!!! Thank you, man! Genius! This also helps with my modding because of the other stuff, but that -1 saved my day.
EDIT 2:
Alright, got it to work perfectly. What I had to add was an if statement, like I saw someone do earlier. My code now is:
The new piece of code is the if(j.getItemDamage() < j.getMaxDamage()) right before the last if.
This checks to see if the Item damage is less than max damage. If the item damage is greater than max damage, it will not create a second item.
It's clearly working, because the item stays in the crafting bench.
I just can't get the bar to show up.
so yeah i have no idea what's wrong with it but wut im trying to do is take an iron mallet and use them on the gems to create dust, the higher tier mallet you use the more dust u get from the gems. this is a crucial component in my mod because it allows you to get the highest tier tools.
thanks for any help that is given!
~Lamp
Code:
public class CraftingHandlerCC implements ICraftingHandler {
@Override
public void onCrafting(EntityPlayer player, ItemStack item, IInventory matrix) {
// TODO Auto-generated method stub
for(int i=0; i<matrix.getSizeInventory(); i++)
{
if(matrix.getStackInSlot(i) != null)
{
ItemStack itemnew = matrix.getStackInSlot(i);
if(itemnew != null)
{
if (itemnew.getItem() == ToolsCC.axeBronze){
ItemStack k = new ItemStack(ToolsCC.axeBronze, 2);
giveDamage(player, item, matrix, i, k);
}
else if (itemnew.getItem() == ToolsCC.axeCarbide){
ItemStack k = new ItemStack(ToolsCC.axeCarbide, 2);
giveDamage(player, item, matrix, i, k);
}
else if (itemnew.getItem() == ToolsCC.axeCopper){
ItemStack k = new ItemStack(ToolsCC.axeCopper, 2);
giveDamage(player, item, matrix, i, k);
}
else if (itemnew.getItem() == ToolsCC.axeDiamondCarbide){
ItemStack k = new ItemStack(ToolsCC.axeDiamondCarbide, 2);
giveDamage(player, item, matrix, i, k);
}
else if (itemnew.getItem() == ToolsCC.axeDUranium){
ItemStack k = new ItemStack(ToolsCC.axeDUranium, 2);
giveDamage(player, item, matrix, i, k);
}
else if (itemnew.getItem() == ToolsCC.axeFlint){
ItemStack k = new ItemStack(ToolsCC.axeFlint, 2);
giveDamage(player, item, matrix, i, k);
}
else if (itemnew.getItem() == ToolsCC.axeSteel){
ItemStack k = new ItemStack(ToolsCC.axeSteel, 2);
giveDamage(player, item, matrix, i, k);
}
else if (itemnew.getItem() == ToolsCC.axeTitanium){
ItemStack k = new ItemStack(ToolsCC.axeTitanium, 2);
giveDamage(player, item, matrix, i, k);
}
}
}
}
}
public void giveDamage(EntityPlayer player, ItemStack item, IInventory matrix, int i, ItemStack k){
k.damageItem(item.getItemDamage() + 1, player);
matrix.setInventorySlotContents(i, k);
}
}
Sample Recipe: GameRegistry.addRecipe(new ItemStack (Block.planks, 4, 0),new Object[]{ "y", "x", 'x', new ItemStack (Block.wood, 1, 0), 'y', new ItemStack (ToolsCC.axeFlint, 1, -1)});
Check it out here: Scrap Metal
I've linked to this tutorial and added you in credits :]
I really appreciate people who put the time in to make helpful material like this.
Basically i'm trying to make a mod that will have an item that get's damaged in crafting and what is supposed to happen is when you upgrade it, the original get's destroyed and you get an upgraded one. What is happening is that I get both the upgraded one and original one. I looked through many class files to try to make it work, but I can't find anything that will help. I am using 1.4.7 right now since all of the mods I use normally have not been updated. Could you help me out with this?