Minecolonies & A new Worker in Town - The Smelter

2 months ago
62 in utopian-io

Hey everyone, besides refactoring our code extensively (as in here) I was also working at a new worker in the past weeks.

This worker is "The Smelter".

Before I talk more about his code some basic specs:

The Smelter is a worker quite similar to the cook. He basically requests ore and fuel to the colony (warehouse, or the player),
and when he receives this he will smelt the ore using the fuel.
Besides that, he's also able to deconstruct tools, weapons or armor the player doesn't need anymore.

In order to create a new Worker in Minecolonies you need the following classes:

Job - The job of the worker which tells you about his model, about his AI and store job-related information even to disk.
Block - The block the worker is connected with and which he uses to execute his job.
Building - The building which contains the block and stores information about the worker to disk as well (Which stays even after worker death).
AI - The actual AI of the worker which defines exactly what he does.

On the basis of that, I created the following classes.

And since we don't have a Model and texture yet, as you can see in the code we defined the current style to be the miner style until we have something more fitting.

Besides that, I had to request certain Building-styles to our community so the worker has a roof over his head and enough furnaces to actually work.

In the next step, I added a functionality to our request-system which allows each worker to request just "ore" and the warehouse will give him the first "ore" he can find.

Our coders did a really great job with the request system, which allows us to add quite generic classes of deliverable items and block which can be fulfilled by the deliveryman.

Then as a first step before implementing the AI, I had to define exactly what the AI has to do and I broke it down into the following basic tasks:

Which can be shortly described as:

  • Getting fuel
  • Smelting ore
  • Gathering things from the chests
  • Retrieving smelted things from the furnace
  • Breaking down tools etc in raw materials

I was then, finally able to start with the AI itself.

First of all, I connected the different AI states and how they'll be called in the constructor of the AI class:

Besides that, I defined that the worker is allowed to pick up items and what his best working skills are (used for leveling).

The most interesting part here is probably "Start-Working" since that is basically the task which starts off most of the other tasks.

When he starts working he first always checks if there is anything he can get from the furnace (if any ore is ready) if that is not necessary he will check if he has ore to smelt and if necessary request it.

After that he will check the furnaces he has and will decide if he a) Will go to retrieve ore since it's ready now or b) start smelting ore since there is ore in a furnace but its missing fuel.
If there is no furnace with anything to do he will try to deconstruct tools, weapons or armor he finds around his inventory.

I hope you liked our new worker, we're pretty happy to have one more great addition to our colonies, see you the next time!



Posted on Utopian.io - Rewarding Open Source Contributors

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:  trending
62
  ·  2 months ago

Thank you for the contribution. It has been approved.

You can contact us on Discord.
[utopian-moderator]

·
53
  ·  2 months ago

@raggaemuffin
minnowbooster you are managing didnt upvote my 5sbd order i did going to 2hrs now and as a first timer, i am most dissapointed as i needed my post to appear on hot. very sad for this. however, great work you guys are doing

·
·
62
  ·  2 months ago

WARNING: RPC Node lag. Currently behind: 9 hours and 32 minutes

And please don't hijack random comments, go to our discord…

65
  ·  2 months ago

Hey @raycoms I am @utopian-io. I have just upvoted you!

Achievements

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • You are generating more rewards than average for this category. Super!;)
  • Seems like you contribute quite often. AMAZING!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x

35
  ·  2 months ago

It's look rly nice keep going ill keep an eye on the project

34
  ·  2 months ago

Buen post de Gaming Technology Education Programming

44
  ·  2 months ago

thank you friend

34
  ·  2 months ago

Thank you for your valuable and useful information

34
  ·  2 months ago

Thank you for the contribution. It has been approved.

63
  ·  last month

Hi Ray, found this a couple of days ago. This will be my reference.

·
62
  ·  last month

Yeah this will definitely help you to start developing it.