Posted November 16, 201311 yr Hi there! I know it's possible to add tools and armors to the anvil repair system by doing this: public boolean getIsRepairable(ItemStack par1ItemStack, ItemStack par2ItemStack) { return ingotSomething == par2ItemStack.itemID ? true : super.getIsRepairable(par1ItemStack, par2ItemStack); } But I made it so that all my swords are put into one class like so: public static Item copperSword = new ItemModSword... public static Item steelSword = new ItemModSword... Which means the getIsRepairable will only allow one item to use for repairing. My question is, is there a way to use more than one item for repairing depending on what tool I put in the anvil, without making new classes?
November 16, 201311 yr You mean you don't know how to use conditions statement like so ? public boolean getIsRepairable(ItemStack par1ItemStack, ItemStack par2ItemStack) { return firstitem == par2ItemStack.itemID || seconditem == par2ItemStack.itemID ? true : super.getIsRepairable(par1ItemStack, par2ItemStack); }
November 16, 201311 yr Author That works, but then the copper sword can be repaired with a steel ingot and a copper ingot. Same thing with a steel sword.
November 16, 201311 yr Hi I'm not sure I understand your question correctly, but it sounds to me like you have many swords made of different materials all within the one class, and each sword should only be repaired by its corresponding material eg copper ingot for copper sword iron ingot for iron sword lead ingot for lead sword Very much like the vanilla ItemSword with wood, stone, diamond, etc If so, your isRepairable might look something like ItemSword.getIsRepairable, except that you have to add your own ingots public boolean getIsRepairable(ItemStack par1ItemStack, ItemStack par2ItemStack) { switch (materialIamMadeOf) { case iron: { return ingotIron == par2ItemStack.itemID ? true : super.getIsRepairable(par1ItemStack, par2ItemStack); } case copper: { return ingotCopper == par2ItemStack.itemID ? true : super.getIsRepairable(par1ItemStack, par2ItemStack); } etc -TGG
November 17, 201311 yr Author Hi I'm not sure I understand your question correctly, but it sounds to me like you have many swords made of different materials all within the one class, and each sword should only be repaired by its corresponding material eg copper ingot for copper sword iron ingot for iron sword lead ingot for lead sword Very much like the vanilla ItemSword with wood, stone, diamond, etc If so, your isRepairable might look something like ItemSword.getIsRepairable, except that you have to add your own ingots public boolean getIsRepairable(ItemStack par1ItemStack, ItemStack par2ItemStack) { switch (materialIamMadeOf) { case iron: { return ingotIron == par2ItemStack.itemID ? true : super.getIsRepairable(par1ItemStack, par2ItemStack); } case copper: { return ingotCopper == par2ItemStack.itemID ? true : super.getIsRepairable(par1ItemStack, par2ItemStack); } etc -TGG Yup, that's what I meant! What should I put in the switch()?
November 17, 201311 yr Hi You need to keep track of what each sword is made of - eg copper, iron, lead, or whatever. The vanilla code does it like this public class ItemSword extends Item { private final EnumToolMaterial toolMaterial; public ItemSword(int par1, EnumToolMaterial par2EnumToolMaterial) { super(par1); this.toolMaterial = par2EnumToolMaterial; and creates it using (for example) public static Item swordIron = new ItemSword(11, EnumToolMaterial.IRON); public static Item swordWood = new ItemSword(12, EnumToolMaterial.WOOD); public static Item swordStone = new ItemSword(16, EnumToolMaterial.STONE); You can't add to the EnumToolMaterial, but you can create a field of your own (can be an int, doesn't have to be an enum) and make the materials whatever you like. -TGG
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.