Hey everyone, we recently developed a new building type for minecolonies which is quite exciting and I'm going to introduce you today.
The new library building which you can see in the above screenshot will provide the colony owner with a way to increase the skills of their citizens.
Citizens come to live with a fixed skillset which influences the speed their leveling.
Now, the library allows the player to hire certain citizens there (which won't lose the level of their previous job while being a student) and they will randomly level up while being employed there.
The max level again depends on their happiness and the amount of citizens which can be employed in the library is restricted by the library level (2x library level).
Now to do this I will walk you through the creation of a new hut/worker.
We start by creating a building block which extends the AbstractBlockHut class.
Then we register its block and item in the ModBlocks.java class.
Afterwards, we create the BuildingLibrary class which will have the specific building information as for example a list of the bookshelves and a list of the employed students.
It's quite important since it defines the schematic name, the job name and the job of the person employed at the building.
Then, we have to register the mapping of the building to the block.
Make sure the building information gets persisted (read and written to NBT)
And, as noted, define how many people can be employed at the building.
While I was at that I found a bug with having multiple people employed which wouldn't get saved accordingly which I fixed then.
The bug was that if the building would have an assigned citizen already it wouldn't store the others.
I also set up that workers don't lose their levels when switching from or to the student's job.
Then we need a job which has the job specific information for the building.
It defines also the model for example which has to be used for a job.
Most important though, is that it defines the used AI class.
Also will have to register the mapping then.
For the model, I had to add a blockstate, a block model, an item model and a recipe.
Would be a bookcase surrounded by planks with a build tool on top.
Also thanks to Imri for providing the model for this.
After that, we have to define the item model in the ClientProxy.java
Now, finally, for the AI I created the EntityAIStudy.
Which has one main A method which checks if the worker is valid and if so will retrieve a random bookshelf position? The path to it, stay there for a while and then try to level up before starting over.
To get the random bookshelf we use the positions we stored in the building which checks if the list is empty (Then he would stick to the building chest) and get a random position of the list and check if it's really a bookshelf (Else it would remove the position from the list).
Finally, to level up it makes a random calc to check if it should try to level up and then select a random skill to level up capping it at the current happiness.
(We mark dirty to make sure the data gets synchronized to the client to make it visible in the GUI).
Besides that, I fixed a bunch of issues with citizens dying while going to bed. The issue was that their bed position was roughly 2 blocks above their bed so they got stuck in the blocks above the bed and died.
What a painful death.
For that, I rendered them higher and decreased their position.
I also made sure that their bed position gets stored in their data so they don't lose it on restart.
And I turned off inWall damage while sleeping.
Which fixed a bunch of issues and should reduce 99% of all bug-related deaths of the citizen.
99% of not bug related deaths are player or barbarian related
https://github.com/ldtteam/minecolonies
https://github.com/ldtteam/minecolonies/pull/2747/files
https://github.com/ldtteam/minecolonies/pull/2741/files