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