Minecolonies & Eating rework

7개월 전

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.

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.

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

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).

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.


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.

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.

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

Then, we finally start with the eating AI task.

It has a number of different stages it runs through.

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.

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.

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.

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.

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

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.

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

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

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 =)



Pull Request:


Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  trending
  • Another yummy update.
  • And by testing you mean playing right? ;-)

Your contribution has been evaluated according to Utopian policies and 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.

Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.


Thank you for your review, @helo! Keep up the good work!

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!

Reply !stop to disable the comment. Thanks!

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 .


It's java =P

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

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 to see the many ways in which SteemPlus can improve your Steem experience on Steemit and Busy.

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 or Steeditor).

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

Vote for Utopian Witness!

Congratulations @raycoms!
Your post was mentioned in the Steemit Hit Parade in the following category:

  • Pending payout - Ranked 9 with $ 138,74

Very interesting! :D I will upvote and share this post!


This post is being supported by Chibera the first MMORPG with blockchain integration because we liked it.

Join our discord for a chance to have your content curated daily.

Be sure to also visit and like our social media
Chibera Facebook | Chibera Twitter
Chibera Instagram | Chibera Discord