Minecolonies & Small Improvements and Refactoring

in #utopian-io6 years ago (edited)

Hi everyone, lately I reworked a bunch of things within Minecolonies but only now I am getting to writing about it.

FPS and TPS improvements

Players had been complaining about their FPS (frames per second) when there are requesting workers around, I noticed that the reason for this was that on each colony update we were synchronizing the whole request manager data over even when it didn't change.

So I added a dirty variable to the request manager which I would trigger on any data change.

It would also mark the colony as dirty to guarantee that the colony refreshes this data.

Then as a second step, I would check if this is dirty when sending over the colony data.

And also check on the receiving site for this.

I later added an improvement to guarantee that the manager is at least once sent.

Guards not dumping

I also noticed that the guards weren't dumping accordingly.
When I dug into the code I found out that this happens because they don't increment the actions they do everywhere they should which was an easy fix.

Additionally, I added that they don't if they are still having a target, to not stop the fight in the middle of it.

return getOwnBuilding(AbstractBuildingGuards.class).getTask() == GuardTask.FOLLOW || target != null ? Integer.MAX_VALUE : ACTIONS_UNTIL_DUMPING * getOwnBuilding().getBuildingLevel();

getActionsUntilDumping returns a value which will be compared with the current actions. Therefore, if we return the max value of the integer, we never dump under these conditions.

Fix Miner Pathfinding

In the next update, I finally found out why miners got stuck when pathfinding since they put their appropriate position to miner be on the ladder they would slide up and down the ladder which would cause a lot of issues.

Therefore, I added some code at all appropriate places where we do this decision to place the position on the other side of the shaft where we want to mine from.

Plus, I found out that he was searching a random node to work from sometimes and not the currently active node (Something which I changed a while ago and forgot updating at this location).

Farmer using Compost

After @Fireruner created the composter a few weeks ago our colony was producing a bunch of compost but no one was using it.

This changed now.

As a first step, I created a new utility method with shrinks a stack in an itemHandler without having to search for it manually.

In the next step, I extracted the code responsible for requesting an item asynchronously and then gathering it from the furnace users in the general AI since several workers can profit from this code.
I also extracted a bunch of constants in our constant classes on the way.

For the farmer, I then needed a method to recognize compost.

And following that the code to check if it is in the building and else request it.

Sorry for the cut-out code line on the top, but it says isCompost and then closes the parenthesis.

While planting the farmer will no check his inventory for compost and will use it on the crop.

If the crop is at the max age he will already harvest it, else he will check for compost in the inventory.
If he has any he will attempt to decrease the stack and send a particle message to the client.
Afterward, it would grow the crop and update the crop stage.
If the crop is at the max age now he can now harvest it.

The harvest method mainly consists of the Minecraft code to spawn the particles.

Nevertheless, while it worked fine in single player it crashed in multiplayer although I did not use a client only class here.

I later found out that this happened because I was casting the client world to the world (indirectly) which would be detected on instantiation on the server.

Therefore, if assigning it to this class directly, nothing would happen since only the cast would have to be executed on the server on instantiation.

I hope you liked the updates today, in the next days I will write an update about some more exciting news!
Stay tuned!

Repository:

https://github.com/ldtteam/minecolonies

Pull Requests:

https://github.com/ldtteam/minecolonies/pull/2845
https://github.com/ldtteam/minecolonies/pull/2853
https://github.com/ldtteam/minecolonies/pull/2846
https://github.com/ldtteam/minecolonies/pull/2854
https://github.com/ldtteam/minecolonies/pull/2848
https://github.com/ldtteam/minecolonies/pull/2852

Sort:  
  • Great coding story telling as always.
  • Did miss seing Minecraft images in this post, such eye candy!
  • Awesome job on the quality of the code.

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.
[utopian-moderator]

Oh, I will make one right now for the moment the farmer uses the compost =P, thanks for the review!

Thank you for your review, @helo!

So far this week you've reviewed 6 contributions. 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!

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

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!