Minecolonies & Waypoints & Tons of Fixes by raycoms

View this thread on steempeak.com
· @raycoms ·
$180.79
Minecolonies & Waypoints & Tons of Fixes
Hey everyone, I had a really productive weekend after the end of the semester and I got a lot of old bugs flattened out and things added to the mod.

Waypoint rendering:
---

First of all, I added back the waypoint rendering. Minecolonies adds waypoints on structures like streets and lamps etc. to help the pathfinding of the citizen. We do this since Minecraft pathfinding is very costly and, therefore, we added our own system based on waypoints which we deploy all over the colony. But, unfortunately, after updating a few of our rendering classes our all system to render these points didn't work anymore and we had to rewrite it.

![](https://i.imgur.com/8s7MMIF.png)


For this, we have a client event handler class.

![](https://i.imgur.com/cYqIwE9.png)

Which in turn has to subscribe to the render event which is being called every render tick on the client.

![](https://i.imgur.com/VDxI7k5.png)

From there, we check if the user wants to render a structure with a waypoint in it atm. And, if so, if this structure belongs to the waypoint group (infrastructure) and if it is inside a valid colony.

![](https://i.imgur.com/EGkCiFh.png)

Now, we calculate the relative position of the player entity in relation to which we will have to render the waypoints.

Then, we instantiate a structure template of the waypoint itself (Only needs to be done once per client session for performance reasons).

![](https://i.imgur.com/o0IVvjI.png)

Afterward, we only have to run through all waypoints within a colony.
Calculate the relative position compared to the player.
And call our template renderer for each of this positions and offsets.

Fixes:
---

Now, while I was debugging the colony I ran into a whole bunch of fixes all over our systems. I spent 2 full days debugging a colony flattening out all bugs which annoyed me on the way.

As small visual bugs as too long lists:

![](https://i.imgur.com/nAaJ8aD.png)

As guards teleporting on roofs because they are stuck, which I prevented by limiting the y difference they can teleport.

![](https://i.imgur.com/15BZCzJ.png)

As fixing an issue where citizens should sleep during barbarian attacks but they didn't obey because we handled it in the AI and not in the decision if they should sleep or not.

![](https://i.imgur.com/wyckty0.png)

> So I added the above to the sleep decision and removed it from the AI.


I also fixed the death penalty of citizens when barbarians are close:

![](https://i.imgur.com/ozT7zPb.png)


> If a citizen gets killed by a player in a colony the happiness of the colony falls to 1, but sometimes they are killed by accident while fighting the barbarians, so they shouldn't affect the happiness so strongly.

The problem was that a new citizen with the wrong position had been taken to check the position and not the citizen we were executing this in.

We also had to make sure that the horde is calculated correctly as barbarians might not be killed and might despawn.

![](https://i.imgur.com/j4dlL8g.png)

Therefore, we added a cleanup task to the method which checks if the entity still exists.

And finally, what took me weeks to figure out:


Request System fixes:
---

Minecolonies is built on top of a complex request system which allows workers to do asynchronous and synchronous requests (blocking and non-blocking).

Now, I fixed one small bug, which triggered two other bugs which I resolved afterward.

I had placed a cook which requested food, but although there was food in the warehouse the deliveryman didn't deliver it.

I debugged this and found out that the request only tries to resolve exact quantity matches.

Therefore, I removed the exact quantity match of all requests.

![](https://i.imgur.com/nw0A4H2.png)

![](https://i.imgur.com/BGNfxle.png)

etc...

Unfortunately, sometimes workers like the cook and smelter executed async requests and got stuck in an infinite resolving loop.
I only recently found out that this happens because their building tries to resolve their requests.

After I had deployed the above fix this started happening really often and I found out this was caused by the following:


> The cook wants to have at least 120 food at all times at his building to be able to supply all possible workers
> The cook will request 64 food since he has less than 120.
> The cooks building notices it has 20 food which is not enough, but since it doesn't need to resolve it exactly it will tell the cook that it can solve the request.
> The cook will then try to pick it up and notices he hasn't enough and he creates another request which in turn the building instantly accepts.

After I found out how this was happening I figured that buildings actually do not need to resolve non-blocking requests since all over our code, the AI actually checks if the buildings have enough and then requests if not, or retrieves from the building if it has the required item.
This means the building resolver should skip these.

Therefore, I added a check to the building resolver to avoid resolving asyn tasks:

```
if (building.getCitizenForRequest(request.getToken()).isPresent() && building.getCitizenForRequest(request.getToken()).get().isRequestAsync(request.getToken()))
{
    return false;
}
```

and I added to the resolver that the async task list is filled before sending the request to the system to be assigned to a resolver.
(Else the resolver wouldn't be able to detect it).


```
/**
     * Create a request for a citizen.
     * @param citizenData the data of the citizen.
     * @param requested the request to create.
     * @param async if async or not.
     * @param <R> the type of the request.
     * @return the Token of the request.
     */
    public <R extends IRequestable> IToken<?> createRequest(@NotNull final CitizenData citizenData, @NotNull final R requested, final boolean async)
     {
        final IToken requestToken = colony.getRequestManager().createRequest(requester, requested);
        if (async)
        {
            citizenData.getJob().getAsyncRequests().add(requestToken);
        }
        addRequestToMaps(citizenData.getId(), requestToken, TypeToken.of(requested.getClass()));
 
        colony.getRequestManager().assignRequest(requestToken);

```

And then to the calling methods, the boolean if async or not:

![](https://i.imgur.com/DhOXju2.png)


But the happy end was not quite there yet.

After deploying this I noticed that the loop was broken but that the worker requested it and the request was only once checked against the resolvers and then never again touched.
I debugged the retrying resolver for a while until I noticed that it didn't have a correct instance of the request manager to reassign the request.

What I quickly fixed by assigning a valid one before each call to the resolver.

![](https://i.imgur.com/0szr3Vp.png)

Our players are pretty psyched by the new update since it will make minecolonies way more stable and the cook finally a reliable provider of food in their colony.

I hope you enjoyed this little update. Until the next time!


Pull requests:
https://github.com/ldtteam/minecolonies/pull/2630/files
https://github.com/ldtteam/minecolonies/pull/2627
πŸ‘  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
πŸ‘Ž  
properties (23)
post_id56,824,475
authorraycoms
permlinkminecolonies-and-waypoints-and-tons-of-fixes
categoryutopian-io
json_metadata{"image":["https:\/\/i.imgur.com\/8s7MMIF.png"],"tags":["utopian-io","development","gaming","technology","programming"],"app":"steemit\/0.1","links":["https:\/\/github.com\/ldtteam\/minecolonies\/pull\/2630\/files","https:\/\/github.com\/ldtteam\/minecolonies\/pull\/2627"],"format":"markdown"}
created2018-07-17 12:55:09
last_update2018-07-17 12:55:09
depth0
children9
net_rshares86,370,841,156,060
last_payout2018-07-24 12:55:09
cashout_time1969-12-31 23:59:59
total_payout_value150.852 SBD
curator_payout_value29.939 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length7,158
author_reputation120,534,427,956,805
root_title"Minecolonies & Waypoints & Tons of Fixes"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (52)
@gaurang ·
As you are Debugging it will certainly solve your problem.Eager to play it when completed. @raycoms
properties (22)
post_id56,827,985
authorgaurang
permlinkre-raycoms-minecolonies-and-waypoints-and-tons-of-fixes-20180717t133033524z
categoryutopian-io
json_metadata{"users":["raycoms"],"tags":["utopian-io"],"app":"steemit\/0.1"}
created2018-07-17 13:30:36
last_update2018-07-17 13:30:36
depth1
children0
net_rshares0
last_payout2018-07-24 13:30:36
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length99
author_reputation1,119,151,519,991
root_title"Minecolonies & Waypoints & Tons of Fixes"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@emtecks ·
I am not a dev myself, but it's always really entertaining for me to read such posts here, thanks a lot for sharing! 
I've actually been doing some "historical" gaming posts lately, covering noteworthy games released in certain years (just made two about 93 and 2000) and I was wondering if you also work on any projects of your own?
πŸ‘  
properties (23)
post_id56,830,695
authoremtecks
permlinkre-raycoms-minecolonies-and-waypoints-and-tons-of-fixes-20180717t135819908z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steemit\/0.1"}
created2018-07-17 13:58:18
last_update2018-07-17 13:58:18
depth1
children0
net_rshares521,838,392
last_payout2018-07-24 13:58:18
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length333
author_reputation655,641,849,417
root_title"Minecolonies & Waypoints & Tons of Fixes"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (1)
@themarkymark ·
Mine Colonies is an awesome mod, need to start a new world with my son and give it a go again.
πŸ‘  
properties (23)
post_id56,832,556
authorthemarkymark
permlinkre-raycoms-minecolonies-and-waypoints-and-tons-of-fixes-20180717t141727674z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steemit\/0.1"}
created2018-07-17 14:17:24
last_update2018-07-17 14:17:24
depth1
children1
net_rshares9,336,469,493
last_payout2018-07-24 14:17:24
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length94
author_reputation806,615,692,176,612
root_title"Minecolonies & Waypoints & Tons of Fixes"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (1)
@raycoms ·
We've had a bunch of progress in the last months, it should be quite a smooth experience now
properties (22)
post_id56,832,852
authorraycoms
permlinkre-themarkymark-re-raycoms-minecolonies-and-waypoints-and-tons-of-fixes-20180717t142104445z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steemit\/0.1"}
created2018-07-17 14:21:03
last_update2018-07-17 14:21:03
depth2
children0
net_rshares0
last_payout2018-07-24 14:21:03
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length92
author_reputation120,534,427,956,805
root_title"Minecolonies & Waypoints & Tons of Fixes"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@helo ·
$0.03
* Great work, beautiful code.
* Did that issue get resolved?
> `return OreDictionary.itemMatches(getStack(), stack, matchMeta);`
> Please revert this Change. This contraticts the other behaviour of Stack.


Your contribution has been evaluated according to [Utopian policies and guidelines](https://join.utopian.io/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](https://review.utopian.io/result/3/1211111).

---- 
Need help? Write a ticket on https://support.utopian.io/. 
Chat with us on [Discord](https://discord.gg/uTyJkNm). 
[[utopian-moderator]](https://join.utopian.io/)
πŸ‘  , ,
properties (23)
post_id56,850,136
authorhelo
permlinkre-raycoms-minecolonies-and-waypoints-and-tons-of-fixes-20180717t173022840z
categoryutopian-io
json_metadata{"app":"steemit\/0.1","tags":["utopian-io"],"links":["https:\/\/join.utopian.io\/guidelines","https:\/\/review.utopian.io\/result\/3\/1211111","https:\/\/support.utopian.io\/","https:\/\/discord.gg\/uTyJkNm","https:\/\/join.utopian.io\/"]}
created2018-07-17 17:30:21
last_update2018-07-17 17:30:21
depth1
children3
net_rshares16,394,068,463
last_payout2018-07-24 17:30:21
cashout_time1969-12-31 23:59:59
total_payout_value0.026 SBD
curator_payout_value0.007 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length696
author_reputation119,612,833,307,875
root_title"Minecolonies & Waypoints & Tons of Fixes"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (3)
@raycoms ·
$0.05
Yeah, we discussed this over Discord.
The function has two possible returns, and the second return was already matching it independent of the stack size, and he hadn't seen that.
πŸ‘  
properties (23)
post_id56,860,432
authorraycoms
permlinkre-helo-re-raycoms-minecolonies-and-waypoints-and-tons-of-fixes-20180717t193514306z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steemit\/0.1"}
created2018-07-17 19:35:15
last_update2018-07-17 19:35:15
depth2
children2
net_rshares22,159,149,771
last_payout2018-07-24 19:35:15
cashout_time1969-12-31 23:59:59
total_payout_value0.045 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length178
author_reputation120,534,427,956,805
root_title"Minecolonies & Waypoints & Tons of Fixes"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (1)
@helo ·
Great work as always. Keep them coming, they’re a joy to review. 
properties (22)
post_id56,860,728
authorhelo
permlinkre-raycoms-re-helo-re-raycoms-minecolonies-and-waypoints-and-tons-of-fixes-20180717t193909878z
categoryutopian-io
json_metadata{"format":"markdown","links":[],"tags":["utopian-io"],"community":"busy","users":[],"image":[],"app":"busy\/2.5.3"}
created2018-07-17 19:39:12
last_update2018-07-17 19:39:12
depth3
children1
net_rshares0
last_payout2018-07-24 19:39:12
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length65
author_reputation119,612,833,307,875
root_title"Minecolonies & Waypoints & Tons of Fixes"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@utopian-io ·
Hey @raycoms
**Thanks for contributing on Utopian**.
We’re already looking forward to your next contribution!

**Want to chat? Join us on Discord https://discord.gg/h52nFrV.**

<a href='https://v2.steemconnect.com/sign/account-witness-vote?witness=utopian-io&approve=1'>Vote for Utopian Witness!</a>
properties (22)
post_id57,060,478
authorutopian-io
permlinkre-minecolonies-and-waypoints-and-tons-of-fixes-20180719t144009z
categoryutopian-io
json_metadata{"app":"beem\/0.19.42"}
created2018-07-19 14:40:09
last_update2018-07-19 14:40:09
depth1
children0
net_rshares0
last_payout2018-07-26 14:40:09
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length299
author_reputation152,913,012,544,965
root_title"Minecolonies & Waypoints & Tons of Fixes"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000