Minecolonies & The Library

in #utopian-io6 years ago

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).

How it's done:

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).

Do citizens die in their sleep?

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

Repository:

https://github.com/ldtteam/minecolonies

Pull Requests:

https://github.com/ldtteam/minecolonies/pull/2747/files
https://github.com/ldtteam/minecolonies/pull/2741/files

Sort:  

Thank you very much for your contribution. I can see you have have some string constants in your source code this will have potential problems e.g. string comparison case inconsistency. You could use enum type which I think could be better and make your code more readable. Also, boolean parameter is kinda code smell you could have putToSleep or wakeMeUp method instead.

Overall, +1 for comments and getters/setters for private attributes!

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? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

Hi, thanks for your review, we actually use most of these Strings because we need these as resource strings as well to find the respective files (blockstates, models, textures, names, etc). Else we could use Enums, that's correct.

Thank you for your review, @justyy!

So far this week you've reviewed 3 contributions. Keep up the good work!

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.

Vote for Utopian Witness!

Coin Marketplace

STEEM 0.31
TRX 0.12
JST 0.033
BTC 64605.91
ETH 3159.61
USDT 1.00
SBD 4.11