diff --git a/src/main/java/com/minelittlepony/unicopia/TreeType.java b/src/main/java/com/minelittlepony/unicopia/TreeType.java index e2590413..334028dd 100644 --- a/src/main/java/com/minelittlepony/unicopia/TreeType.java +++ b/src/main/java/com/minelittlepony/unicopia/TreeType.java @@ -55,7 +55,9 @@ public final class TreeType { return; } - traverseInner(logs, leaves, w, findBase(w, start), recurseLevel, maxRecurse, logConsumer, leavesConsumer); + findBase(w, start).ifPresent(base -> { + traverseInner(logs, leaves, w, base, recurseLevel, maxRecurse, logConsumer, leavesConsumer); + }); } private void traverseInner(Set logs, Set leaves, World w, BlockPos pos, int recurseLevel, int maxRecurse, Reactor logConsumer, Reactor leavesConsumer) { @@ -89,8 +91,8 @@ public final class TreeType { /** * Recursively locates the base of the tree. */ - public BlockPos findBase(World w, BlockPos pos) { - return findBase(new HashSet(), w, new BlockPos.Mutable(pos.getX(), pos.getY(), pos.getZ())).get(); + public Optional findBase(World w, BlockPos pos) { + return findBase(new HashSet(), w, new BlockPos.Mutable(pos.getX(), pos.getY(), pos.getZ())); } private Optional findBase(Set done, World w, BlockPos.Mutable pos) { @@ -124,7 +126,7 @@ public final class TreeType { Set logs = new HashSet<>(); Set leaves = new HashSet<>(); - traverseInner(logs, leaves, w, findBase(w, pos), 0, 50, null, null); + findBase(w, pos).ifPresent(base -> traverseInner(logs, leaves, w, base, 0, 50, null, null)); int logCount = logs.size(); diff --git a/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyKickAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyKickAbility.java index bc52771c..6f9f011e 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyKickAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyKickAbility.java @@ -67,10 +67,9 @@ public class EarthPonyKickAbility implements Ability { TreeType tree = TreeType.get(player.getWorld().getBlockState(pos)); if (tree != TreeType.NONE) { - pos = tree.findBase(player.getWorld(), pos); - if (tree.countBlocks(player.getWorld(), pos) > 0) { - return new Pos(pos); - } + return tree.findBase(player.getWorld(), pos).map(base -> { + return tree.countBlocks(player.getWorld(), pos) > 0 ? new Pos(base) : null; + }).orElse(null); } }