Minecolonies & PvP Event Preparation

in #utopian-io6 years ago

Hi everyone, as announced in a previous post, Minecolonies now allows players to make colony vs colony wars using their guards.
Considering this we wanted to create an event for our players where they could engage in this.
For this reason, we created some additional mechanics:

  • Have guards accept modded armor;
  • Enable the possibility to generate loot drops of buildings which can be insta-placed with higher levels.

And following that, I fixed a bunch of bugs on the way.

And, besides that added some optimizations:

  • Have workers stack their items more efficiently in the inventory;
  • Avoid falling blocks from falling when placed by builder;
  • Fix TownHall reposition;
  • Fix builder advancing;
  • Fix smelter;
  • Fix female models.

Modded Armor:

There are a lot of different mods providing modded armor which makes it quite difficult to support them all and support them correctly.
We, therefore, accept all modded armor which follows the vanilla way of damage resistance and the vanilla way of armor slot mechanic.

Following our tests, all modded armors we tried until now worked fine.

First of all, I created a new armor rank which has a minimal level but no maximum level. (Previously we capped armors and the bottom and top level which made it difficult to diversify).

Then, I grouped all armor into the group, independent of their material:

Armors which similar levels as vanilla armor will be classified with the same level as the vanilla armor. Armors above this level will be classified with level 5.

This connected with removing the cap to armor level 4 (allowing armor level 5) automatically enabled the use of the modded armor parts.

Loot drops:

To create loot drops we need a few small things:

a) Need a command for this:

Which would depend on the parameters create a block with the data the player wants. And then give it to the player.

b) On placement of these with the build tool make sure they are pasted or leveled accordingly.

Therefore, it would retrieve the data from the block and give it to the setup method and paste it if needed.

And the setup method would adapt to the changes.

c)

Make sure workers don't work at the building if not built yet.
I had to make sure there is a variable in each building which tracks that.

Which is called on upgrade complete and persisted and loaded accordingly. (Also if not being able to load it we would have to decide accordingly if the building is built or not).

Efficient inventory handling:

To enable efficient inventory handling I cut this into two separate updates:

  • Efficient dumping into building
  • Efficient picking up of items

Efficient dumping:

Efficient handling means that we try to fill up existing itemStacks first and only then move the items into new slots.
To do this I created three new helper methods related to inventory handling.

The first method searches for the same slot and then merges it. If it doesn't find any it returns the initial stack.

The next method tries to do this merging and if not successful (meaning the resulting stack is not empty) it will try to do it the previous way finding the first empty slot.

The last one is related to providers (one inventory provider can have several handlers) and it tries to merge with all handlers first and if not successful tries to do it the old way.

After that, all I had to do was to switch the old methods out.

Efficient picking up:

Picking up works quite similar but instead of extracting the stack from another inventory we have a specific stack we want to add.

Again I added a bunch of helper methods analog to the previous time.

Similar to the previous one I created one merge method for this.

And then two methods which will call this.
First, a method which allows doing this without returning the rest stack, only returning a boolean.

Then, actually trying to merge it and if not possible put it in the first empty slot.

And afterward switching things out again:

Minor fixes:

Repositioning was messed up because we would set the building null in case of the town hall, but since the building code was changed this would crash the repositioning process. So I removed this part.

Additionally, the builder wasn't able to jump over the blocks he wouldn't need to change accordingly. Because of the wrong comparison.

Falling blocks were placed in mid-air which would cause them to fall, therefore we set if there is no solid block under a falling block we would request and place it.

Fixing Models:

A few of the female models were not working fine since the models were manually rendered and therefore were not flexible enough to sit down for examples. Additionally, the hair was not connected to their head so it changed depending on the head position.

For this reason, I had to adapt the position of the various models and change the position several times.

A funny hack I discovered to improve debugging this helped me with it:

Changing models during runtime is difficult because all models are usually statically loaded on load.

To go around this restriction and avoid restarting after every change I added injection code in the debug watches.
Then, I only had to set a debug point to a position where these were called and it would inject a newly loaded model.
This way I'd runtime inject the new code and runtime inject the new model.

Tree Rework:

Additionally, I reworked our sapling handling a bit.
Saplings were not discovered correctly since several mods only allowed discovery on the client side.

Therefore I changed the code to run on the client side and then synchronize the saplings to the server if the client wants to accept them or needs to read it in the GUI.

For that reason, I had to change the list on the server side to be the list of trees the lumberjack should not cut, and that he cuts on default all trees. This way we would only have to sync the trees if the client clicks one to be not cut.

Repository:

https://github.com/ldtteam/minecolonies

Pull Requests:

https://github.com/ldtteam/minecolonies/pull/2803
https://github.com/ldtteam/minecolonies/pull/2815
https://github.com/ldtteam/minecolonies/pull/2821
https://github.com/ldtteam/minecolonies/pull/2816
https://github.com/ldtteam/minecolonies/pull/2822

Sort:  

Thank you for the contribution. Again a nice work, though for https://github.com/ldtteam/minecolonies/pull/2822 I can see commits from other people too, its best to have a separate pull requests if any one else if also working on the project.

I can see you are doing if(ItemStackUtils.isEmpty(sourceStack)) (https://github.com/ldtteam/minecolonies/pull/2816/commits/703a331a1e7190985224d375286d98dea48632a8#diff-9948b3cd348957b8ea81320a5cde628eR1522) in quite a few places, is there a reason for it.

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]

Hi, about the commits of other people, I did the error and based my PR on his PR, so it showed these in the commit history as well. The model changes are all from me though.

We are using the ItemStackUtils method because it guarantees compatibility between different versions.

That's true but I was seeing a lot of If statement doing the same thing in the same function.

It's because:
We try to put it in the inventory, if it is successful the itemStack turns empty, so if it is empty we can return it, therefore, after each attempt we have to check for that.
So once for all merge attempts and then once for all empty slot attempts.

Thank you for your review, @codingdefined!

So far this week you've reviewed 8 contributions. Keep up the good work!

Hey, @raycoms!

Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Get higher incentives and support Utopian.io!
Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via SteemPlus or Steeditor).

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

Great concept and I really like it. Keep it up.

Good conten

Friendly reminder @raycoms your lease of 1000 SP to me has expired.

Thanks for reminding me, was just about to undelegate =)

I've left you a comment pertaining user retention.

Coin Marketplace

STEEM 0.30
TRX 0.11
JST 0.033
BTC 64320.07
ETH 3154.23
USDT 1.00
SBD 4.34