[API 7.0.0] 🌲 TreeDestroyage 14-DEV

One day, when I was farming trees once again I kind of wanted to be faster at it. I created a plugin to speed it up!
Now, when you use a golden axe (or whatever items specified in the config) on a tree, it will be fully destroyed upwards from the block you hit it at! Now that’s fast! Additionally you can configure if the item that’s used, gets durability damage.

:exclamation:Please note: The current recommended version is only partly tested! Please report any bugs!


Commands & Permissions

Main Permission (needed to destroy trees) TreeDestroyage.destroy

/trds reload: TreeDestroyage.reload
/trds set <option> [value]: TreeDestroyage.set

Using the set command you should be able to directly set configuration values.

Default configuration
    # Only activate when the player hits the very bottom of the tree.
    baseOnly=false
    # Whether the axe should also log the tree downwards.
    breakDownwards=true
    # Whether to consume durability from tools that support it.
    consumeDurability=true
    # Enable/disable this plugin functionality
    enabled=true
    # List of items that can be used as axe
    items=[
        "minecraft:golden_axe",
        "minecraft:diamond_axe"
    ]
    # Maximum amount of blocks that will be destroyed in one hit
    maxBlocks=200
    # Place the according sapling after logging the tree.
    placeSapling=true
    # Amount of time in seconds to protect the placed sapling. (0 to disable)
    saplingProtection=60
    version=7

:floppy_disk: - Download

Recommended version - 0.14-DEV (For Sponge 7.0.0API)
Jenkins for DEV versions (expect bugs and report them to GitHub please!)

Changelog & Source: GitHub - nylser/TreeDestroyage: Sponge plugin which introduces a tool/item to quickly farm trees!

Please report any bugs you encounter! Thank you! I’m always open for feature requests!

6 Likes

Does this drop the wood blocks or are the block just getting removed from the world?

They are dropped. Right now I’m dropping them using the /summon command because as far as I experienced the implementation of the data api isn’t far enough to support the different wood variants.

1 Like

Perfect. Exactly what i wanted :smile:

Another question/feature idea:
could you make the required tool (to use the plugin) configurable?

1 Like

Definitely a possibility! Will do it when I got some more time :slight_smile:

1 Like

Update: It’s now possible to change the required item/tool (it can be any Item in MC)

1 Like

Does this support marking the blocks destroyed by the tool as caused by the player? Would help logging / grief prevention plugins a ton.

Not yet but I think I can implement it. I’m just not sure how to do it. (Maybe fire a ChangeBlockEvent.Break with all the transactions and player as cause?)

With the newest version, it does.

The Data API currently supports log variants, I’ve managed to spawn some Birch Log using it.

1 Like

Oh nice, could you give me a code snippet of how you did it?

Item item = (Item) player.getWorld().createEntity(EntityTypes.ITEM, player.getLocation().getPosition()).get();
item.offer(item.getItemData().item().set(itemStack.createSnapshot()));
player.getWorld().spawnEntity(item, Cause.empty());

itemStack is the Birch Log ItemStack
player is the player at whose position the item will spawn.

Thank you, but actually my problem is creating the specific log ItemStack

Make it simpler:

Entity entity = player.getWorld().createEntity(EntityTypes.ITEM, player.getLocation().getPosition()).get();
entity.offer(Keys.REPRESENTED_ITEM, itemstack.createSnapshot());
player.getWorld().spawnEntity(item, Cause.of(myPluginInstance));

To actually make the ItemStack, you can do the following:

final ItemStackBuilder builder = plugin.game.getRegistry().createItemBuilder();
final ItemStack logItem = builder.itemType(ItemTypes.LOG)
  .quantity(1)
  .build();

Creating the Item works but setting the log type doesn’t work for me, which is what I assume isn’t implemented yet in SpongeForge.
(Using this code it only drops the log item with the default (or first) type:

BlockState state = blockSnapshotTransaction.getOriginal().getState();
Object trait = state.getTraitValues().toArray()[1];
Location loc = blockSnapshotTransaction.getOriginal().getLocation().get();
final ItemStackBuilder builder = getGame().getRegistry().createItemBuilder();
ItemStack itemStack = null;
if (state.getType() == BlockTypes.LOG) {
	itemStack = builder.itemType(ItemTypes.LOG).build();
	id = "minecraft:log";
	if (trait.toString().equalsIgnoreCase("oak")) {
		damage = "0";
		itemStack.offer(Keys.TREE_TYPE, TreeTypes.OAK);
	} else if (trait.toString().equalsIgnoreCase("spruce")) {
		damage = "1";
		itemStack.offer(Keys.TREE_TYPE, TreeTypes.SPRUCE);
	} else if (trait.toString().equalsIgnoreCase("birch")) {
		damage = "2";
		itemStack.offer(Keys.TREE_TYPE, TreeTypes.BIRCH);
	} else if (trait.toString().equalsIgnoreCase("jungle")) {
		damage = "3";
		itemStack.offer(Keys.TREE_TYPE, TreeTypes.JUNGLE);
	}
} else if (state.getType() == BlockTypes.LOG2) {
	id = "minecraft:log2";
	itemStack = builder.itemType(ItemTypes.LOG2).build();
	if (trait.toString().equalsIgnoreCase("acacia")) {
		damage = "0";
		itemStack.offer(Keys.TREE_TYPE, TreeTypes.ACACIA);
	} else if (trait.toString().equalsIgnoreCase("dark_oak")) {
		damage = "1";
		itemStack.offer(Keys.TREE_TYPE, TreeTypes.DARK_OAK);
	}
}

Entity entity = cause.getWorld().createEntity(EntityTypes.ITEM, blockSnapshotTransaction.getOriginal().getPosition()).get(); // 'cause' is the player
entity.offer(Keys.REPRESENTED_ITEM, itemStack.createSnapshot());
cause.getWorld().spawnEntity(entity, Cause.empty());

It is being implemented by @lucdon, but not finished. See the Issue on Github

1 Like

@nylser treedata is implemented

2 Likes

Update: newest version now drops item normally, not using commands anymore. Thanks to the TreeData implementation of @lucdon :smile:!

1 Like

Update to newest sponge version.

1 Like

This requires updating to the newest sponge.

Also, can you implement multiple axe items configurable, instead of just one?