Jump to content

1.8 How to Make Custom Tool Repairable


konxet

Recommended Posts

Hello. I was just wondering how you would go about making a custom tool repairable.

 

Let's say I have an Obsidian Pickaxe (ModItems.obsidian_pickaxe) and I want to repair it with Obsidian (Blocks.obsidian) in an anvil. How might I do that?

 

Best regards,

Jarod Beau

mail.konxet@gmail.com

 

 

Link to comment
Share on other sites

I bunce into this discussion, so we can solve two problems at once ;)

I have my custom ItemArmor class, now to say at the game "if i have a ruby armor and i'm using a ruby in the anvil than repair my armor" how could i do? I think is the same question that the guy above is making

package mw.items;

import mw.core.MW;
import mw.core.MWItems;
import mw.core.utils.Utils;
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;

public class ItemArmorMW extends ItemArmor {

private String material;
public ItemArmorMW(ArmorMaterial par1, int par2, int par3, String name) {
	super(par1, par2, par3);
	Utils.setCombatItemInfo(this, name);
	this.material = par1.name().toLowerCase();
}

public String getArmorTexture(ItemStack stack, Entity entity, int slot, String type)
{
	if(slot == 2)
		return MW.MODID + ":" + "textures/models/armor/" + this.material + "_2.png";
	else
		return MW.MODID + ":" + "textures/models/armor/" + this.material + "_1.png";
}


@Override
public boolean getIsRepairable(ItemStack toRepair, ItemStack repair)
{
	if(repair.equals(MWItems.ruby) && toRepair.equals(this))
		return true;
	else
		return false;
}
}

I've tried overriding the getIsRepairable method but is not working

Don't blame me if i always ask for your help. I just want to learn to be better :)

Link to comment
Share on other sites

Ok, so i found the solution. You need to add to override the function getIsRepairable in your ItemArmor class (wich of course it must extend the vanilla ItemArmor class) or in your custom Tool class. To do this you need to add this lines

@Override
public boolean getIsRepairable(ItemStack toRepair, ItemStack repair)
{

	if(repair.getItem().equals(-MY ARMOR ITEM (example: Obsidian)))
		return true;
	else
		return false;
}

 

Basically what you need to check is if the Item in the second andvil slot is equal to an item that you want (in this case you check if that item is an obsidian block, so you can repair an obsidian armor/tool). Hope this helped, at least for armor it works for me :)

Don't blame me if i always ask for your help. I just want to learn to be better :)

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.