Skip to content

Instantly share code, notes, and snippets.

@kubasz

kubasz/KUtils.java

Created Aug 31, 2011
Embed
What would you like to do?
Tool Detection Code - Minecraft
public class KUtils {
static EnumToolMaterial matFromTool(ItemTool tool)
{
if(tool==Item.axeDiamond||tool==Item.pickaxeDiamond||tool==Item.hoeDiamond||tool==Item.shovelDiamond||tool==Item.swordDiamond)
{
return EnumToolMaterial.EMERALD;
}
if(tool==Item.axeGold||tool==Item.pickaxeGold||tool==Item.hoeGold||tool==Item.shovelGold||tool==Item.swordGold)
{
return EnumToolMaterial.GOLD;
}
if(tool==Item.axeSteel||tool==Item.pickaxeSteel||tool==Item.hoeSteel||tool==Item.shovelSteel||tool==Item.swordSteel)
{
return EnumToolMaterial.IRON;
}
if(tool==Item.axeWood||tool==Item.pickaxeWood||tool==Item.hoeWood||tool==Item.shovelWood||tool==Item.swordWood)
{
return EnumToolMaterial.WOOD;
}
if(tool==Item.axeStone||tool==Item.pickaxeStone||tool==Item.hoeStone||tool==Item.shovelStone||tool==Item.swordStone)
{
return EnumToolMaterial.STONE;
}
return null;
}
}
tile.leftToRepair = 0;
ItemStack is = inv.getStackInSlot(0);
if(is==null)
{
gui.text = "No tool inserted!";
return;
}
if(is.itemID<256)
{
gui.text = "Blocks aren't tools!";
return;
}
if(is.getItem() instanceof ItemTool)
{
ItemTool it = (ItemTool)is.getItem();
refreshMaterial(it);
if(is.getItemDamage()==0)
{
gui.text = "This tool isn't damaged!";
}
else
{
gui.text = "Enter material:"+tile.leftToRepair+" "+etm;
}
}
else
{
gui.text = "This item isn't a tool!";
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment