Minecolonies & Eating rework by raycoms

View this thread on steempeak.com
· @raycoms ·
$105.62
Minecolonies & Eating rework
![](https://i.imgur.com/G5FXfxQ.png)

Hi everyone it has been a few days since my last update but I finally got a few minutes to tell you about a great new feature.

### The Eating Rework

Previously eating did not look very nice and had some complications.

For that reason, we wanted to improve the eating process by making them execute an animation and take some time to eat (and not only despawn the food in their inventory).

Now, another dev started working on it but then abandoned the branch and went missing.

I checked over his code, but it was still very raw so I decided to re-use only one of the mechanics he created and rewrote the rest of the code.

He added to the AITarget system the variable "okayToEat" and then went through all AI tasks to select if a task is okay to stop to eat or not.

He then added two utility methods to the job class.
Which check if the worker is at his hut and to get the AI job from a worker.

![](https://i.imgur.com/JTv1ckA.png)

That's already where his contribution to this pr ends.
All other things I scrapped and reworked myself to integrate it better with the other code we have and to make it less bug-prone.

What has been done:
---

First, I started with an easy fix in the inventory utils.
To make sure we don't get crashes with broken inventories anymore.

![](https://i.imgur.com/s9aYukb.png)

Then, I reworked how we calculate if the worker should keep an item or not.
Previously, the worker would always keep a full stack of an item he should keep even though he wasn't needing so many items.

That's why I reworked the method which checks if the building requires that item so that it returns the amount which can get dumped.

> Previously it returned a boolean only

![](https://i.imgur.com/bg8MTwB.png)

In that sense, I have to make sure that I:

- Store the exact amount I need and the exact amount I kept
- Make sure I respect the min/max amounts which can be dumped.


As previously, it would go through all the requirements of the worker.
Then it would test if the stack we want matches it.
We would then get the matching stack and retrieve from the map how many we should keep and if there is a difference (rest) between how many we have and how many we should keep.

Then we would check if we kept it already (if it is not null)
and then return the complete count if we kept it.
Else, we would update the rest and return a positive rest if there are enough or 0.

If we didn't keep it yet again, we would add it to the map, update the size we stored. We don't have to update the rest because we set it earlier.

Then we would again return either the rest or the size of the remaining stack (which is 0 if we need all).

Then, I updated the required amount of food to be twice the building level. So that workers dump all food they don't need (especially fisherman, baker, and cooks).

![](https://i.imgur.com/DieeKwN.png)

In the dumping method, we would then only dump the exact amount we got as a return and not try to dump the whole stack (or nothing if false).

```
 if (buildingWorker != null && !ItemStackUtils.isEmpty(stackToDump))
        {
            final int amount = dumpAnyway ? stackToDump.getCount() : buildingWorker.buildingRequiresCertainAmountOfItem(stackToDump, alreadyKept);
            if (amount > 0)
            {
                final ItemStack activeStack = new InvWrapper(getInventory()).extractItem(slotAt, amount, false);
                InventoryUtils.transferItemStackIntoNextBestSlotInItemHandler(activeStack, buildingWorker.getCapability(ITEM_HANDLER_CAPABILITY, null));
            }
        }
```

While I was at that I also removed the previous eating code from that class already.

#### Eating:

Now, we finally come to the eating part.

But first, we need a few more utility methods.

Based on the AIStates we have to check in the job and citizen if it is okay to eat.

The citizen would check if he shouldn't sleep or is not sleeping and if that's not the case check if he either has a job or the job allows him to eat right now.

![](https://i.imgur.com/l1rl62G.png)

In the job, we would then iterate through all open tasks and check if any of them does not allow us to eat right now.

![](https://i.imgur.com/YlI4JCJ.png)

Additionally, I checked if the citizen is idling right now anyway. Because then he could go through the restaurant right away.

![](https://i.imgur.com/QMLjJU3.png)
![](https://i.imgur.com/yE1NYrS.png)


Then, we finally start with the eating AI task.

It has a number of different stages it runs through.

![](https://i.imgur.com/ejIHcAu.png)

This one starts with the classic "should execute" which decides if the entity should be executing this task right now (and no lower priority task).

We again check if he is sleeping and we right away return true if he is already executing this AI task (if his current state is not idle).

Then we check if the citizen saturation is too high or if he can not eat right now.

![](https://i.imgur.com/vmdNt0M.png)

Then, if the saturation is too low (Under average) and he either is really hungry (under low saturation) or is waiting a while to eat already.

The update task then would run through all the stages and decide for the right branch and switch the tasks depending on that.

![](https://i.imgur.com/GN9Ossw.png)

He starts by checking if he has food on him, if so he would eat, else he would search a restaurant, walk to it, wait for the cook to deliver him food (or after a while gets it himself) and then eat.

> Strongly simplified.

Going through all these would be a bit of an overkill in this post so I will focus on the core element: Eating.

It will only run into the eating AI task if he has food and previously went through the check task.

So, the food slot should be set, if not set, we will return to another state. Similar, if set but not food (the player might've interfered) we will also return to the previous state.

If we then have the food we will set it so the worker holds it in the hand, and then every 10 ticks execute a sound, swing the arm (twice every second) and execute a nice particle effect.

If the "eat time" is over we increase our saturation and decrease the inventory.

Then, we check if we still need saturation and if our food stack is not empty yet if we have enough to eat we start this all over again.

![](https://i.imgur.com/GjOMRqM.png)

Since Minecraft eating requires a player and I lose control of the eating process I had to write my own particle effect code.

For that, I created the message to send the data to the client.

![](https://i.imgur.com/iT8kt3O.png)

And then updated the Minecraft code to our need in the message execution.

![](https://i.imgur.com/8H99y9I.png)


### Cook additions:

Besides that, the cook also got some nice additions.
First of all, I found out that the cook had some bad issues not being able to path to certain citizens.

So, first I generalized so the player also can be delivered food and then I made sure that the distance to the player is within the building and that the worker is not stuck trying to reach him.

![](https://i.imgur.com/W6QjvkY.png)

Then, I made sure that the citizen or player gets served and the player gets notified if so.

![](https://i.imgur.com/Te9yN4r.png)

In the context of that, I also had to update that the cook detects if the player needs food.

![](https://i.imgur.com/gjM49fe.png)

Besides that, we added at a bunch of locations to decrease the saturation of the workers to increase the food requirements (until now most workers did not consume enough food and one good fisherman could sustain a whole colony).

This had to be carefully balanced and required many hours of testing from me and some of my dedicated testers to flesh it out.


I hope you like the new update and I see you the next time =)

#### Repository: 
https://github.com/ldtteam/minecolonies

#### Pull Request:
https://github.com/ldtteam/minecolonies/pull/3022
πŸ‘  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 144 others
properties (23)
post_id65,910,860
authorraycoms
permlinkminecolonies--eating-rework
categoryutopian-io
json_metadata{"app":"steem-plus-app","tags":["utopian-io","development","gaming","technology","programming"]}
created2018-11-12 14:00:30
last_update2018-11-12 14:00:30
depth0
children11
net_rshares127,072,770,572,955
last_payout2018-11-19 14:00:30
cashout_time1969-12-31 23:59:59
total_payout_value79.050 SBD
curator_payout_value26.565 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length7,940
author_reputation120,534,427,956,805
root_title"Minecolonies & Eating rework"
beneficiaries
0.
accountsteemplus-pay
weight100
1.
accountutopian.pay
weight500
max_accepted_payout100,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (208)
@ilovecoding ·
Hello! Your post has been resteemed and upvoted by @ilovecoding because **we love coding**! Keep up good work! Consider upvoting this comment to support the @ilovecoding and increase your future rewards! ^_^ Steem On! 
 ![](https://codingforspeed.com/images/i-love-coding.jpg) 
*Reply !stop to disable the comment. Thanks!*
πŸ‘  
properties (23)
post_id65,910,878
authorilovecoding
permlink20181112t140042348z
categoryutopian-io
json_metadata{"app":"ilovecoding","tags":["ilovecoding"]}
created2018-11-12 14:00:42
last_update2018-11-12 14:00:42
depth1
children0
net_rshares382,445,601
last_payout2018-11-19 14:00:42
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length323
author_reputation40,842,386,526
root_title"Minecolonies & Eating rework"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (1)
@cassillas5553 · (edited)
Wow. I am just a rookie while it comes to coding but I think here u used C  language here which I am currently learning lol .
properties (22)
post_id65,912,089
authorcassillas5553
permlinkre-raycoms-minecolonies--eating-rework-20181112t142553891z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steemit\/0.1"}
created2018-11-12 14:25:54
last_update2018-11-12 14:53:48
depth1
children1
net_rshares0
last_payout2018-11-19 14:25:54
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length125
author_reputation13,558,830,206,659
root_title"Minecolonies & Eating rework"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@raycoms ·
$0.03
It's java =P
πŸ‘  
properties (23)
post_id65,916,702
authorraycoms
permlinkre-cassillas5553-re-raycoms-minecolonies--eating-rework-20181112t155838155z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steemit\/0.1"}
created2018-11-12 15:58:39
last_update2018-11-12 15:58:39
depth2
children0
net_rshares33,999,963,535
last_payout2018-11-19 15:58:39
cashout_time1969-12-31 23:59:59
total_payout_value0.022 SBD
curator_payout_value0.006 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length12
author_reputation120,534,427,956,805
root_title"Minecolonies & Eating rework"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (1)
@helo ·
$7.99
- Another yummy update.
- And by testing you mean playing right? ;-)


Your contribution has been evaluated according to [Utopian policies and guidelines](https://join.utopian.io/guidelines), as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, [click here](https://review.utopian.io/result/3/1211111).

---- 
Need help? Write a ticket on https://support.utopian.io/. 
Chat with us on [Discord](https://discord.gg/uTyJkNm). 
[[utopian-moderator]](https://join.utopian.io/)
πŸ‘  , , , , , , , ,
properties (23)
post_id65,941,914
authorhelo
permlinkre-raycoms-minecolonies--eating-rework-20181113t024818362z
categoryutopian-io
json_metadata{"app":"steemit\/0.1","tags":["utopian-io"],"links":["https:\/\/join.utopian.io\/guidelines","https:\/\/review.utopian.io\/result\/3\/1211111","https:\/\/support.utopian.io\/","https:\/\/discord.gg\/uTyJkNm","https:\/\/join.utopian.io\/"]}
created2018-11-13 02:48:18
last_update2018-11-13 02:48:18
depth1
children1
net_rshares9,316,374,077,288
last_payout2018-11-20 02:48:18
cashout_time1969-12-31 23:59:59
total_payout_value6.044 SBD
curator_payout_value1.941 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length560
author_reputation119,612,833,307,875
root_title"Minecolonies & Eating rework"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (9)
@utopian-io ·
Thank you for your review, @helo! Keep up the good work!
properties (22)
post_id66,070,194
authorutopian-io
permlinkre-re-raycoms-minecolonies--eating-rework-20181113t024818362z-20181115t125608z
categoryutopian-io
json_metadata{"app":"beem\/0.20.9"}
created2018-11-15 12:56:09
last_update2018-11-15 12:56:09
depth2
children0
net_rshares0
last_payout2018-11-22 12:56:09
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length56
author_reputation152,913,012,544,965
root_title"Minecolonies & Eating rework"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@steem-ua ·
#### Hi @raycoms!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your post is eligible for our upvote, thanks to our collaboration with @utopian-io!
**Feel free to join our [@steem-ua Discord server](https://discord.gg/KpBNYGz)**
properties (22)
post_id65,942,905
authorsteem-ua
permlinkre-minecolonies--eating-rework-20181113t031819z
categoryutopian-io
json_metadata{"app":"beem\/0.20.9"}
created2018-11-13 03:18:21
last_update2018-11-13 03:18:21
depth1
children0
net_rshares0
last_payout2018-11-20 03:18:21
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length286
author_reputation23,203,609,903,979
root_title"Minecolonies & Eating rework"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@steem-plus ·
SteemPlus upvote
Hi, @raycoms!

You just got a **11.11%** upvote from SteemPlus!
To get higher upvotes, earn more SteemPlus Points (SPP). On your Steemit wallet, check your SPP balance and click on "How to earn SPP?" to find out all the ways to earn.
If you're not using SteemPlus yet, please check our last posts in [here](https://steemit.com/@steem-plus) to see the many ways in which SteemPlus can improve your Steem experience on Steemit and Busy.
properties (22)
post_id65,952,209
authorsteem-plus
permlinkminecolonies--eating-rework---vote-steemplus
categoryutopian-io
json_metadata{}
created2018-11-13 07:58:48
last_update2018-11-13 07:58:48
depth1
children0
net_rshares0
last_payout2018-11-20 07:58:48
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length435
author_reputation247,995,867,762,997
root_title"Minecolonies & Eating rework"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@utopian-io ·
Hey, @raycoms!

**Thanks for contributing on Utopian**.
We’re already looking forward to your next contribution!

**Get higher incentives and support Utopian.io!**
 Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via [SteemPlus](https://chrome.google.com/webstore/detail/steemplus/mjbkjgcplmaneajhcbegoffkedeankaj?hl=en) or [Steeditor](https://steeditor.app)).

**Want to chat? Join us on Discord https://discord.gg/h52nFrV.**

<a href='https://steemconnect.com/sign/account-witness-vote?witness=utopian-io&approve=1'>Vote for Utopian Witness!</a>
properties (22)
post_id65,958,180
authorutopian-io
permlinkre-minecolonies--eating-rework-20181113t103322z
categoryutopian-io
json_metadata{"app":"beem\/0.20.9"}
created2018-11-13 10:33:24
last_update2018-11-13 10:33:24
depth1
children0
net_rshares0
last_payout2018-11-20 10:33:24
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length589
author_reputation152,913,012,544,965
root_title"Minecolonies & Eating rework"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@arcange ·
Congratulations @raycoms!
Your post was mentioned in the [Steemit Hit Parade](https://steemit.com/hit-parade/@arcange/daily-hit-parade-20181112) in the following category:

* Pending payout - Ranked 9 with $ 138,74
properties (22)
post_id65,974,578
authorarcange
permlinkre-minecolonies--eating-rework-20181112t175349000z
categoryutopian-io
json_metadata{}
created2018-11-13 16:55:45
last_update2018-11-13 16:55:45
depth1
children0
net_rshares0
last_payout2018-11-20 16:55:45
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length215
author_reputation231,443,210,169,699
root_title"Minecolonies & Eating rework"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@izonaka ·
Very interesting! :D I will upvote and share this post!
properties (22)
post_id65,994,458
authorizonaka
permlinkre-raycoms-minecolonies--eating-rework-20181114t020233113z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steemit\/0.1"}
created2018-11-14 02:02:36
last_update2018-11-14 02:02:36
depth1
children0
net_rshares0
last_payout2018-11-21 02:02:36
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length55
author_reputation40,530,109,565
root_title"Minecolonies & Eating rework"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@chibera ·
<center>![smallsmall.png](https://cdn.steemitimages.com/DQmcSHgWmCJJiXxm31QwyrZUcX54fVtNByfQ5QtTkC49q88/smallsmall.png)</center>

<center>This post is being supported by [Chibera](https://steemit.com/chibera/@chibera/chibera-the-steem-mmorpg) the first MMORPG with blockchain integration because we liked it. 

#### Join our discord for a chance to have your content curated daily.
</center>

---

<center>Be sure to also visit and like our social media
[Chibera Facebook](https://www.facebook.com/chiberacom) | [Chibera Twitter](https://twitter.com/chiberacom)
[Chibera Instagram](https://www.instagram.com/chiberacom/) | [Chibera Discord](https://discord.gg/tgwfjjy)</center>
properties (22)
post_id66,147,252
authorchibera
permlinkre-raycoms-minecolonies--eating-rework-20181117t004543991z
categoryutopian-io
json_metadata{"image":["https:\/\/cdn.steemitimages.com\/DQmcSHgWmCJJiXxm31QwyrZUcX54fVtNByfQ5QtTkC49q88\/smallsmall.png"],"links":["https:\/\/steemit.com\/chibera\/@chibera\/chibera-the-steem-mmorpg","https:\/\/www.facebook.com\/chiberacom","https:\/\/twitter.com\/chiberacom","https:\/\/www.instagram.com\/chiberacom\/","https:\/\/discord.gg\/tgwfjjy"],"app":"steemit\/0.1","tags":["utopian-io"]}
created2018-11-17 00:45:45
last_update2018-11-17 00:45:45
depth1
children0
net_rshares0
last_payout2018-11-24 00:45:45
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length677
author_reputation75,857,757,502,918
root_title"Minecolonies & Eating rework"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000