Minecolonies & Some long-awaited improvements

in utopian-io •  2 months ago

Hi everyone, I was also able to do some long-awaited improvements since we were pushing out a bunch more updates and were needing some more stability again.

Fewer ticks:

One of the first things I did was wanting to reduce the server-side load.
Until now colonies even if their player is not around, we're still partially ticking every tick (20 ticks per second) which was causing some lag on servers with a few hundred colonies.

For that reason, I added in the server and world tick method of the colony as the first method call the detection of "subscribers" of the colony and would then not tick at all if no player is around.

After that, I added an active check in the colony.

Which I would update if the colony would tick following the rule I previously implemented.

The colony would until now write itself to file every time we store the list of colonies. But this is wasting a lot of programming time since the colony didn't change at all.

So we cache as previously the byte data and only write it if it is actually active or not existent.

And would then, when writing the colony just return the cached version.

Structures

A small fix I did also was that our structure builders would crash if they would run in the pickup mode after finalizing a structure and then reloading, so I added a safeguard.

Besides that, I added that builders finally accept existing entities in the world and only buildings them if they don't exist yet.

So, I added the getEntityAtPosition method which will search for an entity within a certain range which has the same position as another entity (the one we want to place)

    /**
     * Checks if a certain entity is in the world at a certain position already.
     *
     * @param entity the entity.
     * @param world  the world.
     * @return true if there.
     */
    public static boolean isEntityAtPosition(final Entity entity, final World world, final Entity placer)
    {
        final List<ItemStorage> existingReq = ItemStackUtils.getListOfStackForEntity(entity, placer);
        return world.getEntitiesWithinAABB(Entity.class, new AxisAlignedBB(entity.getPosition().add(1, 1, 1), entity.getPosition().add(-1, -1, -1)))
                 .stream()
                 .anyMatch(ent -> ent.posX == entity.posX && ent.posY == entity.posY && ent.posZ == entity.posZ && ItemStackUtils.getListOfStackForEntity(entity, placer).equals(existingReq));
    }

So that, when we try to place entities we verify if there is not a similar entity there yet.

Similarly, when getting the required stacks for a build we would also do that.

Placeholders:

Something which always bothered our structure builders was that when they used to build the barracks they had to be oddly specific with the placement of the tower block since it had a fixed difference.

To go around this limitation I created the barracks tower substitution block which they can now place in the schematic and it will serve as a source of rotation and location of the tower.

So the barracks building now stores the position of the tower.

It would get these on registering the block position when the builder builds the building.

Int his case we would check if the block is a barracks tower substitution block and if so replace it with a real barracks tower block with the correct rotation, assign it to this barrack and add it to the list.

So that we, on destroy are able to clean the positions up.

First of all, I added that the builder won't require that block to build the building.

By adding its own placement handler.

Small stuff:

Also, I changed that replacement blocks in the desert are sandstone and not dirt anymore.

Also made the feeding people only eat cooked food since that is more efficient and would complain if they only had uncooked food.

Also, I added that we now tell the player specifically which job the citizen had that died.

Besides that I allowed the sawmill worker (Crafter) to craft our own shingles as well.

        final Item item = storage.getPrimaryOutput().getItem();
        if (item instanceof ItemBlock && (((ItemBlock) item).getBlock() instanceof BlockShingle || ((ItemBlock) item).getBlock() instanceof BlockShingleSlab))
        {
            return true;
        }

Building GUI

Finally, I did some clean up in the hut build GUI.

In the hut build GUI, I changed the cancel button for repair.

And added the cancel button as a black X in the top right corner.

Which allows me to declutter the main GUI.

So I had to move the repair clicked method into this GUI class, allowing to assign a specific builder to it.

So where previously were two buttons, one for repair and one for building, the GUI only has one which makes it lay less cluttered.

Besides that in the building options GUI we got now only one small X button more but are now able to assign a builder specifically to a repair as well.

Many of these things were requested for a long time but didn't make their way up to the queue yet. Now that the crafters are starting to flow we are able to add a bunch of things of our big backlog to the game.

Pull Requests:

https://github.com/ldtteam/minecolonies/pull/3283/files
https://github.com/ldtteam/minecolonies/pull/3301/files
https://github.com/ldtteam/minecolonies/pull/3300/files
https://github.com/ldtteam/minecolonies/pull/3312/files

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 article, and we got more images!
  • So we check if active else we destroy, got it. ;-)
  • Code is awesome as always.

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!

Hallo, ich bin @nr5lebt.
Ein kleiner Testbot, dem dein Beitrag gefällt und dir ein Upvote da lässt. Vielleicht freust dich ja drüber.

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

Hi, @raycoms!

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

This post has been included in the latest edition of SoS Daily News - a digest of all you need to know about the State of Steem.

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!

hola! lo probare para ver que tal