Posted September 10, 201411 yr I'm trying to make an Item that can be refilled/repaired after it gets used up, like a Cammel pack. I already got the whole getting used up part, but now I don't find any way to reapair my item in a vanilla crafting grit. It also should keep its NBT. Any help is greatly appreciated. Thanks!!
September 10, 201411 yr A little more information is required, , how are you wanting to repair / refill the the item , custom block,? putting it on the crafting table with another item to refill/recharge ?
September 10, 201411 yr Author I want to use the crafting bench/survival grid and a custom Item to repair it.
September 10, 201411 yr ok, in one of my mods i created a recipe that sets an item to data in another item, this is how a player uses it, put both items on the crafting table , and its done automatically the items remain on the crafting grid here is the recipe package me.el.LoonTools; import net.minecraft.inventory.InventoryCrafting; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.IRecipe; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; public class TrackerRecipe implements IRecipe { public ItemStack getCraftingResult(InventoryCrafting inv) { return null; } public ItemStack getRecipeOutput() { return null; } public int getRecipeSize() { return 0; } public boolean matches(InventoryCrafting inv, World w) { ItemStack cr=null; ItemStack tr=null; int sn=0; for (int s=0;s<inv.getSizeInventory();s++){ ItemStack i=inv.getStackInSlot(s); if (i!=null){ Item it = i.getItem(); if(it instanceof ItemCrystal){ if (cr!=null) return false; cr=i; }else if(it instanceof ItemLocationTracker){ if (tr!=null) return false; tr=i; sn=s; }else return false; } } if(cr==null || tr==null) return false; if (!cr.hasTagCompound()) return false; try { NBTTagCompound c = cr.getTagCompound(); float x=c.getFloat("bx"); float z=c.getFloat("bz"); String wld=c.getString("bw"); NBTTagCompound t; if (tr.hasTagCompound()){ t=tr.getTagCompound(); try { float tx = t.getFloat("bx"); float tz = t.getFloat("bz"); String tw=t.getString("bw"); System.out.println(tx+" "+tz+" "+tw); System.out.println(x+" "+z+" "+wld); if (x==tx && z==tz && tw.equals(wld)) return false; } catch (Exception e) { } }else{ t=new NBTTagCompound(); } t.setFloat("bx", x); t.setFloat("bz", z); t.setString("bw", wld); ItemStack result = tr.copy(); result.setTagCompound(t); result.setStackDisplayName(cr.getDisplayName()); inv.setInventorySlotContents(sn, result); return false; } catch (Exception e) { return false; } } } you will notice that everything is done in the matches method you will also notice that matches always returns false, this prevents items being lost by consumption during crafting Hope this helps
September 10, 201411 yr here is a brief explanation of the process search slots for items you dont want on the crafting table also getting the slot numbers of the items you do want then perform the changes to the items simple
September 10, 201411 yr oh, another thing you need to make sure of, is that you only make changes and replace the items on the crafting grid when necessary , otherwise you get a non exiting loop and a stack error crash so in your case if the item is full / repaired , or the filling/repairing item is empty, exit with out changing either item
September 10, 201411 yr Author Thanks. Code should do, just I dont know how to implement it in my base class (register in GameRegistry like Craftinghandler?). Also I suppose your code doesnt need a recipe that you modify, like the CraftingHandler does, right? Edit: Its a IRecipe, so I suppose I have to register a recipe?!
September 10, 201411 yr once you have created your recipe add it with GameRegistry.addRecipe(new TrackerRecipe()); in your init event
September 10, 201411 yr Author Thanks, mate, you are a great help. I'm jumping to work now. I hope I'm not that dumb to fuck it up
September 12, 201411 yr Author If you, yes YOU, also want an item that is repaired in the crafting table or in the survival crafting grid then feel free to use this code public boolean matches(InventoryCrafting inventory, World world) { ItemStack itemThatWillBeRepaired = null; ItemStack itemThatIsUsedToRepaire = null; for (int i=0; i < inventory.getSizeInventory(); i++){ ItemStack itemStack = inventory.getStackInSlot(i); if (itemStack != null){ if (itemStack.getItem() == YourMod.itemThatWillBeRepaired){ if (itemThatWillBeRepaired != null)return false; itemThatWillBeRepaired = itemStack; }else if (itemStack.getItem() == Items.stick){ if (itemThatIsUsedToRepaire != null)return false; itemThatIsUsedToRepaire = itemStack; } } } return itemThatWillBeRepaired != null && itemThatIsUsedToRepaire != null; } public int getRecipeSize() { return 9; } If anything doesnt work, please post it in comments for other users
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.