Hi!
I would like to check if a log belongs to a tree to implement a tree breaking axe. Any ideas how to do the check? It should prevent destroying a whole house if it is built entirely with logs.
Thanks!
Hi!
I would like to check if a log belongs to a tree to implement a tree breaking axe. Any ideas how to do the check? It should prevent destroying a whole house if it is built entirely with logs.
Thanks!
The options I can think of
From a ChangeBlockEvent:
BlockSnapshot leaf = event.getTransactions().get(0).getOriginal();
if (leaf.getState().getType().equals(BlockTypes.LOG) || leaf.getState().getType().equals(BlockTypes.LEAVES)) {
if(!(leaf.getCreator().isPresent()))
{
restore = taskBuilder.execute(() -> restore(leaf)).async().delayTicks(100).submit(plugin);
}
}
} ```
Its basically creating a block snapshot, and if world gen placed it, no creator would be present... if a player placed it, it would be present. Obviously only trees would have logs... or you can check if the creator is identical to the player trying to break it...
I think player grown tree’s have an owner of player.
You are probably right, and I think I might have found that when I last used this code… but even if it gives OP an idea, it is worth sharing.
This is a good idea, also worth checking is the data on the leaves once found. player placed leaves behave differently to natural leaves, and there is blockstates to represent their lack of decaying!
That’s by far the most efficient way of telling.
The other option is just to say screw it, and let them tree-chop man made tree’s that they have permission to.
That’s very good! I looked for such a clever solution.
Thanks to all for the help!