Tutorial 18. Food and Potion effects

Before you read, make sure you have seen the previous tutorial

Code is on github

So, a really small tutorial on Food and Potion Effects:

add the new food item.

So, basic food. The ItemFood needs 3 params.

  1. Heal amount (nr of half ‘food points’ it heals)
  2. saturation modifier*
  3. can a wolve eat this

*Saturation is a invisible bar, which determines how long it takes before you lose food points again. So if your saturation is full, you will not lose food points for a long time. Look at Item.java for references.


Ofcouse, we also add the normal stuff

For the fun, we make this item eatable super fast

Default = 32;

Lastly, we will add a potion effect when the player eats this.
We do this by calling setPotionEffect in the constructor.
This takes 4 parameters

  1. Potion ID. Look here for a list.
  2. Duration in seconds.
  3. Amplifier. Level of potion
  4. Effect Probability.

 

 

Back to List

Next tutorial


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">