This is just a basic guide on how to emulate the effect seen in RP2, where the handsaws have a durability, which is drained when they're used in a crafting table.
Goes in the mod_ file.
takenFromCrafting is a ModLoader hook which does what you might think. It's run whenever an item is taken from a crafting table, or the 2x2 crafting grid in your inventory.
The for loop goes through all the available slots in the crafting matrix.
Anytime the matrix slot isn't null, it checks if the item is what we want, if it is, it will create a new item stack in that slot, with two copies of that item, since one will be consumed by the recipe. The other is given an increased damage value.
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.
This can also be used to keep items in the crafting interface. Just remove the damage value modification.
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.
It says where you put it, right at the top of the boldest section. -1 IS required, because othere item will only be recognized when it's at that specific damage level. This code has worked just fine for me and others, so don't go saying it's wrong. Because it's not. You'redoing something wrong.
Oh, I see the issue. ItemStack k = new ItemStack(Grinder, 2, -1); needs to be ItemStack k = new ItemStack(Grinder, 2).
The negative one is only used in ModLoader.addRecipe. By default, Minecraft assumes that any item defined in a recipe has a damage value of zero. Because of that, if you don't use -1, it'll look at the item, see that it has a damage value other than zero, and assume it's not the item you want to use for the recipe. -1 simply tells Minecraft to accept any damage value.
Is the issue. Just using StuffGrinder will automatically make Minecraft only accept that recipe if the damage value is zero. This is what the bolded part in the main post fixes. Change it to...
ModLoader.addRecipe(new ItemStack(DiamondDust, 3), new Object [] {"#","%", '#', Item.diamond, '%', new ItemStack(StuffGrinder, 1, -1});
I have tried this several times, and never has this worked for me. I first started using this about two weeks ago, and it only kept the item in the bench. But after tonight, I'm just going to ask for your help. Here is my current code:
//
public static final Item Extractor = (new Item(158)).setTabToDisplayOn(CreativeTabs.tabTools).setIconIndex(ModLoader.addOverride("/gui/items.png", "/Junkdrop/Extractor.png")).setMaxStackSize(1).setItemName("Extractor");
//
ModLoader.addRecipe(new ItemStack(Syrup, 1), new Object[]
{
" ", "SE ", " G ",
'E', new ItemStack(Extractor, 1, -1), 'S', StripWood, 'G', Item.glassBottle
});
//
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.getItem() == Extractor)
{
ItemStack k = new ItemStack(Extractor, 2, -1);
k.damageItem(itemnew.getItemDamage() + 1, player);
matrix.setInventorySlotContents(i, k);
}
if(itemnew.getItem() == Grinder)
{
ItemStack k = new ItemStack(Grinder, 2, -1);
k.damageItem(itemnew.getItemDamage() + 1, player);
matrix.setInventorySlotContents(i, k);
}
}
}
}
I have tried this several times, and never has this worked for me. I first started using this about two weeks ago, and it only kept the item in the bench. But after tonight, I'm just going to ask for your help. Here is my current code:
//
public static final Item Extractor = (new Item(158)).setTabToDisplayOn(CreativeTabs.tabTools).setIconIndex(ModLoader.addOverride("/gui/items.png", "/Junkdrop/Extractor.png")).setMaxStackSize(1).setItemName("Extractor");
//
ModLoader.addRecipe(new ItemStack(Syrup, 1), new Object[]
{
" ", "SE ", " G ",
'E', new ItemStack(Extractor, 1, -1), 'S', StripWood, 'G', Item.glassBottle
});
//
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.getItem() == Extractor)
{
ItemStack k = new ItemStack(Extractor, 2, -1);
k.damageItem(itemnew.getItemDamage() + 1, player);
matrix.setInventorySlotContents(i, k);
}
if(itemnew.getItem() == Grinder)
{
ItemStack k = new ItemStack(Grinder, 2, -1);
k.damageItem(itemnew.getItemDamage() + 1, player);
matrix.setInventorySlotContents(i, k);
}
}
}
}
Goes in the mod_ file.
takenFromCrafting is a ModLoader hook which does what you might think. It's run whenever an item is taken from a crafting table, or the 2x2 crafting grid in your inventory.
The for loop goes through all the available slots in the crafting matrix.
Anytime the matrix slot isn't null, it checks if the item is what we want, if it is, it will create a new item stack in that slot, with two copies of that item, since one will be consumed by the recipe. The other is given an increased damage value.
There are cleaner ways to do this, where you simply modify the existing ItemStack instead of making a new once, but I had some trouble getting that to work.
Enjoy!
This doesnt work for me. What happens is I use the item (anvil) once to make stone blades. It takes a little durability. I use it again to make more blades, and, though it works, it doesnt take any durability.
Heres my code.
package net.minecraft.src;
public class mod_Handle extends BaseMod {
public static final Item handle=new Item(2081).setItemName("handle");
public static final Item anvil=new Item(2082).setItemName("anvil").setMaxDamage(50);
public static final Item woodBlade=new Item(2083).setItemName("woodBlade");
public static final Item stoneBlade=new Item(2084).setItemName("stoneBlade");
public static final Item ironBlade=new Item(2085).setItemName("ironBlade");
public static final Item goldBlade=new Item(2086).setItemName("goldBlade");
public static final Item diamondBlade=new Item(2087).setItemName("diamondBlade");
@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_Handle.anvil)
{
ItemStack k = new ItemStack(mod_Handle.anvil, 2, 1);
k.damageItem(itemnew.getItemDamage() + 1, player);
matrix.setInventorySlotContents(i, k);
}
}
}
}
@Override
public String getVersion() {
// TODO Auto-generated method stub
return null;
}
@Override
public void load() {
//Handle properties
ModLoader.addRecipe(new ItemStack(handle,2), new Object[]{
" "," x "," x ",'x',Item.stick
});
ModLoader.addName(handle,"Handle");
handle.iconIndex=ModLoader.addOverride("/gui/items.png", "/Item/Handle.png");
//Wood blade properties
ModLoader.addRecipe(new ItemStack(woodBlade,3), new Object[]{
" ","xxx"," y ",'x',Block.planks,'y',anvil
});
ModLoader.addName(woodBlade, "Wooden Blade");
woodBlade.iconIndex=ModLoader.addOverride("/gui/items.png","/Item/woodblade.png");
//Stone blade properties
ModLoader.addRecipe(new ItemStack(stoneBlade,3), new Object[]{
" ","xxx"," y ",'x',Block.cobblestone,'y',new ItemStack(mod_Handle.anvil, 1, -1) // allows use with a damaged anvil
});
ModLoader.addName(stoneBlade, "Stone Blade");
stoneBlade.iconIndex=ModLoader.addOverride("/gui/items.png","/Item/stoneblade.png");
//Iron blade properties
ModLoader.addRecipe(new ItemStack(ironBlade,3), new Object[]{
" ","xxx"," y ",'x',Item.ingotIron,'y',anvil
});
ModLoader.addName(ironBlade, "Iron Blade");
ironBlade.iconIndex=ModLoader.addOverride("/gui/items.png","/Item/ironblade.png");
//Gold blade properties
ModLoader.addRecipe(new ItemStack(goldBlade,3), new Object[]{
" ","xxx"," y ",'x',Item.ingotGold,'y',anvil
});
ModLoader.addName(goldBlade, "Golden Blade");
goldBlade.iconIndex=ModLoader.addOverride("/gui/items.png","/Item/goldblade.png");
//Diamond blade properties
ModLoader.addRecipe(new ItemStack(diamondBlade,3), new Object[]{
" ","xxx"," y ",'x',Item.diamond,'y',anvil
});
ModLoader.addName(diamondBlade, "Diamond Blade");
diamondBlade.iconIndex=ModLoader.addOverride("/gui/items.png","/Item/diamondblade.png");
//Anvil properties
ModLoader.addRecipe(new ItemStack(anvil,1), new Object[]{
"xxx","x x","xxx",'x',Block.stone
});
ModLoader.addName(anvil, "Anvil");
anvil.iconIndex=ModLoader.addOverride("/gui/items.png","/Item/anvil.png");
// TODO Auto-generated method stub
}
}
This doesnt work for me. What happens is I use the item (anvil) once to make stone blades. It takes a little durability. I use it again to make more blades, and, though it works, it doesnt take any durability.
Heres my code.
package net.minecraft.src;
public class mod_Handle extends BaseMod {
public static final Item handle=new Item(2081).setItemName("handle");
public static final Item anvil=new Item(2082).setItemName("anvil").setMaxDamage(50);
public static final Item woodBlade=new Item(2083).setItemName("woodBlade");
public static final Item stoneBlade=new Item(2084).setItemName("stoneBlade");
public static final Item ironBlade=new Item(2085).setItemName("ironBlade");
public static final Item goldBlade=new Item(2086).setItemName("goldBlade");
public static final Item diamondBlade=new Item(2087).setItemName("diamondBlade");
@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_Handle.anvil)
{
ItemStack k = new ItemStack(mod_Handle.anvil, 2, 1);
k.damageItem(itemnew.getItemDamage() + 1, player);
matrix.setInventorySlotContents(i, k);
}
}
}
}
@Override
public String getVersion() {
// TODO Auto-generated method stub
return null;
}
@Override
public void load() {
//Handle properties
ModLoader.addRecipe(new ItemStack(handle,2), new Object[]{
" "," x "," x ",'x',Item.stick
});
ModLoader.addName(handle,"Handle");
handle.iconIndex=ModLoader.addOverride("/gui/items.png", "/Item/Handle.png");
//Wood blade properties
ModLoader.addRecipe(new ItemStack(woodBlade,3), new Object[]{
" ","xxx"," y ",'x',Block.planks,'y',anvil
});
ModLoader.addName(woodBlade, "Wooden Blade");
woodBlade.iconIndex=ModLoader.addOverride("/gui/items.png","/Item/woodblade.png");
//Stone blade properties
ModLoader.addRecipe(new ItemStack(stoneBlade,3), new Object[]{
" ","xxx"," y ",'x',Block.cobblestone,'y',new ItemStack(mod_Handle.anvil, 1, -1) // allows use with a damaged anvil
});
ModLoader.addName(stoneBlade, "Stone Blade");
stoneBlade.iconIndex=ModLoader.addOverride("/gui/items.png","/Item/stoneblade.png");
//Iron blade properties
ModLoader.addRecipe(new ItemStack(ironBlade,3), new Object[]{
" ","xxx"," y ",'x',Item.ingotIron,'y',anvil
});
ModLoader.addName(ironBlade, "Iron Blade");
ironBlade.iconIndex=ModLoader.addOverride("/gui/items.png","/Item/ironblade.png");
//Gold blade properties
ModLoader.addRecipe(new ItemStack(goldBlade,3), new Object[]{
" ","xxx"," y ",'x',Item.ingotGold,'y',anvil
});
ModLoader.addName(goldBlade, "Golden Blade");
goldBlade.iconIndex=ModLoader.addOverride("/gui/items.png","/Item/goldblade.png");
//Diamond blade properties
ModLoader.addRecipe(new ItemStack(diamondBlade,3), new Object[]{
" ","xxx"," y ",'x',Item.diamond,'y',anvil
});
ModLoader.addName(diamondBlade, "Diamond Blade");
diamondBlade.iconIndex=ModLoader.addOverride("/gui/items.png","/Item/diamondblade.png");
//Anvil properties
ModLoader.addRecipe(new ItemStack(anvil,1), new Object[]{
"xxx","x x","xxx",'x',Block.stone
});
ModLoader.addName(anvil, "Anvil");
anvil.iconIndex=ModLoader.addOverride("/gui/items.png","/Item/anvil.png");
// TODO Auto-generated method stub
}
}
Im only testing it with stone blades obvisouly
I just realised i am having the same problem, after testing it. Any fixs?
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:
This is just a basic guide on how to emulate the effect seen in RP2, where the handsaws have a durability, which is drained when they're used in a crafting table.
Goes in the mod_ file.
takenFromCrafting is a ModLoader hook which does what you might think. It's run whenever an item is taken from a crafting table, or the 2x2 crafting grid in your inventory.
The for loop goes through all the available slots in the crafting matrix.
Anytime the matrix slot isn't null, it checks if the item is what we want, if it is, it will create a new item stack in that slot, with two copies of that item, since one will be consumed by the recipe. The other is given an increased damage value.
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.
This can also be used to keep items in the crafting interface. Just remove the damage value modification.
Enjoy!
ALSO DONE IN:
TFC
EE
EDIT: BEFORE ANYONE ASKED FORGE COMES WITH MODLOADER SO YES IT WIL LWORK WITH FORGE
The negative one is only used in ModLoader.addRecipe. By default, Minecraft assumes that any item defined in a recipe has a damage value of zero. Because of that, if you don't use -1, it'll look at the item, see that it has a damage value other than zero, and assume it's not the item you want to use for the recipe. -1 simply tells Minecraft to accept any damage value.
I'll see if I can get a video up, yeah.
Is the issue. Just using StuffGrinder will automatically make Minecraft only accept that recipe if the damage value is zero. This is what the bolded part in the main post fixes. Change it to...
See what I'm getting at?
Please help me out with this!
The item uses is set in the item file. setMaxDamage(int);
You only need to supply the negative one value when defining your recipe.
Edit:Nevermind, got it working. I feel like an idiot, I never set the durability to the item!
This doesnt work for me. What happens is I use the item (anvil) once to make stone blades. It takes a little durability. I use it again to make more blades, and, though it works, it doesnt take any durability.
Heres my code.
Im only testing it with stone blades obvisouly
I just realised i am having the same problem, after testing it. Any fixs?
Doesn't work
And I know why...
You have to do this:
To this:
Dude.. Thanks you so much!!!!!!!!!!!!!!!!!!!! This finally got it working!
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: