Minecolonies & What we can do after Abstracting

in #utopian-io6 years ago

As announced in my last post here, the abstraction done there, opened a lot of new doors to easily develop new things.

Small adjustments:

When I started porting the other GUIs over I noticed that I needed a bit more functionality for a few of them.

For example, I needed the isInverted field to be able to switch between the "Whitelist" and "Blacklist" approach.
In general, all items in the list are considered on (allowed) and all besides that off (not allowed).
But in some cases like the lumberjack, we want the ones which are off (not allowed) to be in the list since that is more efficient.

This way, depending on the state of the field we have to set the button differently

if ((isInverted && !building.isAllowedItem(new ItemStorage(resource))) || (!isInverted && building.isAllowedItem(new ItemStorage(resource))))
                {
                    switchButton.setLabel(ON);
                }

I also noticed that the panes needed a way to set the parentView of an element since if this is not set buttons which are added to the view after construction would not work.

This way, on each addChild, I would also manually set the parent.

Also, I improved the StackList request to include a description field which would be displayed in the GUI to the player as a human-readable field and not only "StackList" as previously.

And then return this value when needed on the client side.

I also fixed a small bug with the walking distance of the workers where the wrong value and not a constant was being used.

What I was able to remove:

Due to the previous abstraction, I was able to remove:

Baker:

  • Most of the Baker Window

Reducing it to a page around the size of the composter window where only the blocklist query is different.

  • Most of the Baker Building code

Including everything related to the list, to deserialization or serialization, storing from and to disk etc and the same counts for the baker building client-side representation.

  • A bunch of the baker AI
    A lot of the baker AI class which was previously poorly managed with having the list store all items independent if on or off.
  • The Baker recipe message
  • The Baker GUI XML

Lumberjack:

  • Reduce the Window Class

The lumberjack class is a bit more complex because it is a) Inverted and b) needs extra functionality.
The beginning is quite similar, as in getting the blockList and extending the same class as the baker.

But, on open it would load a new button which allows toggling between replanting or not the saplings.

This is what I needed the add child method for.

And then needed to set up the replant button with the methods.

  • Reduce the building Class
    Where I was able to remove similar to the baker all the items which previously were needed to manage the list.

  • The lumberjack sapling selector message

  • The lumberjack GUI XML

After adding a bunch of new functionalities the first pull requests resulted in:

Long awaited features:

Which brings us to a bunch of long-awaited features based on the new abstractions.
People previously complained a lot that the smelter and cook would use quite expensive materials to fire the furnaces. With this new abstraction, it was very easy to add to their two GUIs the functionality to let the player select which materials they want them to use.

Which was just too easy.

For the windows:

For the building:

To allow to query this new info:

    /**
     * Getter for all allowed fuel from the building.
     * @return the list of itemStacks.
     */
    public List<ItemStack> getAllowedFuel()
    {
        return getCopyOfAllowedItems().stream().map(ItemStorage::getItemStack).peek(stack -> stack.setCount(stack.getMaxStackSize())).collect(Collectors.toList());
    }

And then add in the entity AI code of the workers a way to detect if no fuel is set and notify the player about it.

And then request the StackList instead of a burnable.

            worker.getCitizenData().createRequestAsync(new StackList(getOwnBuilding(AbstractBuildingFurnaceUser.class).getAllowedFuel(), COM_MINECOLONIES_REQUESTS_BURNABLE));

Pull Requests:

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

Repository:

https://github.com/ldtteam/minecolonies

Sort:  
  • Great article, showing what can be done with abstraction
  • Nice removal of code! Goodbye Baker & Lumberjack code.
  • Please tell me what kind of fuel to use in my furnace!

Here is an abstraction of your image as a gift:
minecroft.jpg

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? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

This is not the abstraction you are looking for =P

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

Your mod reminds me of the things that Minecraft desperately needs...

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!

Me gusta que este relacionado con minecraft ya que muchas personas no se atreven a compartir estas cosas ya probé esta minicolonia y me gusto .gracias por compartir cosas como esta nuevo seguidor

Hi, @raycoms!

You just got a 7.55% 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.