Minecolonies & Smelter Workers

in utopian-io •  12 days ago

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.

Small Fixes:

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

Preparations:

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.

Setup:

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.

The AI:

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.

Pull Requests:

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

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!
  • Plenty of code samples, great 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? 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.52% 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.

Congratulations @raycoms! Your post received a small up-vote from @wod-game as little gift.
We are a small group of people who want to create the next big Video game for Steem.
Want to know more about us?
Steem: @wod-game
Discord: Click here!

Have a nice Day!

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!