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

[1.7.2] Enchant on craft not working


kulalolk
 Share

Recommended Posts

Hi, I've been working on this for a few days now and I can't seem to get it to work. I'm making a pick to have fortune 5 when crafted. I've tried many different sources, Forge forums, MC forums, etc.

 

 

Here's the code for the Pickaxe class

 

package DiamondEnder.items.tools.witherEnder;

 

import net.minecraft.enchantment.Enchantment;

import net.minecraft.item.ItemPickaxe;

import net.minecraft.item.ItemStack;

import DiamondEnder.DiamondEnder;

 

public class WitherEnderPickaxe extends ItemPickaxe {

 

// Constructors

public WitherEnderPickaxe(ToolMaterial material)

{

 

super(material);

this.setUnlocalizedName("WitherEnderPickaxe");

this.setTextureName("diamondender:WitherEnderPickaxe");

this.setCreativeTab(DiamondEnder.tabDiamondEnderT4);

ItemStack WitherEnderPickaxe = new ItemStack(DiamondEnder.WitherEnderPickaxe);

        {

            if(!WitherEnderPickaxe.hasEffect(Enchantment.fortune.effectId))

            {

              WitherEnderPickaxe.addEnchantment(Enchantment.fortune, 5);

            }

            }

}

}

 

What am I doing wrong?

Thanks in advance for any help I get

Link to comment
Share on other sites

when you register your recipe do it like this.

ItemStack enchantedPick = new ItemStack(Items.diamond_pickaxe);
enchantedPick.addEnchantment(Enchantment.fortune, 5);
CraftingManager.getInstance().addRecipe(enchantedPick, "DDD", " S ", "BSB", 'D', Items.diamond, 'S', Items.stick, 'B', Items.book);

The way this works is you are creating a new instance of the pick (in this case diamond) and adding the enchant to that then in the recipe you return the enchanted pick.

tDmixXt.png

I am the author of Draconic Evolution

Link to comment
Share on other sites

Why's that? I've just starting modding in 1.7.2 and have never done anything other than basic wepons and blocks, etc. I had no idea how to do it, I studied the web and found nothing. Just because you're really good at thisa doesn't mean everyone else is. Give me a break

 

Link to comment
Share on other sites

This thread makes me sad.

Oh didnt see your post. Yes that is a much better way to do it!

@Override
public void onCreated(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
{
par1ItemStack.addEnchantment(Enchantment.fortune, 5);
super.onCreated(par1ItemStack, par2World, par3EntityPlayer);
}

Not sure if you need the super call or not.

 

Edit: no i dont think you do.

I think he was sad because he gave a perfect solution (which i didnt see) then i gave another solution which works but isnt nearly as good and you decided to go with mine.

I am the author of Draconic Evolution

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



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.