Minecolonies & New Scan Tool GUI
Hey everyone, during the weekend I was also able to improve one very important part of our mod, namely the scan tool.
The context:
The scan tool can be used to scan certain parts of the world to have the Minecolonies builder reconstruct copies of this.
This very functionality we use to scan in the buildings (Mine, Sawmill, Townhall) and connect the structure files with the buildings.
Then, when the player requests the construction of these buildings, the builder will be able to reconstruct them.
The scan tool enables us to scan in those building and decorations but also enables the player to create custom styles and decorations during play time, in single and multiplayer.
Additionally, it can be used to copy paste easily when in creative mode.
As an example the build tool GUI, it allows the player to adjust the buildings position and then approve it to let the builder build it, or use the buttons at the bottom right to paste it into the world in creative mode.
But let's get to the new feature.
How it was:
Previously, when the player or admin wanted to scan something he would use the scan tool (an in-game item) and right click the bottom right corner and then right-click the top left corner of the structure which selects the area. Then, after another right click, it would store the selected area as an NBT with a random name.
While this is fast, the player had to open the build tool to change the name.
Additionally, regularly we had issues with players which scanned in wrong blocks which are not obtainable for normal players or contained entities by accident.
Besides that, they also didn't have a confirmation of the area they selected.
And now:
Now, the scan tool got a nice GUI which opens on the last right click.
This GUI will display the position which can be edited in creative mode.
Additionally, it offers a way to suggest a name for the file.
And, finally, the player is able to check the resources within the scanned area.
This will allow the player to check if he scanned entities or unobtainable blocks.
For players who want to scan as fast as previously people can shift right click to scan in the area which will result in an instant scan on the last right click.
How it is done:
To achieve this I had to construct a number of things.
First of all, I had to create the GUI class as well as a style template.
Our GUI framework parses the XML to create a template which we'll be able to fill from the Window class.
This window class gets the resource prefix.
And registers button handlers on creation.
On being opened it then reacts to the content which it got on creation.
The button methods are quite straightforward.
Discard closes the GUI.
Confirm gets the new data from the GUI and sends it to the server to create the scan.
I'll get into that deeper later.
And show resources parses the number fields (it will close the GUI if invalid) and after that go through all blocks within the boundaries and calculate the blocks and entities within and add them to a map in the window class.
The code regarding the map already existed quite similar in some other places since it's the same code we use for the builder to tell the player which resources he needs for a certain build.
Finally, we detect the enter key, which triggers a recalculation of the resources.
Assuming the player would click enter after changing the values in the boxes.
Then, in order to trigger the GUI, I had to add a call to the scanTool item.
Particularly, to make sure it only opens if the player is not sneaking (shift right-clicking) and making sure this is only being called on the client side.
Last but not less important I had to create a message which sends the requisition of the scan to the server with the new data.
and register it to the network manager.
Besides that I had to refactor some methods in the code to be able to reuse some parts of the detection of entities and tileEntities in a certain area, to avoid re-inventing the wheel.
I hope you guys liked the new feature, I've used it a bunch already and it really increases the functionality and comfort but also productivity.
Pull request: https://github.com/Minecolonies/minecolonies/pull/2429
I'll see you the next time!
Thanks for the contribution. It has been approved.
Great post as always. I never have any doubt that a lot of work went into your posts.
Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]
Hey! I love minecraft! and I love building with symmetry, this can be an excellent tool to achieve it, thanks for sharing this friend! , the explanations are simple and specific, perfect!
good art
@raycoms we really enjoyed your new feature.and i personally appreciate you for your such kind of work
Resteem bot Service! Promote Your New Post.Find New Followers - Upvotes. Send 0.400 SBD to @stoneboy and your post url in memo and we will resteem your post to 9500+ followers from two different account.@stoneboy and @vimal-gautam.
Sweet option add up. Great efforts. I will endeavour to check it out soon.
i must try it out :D !! great work !! is there a guide on how to implement it ??
There are instructions on our GitHub on how to run it =)
Fantastic :=)
Hey @raycoms
Thanks for contributing on Utopian.
We're already looking forward to your next contribution!
Contributing on Utopian
Learn how to contribute on our website or by watching this tutorial on Youtube.
Want to chat? Join us on Discord https://discord.gg/h52nFrV.
Vote for Utopian Witness!
ooooooh yah baby
Sir good day is the new update fully functional for the minecraft accounts.. during buildings in the game is there no possibility that it will be crashed the game launcher. thank you for your answer. will appreciate your feedback.
Yes, it is fully functional. It shouldn't crash at all, if you find any crashes or bugs please report them on our github.
Thank you for your verification sir.