Jump to content

Adding enchantments to tools


ashtonr12

Recommended Posts

I was wondering how i would go about giving a tool and enchantment without having to enchant it, ie when you craft it it comes with an enchantment, sort of like how you can make armour give a potion effect when worn in the armour slots?

some example code would be usefull or any constuctive help at all :)

Use examples, i have aspergers.

Examples make sense to me.

Link to comment
Share on other sites

I somewhere read that when creating a recipe you can pass it an enchanted item as a result and it should work.

 

EDIT: Yep, it works. Sample code:

        ItemStack hoe = new ItemStack(hoeJaffarrol);
        hoe.addEnchantment(Enchantment.fortune, 2);    // <<
        hoe.addEnchantment(Enchantment.unbreaking, 2); // <<
        GameRegistry.addRecipe(hoe, "JJL", "LS ", " S ", 'J', jaffarrol, 'S', Item.stick, 'L', limsew);

mnn.getNativeLang() != English

If I helped you please click on the "thank you" button.

Link to comment
Share on other sites

I think it could be done via onUpdate (called every tick when in players inventory) or onBlockDestroyed (less cpu intensive, but not exactly thing you wanted).

mnn.getNativeLang() != English

If I helped you please click on the "thank you" button.

Link to comment
Share on other sites

yea, using tick handler would be possible. you'd probably use the player tick on a server side, I recommend using scheduled tick handler (to not stress a server too much, checking every tick for every player seems a bit much, every 10 or 20 ticks should be fine).

 

brief howto of tickhandler: implement IScheduledTickHandler, ticks() should return player. on tickEnd you'll do the testing of a player for your tool and applying potion effect to the player. the TickType is well commented. when you have done tick handler you just register it in your load method (via TickRegistry.registerTickHandler) and you're done :).

mnn.getNativeLang() != English

If I helped you please click on the "thank you" button.

Link to comment
Share on other sites

Idofindthat example code helps me the most becasue then i can be 100% sure that i amcorrect in it and i can refer to it later on if i have problems :) i have already got a method for adding potion effects to armours i will post itlater for you to scan over but i am wondering if it is a similar method with just tools instead of armours. On another note the way i have handled armours is so that if you are wearing helmet or plate or legs or boots you get potion slowness (for example) i was wondering if there was a way for me to have it so that it is when you are wearing helmet and plate and boots and legs.

thankyou :)

Use examples, i have aspergers.

Examples make sense to me.

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.