Posted December 16, 201212 yr I'm working on a mod at the moment and I'm trying to make a Red Power 2 handsaw or Equivalent Exchange 3 minium stone type item where you can use it in a crafting recipe and it will give it back but more damaged but I cant figure out how, if anybody knew I would be really thankful.
December 17, 201212 yr Hey, you need a crafting handler, create a new class an name it as you want. Then define it in your mod_xxx.java in the "public void init..." method with GameRegistry.registerCraftingHandler(new CraftingHandler()); In this example I called the CraftingHandler "CraftingHandler" Now you have to make your Item and then add the following: aloeVeraMilk = (new ItemXXX(975)).setIconIndex(75).setItemName("Test Item").setMaxDamage(10); // Add your Max. Damge here!!! Now we want, that you won't loose your Item after crafting. Go the crafting handler and add: public class CraftingHandler implements ICraftingHandler { @Override public void onCrafting(EntityPlayer player, ItemStack item, IInventory craftMatrix) { for(int i=0; i < craftMatrix.getSizeInventory(); i++) { if(craftMatrix.getStackInSlot(i) != null) { ItemStack j = craftMatrix.getStackInSlot(i); if(j.getItem() != null && j.getItem() == mod_eltrixscience.vaporizerItem) { ItemStack k = new ItemStack(mod_xxx.xxxItem, 2, (j.getItemDamage() - 1)); // <-- Set the Damage after crafting... craftMatrix.setInventorySlotContents(i, k); //<-- Put the item back into the crafting gui! } } } } } Hope I helped you! Greetings from germany!
December 17, 201212 yr Author Thanks a lot I've been looking for this for a while, I found the code that you put in the CraftingHandler class before but I didn't say that I had to put it in its own class so when I tried it in the base class it didn't work.
December 17, 201212 yr Author Oh by the way this line of code: ItemStack k = new ItemStack(mod_xxx.xxxItem, 2, (j.getItemDamage() - 1)); Should be changed to: ItemStack k = new ItemStack(mod_xxx.xxxItem, 2, (j.getItemDamage() + 1)); Because otherwise you are taking away from the damage value which adds to the durability so it will go from 123 to 124 instead of 123 to 122.
December 17, 201212 yr Author Also you will want to remove this piece of code at the bottom of the code: craftMatrix.setInventorySlotContents(i, k); And put in this if else statement so if the item has no durability left it gets destroyed: if(k.getItemDamage() < k.getMaxDamage()){ craftMatrix.setInventorySlotContents(i, k); }else{ ItemStack l = new ItemStack(Block.blockClay, 0); craftMatrix.setInventorySlotContents(i, j); } The Block.blockClay can be replaced with anything because the 0 after it means that 0 of whatever item is stated will be put in your inventory. So the final code should look like this: @Override public void onCrafting(EntityPlayer player, ItemStack item, IInventory craftMatrix) { for(int i = 0; i < craftMatrix.getSizeInventory(); i++ ){ if(craftMatrix.getStackInSlot(i) != null){ ItemStack j = craftMatrix.getStackInSlot(i); if(j.getItem() != null && j.getItem() == YourMod.yourItem){ ItemStack k = new ItemStack(YourMod.yourItem, 2, (j.getItemDamage() + 1)); if(k.getItemDamage() < k.getMaxDamage()){ craftMatrix.setInventorySlotContents(i, k); }else{ ItemStack l = new ItemStack(Block.blockClay, 0); craftMatrix.setInventorySlotContents(i, j); } } } } }
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.