Posted July 17, 201312 yr Alrighty, so heres the problem, I have a "redstone powered" item, and I have everything setup, if the metadata is not minimum, it will give the effects. My problem is when I want to repair it, and I do not want it to be repaired in an anvil (because it costs 120 levels per 10000 durability) nor do i want it to cost anything at all. So I want it to be repairable in the crafting table, so when you put a redstone and a plate of dual hearts (the item i want repaired), it will add, lets say 1000 durability/metadata. I dont know how to go about any of this, can someone throw me some code and explain it please Thanks!
July 17, 201312 yr The way you want to do it would be best done using the IRecipe interface. Basically for getCraftingResult() you'll want to check and make sure the items are redstone and plate of dual hearts in the crafting inventory (a parameter for this method). From there you can get the damage value of the plate (plate.getItemDamage()) and subtracting 1000 (will remove 1000 damage from it) for every piece of redstone your recipe finds. Then make the method return a new plate of dual hearts with the proper damage (item.getItemDamage - 1000 * redCount). Hopefully this helps!
July 17, 201312 yr Author The way you want to do it would be best done using the IRecipe interface. Basically for getCraftingResult() you'll want to check and make sure the items are redstone and plate of dual hearts in the crafting inventory (a parameter for this method). From there you can get the damage value of the plate (plate.getItemDamage()) and subtracting 1000 (will remove 1000 damage from it) for every piece of redstone your recipe finds. Then make the method return a new plate of dual hearts with the proper damage (item.getItemDamage - 1000 * redCount). Hopefully this helps! Can you give me some small examples of how this is done please? I understand what your saying however.
July 17, 201312 yr Yes, I took the liberty of just making the recipe to study, you can use it for future reference when doing this sort of thing. public class RecipeRepair implements IRecipe { private int repairAmount; private int toRepair; private ItemStack repairMaterial; public RecipeRepair(int toRepair, ItemStack repairMaterial, int repairAmount) { this.toRepair = toRepair; this.repairMaterial = repairMaterial; this.repairAmount = repairAmount; } @Override public boolean matches(InventoryCrafting inventory, World world) { int count = 0; for(int i = 0; i < inventory.getSizeInventory(); i++) { ItemStack stack = inventory.getStackInSlot(i); if(stack != null) { if(stack.itemID == this.toRepair) { count++; } if(stack.itemID == this.repairMaterial.itemID && stack.getItemDamage() == this.repairMaterial.getItemDamage()) { count++; } } } return count >= 2; } @Override public ItemStack getCraftingResult(InventoryCrafting inventory) { ItemStack repair = null; int count = 0; int damage = 0; for(int i = 0; i < inventory.getSizeInventory(); i++) { ItemStack stack = inventory.getStackInSlot(i); if(stack != null) { if(stack.itemID == this.toRepair) { repair = stack; damage = repair.getItemDamage(); } if(stack.itemID == this.repairMaterial.itemID && stack.getItemDamage() == this.repairMaterial.getItemDamage()) { count++; } } } int rep = count * this.repairAmount; if(damage - rep < (-this.repairAmount + 1)) { return null; } ItemStack ret = new ItemStack(PlunderRummageProxy.pulseShield, 1, damage - rep); return ret; } @Override public int getRecipeSize() { return 0; } @Override public ItemStack getRecipeOutput() { return null; } } This is a generalized version of what you want, which is handy for in case you want to add MULTIPLE repair recipes. So the key things to note are that the constructor uses an item id for which item you want to repair, an ItemStack for which item will repair it, and an amount for the item to be repaired. I added a safety catch so the recipe doesn't try to 'over-repair' your items, namely if one repair material will finish the repair (your item has no damage after getting repaired) then adding another repair item into the grid will not yield a result since it will waste your repair material otherwise. Here's how to add the recipe to the game: CraftingManager.getInstance().getRecipeList().add(new RecipeRepair(plateOfHearts.itemID, new ItemStack(Item.redstone), 1000)); I added the itemstack sensitivity in case you wanted to do something like this: CraftingManager.getInstance().getRecipeList().add(new RecipeRepair(Item.pickaxeWood.itemID, new ItemStack(Block.planks, 1, 2), 20)); That would allow wooden pickaxes to be repaired 1/3 of the way with ONLY jungle planks. Hope this helps!
July 18, 201312 yr Author -snip- Thanks! It was easy to read and understand and works like a charm for all my tools and armor that will use power
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.