Posted March 30, 201411 yr i was wondering how I would make it so a tool would have an enchant on crafting?
March 30, 201411 yr Override Item#onCreated(ItemStack stack, World world, EntityPlayer player) in your item class and add whatever enchantment you want to the stack. Or, if it's not a custom class, use FML's ItemCraftedEvent. http://i.imgur.com/NdrFdld.png[/img]
March 30, 201411 yr Something like this: public void onCreated(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) { par1ItemStack.addEnchantment(Enchantment.sharpness, 2); // NAME LVL } Not new to java >> New to modding.
July 1, 201411 yr The problem with onCreated is that its run twice. Both on server and client. I have some code where I random choose an enchantment and I can see that it runs it twice. It gives me a problem because I want to take levels from the player when the item is crafted.
July 1, 201411 yr You check to see if its server world before you add the enchantment... Also, you can add the enchanted item as the output of the recipe. We all stuff up sometimes... But I seem to be at the bottom of that pot.
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.