Minecolonies & Reworking Sapling and Ore Handling

in #utopian-io6 years ago

Hey everyone,

The last two days I was quite busy reworking the way we were recognizing ores and Saplings.

Previously our sapling code worked the following:

On placement of the Lumberjack we calculated all existing saplings. using the Forge OreDict which allowed us to find all existing.
These saplings we then stored in the Building of the Lumberjack in a Map with a boolean which describes if the lumberjack should cut it or not.

Now, this part was working well, but, when we were trying to recognize trees, we used the metadata from the log of the tree and the metadata from the sapling to check if we should cut it.
Now, this is quite bad since the saplings are often different blocks with completely different metadata. Therefore, modded trees just didn't respond to the restrictions and would even, if deactivated block our existing trees.

Therefore, I did the following to fix this:

I created a CompatabilityManager (which will also be used for Ores) to generate all saplings and ores once on gamestart.
It fills a list of saplings the buildings will query on load and on creation.
We do the same thing with the ores.

Additionally, I created a BiMap which stores leaves and saplings (Leaves as IBlockStates and Saplings as ItemStorage (Our own implementation of items).
This way, when the lumberjack finds a tree it will register the leave of the tree with the sapling it drops (We can't do this on startup since we don't have access to all leaveblocks in a certain position in the world yet).

So as visible in the picture we check if we registered anything to the sapling or leave yet and we try to get a blockState without any additional data (like rotation etc) to store it as clean as possible.

Then, everytime we encounter a tree we just query the list of saplings in the lumberjack, take a leave from the tree and check it with the leaveToSapling map to see if we should cut this tree or not.
Then after we cut it, we can decide on the basis of the leave which sapling to use.

This way we easily find all saplings for all trees and place the correct one.

Our previous ore code only considered ores which extend the default minecraft ore class, but, unfortunately, we noticed that most mods don't do that, therefore we load all ores which are "somewhat an ore" in the OreDictionary and register it, as the saplings, on game load.
The miner then only queries if the ores are in the list and can decide on basis of that if it is an ore or not.

Besides that I fixed a bunch of other bugs:

  • Double registering of buildings
  • Correct spawning and requesting of entities with the Request system
  • Correct ignoring of air spaces in whichever tileEntities.

I hope you liked our progress.
I'll keep you in touch.

Ray



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Congratulations @raycoms, this post is the forth most rewarded post (based on pending payouts) in the last 12 hours written by a Superuser account holder (accounts that hold between 1 and 10 Mega Vests). The total number of posts by Superuser account holders during this period was 1229 and the total pending payments to posts in this category was $8979.99. To see the full list of highest paid posts across all accounts categories, click here.

If you do not wish to receive these messages in future, please reply stop to this comment.

Thank you for the contribution. It has been approved.

You can contact us on Discord.
[utopian-moderator]

Hey @raycoms I am @utopian-io. I have just upvoted you!

Achievements

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • You are generating more rewards than average for this category. Super!;)
  • Seems like you contribute quite often. AMAZING!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x

yes i like it , it helps thank you for sharing this great post with us

Coin Marketplace

STEEM 0.31
TRX 0.12
JST 0.034
BTC 64742.01
ETH 3172.49
USDT 1.00
SBD 4.10