Minecolonies - More Workers!

in utopian-io •  8 days ago

Hi everyone, sorry for the absence over the last weeks, I've been quite busy and we've got quite some progress as well.

Let's head right into it.

The Workers:

One of the first thing I worked on after the last update were more crafter workers to help the sawmill.
Those were in this case primarily the stonemason and blacksmith.

This time I didn't have to setup the mappings since these blocks were in the game already although without functionality.

So I moved a good part of the sawmill code into the right class.

And then generalized some things to make them work for any type of crafter.

Resulting in the final AI code for the blacksmith only being mainly the constuctor and some javadoc.

Which is the same thing for the stonemason.

Then, I had to create two copies of the sawmill job as well (as well as abstract it) and make them fit for the stonemason and blacksmith.

The main interest and the main difference between the crafters then is mainly what type of recipe they may learn and execute.

Each of them has a canRecipeBeAdded function which controls this.

This function first checks in the super class if there is enough space in the building in terms of quantity of recipes.

Then checks if such a recipe exists.

And then it runs through the input and output.

In case of the blacksmith it would count the quantity of ingots.

It would then accept the recipe if it is some type of armor, sword or tool.

Or if all blocks of the recipe are ingots.

The same thing happens on the side of the stonemason.
But here it is a bit more difficult.
We have to check for once if the block is some kind of stone type.

This might either be because of the type of block or because of the id of the block (containing stone).

And then we make sure that the recipe doesn't contain sticks, wood, redstone or string.

And finally, we check if the min percentage of valid blocks is met.

The fix:

Nonetheless, when testing this I noticed that the deliveryman was constantly stealing items from the crafters which led to starvation.

I checked the code and the existing code which was making sure this doesn't happen was a bit confusing.

I removed all the existing code and rewrote it.

For this purpose we got a method called getRequiredItemsAndAmount which gets queried by the deliveryman when trying to get an item.

Here I would go through all citizens who work in the building, make sure they are crafters, get the assigned tasks to them from the datastore and then analyze this data.

Here I would retrieve the input from the system and then add them to the map while making sure to not any duplicate blocks which might confuse the deliveryman.
Finally, I would then add them to the map and return it.

This stopped the deliveryman running around stealing those blocks and made our crafters worker quite nicely.

Small Fixes:

A bit later I had some reports about crashing inventory accesses and decided to defuse our code a bit.

I'm a fan of defensive programming and consider the worst case.

So I defused our inventory access code to accept null inventories and added a log in this case.

Then, I noticed what was causing this crash and fixed it along this.
Since I was calling the tileEntity directly without trying to check if the tileEntity exists yet (which might not have loaded yet).

Which was a similar reason in the display string crash.

Pull Request:

https://github.com/ldtteam/minecolonies/pull/3249

Repository:

https://github.com/ldtteam/minecolonies

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:  
  • Great post again. Please give us more images!
  • I like the idea of defensive programming and defusing code. #LearningEveryday ;-)

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? Chat with us on Discord.

[utopian-moderator]

·

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

Hi, @raycoms!

You just got a 10% 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.

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!