Posted July 15, 201312 yr Hey everyone, just wondering if any of y'all could help me with a little problem I'm having. Basically, I have added a new crafting table-like block to the game, and it uses multiple different crafting managers depending on what item is in a Modifier Slot. It has a traditional 3x3 grid with an output, as well as the modifier. What I want to do is damage the modifier slot's item when I craft something in the grid. I have seen posts on damaging items used in crafting, however those don't work for this. I've added a method to my CraftingHandler that should do the job, but I don't know where to call it. public void DamageModifier(ContainerXXXXXX container) { if(container.ModifierSlot.getStack() != null) { ItemStack j = container.ModifierSlot.getStack(); if(j.getItem() != null && j.getItem() == ModFile.Modifier) { ItemStack k = new ItemStack(ModFile.Modifier, 1, j.getItemDamage() + 1); container.ModifierSlot.putStack(k); } } } I would call that in OnCrafting, but I don't have a ContainerXXXXXXX object there, and it would cause a crash if the player crafted something in a vanilla table because that doesn't use a ContainerXXXXXXX file. I guess my main questions are: is there a way to check what container the player used to craft something, and how should I do this? EDIT: I thought about using OnStackTakenFromSlot(), but I can't think of a way to make it work.
July 16, 201312 yr Try adding a catch: if(CONTAINERNAME instanceof SPECALCRAFTINGTABLE){ //Your code here } http://i.imgur.com/gWwyMMO.jpg[/img]
July 17, 201312 yr This is the way how i would do it. That make it easy extendable. Oh now i understand. You want to add craftdamage to your thingy^^ Easy Enough. You have to convert the code a little bit but its not that hard. (its a tile code)(just change it to a container code) ContainerClass public void onCraftMatrixChanged(IInventory par1IInventory) { this.craftResult.setInventorySlotContents(0, CraftingManager.getInstance().findMatchingRecipe(this.craftMatrix, this.worldObj)); DamageModifire(); } public void DamageModifier() { if(modifireslot[id] != null && modifireslot[id].getItem() instanceof ModifireTool) { ModifireTool mt = (ModifireTool)modifireslot[id].getItem(); modifireslot[id] = mt.damageTool(modifireslot[id], 1); } } ItemClass public class ModifireTool extends Item { public ModifireTool(int id) { super(id); setMaxDamage(3); } public ItemStack damageTool(ItemStack tool, int damage) { tool.setItemDamage(tool.getItemDamage()+damage); if(tool.getItemDamage() > tool.getMaxDamage()) { return null; } return tool; } } I hope that helps^^
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.