Minecolonies & Dynamic Tree's Mod Compatibility

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

H2
H3
H4
3 columns
2 columns
1 column
Join the conversation now