Jump to content

Recommended Posts

Posted

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!

Posted

Wouldn't that only work if I was trying to repair the repair catalyst? Like I would have to be trying to repair a silver ingot.  This.itemID returns the ID of the tool I'm putting into the anvil, right?

Posted

yeah, it would.

you would have to do a switch and case where you would switch this.ID

case mod.whatever.pick: return true;

case mod.whatever.spade: return true;

etc.

Also, I should have you know that you are reading my signature.

Posted

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;

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I bestow up to thee, for thy contributions to my enjoyment of this game, my kindest regards, and most heartfelt blessings. May both sides of your pillow be cold tonight. 
    • I wasn't excepting this to be seen this fast and left the post marinating for a while, but thank you for such a quick reply! Regarding what the console shows me when the server fails to boot, you can find those logs on this pastebin link here. From what I could gather, the issue here is with the mod Night Lights. Should I remove this mod, I get the same issue with Rings of Ascension, and lastly with Oh The Biomes We've Gone. When I remove these three mods, the issue goes away, but since the world was generated with the biome mod, I would rather not part ways with it. Thank you for taking some time to read my extensive description, hope the link with the logs helps!
    • Please see https://forums.minecraftforge.net/topic/125488-rules-and-frequently-asked-questions-faq/ for information on how to post your log correctly.
    • Hello!  The detailed description of how you got to where you are is certainly valuable.  But, at the end of the day (well, any time of the day actually), it is going to be the actual logs that going to provide the necessary details to hopefully solve your startup issue. Part of me wonders if you have installed a client-only mod on a dedicated server.  But I may very well be wrong, and it will be the logs that will tell that story.
    • Hello there! I didn't quite know where to go regarding this, but ended up deciding to post it here. I have been running a forge server with around 200 mods for me and some friends to play on casually, but have recently started to get an issue when booting the server. This all started after I decided to add some new mods to the server. Like usual, I add a mod, test run the server for any issues, and if all is well, I'll add a next one and so on until I have added all that I wanted to. After doing so, in all test runs, it all seemed to work just fine. However, the next day, after trying to boot the server, I kept getting an error regarding java.lang.NullPointerException, towards one of the mods I had recently added. So far so good, I removed the mod that was causing the issue, started up the server again, and here in when things took a turn for the worse. I received another java.lang.NullPointerException null error that wouldn't allow me to boot the server, but this time with a mod that wasn't part of the new ones I had recently added. I found this weird, but nonetheless, I removed it thinking it might be causing some conflicts with some of the new ones. Afterwards, booting the server again proved to be impossible, as it gave me another java.lang.NullPointerException null error with the 3rd mod I had ever installed on the server! This mod was there since the start, it added some biomes and had been just fine so far. This turn of events made me remove all the newer mods I had recently added in hopes to fix this whole ordeal, but alas, to no avail. Same error, with that same biome mod that had been there since day one. Reluctantly, I removed the biome mod, booted the server, and voila! The server was running, although without a major mod that had always been there to begin with. As I do not wish to part ways with this mod, specially since it had been working so far without any issues, I tried to bring everything back to how it was before I added those new mods, but kept on getting the same java.lang.NullPointerException null error for the biome mod. Even adding the newer mods won't cause me this error, with exception of the one that started it all, which I find quite odd since the mods I had been using without any issues are now giving me the same error the newer one that started it all gave me. Now, I have checked that everything is up to date regarding the mods, forge (forge-1.20.1-47.3.12) and java. The modpack runs perfectly fine when I start Minecraft itself, and play singleplayer, or even when I open a LAN world, everything works. Everything aside from the server. From what I could gather, this java.lang.NullPointerException null error would point to a missing value of sorts, for an item perhaps, within the mod that is causing the error, but aside from removing the whole mod, I lack the knowledge on how to fix this. With this in mind, if anyone would be so kind as to shine some light into this situation, with a way to fix all this blunder, I would be most grateful!
  • Topics

×
×
  • Create New...

Important Information

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