Hi everyone, the next worker after blacksmith and stonemason I wanted to work on was the Stone smelter (the worker which smelts certain variants of stone to create others).
For that, I had to move around quite some code since the existing crafting code wouldn't deal with it.
First I started with some small fixes.
First I found out why our teleport command failed because the position was one too high, mid air so it failed to find the floor.
Some cleaning up in the other classes around.
Allowing more than the max stack size (64 usually) to be requested with the postbox, by creating multiple requests if the stacksize is exceeded.
Canceling all requests on the firing of a citizen (to avoid infinite requests for not needed things).
Fixing fall damage with teleport by making the fall distance negative (so if a positive one is applied it cancels it out).
Creation of the block of the smelter hut.
Adding the newly created block to the mod block registry.
Adding a mapping of the block to the building.
Adding a mapping for the job.
And adding the custom model for the block for the inventory.
I moved some utility functions from the general smelter classes in the itemStack utils and added some documention.
Making some methods public and adding documentation to override them.
And finally, allowing to send the intermediate block when crafting to allow recipes with a furnace.
Now that we're prepared we need to setup all the classes we need.
One of the first things I needed was a GUI to teach these recipes.
As with the 3x3 recipes where we got a GUI to teach those we need it for the furnace as well.
This would be this class.
I will cut a few of the details here as of setting up the inventory since it is very similar to the existing code and I had to trim it down to the size I need (3 slots, input, output, fuel).
What really does matter is that we will try to calculate out of the input and output on every slot change by getting the stack in the input and putting it in the FurnaceRecipes class.
Once this is created, I had to add it to the GUIHandler so it does know when to open this GUI and no other.
But, having the container is not enough, since the container will handle things on the server side, I had to add programatically the client side window as well.
It handles the drawing of the container and especially, on button click, the addition of the new recipe and the trigger of the message to the server side.
After that I setup the job.
And also the building.
Since there will be a particular item handling in terms of which recipes are allowed I added an extra method to return true for all the block we want to allow to craft.
And, as you saw, it didn't extend the crafter building, it extended its own class.
This class has the filterablelist handling to be able to select the fuel but besides that copies a bunch of the crafting building behavior to make sure it works as well as the crafter building (sometimes we'd love to extend from more than one class).
Finally, because of that I setup the WindowHutStoneSmelter which is very similar to the other filterabellist windows.
Which brings us, finally, to the AI.
Which, as you can see, is very simple.
Because, I put all the code in an abstract class already (thought it would be that easy, did you?)
Now the actual AI class, got very big since it combines handling of the smelter AI and crafter AI.
In this sense, it has methods to receive things from the oven and to check for items in the oven as well as inhereting the crafter class for the crafting.
The most important method here is the craft() method.
This method will first check if it has recipe storage and else will abort, then make sure it is at the building, and then even check if the recipe needs a furnace, if no furnace is needed it can do the traditional crafting handling.
Following that it checks if there is any fuel registered and if there is an oven which needs retrieving.
If there is an oven to retrieve from it will retrieve and fulfill the requst with the result.
Finally, it will check if it has enough fuel in the inventory and building and else request.
If everything is already it will check if it is able to smelt.
Here the AI checks if it the furnace is too full to put anything in, if it finds a decent furnace it will use it.
Quite similar as in the normal smelter it would then fill the furnace, but differently, it will take as input only the current crafting input.
I hope you enjoy this new worker as much as our community does, and you'll hear soon from me.