Skip to content
Permalink
Browse files

Add option to prevent leaves damaging the axe with TreeLopper

  • Loading branch information
me4502 committed Dec 3, 2019
1 parent c9d8182 commit df4dcf6855179fa56a38e9b771aaed3f8c054278
Showing with 12 additions and 5 deletions.
  1. +12 −5 src/main/java/com/sk89q/craftbook/mechanics/TreeLopper.java
@@ -89,9 +89,10 @@ public void onBlockBreak(BlockBreakEvent event) {
for(Block block : allowDiagonals ? BlockUtil.getIndirectlyTouchingBlocks(usedBlock) : BlockUtil.getTouchingBlocks(usedBlock)) {
if(block == null) continue; //Top of map, etc.
if(visitedLocations.contains(block.getLocation())) continue;
Material blockMaterial = block.getType();
if(canBreakBlock(event.getPlayer(), originalBlock, block))
if(searchBlock(event, block, player, originalBlock, visitedLocations, broken, planted)) {
if (!singleDamageAxe) {
if (!singleDamageAxe && (leavesDamageAxe || !Tag.LEAVES.isTagged(blockMaterial))) {
ItemUtil.damageHeldItem(event.getPlayer());
}
}
@@ -149,10 +150,12 @@ else if (data instanceof Tree)
visitedLocations.add(block.getLocation());
broken += 1;
for(BlockFace face : allowDiagonals ? LocationUtil.getIndirectFaces() : LocationUtil.getDirectFaces()) {
if(visitedLocations.contains(block.getRelative(face).getLocation())) continue;
if(canBreakBlock(event.getPlayer(), originalBlock, block.getRelative(face)))
if(searchBlock(event, block.getRelative(face), player, originalBlock, visitedLocations, broken, planted)) {
if (!singleDamageAxe) {
Block relativeBlock = block.getRelative(face);
Material relativeMaterial = relativeBlock.getType();
if(visitedLocations.contains(relativeBlock.getLocation())) continue;
if(canBreakBlock(event.getPlayer(), originalBlock, relativeBlock))
if(searchBlock(event, relativeBlock, player, originalBlock, visitedLocations, broken, planted)) {
if (!singleDamageAxe && (leavesDamageAxe || !Tag.LEAVES.isTagged(relativeMaterial))) {
ItemUtil.damageHeldItem(event.getPlayer());
}
}
@@ -168,6 +171,7 @@ else if (data instanceof Tree)
private boolean placeSaplings;
private boolean breakLeaves;
private boolean singleDamageAxe;
private boolean leavesDamageAxe;

@Override
public void loadConfiguration (YAMLProcessor config, String path) {
@@ -194,6 +198,9 @@ public void loadConfiguration (YAMLProcessor config, String path) {

config.setComment(path + "single-damage-axe", "Only remove one damage from the axe, regardless of the amount of logs removed.");
singleDamageAxe = config.getBoolean(path + "single-damage-axe", false);

config.setComment(path + "leaves-damage-axe", "Whether the leaves will also damage the axe when single-damage-axe is false and break-leaves is true.");
leavesDamageAxe = config.getBoolean(path + "leaves-damage-axe", true);
}

private static class SaplingPlanter implements Runnable {

0 comments on commit df4dcf6

Please sign in to comment.
You can’t perform that action at this time.