Minecolonies & Fix Racks and Rework Placement handlers

in #utopian-io6 years ago

Hey everyone, I finally got some time for Minecolonies this weekend again and worked on a few essential things.

Minecolonies Racks:

First of all, a lot of players were complaining about issues with our racks (It's a block with a performance-optimized inventory).
Racks can be placed as a single block for a single inventory, or, if placed side by side, used as a double inventory.

When using them as a double inventory one of the racks has to become the main rack and has to take care of the inventory as well as of the rendering.

I noticed that we ran into problems with this since in the rack we stored the absolute position of the neighboring rack and not the relative.

Meaning: We stored the x,y,z where it is and not the x,y,z distance to the current rack.
This got us into issues because when we scanned racks at one position to paste them at another position they had stored the absolute positions in them which caused a row of issues.

First of all, I moved all constants in the class to our Constants and NBT Constants classes. This makes the file smaller and easier to maintain.

Then, I removed the neighbor field for the relative neighbor field.

This also showed me where I was using it.

Now, to guarantee backward compatibility, on loading of the rack in the world we check if it has the old neighbor tag, and if so we recalculate it:

Then, when the rack detects a neighbor change and it doesn't have another rack attached yet, it will now not store directly the position it will store the relative position.

Subtracting the current position from the neighbor position.

Then, when I want the real position I just subtract the relative position again.

I also make sure, that we do this right when we set the neighbor manually in code.

Now, I only had to replace all occurrences of the field "neighbor" with the subtraction to calculate the absolute position.

Another small fix for the rack included simplifying the client side update code by calling methods we already had (Removed duplicated code).

Placement handlers:

Now, since we did so much progress with the build and scan tool in the last weeks we decided to extract this into a separate mod to allow people to use it without minecolonies. But, this means we need to abstract the placement code of the structures so it does not depend on minecolonies classes.

This basically means to remove all occurrences of:

  • AIs from the placement code.
  • Minecolonies blocks from the placement code.
  • Of the colony or colony manager.

Which I did in three steps:

Step 1:

I enriched the IPlacementHandler interface by 2 additional methods:

  • CanHandle

So we don't call all placement handlers until we find one which does the job, but explicitly check if they do.

  • getRequiredItems

So we do not have to do the requesting in the placement handler but can do this in the AI itself.

Step 2:

I added a specific MinecoloniesPlacementHandler which receives all Minecolonies related blocks or blocks which need interaction with the colony.

This class then overloads the existing placement handlers methods.

And we call the init method when loading our mod to make sure it overrides the original placement handlers.

Step 3:

Move the tileEntity info from the AI to the placement handler.

TileEntities are special entities which enrich blocks with additional data until now the AI took care of it.

This also decreased the code a lot since we had part of this code in the AI and part of it in the structure handling (For the build and scan tool).

For this, we had to add the info to the call of the handle and getRequested items method.

Finally, I also fixed 2 small issues:

Replacing disable with hiding for buttons: (Disable bugs with image buttons)

Removing not necessary code:

This PR removed a lot of duplicated code and will allow us to extract a few parts into a separate mod.

Pull Request:

https://github.com/ldtteam/minecolonies/pull/2626

Sort:  

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!

Thank you for your contribution.

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]