Minecolonies & The better Builder!

8 comments

raycoms
70
12 days ago4 min read

Repository:

https://github.com/ldtteam/minecolonies
Hi everyone, one of the things I noticed when we had our Patreon competition was that one of the biggest bottlenecks was the speed of the builder. This was due to a number of reasons but mainly due to the numerous trips he has to make and how much he has to walk around in the building he is building.

For that reason, I changed a bunch of things around this to improve it.

I started by making sure that the builder would not take items with him he doesn't need in his current building phase.

Since he has two primarily important phases where he has to take items with him I separated into decorative and normal blocks.

Where I would check for a number of conditions to determine if a block is decoration or not.

And then, in the pickup code, I would check if the stage is not equal to the decoration stage and would then add the "is not a decoration" predicate to the pickup code.

Besides that, if his inventory is full but he wants to pick up more items I had him previously have a 50% chance to dump an item after a certain slot.

I now adjusted this to make it less likely to dump big stacks.

One of the main things I changed was allowing people to assign certain builders directly to a build request.

This is very useful since this way you can tell the closest builder to take care of a building which reduces the time to build essentially.

For that, I'd add in the window class (the code side of the client GUIs) for once a method which would get all builders from the colony and make sure it's the right builders as well.

  /**
     * Update the builder's list but try to keep the same one.
     */
    private void updateBuilders()
    {
        builders.clear();
        builders.add(new Tuple<>(LanguageHandler.format("com.minecolonies.coremod.job.Builder") + ":", BlockPos.ORIGIN));
        builders.addAll(building.getColony().getBuildings().stream()
                          .filter(build -> build instanceof AbstractBuildingBuilderView && !((AbstractBuildingBuilderView) build).getWorkerName().isEmpty() && !(build instanceof BuildingMiner.View))
                          .map(build -> new Tuple<>(((AbstractBuildingBuilderView) build).getWorkerName(), build.getLocation()))
                          .collect(Collectors.toList()));
        initBuilderNavigation();
    }

And then make sure they get displayed nicely in the dropdown list.

One of the requirements to make this work was to change the claiming code from claimed by a citizen to claimed by building and just having the main citizen displayed in the GUI.

Then, I would, on work order creation add the position of the builder as a possible parameter.
So, I'd first check if the distance is too far from any builder to be built (more than 100 blocks on default if the builder is not specifically assigned.)

Then, if there would be a directly assigned builder and he can build this building (in terms of level requirements).
He would accept it and claim it.

Important here was also, to make sure that if a builder has a request manually assigned to him, he would do those with a higher priority as well. Meaning, that when he checks for open work orders he would check first if there are any assigned to him.

final WorkOrderBuildDecoration order = list.stream().filter(w -> w.getClaimedBy() != null && w.getClaimedBy().equals(getLocation())).findFirst().orElse(null);
        if (order != null)
        {
            citizen.getJob(JobBuilder.class).setWorkOrder(order);
            order.setClaimedBy(citizen);
            return;
        }

The next thing I changed was adding a progress counter in the GUI.

For that, I would take the total quantity of blocks which has to be placed and compare it with the number of blocks which had been placed already and send the result to the client.

That would then be displayed and requested from the view of the builder.

To make sure we know the total number this would be stored in the work order the first time the builder scans for the required resources.
For backward compatibility, we would always calculate this if it is at 0 at the moment and we're recalculating it anyway.

I hope you liked this update, I certainly did because of the slow speed and repetitive running there and back from a faraway hut was starting to drive me crazy!
See you in the next update =)

Pull Requests:

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

Comments

Sort byBest