diff --git a/src/main/java/com/gmail/nossr50/skills/woodcutting/TreeFeller.java b/src/main/java/com/gmail/nossr50/skills/woodcutting/TreeFeller.java index 63ba8b0af..50f90c4e6 100644 --- a/src/main/java/com/gmail/nossr50/skills/woodcutting/TreeFeller.java +++ b/src/main/java/com/gmail/nossr50/skills/woodcutting/TreeFeller.java @@ -7,13 +7,11 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; import org.bukkit.entity.Player; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.inventory.ItemStack; import com.gmail.nossr50.mcMMO; -import com.gmail.nossr50.config.Config; import com.gmail.nossr50.datatypes.mods.CustomBlock; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.skills.Combat; @@ -70,36 +68,24 @@ public abstract class TreeFeller { * @param treeFellerBlocks List of blocks to be removed */ private static void processRecursively(Block block, List treeFellerBlocks) { - List futureCenterBlocks = new ArrayList(); - boolean centerIsLog = BlockChecks.isLog(block); - Block nextBlock = block.getRelative(BlockFace.UP); - - // Handle the block above 'block' - if (addBlock(nextBlock, treeFellerBlocks)) { - if (treeFellerReachedThreshold) { - return; - } - - if (centerIsLog) { - futureCenterBlocks.add(nextBlock); - } + if (!BlockChecks.isLog(block)) { + return; } + List futureCenterBlocks = new ArrayList(); World world = block.getWorld(); // Handle the blocks around 'block' - for (int x = -1 ; x <= 1 ; x++) { - for (int z = -1 ; z <= 1 ; z++) { - nextBlock = world.getBlockAt(block.getLocation().add(x, 0, z)); + for (int y = 0 ; y <= 1 ; y++) { + for (int x = -1 ; x <= 1 ; x++) { + for (int z = -1 ; z <= 1 ; z++) { + Block nextBlock = world.getBlockAt(block.getLocation().add(x, y, z)); + + handleBlock(nextBlock, futureCenterBlocks, treeFellerBlocks); - if (addBlock(nextBlock, treeFellerBlocks)) { if (treeFellerReachedThreshold) { return; } - - if (centerIsLog) { - futureCenterBlocks.add(nextBlock); - } } } } @@ -115,24 +101,26 @@ public abstract class TreeFeller { } /** - * Adds a block to the list of blocks to be removed + * Handle a block addition to the list of blocks to be removed + * and to the list of blocks used for future recursive calls of 'processRecursively()' * * @param block Block to be added + * @param futureCenterBlocks List of blocks that will be used to call 'processRecursively()' * @param treeFellerBlocks List of blocks to be removed - * @return True if 'block' was added */ - private static boolean addBlock(Block block, List treeFellerBlocks) { - if (BlockChecks.treeFellerCompatible(block) && !treeFellerBlocks.contains(block) && !mcMMO.placeStore.isTrue(block)) { - treeFellerBlocks.add(block); - - if (treeFellerBlocks.size() >= Config.getInstance().getTreeFellerThreshold()) { - treeFellerReachedThreshold = true; - } - - return true; + private static void handleBlock(Block block, List futureCenterBlocks, List treeFellerBlocks) { + if (!BlockChecks.treeFellerCompatible(block) || mcMMO.placeStore.isTrue(block) || treeFellerBlocks.contains(block)) { + return; } - return false; + treeFellerBlocks.add(block); + + if (treeFellerBlocks.size() > Woodcutting.TREE_FELLER_THRESHOLD) { + treeFellerReachedThreshold = true; + return; + } + + futureCenterBlocks.add(block); } /** diff --git a/src/main/java/com/gmail/nossr50/skills/woodcutting/Woodcutting.java b/src/main/java/com/gmail/nossr50/skills/woodcutting/Woodcutting.java index 0763a7c3b..b93c59bad 100644 --- a/src/main/java/com/gmail/nossr50/skills/woodcutting/Woodcutting.java +++ b/src/main/java/com/gmail/nossr50/skills/woodcutting/Woodcutting.java @@ -27,6 +27,7 @@ public abstract class Woodcutting { public static final double DOUBLE_DROP_CHANCE = AdvancedConfig.getInstance().getMiningDoubleDropChance(); public static final int LEAF_BLOWER_UNLOCK_LEVEL = AdvancedConfig.getInstance().getLeafBlowUnlockLevel(); public static final boolean DOUBLE_DROP_DISABLED = Config.getInstance().woodcuttingDoubleDropsDisabled(); + public static final int TREE_FELLER_THRESHOLD = Config.getInstance().getTreeFellerThreshold(); /** * Begins the Tree Feller ability