Minecolonies & You have Mail!

View this thread on: d.buzz | hive.blog | peakd.com | ecency.com
·@raycoms·
0.000 HBD
Minecolonies & You have Mail!
Hi everyone, exciting news in a collaborative effort we finally finished our crafting request system and can finally start building new things on top of that (the subject of the following posts).
Since I worked with this with another person I decided not to make a post about it since it would a) Become way too huge and b) A lot of work is mine, his, and all is entangled together so some parts are difficult to explain as well.
Nonetheless, this is the first feature we released based on this which is also going to allow us to test the workers nicely.


The PostBox:
---
![](https://i.imgur.com/ThMtyFL.png)

It's a nice box designed by one of our graphic artists.
It allows the player to request any block to his colony which the deliveryman would deliver and the crafter's craft on demand.

In that, it has a nice GUI which allows the player to select the block from a list of blocks.

The request then displays on the right-hand side so they can follow it through.

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

The code:
---

As always, everything starts with the new block.

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

Continuing with adding them to the modblock class.

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

Setting up the custom inventory model.

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


Creating the building:
![](https://i.imgur.com/dsJYtq7.png)


Registering the building:

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

Making sure it does not get loaded as other buildings with an actual building around it.

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

Then, added a method to the building view to get all requests of the building and not only the ones of a particular citizen.

But, it wouldn't be my PR if there wouldn't be a good bunch of refactoring involved.

That's why I extracted all the citizen window request code into an abstract class.

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

Which has a bunch of overridable methods when needed.

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

The citizen would just override the first one of them to request by a citizen and not by building.

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

And would override the fulfill methods to allow to fulfill requests to the citizen.

The window for the postbox wouldn't have to.

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

Since it only needs a button to create the request.
Where it would first extract the row of the stack to get the itemStack, then iterate through the children until it finds the quantity input field and assign the quantity to it and then execute the request message.

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


Creating the message which registers on the server side the request of the postbox.

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


Register message:

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

The message would then create a "-1 request" which is not assigned to any citizen but directly to the building.
Which allows us to request things by buildings and not only by citizens.

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




Fixes:
---

Besides that, it helped us to find a few bugs, for once the request system did not load from NBT as it should since there was a small issue in the loading code.

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


Barbarians were not breaking through doors:

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

Having all our buildings display their type above them by using their translation key.

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

Deliveryman only extracts the quantity he needs from the warehouse and not one stack.

Where I made a util method which exactly transfers a certain quantity over.

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

and then changed the method he uses for a custom method which calls this transfer method.

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

Also, added a canBeGathered method to the buildings where the dman can call that instead of having to know individually the types.

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


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

Also added the "prevWindow" variable to the detailed request view which makes it more modular and easier to transfer back to it.

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

So that, on button click, it wouldn't have to decide between the types but just open the previous window.

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


#### Repository: 
https://github.com/ldtteam/minecolonies

#### Pull Request:
https://github.com/ldtteam/minecolonies/pull/3236
👍 , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,