Minecolonies & The Sifter

in #utopian-io6 years ago (edited)

Hi everyone, this time I coded the entire thing live and will even link of the videos here at the beginning of the post already.

Videos: Part 1, Part 2, Part 3, Part 4

Nonetheless, I'll still depict the main parts of the code in this post.

Crusher Changes:

In a first thing (as a preparation for the video) I improved the crusher to allow to configure the material he crushes in the config file so that he doesn't he need this hardcoded.

For that reason, I created a map containing the input and output stacks in the compatibility manager.

Which is going to get scanned and fill it with the data from the config file. Where I have separated two blocks with an exclamation point to parse the data on startup.

Where I would go through the config strings, try to parse the items, then try to parse metadata if possible and then fill the map.

In the building, I would store and load this data on load then.

Sifter Changes:

The sifter changes were quite similar. It has three data structures to store the meshes used to sift, the blocks which can be sifted and the data structure with the results.

Similar to other structures, we would shuffle the list in to obtain a random drop.

I am going to save you most of the discussion of the parsing code since I talk about it in the video a lot already.

The main difference to the crushing code is that I load all the drops first in a temporary map of maps of maps.

In order to load it afterward in the final map of maps of lists which contains the drops for a combination of blocks with meshes.

For this, I sum the probabilities and fill the rest with air.

At this point, I'll also save you the creation of the block and window classes which are very similar to the other workers (and shown int he videos).

To remember: I have to create a block, register it, create the building, register the building with the block and with the GUI. Create the job and also register the job with the building so I can register the AI with the job.

The GUI

One of the more interesting parts is the GUI where the player selects the block and can buy the mesh.

When creating the list of meshes we make sure we highlight the currently selected one and enable a button for the one we have the item in the inventory to buy.

Buying executes a message which selects the new mesh and decreases the stack in the inventory.

The AI

The AI is a bit simpler than the crusher since the sifter doesn't produce guaranteed outcomes he is not included in the request system.

We have one state to check if we have all the blocks we need to sieve.

And one state for actual sieving.
Where we first make sure he is at the building and faces his block, then check if his inventory is full or he already is over the daily max.

And then execute the sifting code which is very similar to the crushing code.

Pull Requests:

https://github.com/ldtteam/minecolonies/pull/3458
https://github.com/ldtteam/minecolonies/pull/3461

Repository

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

Sort:  

Thank you for your contribution. Nice work and the code looks clean in general.

  1. In here I don't see NumberFormatException should be thrown? Can you handle the exception instead without catch? the `catch in for loop in general has a performance hit.
  2. In here have you considered the case when indexOf returns -1?
  3. Can you move this outside the loop?
  4. Could the probablySum be accumulated to be more than 1?
  5. I understand in here you are parsing the string for probability, but may be better to re-structured this as a key value pair to speed up the performance.

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]

Thanks for reviewing my code.
1: Integer.parseInt here will throw it.
2 and 3: I think either chrome plays with me or the two links are the same as 1.
4: Yes when someone sets the config values wrong.
5: I wanted to take one which has the guaranteed indexes since I need to retrieve the mesh by index.

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

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

This post has been included in the latest edition of SoS Daily News - a digest of all the latest news on the Steem blockchain.

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!

Great post! I invite you to watch the last video on channel54

Coin Marketplace

STEEM 0.17
TRX 0.15
JST 0.028
BTC 62094.36
ETH 2436.39
USDT 1.00
SBD 2.50