Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[Solved]Make New Items Enchantable?


silenthunder2
 Share

Recommended Posts

So I've been following tutorials and learning how to work with forge, and I've got a new material that can be made into tools.  For some reason, I can't enchant any of them. 

 

Here's some example code for the pickaxe:

 

package moar.main;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.item.EnumToolMaterial;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeHooks;
import net.minecraft.item.Item;
import net.minecraft.creativetab.*;
import moar.main.Moar;

public class MoarPickaxe extends MoarTool
{
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, Moar.oreSilver};
public MoarPickaxe(int ID, EnumToolMaterial m, int texture, String name)
{
         super(ID, 1, m, blocksEffectiveAgainst);
         this.setCreativeTab(CreativeTabs.tabTools);
         setIconIndex(texture);
         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 String getTextureFile() 
{
        return CommonProxy.ITEMS_PNG;
}
public boolean getIsRepairable(ItemStack par1ItemStack, ItemStack par2ItemStack) {
return Moar.silverIngot.itemID == par2ItemStack.itemID ? true:
super.getIsRepairable(par1ItemStack, par2ItemStack);
}
}

 

 

And my main class:

 

package moar.main;


import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.MinecraftForge;
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.Mod.PostInit;
import cpw.mods.fml.common.Mod.PreInit;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;
import net.minecraft.item.EnumAction;
import net.minecraft.item.EnumToolMaterial;


@Mod(modid="moar", name="MOAR", version="0.0.0")
@NetworkMod(clientSideRequired=true, serverSideRequired=false)
public class Moar {
        
        
        @Instance("moar")
        public static Moar instance;
        public static EnumToolMaterial silver = net.minecraftforge.common.EnumHelper.addToolMaterial("silver", 2, 1561, 4.0F, 2, 10);
        
        //Items
        public final static Item silverIngot = new MoarItem(5000).setMaxStackSize(64).setIconIndex(0).setItemName("silverIngot"); 
        
        //Tools and Weapons
        public final static Item silverSword = new MoarSword(5001, silver, 1, "silverSword");
        public final static Item silverShovel = new MoarShovel(5002, silver, 2, "silverShovel");
        public final static Item silverPickaxe = new MoarPickaxe(5003, silver, 3, "silverPickaxe");
        public final static Item silverAxe = new MoarAxe(5004, silver, 4, "silverAxe");
        public final static Item silverHoe = new MoarHoes(5005, silver, 5, "silverHoe");
        
        //Blocks
        public final static Block oreSilver = new MoarBlock(500,16,Material.iron);
        
        @SidedProxy(clientSide="moar.main.client.ClientProxy",
                        serverSide="moar.main.CommonProxy")
        public static CommonProxy proxy;
        
        @PreInit
        public void preInit(FMLPreInitializationEvent event) {
                // Stub Method
        }
        
        @Init
        public void load(FMLInitializationEvent event) {

        		//Names
                LanguageRegistry.addName(silverIngot, "Silver Ingot");
                LanguageRegistry.addName(oreSilver, "Silver Ore");
                LanguageRegistry.addName(silverSword, "Silver Sword");
                LanguageRegistry.addName(silverPickaxe, "Silver Pickaxe");
                LanguageRegistry.addName(silverShovel, "Silver Shovel");
                LanguageRegistry.addName(silverAxe, "Silver Axe");
                LanguageRegistry.addName(silverHoe, "Silver Hoe");
                
                //Harvest Levels
                MinecraftForge.setBlockHarvestLevel(oreSilver, "pickaxe", 2);
                
                //Block Registry
                GameRegistry.registerBlock(oreSilver, "oreSilver");
                
                //Crafting Recipes
                GameRegistry.addRecipe(new ItemStack(Moar.silverSword, 1), "#", "#", "X", '#', Moar.silverIngot, 'X', Item.stick);
                GameRegistry.addRecipe(new ItemStack(Moar.silverShovel, 1), "#", "X", "X", '#', Moar.silverIngot, 'X', Item.stick);
                GameRegistry.addRecipe(new ItemStack(Moar.silverPickaxe, 1), "###"," X ", " X ", '#', Moar.silverIngot, 'X', Item.stick);
                GameRegistry.addRecipe(new ItemStack(Moar.silverAxe, 1), "## ", "#X ", " X ", '#', Moar.silverIngot, 'X', Item.stick);
                GameRegistry.addRecipe(new ItemStack(Moar.silverHoe, 1), "## ", " X ", " X ", '#', Moar.silverIngot, 'X', Item.stick);
                
                //Furnace Recipes
                GameRegistry.addSmelting(oreSilver.blockID, new ItemStack(silverIngot), 0.5F);
        }
        
        @PostInit
        public void postInit(FMLPostInitializationEvent event) {
                // Stub Method
        }
}

 

 

Is there something that I'm missing to make them enchantable?

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
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.

 Share



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • What do you mean "not working"? Your code (if it were logical) does nothing. Additionally, you have the following issues: You are using a client-only class (Minecraft) from common code (ClientSyncPacket). Your packet does not tell the client which player this is about. It needs to do so using the player's ID. Currently your packet just uses Minecraft#player, which is not necessarily the correct player.
    • when i tried joining a world my mc crashed exit code -805306369
    • Hello There! In the 73rd episode of Bed Wars we get into a lobby with a guy who had a cool name and for some reason Ben is very impressed with the name and thus the title!  
    • I have been trying to install forge, but I can't even get the installer to run. I'm really not sure what the issue is, first let me make sure I am even using the installer right, I downloaded the forge installer matching my minecraft version (1.19.2), if I double click the .jar from the download then I see a flash of a black window that immediately disappears. If I use a command prompt, I receive the following output: C:\Users\austi> java -jar forge-1.19.2-43.0.19-installer.jar Error: Unable to access jarfile forge-1.19.2-43.0.19-installer.jar   I feel like this is more likely a java issue than a forge issue but I was hoping that people here might be able to help. I've tried a couple versions of java, at first I was using 8 I believe because all of the install guides for forge were a bit older so they linked to the java website rather than oracle. I tried version 18 from the oracle site and received the same result from command prompt. It is also entirely possible that I am doing something else wrong that is blatantly obvious to everyone else.
    • Here is my configuration: % java -version java version "18.0.2" 2022-07-19 Java(TM) SE Runtime Environment (build 18.0.2+9-61) Java HotSpot(TM) 64-Bit Server VM (build 18.0.2+9-61, mixed mode, sharing) forge-1.19-41.1.0-mdk on macOS Monterey 12.5 I ran the command: ./gradlew genEclipseRuns and was hoping it will generate the Eclipse project files for me. The run log is at https://gist.github.com/arun-gupta/06b983a6976b4c0a0f510d0dc225ddd3 and the generated directory structure is at https://gist.github.com/arun-gupta/3f5bfc70ec5d3d903b0f97d42840abda. In previous versions (1.12-ish), it used to generate an eclipse directory but 1.19 does not seem to have it. I tried opening the top-level forge directory but Eclipse does not recognize it as a project as well. How do I open this project in Eclipse now?  
  • Topics

×
×
  • Create New...

Important Information

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