Custom Food
Creating custom food items in AbyssalLib is highly flexible thanks to the DataComponent system. In this guide, we will transform a standard item into something a player can eat to restore hunger and saturation.
To create a custom food, you need to utilize Item#setData and apply both the Food and Consume components.
Adding the Food component
To make the item mathematically "edible" to the server (providing hunger/saturation), we will set the Food DataComponent.
Method | Information |
|---|---|
| Whether or not the player can eat the item while their nutrition is already full. |
| Amount of nutrition to restore. |
| Amount of saturation (hidden anti-hunger mechanic) to restore. |
While this gives the item food properties, if you try to eat the item in-game now, it will not work because the item lacks the timing needed to be consumed.
Adding the Consumable component
To make the item physically eaten by the player, we add the Consume component similarly to the Food DataComponent.
Method | Information |
|---|---|
| Adds a single |
| Adds multiple |
| Sets the |
| Sets the time (in seconds) it takes to finish eating the item. |
| Sets the |
| Sets whether crumb particles should spawn during consumption. |
| Sets the sound that should play during consumption. |
Bringing it all together
With both components applied, our food item is fully functional. Here is how a complete registration might look: