Minecolonies & Dynamic Tree's Mod CompatibilitysteemCreated with Sketch.

in #utopian-io6 years ago (edited)

Hi everyone, I'm SomeAddons and recently joined the Minecolonies Team. The first Task I contributed was the mod compatibility with the Dynamic Trees mod and minecolonies Lumberjack NPC, which I'll talk about a bit here.
2018-11-17_00.35.32.png

Dynamic Trees

Dynamic trees is a minecraft mod which adds dynamically grown trees and can be found on https://github.com/ferreusveritas/DynamicTrees

This image shows a dynamic tree which has various branches of different size, making them look more realistic:
2018-11-16_23.44.34.png

Now here is the default vanilla minecraft tree, which is a lot simpler as it only consists of a few wooden blocks and some leaves ontop:
2018-11-16_23.45.14.png

Compatibility

As can be seen dynamic trees are quite a bit more complex than the normal trees, especially if I want to chop them down with the Lumberjack NPC. Now to implement it I needed to make it optional since not every players is using the dynamic tree mod, so it is not always present. For this I've used a compatibility class with optional overrides.
In DynamicTreeProxy.java:

In DynamicTreeCompat.java:

We have a base method which always returns false and a method which contains the actual functionality but only overrides when the dynamic tree modID is present, this is how all compatibility functions at minecolonies work.
Checking a block for dynamic trees becomes simple as this:

Now since I can check for dynamic trees the actual logic for the Lumberjack can be created.

Tree detection

This is an important part for the Lumberjack NPC, as he has to recognize which blocks represent a tree. The checkTree method does it:

Here I check for Dynamic Trees blocks and it's growth using a radius property which says how large a dynamic tree branch has grown:

Default minecraft trees do not have a growth value like this at all, they're either still a sapling or fully grown.
Apart from growth dynamic trees are detected the same way as default minecraft trees, except that they do not have a top wood log, just a bottom one. Which works just fine since dynamic trees are felled by chopping its lowest wooden block, unlike normal trees where you have to chop every single block of the tree.

After detecting the tree I calculate its sapling from a leaf to let the Lumberjack replant the tree after felling. This is done by checking the Leafblock of the tree for its drops, in minecraft the saplings always drop from leaves.

Chopping Tree

Next after detecting the tree and which sapling to use to replant is chopping the dynamic tree. Until now "chopping" was done by replacing the wood block of the tree with air and putting it into the Lumberjacks inventory as drop, but this does not work for dynamic trees. For those you chop the lowest wooden block and the tree is completely felled. Luckily the dynamic tree mod has a method we can use to fell the tree. To use this I've added a runnable as optional block break action to the mineBlock method:

The runnable for dynamic trees uses a function implemented by dynamic tree's so it is created in the Dynamic tree compatibility class again:

Here I'm creating a fakeplayer entity which allows the Lumberjack to act as if a player would fell the tree, a fakeplayer is required to use dynamic tree's chopping method. Since fakeplayers are somewhat more expensive to generate I just create one per dimension and save them in a hashmap, using the dimension id as key.

Finally as a result the lumberjack does chop the dynamic tree:
2018-11-17_10.53.30.png

I hope you liked this little write-up, looking forward to write some more on further updates to minecolonies.

Repository:

https://github.com/ldtteam/minecolonies

Pull Request for further details:

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

Sort:  
  • Good post, it seems you've learned well from @raycoms.
  • Do my eyes deceive me? Blocks at an angle in Minecraft! Mind blown.
  • Great catch since the singular of leaves is not leave but leaf.

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]

Actually the "blocks at an angle" is smart use of an entity by dynamic trees :D

Thank you for your review, @helo! Keep up the good work!

Hey, @someaddons!

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 job, until now I didn't see yet how the dynamic trees look and get fell. Looks amazing!

Hello! Your post has been resteemed and upvoted by @ilovecoding because we love coding! Keep up good work! Consider upvoting this comment to support the @ilovecoding and increase your future rewards! ^_^ Steem On!

Reply !stop to disable the comment. Thanks!

Congratulations @someaddons! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

You published your First Post
You received more than 10 upvotes. Your next target is to reach 50 upvotes.

Click here to view your Board of Honor
If you no longer want to receive notifications, reply to this comment with the word STOP

Do not miss the last post from @steemitboard:

The Meet the Steemians Contest is over - Results are coming soon ...

Support SteemitBoard's project! Vote for its witness and get one more award!

Hi @someaddons!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your post is eligible for our upvote, thanks to our collaboration with @utopian-io!
Feel free to join our @steem-ua Discord server

Congratulations @someaddons! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

You made more than 10 upvotes. Your next target is to reach 50 upvotes.

Click here to view your Board of Honor
If you no longer want to receive notifications, reply to this comment with the word STOP

Do not miss the last post from @steemitboard:

The Meet the Steemians Contest is over - Results are coming soon ...

Support SteemitBoard's project! Vote for its witness and get one more award!

Congratulations @someaddons! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

You made more than 50 upvotes. Your next target is to reach 100 upvotes.

Click here to view your Board of Honor
If you no longer want to receive notifications, reply to this comment with the word STOP

Do not miss the last post from @steemitboard:

Meet the Steemians Contest - The results, the winners and the prizes
Meet the Steemians Contest - Special attendees revealed
Meet the Steemians Contest - Intermediate results

Support SteemitBoard's project! Vote for its witness and get one more award!

Congratulations @someaddons! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

You got your First payout
You received more than 50 as payout for your posts. Your next target is to reach a total payout of 100

Click here to view your Board of Honor
If you no longer want to receive notifications, reply to this comment with the word STOP

Do not miss the last post from @steemitboard:

Meet the Steemians Contest - The results, the winners and the prizes
Meet the Steemians Contest - Special attendees revealed

Support SteemitBoard's project! Vote for its witness and get one more award!

Congratulations @someaddons! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

You made more than 100 upvotes. Your next target is to reach 200 upvotes.

Click here to view your Board of Honor
If you no longer want to receive notifications, reply to this comment with the word STOP

Support SteemitBoard's project! Vote for its witness and get one more award!

Coin Marketplace

STEEM 0.15
TRX 0.12
JST 0.027
BTC 55213.27
ETH 2919.78
USDT 1.00
SBD 1.95