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!