Minecolonies & New Scan Tool Features

in #utopian-io6 years ago (edited)

Hey everyone, in one of my previous posts [this one]
I already announce our new scan tool GUI.

Which shows the player the list of blocks within a certain selected area.

Now, this update I enhanced this further (and we have even more planned!).

If a player is in the creative mode he is going to see the following screen now:

Which will allow him to remove certain entities or blocks before scanning, but also enables the player to replace a certain block for this area.

When he clicks on the "Replace button" the following GUI will open.

The GUI will show the player a browsable list of all blocks within the game (including modded blocks). The list is fully searchable and will check all blocks which contain the info:

Also, on selecting a block it will display the transformation at the top of the screen.

This also has been a bunch of works since blocks can have certain orientations.
The mechanic, therefore, respects the rotation and position of the block and replaces it accordingly.

An example with slabs:

Before:

After:

Another example with stairs.

Before:

Selection:

Block choice:

After:


Now, implementing this has been a bunch of work.

I'll separate it into a bunch of sub-issues:

  • Creating the GUI (XML)
  • Creating the GUI functionality (java)
  • Creating the messages to execute the functions.

Creating the XML:

Now, those of you which are following my blog now that we're having a nice framework for GUIs.

We create the XML (soon also jsons) which get parsed to define the style.

These elements include labels, item icons, lists, buttons and a bunch more.

Creating the GUI functionality:

We can split this up into two sub-steps:

  • Scan GUI
  • Replacement GUI

Scan GUI

In order to make this I had to enhance the scan GUI with some additional functionalities.

First, I had to add a list of entities since, until now, we only stored the blocks.

A string identifier and an entity storage.

I could've stored the string only, but we might want to display further information in the future.

Additionally, I extracted the list variables to be class-wide since we'll need to access them on several occasions.

Following that I registered the new buttons:

And the lists:

The code, to execute the messages is pretty much the same for all three methods then.

For those who aren't experienced Minecraft modders:
Minecraft is split into client and server side, certain actions have to be sent with a message to the server side to persist. GUIs are always on the client side, therefore, to make changes to the world, these have to be executed on the serverside and, therefore, require a message.

Then, I added a supplier for the list of entities:

Which works pretty straightforward.
It creates a list with the length of the entities and then, in the update element it will get filled from the list.

In order, to avoid, players on servers griefing the world, there will be a check which disables the button in that case.

I've also added the same check to the block list.
And a similar check within the messages to protect against hackers.

Replacement GUI

The replacement GUI is quite similar.

It also has a list of resources which will be updated using a list and filled with the info from it.

These list of resources will get filled by a method which runs through all blocks in the forge registry and checks if they match certain conditions.

In this case: We filter all blocks which are not item blocks but include item donors and we especially include Buckets of Lava and Water.

Additionally, we filter and check if the name contains a certain filter string.

Which we will fill on key typed.

On clicking DONE, we send another message to the world.
(If the block is empty we do nothing)

On Cancel, we open the previous GUI.

and on Select, we fill the selected block and add icon and name to the GUI.

Messages:

For the messages, I created three new classes and registered them in the class Minecolonies.java.

The code of the remove messages is quite similar and simple.

They pass through the selected area and remove the block/entity from the world matching a certain string.

The replace message, on the other hand, is a bit more complex as I mentioned earlier.

Again, we go through all blocks within a given range (Omitted in the image).

And check if the block matches the block we want to replace.
Then, we check if it is a door, or bed since these consist of two blocks but we only want to place/remove one of them

Following that we remove the old block, and make a copy of the block we want to place. In order to place an itemStack correctly in the world, we need to add a fake player to it (We don't want to use the player because we don't want to consider the player's rotation which affects the rotation of the block).

This includes setting up the held item and in some cases also the rotation of the fake player.

Then, we adjust the facing since this also affects certain blocks.

In this case Doors, Beds and slabs require EnumFacing.UP to place them correctly.

Finally, we go through a huge list of different handlings depending on the target block.

I omitted a part of it because it was too huge.

What we're basically doing is checking if the old block is of the same type as the new block and we give the new block the special attributes like the way they're facing, their shape etc.

Pull requests:
https://github.com/Minecolonies/minecolonies/pull/2470/files
https://github.com/Minecolonies/minecolonies/pull/2477

Sort:  

Thanks for the contribution!

Great job at creating an amazing overview of what you added and how you implemented it!

Is there a reason why some lines of code have more than 150 characters? In my opinion it would be best to limit it to a lower amount.

Click here to see how your contribution was evaluated.


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

Hi, thanks for the fast evaluation.
Our rule regarding max line length is set to 180 characters. We've chosen that since it's the max length which fits on 1 line.
Although, you're correct, in some cases we should probably add more line breaks for a better visibility.

Awesome code, great results! @raycoms I'm kind of new around here. What is #utopian-io for? I'd like to know more about github also.

Github is a repository for code (Where projects store their code to contribute to it).
Utopian-IO is a project which upvotes open-source contributions depending on the quality of the contribution.

Now I get it. Thanks!

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!

Coin Marketplace

STEEM 0.18
TRX 0.16
JST 0.031
BTC 62419.28
ETH 2628.28
USDT 1.00
SBD 2.56