Jump to content

Make Tools Repairable AND Enchantable


silenthunder2

Recommended Posts

So I'm learning to mod, and I've made a couple new materials, Silver and Electrum.  Everything works but repair; i.e the pickaxes function as a normal pickaxe except they can't be repaired at an anvil.  I want to make them repairable as well as enchantable and I want to do this so that I only need to make one pickaxe class.  I need to keep each tool an extension of the vanilla tool class so it can be enchanted.  The only way I can get the tools repairable with these requirements is by changing this:

public boolean getIsRepairable(ItemStack par1ItemStack, ItemStack par2ItemStack)
{
return this.toolMaterial.getToolCraftingMaterial() == par2ItemStack.itemID ? true : super.getIsRepairable(par1ItemStack, par2ItemStack);
}

To this:

public boolean getIsRepairable(ItemStack par1ItemStack, ItemStack par2ItemStack)
{
return SunMod.silverIngot.itemID == par2ItemStack.itemID ? true : super.getIsRepairable(par1ItemStack, par2ItemStack);
}

But of course when I make an Electrum tool, this makes it repairable only by silver ingots, which is obviously not correct.  If that's the only way to do it that means I have to make a new class for every tool from every material, which I'd like to avoid.  Another way is editing the base classes, but I'd really like to avoid that if possible.

 

Can anyone help?

 

Here's my pickaxe class:

 


package SunMod.tools;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.EnumToolMaterial;
import net.minecraft.item.Item;
import net.minecraft.item.ItemPickaxe;
import net.minecraft.item.ItemStack;
import SunMod.*;
import net.minecraft.item.ItemPickaxe;
import net.minecraft.item.ItemTool;
public class SunPickaxe extends ItemPickaxe
{
public static final Block[] blocksEffectiveAgainst = new Block[] {Block.cobblestone,
Block.stoneDoubleSlab, Block.stoneSingleSlab, Block.stone, Block.sandStone,
Block.cobblestoneMossy, Block.oreIron, Block.blockSteel, Block.oreCoal, Block.blockGold,
Block.oreGold, Block.oreDiamond, Block.blockDiamond, Block.ice, Block.netherrack, Block.oreLapis,
Block.blockLapis, Block.oreRedstone, Block.oreRedstoneGlowing, Block.rail, Block.railDetector, Block.railPowered};



public SunPickaxe(int par1, EnumToolMaterial m, int tex, String name) {
super(par1, m);
setTextureFile("/SunMod/ITEMS.png");
this.setCreativeTab(CreativeTabs.tabTools);
setIconIndex(tex);
setItemName(name);

}

public boolean canHarvestBlock(Block par1Block)
{
return par1Block == Block.obsidian ? this.toolMaterial.getHarvestLevel() == 3 : (par1Block != Block.blockDiamond && par1Block != Block.oreDiamond ? (par1Block != Block.oreEmerald && par1Block != Block.blockEmerald ? (par1Block != Block.blockGold && par1Block != Block.oreGold ? (par1Block != Block.blockSteel && par1Block != Block.oreIron ? (par1Block != Block.blockLapis && par1Block != Block.oreLapis ? (par1Block != Block.oreRedstone && par1Block != Block.oreRedstoneGlowing ? (par1Block.blockMaterial == Material.rock ? true : (par1Block.blockMaterial == Material.iron ? true : par1Block.blockMaterial == Material.anvil)) : this.toolMaterial.getHarvestLevel() >= 2) : this.toolMaterial.getHarvestLevel() >= 1) : this.toolMaterial.getHarvestLevel() >= 1) : this.toolMaterial.getHarvestLevel() >= 2) : this.toolMaterial.getHarvestLevel() >= 2) : this.toolMaterial.getHarvestLevel() >= 2);
}

public float getStrVsBlock(ItemStack par1ItemStack, Block par2Block)
{
return par2Block != null && (par2Block.blockMaterial == Material.iron || par2Block.blockMaterial == Material.anvil || par2Block.blockMaterial == Material.rock) ? this.efficiencyOnProperMaterial : super.getStrVsBlock(par1ItemStack, par2Block);
}

public boolean getIsRepairable(ItemStack par1ItemStack, ItemStack par2ItemStack)
{
return this.toolMaterial.getToolCraftingMaterial() == par2ItemStack.itemID ? true : super.getIsRepairable(par1ItemStack, par2ItemStack);
}
}

 

And my main mod class:

 

 

package SunMod;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;
import cpw.mods.fml.common.network.NetworkMod.SidedPacketHandler;
import cpw.mods.fml.common.SidedProxy;
import SunMod.blocks.BlockSilver;
import SunMod.core.proxies.ClientProxy;
import SunMod.core.proxies.CommonProxy;
import SunMod.core.handlers.*;
import SunMod.items.*;
import SunMod.blocks.*;
import SunMod.tools.*;
import SunMod.weapons.*;
import net.minecraft.item.EnumToolMaterial;
import net.minecraft.item.EnumArmorMaterial;
import net.minecraftforge.common.MinecraftForge;

@NetworkMod(clientSideRequired=true,serverSideRequired=false, //Whether client side and server side are needed
clientPacketHandlerSpec = @SidedPacketHandler(channels = {"SunMod" }, packetHandler = ClientPacketHandler.class), //For clientside packet handling
serverPacketHandlerSpec = @SidedPacketHandler(channels = {}, packetHandler = ServerPacketHandler.class)) //For serverside packet handling
@Mod(modid="SunMod",name="The Sun Mod",version="1.0") //Gives Forge extra info about your mod
public class SunMod { //The class file

@Instance("SunMod") //The instance, this is very important later on
public static SunMod instance = new SunMod();

//Materials
public static EnumToolMaterial silver = net.minecraftforge.common.EnumHelper.addToolMaterial("silver", 2, 1561, 4.0F, 2, 10);
public static EnumToolMaterial electrum = net.minecraftforge.common.EnumHelper.addToolMaterial("electrum", 3, 750, 12.0F, 3, 22);

//Armor Materials
public static EnumArmorMaterial silverArmor = net.minecraftforge.common.EnumHelper.addArmorMaterial("silver", 33, new int [] {2,5,4,1}, 9);
public static EnumArmorMaterial electrumArmor = net.minecraftforge.common.EnumHelper.addArmorMaterial("electrum",25,new int [] {3,8,6,3}, 25);

//Items
public static Item silverIngot = new ItemIngot(200, 0).setItemName("silverIngot");
public static Item electrumIngot = new ItemIngot(201, 1).setItemName("electrumIngot");

//Blocks
public static Block blockSilver = new BlockSilver(501);
public static Block blockElectrum = new BlockSilver(502);

//Ores
public static Block oreSilver = new OreBasic (500, 0, Material.iron);

//Tools
public final static Item silverSword = new SunSwordBasic(5000, silver, 1, "silverSword");
public final static Item silverShovel = new SunShovel(5001, silver, 2, "silverShovel");
public final static Item silverPickaxe = new SunPickaxe(5002, silver, 3, "silverPickaxe");
public final static Item silverAxe = new SunAxe(5003, silver, 4, "silverAxe");
public final static Item silverHoe = new SunHoe(5004, silver, 5, "silverHoe");
public final static Item electrumSword = new SunSwordBasic(5005, electrum, 1, "electrumSword");
public final static Item electrumShovel = new SunShovel(5006, electrum, 2, "electrumShovel");
public final static Item electrumPickaxe = new SunPickaxe(5007, electrum, 3, "electrumPickaxe");
public final static Item electrumAxe = new SunAxe(5008, electrum, 4, "electrumAxe");
public final static Item electrumHoe = new SunHoe(5009, electrum, 5, "electrumHoe");

//Armors
//Silver
public final static Item helmetSilver = new SunHelmet(5010, silverArmor,0, 0, 6, "helmetSilver");
public final static Item chestplateSilver = new SunChestplate(5011, silverArmor,0, 1, 7, "chestplateSilver");
public final static Item legsSilver = new SunLegs(5012, silverArmor,0, 2, 8, "legsSilver");
public final static Item bootsSilver = new SunBoots(5013, silverArmor,0, 3, 9, "bootsSilver");

//Electrum
public final static Item helmetElectrum = new SunHelmet(5014, electrumArmor,0, 0, 6, "helmetElectrum");
public final static Item chestplateElectrum = new SunChestplate(5015, electrumArmor,0, 1, 7, "chestplateElectrum");
public final static Item legsElectrum = new SunLegs(5016, electrumArmor,0, 2, 8, "legsElectrum");
public final static Item bootsElectrum = new SunBoots(5017, electrumArmor,0, 3, 9, "bootsElectrum");




@SidedProxy(clientSide = "SunMod.core.proxies.ClientProxy", serverSide = "SunMod.core.proxies.CommonProxy") //Tells Forge the location of your proxies
public static CommonProxy proxy;




@Init
public void InitCobaltCraft(FMLInitializationEvent event){ //Your main initialization method
proxy.registerBlocks();
proxy.addNames();
proxy.addRecipes();
proxy.registerRenderInformation();
MinecraftForge.setToolClass(silverPickaxe, "pickaxe", 2);
NetworkRegistry.instance().registerGuiHandler(this, proxy); //Registers the class that deals with GUI data
}
}

 

Thanks!

Link to comment
Share on other sites

use this.

private EnumToolMaterial material;

public boolean getIsRepairable(ItemStack stack, ItemStack stack2)
{
	if(stack.getItem() ==  SunMod.silverIngot && material == silver)
	{
		return true;
	}
	else if(stack.getItem() ==  SunMod.electrumIngot && material == electrum)
	{
		return true;
	}
}

and in the constructor do

material = par2EnumToolMaterial;

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.