create account

Minecolonies & Eating rework by raycoms

View this thread on steemit.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 143 others
properties (37)
authorraycoms
permlinkminecolonies--eating-rework
categoryutopian-io
json_metadata{"tags":["utopian-io","development","gaming","technology","programming"],"app":"steem-plus-app"}
last_update2018-11-12 14:00:30
created2018-11-12 14:00:30
active2018-11-17 00:45:45
last_payout2018-11-19 14:00:30
depth0
children11
net_rshares0
vote_rshares0
children_abs_rshares0
cashout_time1969-12-31 23:59:59
max_cashout_time1969-12-31 23:59:59
total_vote_weight0
reward_weight10,000
total_payout_value79.050 SBD
curator_payout_value26.565 SBD
author_rewards135,360
net_votes193
root_authorraycoms
root_permlinkminecolonies--eating-rework
max_accepted_payout100,000.000 SBD
percent_steem_dollars10,000
allow_repliestrue
allow_votestrue
allow_curation_rewardstrue
beneficiaries
0.
accountsteemplus-pay
weight100
1.
accountutopian.pay
weight500
root_title"Minecolonies & Eating rework"
pending_payout_value0.000 SBD
total_pending_payout_value0.000 STEEM
author_reputation67,809,918,060,777
promoted0.000 SBD
body_length0
reblogged_by[]
author_curate_reward""
vote details (207)
@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 (37)
authorilovecoding
permlink20181112t140042348z
categoryutopian-io
json_metadata{"tags":["ilovecoding"],"app":"ilovecoding"}
last_update2018-11-12 14:00:42
created2018-11-12 14:00:42
active2018-11-12 14:00:42
last_payout2018-11-19 14:00:42
depth1
children0
net_rshares0
vote_rshares0
children_abs_rshares0
cashout_time1969-12-31 23:59:59
max_cashout_time1969-12-31 23:59:59
total_vote_weight0
reward_weight10,000
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
author_rewards0
net_votes1
root_authorraycoms
root_permlinkminecolonies--eating-rework
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
allow_repliestrue
allow_votestrue
allow_curation_rewardstrue
beneficiaries[]
root_title"Minecolonies & Eating rework"
pending_payout_value0.000 SBD
total_pending_payout_value0.000 STEEM
author_reputation40,840,060,287
promoted0.000 SBD
body_length0
reblogged_by[]
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 (36)
authorcassillas5553
permlinkre-raycoms-minecolonies--eating-rework-20181112t142553891z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steemit/0.1"}
last_update2018-11-12 14:53:48
created2018-11-12 14:25:54
active2018-11-12 15:58:39
last_payout2018-11-19 14:25:54
depth1
children1
net_rshares0
vote_rshares0
children_abs_rshares0
cashout_time1969-12-31 23:59:59
max_cashout_time1969-12-31 23:59:59
total_vote_weight0
reward_weight10,000
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
author_rewards0
net_votes0
root_authorraycoms
root_permlinkminecolonies--eating-rework
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
allow_repliestrue
allow_votestrue
allow_curation_rewardstrue
beneficiaries[]
root_title"Minecolonies & Eating rework"
pending_payout_value0.000 SBD
total_pending_payout_value0.000 STEEM
author_reputation9,778,956,778,961
promoted0.000 SBD
body_length0
reblogged_by[]
@raycoms ·
$0.03
It's java =P
πŸ‘  
properties (37)
authorraycoms
permlinkre-cassillas5553-re-raycoms-minecolonies--eating-rework-20181112t155838155z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steemit/0.1"}
last_update2018-11-12 15:58:39
created2018-11-12 15:58:39
active2018-11-12 15:58:39
last_payout2018-11-19 15:58:39
depth2
children0
net_rshares0
vote_rshares0
children_abs_rshares0
cashout_time1969-12-31 23:59:59
max_cashout_time1969-12-31 23:59:59
total_vote_weight0
reward_weight10,000
total_payout_value0.022 SBD
curator_payout_value0.006 SBD
author_rewards39
net_votes1
root_authorraycoms
root_permlinkminecolonies--eating-rework
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
allow_repliestrue
allow_votestrue
allow_curation_rewardstrue
beneficiaries[]
root_title"Minecolonies & Eating rework"
pending_payout_value0.000 SBD
total_pending_payout_value0.000 STEEM
author_reputation67,809,918,060,777
promoted0.000 SBD
body_length0
reblogged_by[]
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 (37)
authorhelo
permlinkre-raycoms-minecolonies--eating-rework-20181113t024818362z
categoryutopian-io
json_metadata{"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/"],"app":"steemit/0.1"}
last_update2018-11-13 02:48:18
created2018-11-13 02:48:18
active2018-11-15 12:56:09
last_payout2018-11-20 02:48:18
depth1
children1
net_rshares0
vote_rshares0
children_abs_rshares0
cashout_time1969-12-31 23:59:59
max_cashout_time1969-12-31 23:59:59
total_vote_weight0
reward_weight10,000
total_payout_value6.044 SBD
curator_payout_value1.941 SBD
author_rewards10,460
net_votes9
root_authorraycoms
root_permlinkminecolonies--eating-rework
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
allow_repliestrue
allow_votestrue
allow_curation_rewardstrue
beneficiaries[]
root_title"Minecolonies & Eating rework"
pending_payout_value0.000 SBD
total_pending_payout_value0.000 STEEM
author_reputation34,130,367,033,437
promoted0.000 SBD
body_length0
reblogged_by[]
author_curate_reward""
vote details (9)
@utopian-io ·
Thank you for your review, @helo! Keep up the good work!
properties (36)
authorutopian-io
permlinkre-re-raycoms-minecolonies--eating-rework-20181113t024818362z-20181115t125608z
categoryutopian-io
json_metadata"{"app": "beem/0.20.9"}"
last_update2018-11-15 12:56:09
created2018-11-15 12:56:09
active2018-11-15 12:56:09
last_payout2018-11-22 12:56:09
depth2
children0
net_rshares0
vote_rshares0
children_abs_rshares0
cashout_time1969-12-31 23:59:59
max_cashout_time1969-12-31 23:59:59
total_vote_weight0
reward_weight10,000
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
author_rewards0
net_votes0
root_authorraycoms
root_permlinkminecolonies--eating-rework
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
allow_repliestrue
allow_votestrue
allow_curation_rewardstrue
beneficiaries[]
root_title"Minecolonies & Eating rework"
pending_payout_value0.000 SBD
total_pending_payout_value0.000 STEEM
author_reputation113,903,503,488,639
promoted0.000 SBD
body_length0
reblogged_by[]
@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 (36)
authorsteem-ua
permlinkre-minecolonies--eating-rework-20181113t031819z
categoryutopian-io
json_metadata"{"app": "beem/0.20.9"}"
last_update2018-11-13 03:18:21
created2018-11-13 03:18:21
active2018-11-13 03:18:21
last_payout2018-11-20 03:18:21
depth1
children0
net_rshares0
vote_rshares0
children_abs_rshares0
cashout_time1969-12-31 23:59:59
max_cashout_time1969-12-31 23:59:59
total_vote_weight0
reward_weight10,000
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
author_rewards0
net_votes0
root_authorraycoms
root_permlinkminecolonies--eating-rework
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
allow_repliestrue
allow_votestrue
allow_curation_rewardstrue
beneficiaries[]
root_title"Minecolonies & Eating rework"
pending_payout_value0.000 SBD
total_pending_payout_value0.000 STEEM
author_reputation18,820,964,596,990
promoted0.000 SBD
body_length0
reblogged_by[]
@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 (36)
authorsteem-plus
permlinkminecolonies--eating-rework---vote-steemplus
categoryutopian-io
json_metadata{}
last_update2018-11-13 07:58:48
created2018-11-13 07:58:48
active2018-11-13 07:58:48
last_payout2018-11-20 07:58:48
depth1
children0
net_rshares0
vote_rshares0
children_abs_rshares0
cashout_time1969-12-31 23:59:59
max_cashout_time1969-12-31 23:59:59
total_vote_weight0
reward_weight10,000
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
author_rewards0
net_votes0
root_authorraycoms
root_permlinkminecolonies--eating-rework
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
allow_repliestrue
allow_votestrue
allow_curation_rewardstrue
beneficiaries[]
root_title"Minecolonies & Eating rework"
pending_payout_value0.000 SBD
total_pending_payout_value0.000 STEEM
author_reputation74,563,960,287,999
promoted0.000 SBD
body_length0
reblogged_by[]
@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 (36)
authorutopian-io
permlinkre-minecolonies--eating-rework-20181113t103322z
categoryutopian-io
json_metadata"{"app": "beem/0.20.9"}"
last_update2018-11-13 10:33:24
created2018-11-13 10:33:24
active2018-11-13 10:33:24
last_payout2018-11-20 10:33:24
depth1
children0
net_rshares0
vote_rshares0
children_abs_rshares0
cashout_time1969-12-31 23:59:59
max_cashout_time1969-12-31 23:59:59
total_vote_weight0
reward_weight10,000
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
author_rewards0
net_votes0
root_authorraycoms
root_permlinkminecolonies--eating-rework
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
allow_repliestrue
allow_votestrue
allow_curation_rewardstrue
beneficiaries[]
root_title"Minecolonies & Eating rework"
pending_payout_value0.000 SBD
total_pending_payout_value0.000 STEEM
author_reputation113,903,503,488,639
promoted0.000 SBD
body_length0
reblogged_by[]
@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 (36)
authorarcange
permlinkre-minecolonies--eating-rework-20181112t175349000z
categoryutopian-io
json_metadata""
last_update2018-11-13 16:55:45
created2018-11-13 16:55:45
active2018-11-13 16:55:45
last_payout2018-11-20 16:55:45
depth1
children0
net_rshares0
vote_rshares0
children_abs_rshares0
cashout_time1969-12-31 23:59:59
max_cashout_time1969-12-31 23:59:59
total_vote_weight0
reward_weight10,000
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
author_rewards0
net_votes0
root_authorraycoms
root_permlinkminecolonies--eating-rework
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
allow_repliestrue
allow_votestrue
allow_curation_rewardstrue
beneficiaries[]
root_title"Minecolonies & Eating rework"
pending_payout_value0.000 SBD
total_pending_payout_value0.000 STEEM
author_reputation129,972,126,462,581
promoted0.000 SBD
body_length0
reblogged_by[]
@izonaka ·
Very interesting! :D I will upvote and share this post!
properties (36)
authorizonaka
permlinkre-raycoms-minecolonies--eating-rework-20181114t020233113z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steemit/0.1"}
last_update2018-11-14 02:02:36
created2018-11-14 02:02:36
active2018-11-14 02:02:36
last_payout2018-11-21 02:02:36
depth1
children0
net_rshares0
vote_rshares0
children_abs_rshares0
cashout_time1969-12-31 23:59:59
max_cashout_time1969-12-31 23:59:59
total_vote_weight0
reward_weight10,000
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
author_rewards0
net_votes0
root_authorraycoms
root_permlinkminecolonies--eating-rework
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
allow_repliestrue
allow_votestrue
allow_curation_rewardstrue
beneficiaries[]
root_title"Minecolonies & Eating rework"
pending_payout_value0.000 SBD
total_pending_payout_value0.000 STEEM
author_reputation40,116,031,924
promoted0.000 SBD
body_length0
reblogged_by[]
@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 (36)
authorchibera
permlinkre-raycoms-minecolonies--eating-rework-20181117t004543991z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"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"}
last_update2018-11-17 00:45:45
created2018-11-17 00:45:45
active2018-11-17 00:45:45
last_payout2018-11-24 00:45:45
depth1
children0
net_rshares0
vote_rshares0
children_abs_rshares0
cashout_time1969-12-31 23:59:59
max_cashout_time1969-12-31 23:59:59
total_vote_weight0
reward_weight10,000
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
author_rewards0
net_votes0
root_authorraycoms
root_permlinkminecolonies--eating-rework
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
allow_repliestrue
allow_votestrue
allow_curation_rewardstrue
beneficiaries[]
root_title"Minecolonies & Eating rework"
pending_payout_value0.000 SBD
total_pending_payout_value0.000 STEEM
author_reputation63,527,186,803,557
promoted0.000 SBD
body_length0
reblogged_by[]