Minecolonies & More Scan Tool & Fixes

in #utopian-io6 years ago

Hey everyone, a few days ago I introduced some nice changed to our scan-tool [here] which will make our lives way easier in the future regarding scanning in certain buildings for our mod.

Nevertheless, a few players wanted some additional changes they thought would be useful, so I implemented that right away as well.

Besides that, I fixed a small issue and found a huge source of our lag.

Let's start with the lag:

For quite a while now players were reporting issues with lag when night approaches. But, unfortunately, I was never able to figure out why.

Then, these days I got my fingers on this.

It's a warmroast analysis which shows the time each process needs in a certain method.
Surprisingly the method for this was the method which persists colony changes.

I got quite puzzled at first since a while ago I had pushed out a fix to this.

The approach of my fix was to wait a random amount of time when colony data changed until persisting the changes, this way not all colonies will persist their changes at the same time. While this helped a lot, it didn't entirely solve the problem.

But, when I went through our code the other day I found the issue.
Every time night approaches, we update the happiness of all colonies.
And, after updating the happiness, it would mark the colony "dirty" which means that the colony has to persist the changes.

Now, this has no impact on a single player game. But, on a server with over 300 colonies, this easily creates a huge issue.

The fix was really straightforward then:

Since we keep track of all players connected to a colony (Officer, Owner, etc) we just check if any of them are only and only then update the happiness.

Small hotfix:

Following that we had gotten a report about colonies crashing with certain mods.

I tracked it down just to the second line in the above screenshot.
We assume that if the builder searches a flowerpot at a location it will find it as well (Which in 99% of all scenarios works), but in some cases fails if the player or another worker removed it in a short timeframe.

The fix was quite easy as well. When the entity is null, we will create an entity with the right data.
Else, we'll update it as previously.

More Scan Tool:

Similar to the previous post I'll first show you guys what's new and then I'll get into the details.

#1:

The scan Tool now saves on the left click the first point and on the right click the second point (Previously you had to click right click for pos1, right click again for pos2 and then right click for the GUI).

The advantage of this is that you can easily change the position if you miss-clicked once.

Additionally, the GUI now opens when you right click in the air.

#2:

The Scan tool now got a nice box rendered around it which shows the boundaries (updates when you change the position).

#3:

There is now a search bar in the current blocks and entities list.

#4:

Improved search on all search bars.


Let's check out how I did each of these things.

First of all, I had to change a lot of things in the scan tool item class to detect a different kind of clicks.

"onItemRightClick" is just a right-click in the air which triggers the GUI.
Therefore, it tries to retrieve the position data from the item stack.
(We store it in the itemStack).

And then it checks if the player is sneaking or not and if it has been called on the server side in order to trigger the new window.

Then, in "onItemUse", which is triggered when right-clicking on a block I added that it only adds the 2nd position.

Now, unfortunately, there is no way to access a left-click action directly from the tool.

For that, I had to go into the general event handlers.
To be exact in the "onBlockBreakEvent".

In there I have to check for the type of tool.

Then, store the position in the tool, and afterward cancel the event (to make sure the block isn't going to break for real).

To make sure the block will really break I gave it the max destroy speed possible:

Following that, I added to our "Client Singleton" the position tuple...

and means to access it.

The Client Singleton is the class "Settings.java" which has a static instance on each client which we can access from anywhere but is unique to each client playing the game.
(We can't access this on the server side, only on the client-side as well).

On discard or success, we empty this variable.

And on opening the GUI we set it.

Now, that everything is setup we can take care of the rendering.

Rendering is usually done in an event class as well.

Particularly in the

public void renderWorldLastEvent(@NotNull final RenderWorldLastEvent event)

In there, we check if the box variable has the two values and if so we run into the following code.

In this code, we fetch the variables and make it that the bounding box we're going to include also includes the positive extremes.

Else the size would be -x to x-1 and -z to z-1 and -y to y-1 which isn't actually what we're searching for.

After that, we calculate the relative position from the player position where it should be rendered.

Since rendering happens relative to the player and not static in the world.

After that, we set the GlStateManager up.

Basically, we set up the type of thing we're going to render and the width of it.

After that, the Bounding box is created and handed to the manager.

And I tinkered hours to do it myself before I noticed that Minecraft actually had a method for that.

Now, the other issue we had, was that Minecraft has a bunch of names for everything.

Like, there is a block which internally is called clay but to the player is called terracotta.

Since a player might want both I added both to the filter.

Finally, I wanted to add a search box to the front page as well.
Unfortunately, the page was crowded already so I had a hard time finding the right spot.
But, fortunately, I had the idea to hide the button and show the input bar instead when the button is clicked to show the resources list.

After that, I set up the search filter as explained in the previous post again.

I hope you liked the new updates, our players are excited already to see it on our official server.

Pull requests:
https://github.com/Minecolonies/minecolonies/pull/2486
https://github.com/Minecolonies/minecolonies/pull/2481
https://github.com/Minecolonies/minecolonies/pull/2473

Sort:  
  • Very high quality post and well maintained repo
  • Your repo, PRs and commits are an example for us all.

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]

First I want to wish you congratulations for your blog is an excellent job I hope you follow me @luisa-pinto and can count on your support in my blog

Impresionante publicación. Gracias por compartirla.

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.15
JST 0.028
BTC 63064.93
ETH 2468.39
USDT 1.00
SBD 2.55