Minecolonies & Moving Buildings

in #utopian-io6 years ago (edited)

Hey everyone, I got some time yesterday and today again so I was able to work on something quite new and neat you'll love!

What changed:

I implemented a way to relocate existing buildings easily.
Let's imagine you had set your building already.

A nice level 5 citizen hut, now, if you want to move it you'd have to rebuild it, but of course, you don't want to have to build level 1-5 again to go through all steps.

For that reason, I added a way to relocate buildings easily.
If you go into the switch-style/upgrade window you can now choose reposition as an option.

And when you click on it it will open a quite familiar GUI.

Which allows you to move/rotate and mirror the building wherever you want.
If you want to review it just click etc and walk around the building to see the projection.

If you want to adjust it further you can go back in and adjust it more and then if you're ready you'll just click the green arrow.

The builder will then build this building at the level with all the stats and important levels and workers/inhabitants.

But how?

Let's dive into the code.

To code this I had to take care of a few things first.
Let's start easy.

First I needed a GUI, using our Blockout GUI library I first designed an XML for the layout.

And then linked the existing GUI to it.

In the next step, I created the Window class, which is the client-side representation of the GUI.

Fortunately, some of the code already existed of the building code and I only had to move it over, so I'll only go into detail for the new code parts I had to add to the code.

First of all, when creating the GUI, which happens from the previous GUI window, we add the building position and schematic name to it.

Which we then store as a local variable.

Then, to the most important and biggest part:
In the "onOpened()" method all the magic happens.

When opened we check if we're already rendering the structure if that is so we don't need to care about anything of it because it has been instantiated already.

We store the temporary objects in the Settings.instance variables which are a static client-side singleton which contains all information we require for rendering.

Therefore, we set the rotation and the mirror if required first as well as the position.

Then we get the structure-name from the name we saved locally previously.
The following code is identical to the code in the build tool which takes care if the structure file exists on the client already or if the client has to download it from the server.
In the end, if the file exists it gets set into the instance and the rendering will start.

After that, on confirm I had to create a message which takes care of the new placement. This message takes the name of the structure, the position, rotation, mirror and the building itself.

Within this class, we find the handle hut message which makes sure we are allowed to place this building and it makes sure that if the building is a townhall it gets removed before we place another one (because we allow only 1 townhall per colony).

In the next step, we set the style of the new building as well as the rotation and mirror and, most importantly the level.
If the building has a valid colony.

Then, the real work starts.

If the building is a worker building we have to copy all workers over, similarly if it's a home building we have to copy the resident data over.

For this, I had to make a public accessor method for the resident data in the building.

If it's a baker we have to copy over the unfinished baking products we store in the code and if it's a deliveryman we have to take care of the current deliveryman task.

Finally, we request a repair on the new building and then set the old building to air to remove it.

Then, to finalize it I had to register the message in the network.

And send it to our testers.

These reported some small issues like level 0 buildings can't be moved because they have no structure yet.

So I had to add a disable option for that to avoid crashes.
And people wanted that automatically a repair request was filed, which I showed in the above code already.

I hope you enjoyed this nice update.
A lot of our players were requesting this for quite a while already.

As in Issue #488.

I'll see you for the next update!



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

hackerman :)

wow! i love your creativity. hope we get to see more of this from u@raycoms

Thanks for the contribution. It has been approved.


Need help? Write a ticket on https://support.utopian.io.
Chat with us on Discord.

[utopian-moderator]

Hey @raycoms I am @utopian-io. I have just upvoted you!

Achievements

  • People loved what you did here. GREAT JOB!
  • Seems like you contribute quite often. AMAZING!

Utopian Witness!

Participate on Discord. Lets GROW TOGETHER!

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x

Great creativity and talent.. superb..

Coin Marketplace

STEEM 0.37
TRX 0.12
JST 0.040
BTC 70162.45
ETH 3540.43
USDT 1.00
SBD 4.79