mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-27 15:17:59 +01:00
Fixed exception when breaking trees (whilst not looking at one) Closes #33
This commit is contained in:
parent
0a06dee124
commit
c59848544a
2 changed files with 9 additions and 8 deletions
|
@ -55,7 +55,9 @@ public final class TreeType {
|
||||||
return;
|
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<BlockPos> logs, Set<BlockPos> leaves, World w, BlockPos pos, int recurseLevel, int maxRecurse, Reactor logConsumer, Reactor leavesConsumer) {
|
private void traverseInner(Set<BlockPos> logs, Set<BlockPos> 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.
|
* Recursively locates the base of the tree.
|
||||||
*/
|
*/
|
||||||
public BlockPos findBase(World w, BlockPos pos) {
|
public Optional<BlockPos> findBase(World w, BlockPos pos) {
|
||||||
return findBase(new HashSet<BlockPos>(), w, new BlockPos.Mutable(pos.getX(), pos.getY(), pos.getZ())).get();
|
return findBase(new HashSet<BlockPos>(), w, new BlockPos.Mutable(pos.getX(), pos.getY(), pos.getZ()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Optional<BlockPos> findBase(Set<BlockPos> done, World w, BlockPos.Mutable pos) {
|
private Optional<BlockPos> findBase(Set<BlockPos> done, World w, BlockPos.Mutable pos) {
|
||||||
|
@ -124,7 +126,7 @@ public final class TreeType {
|
||||||
Set<BlockPos> logs = new HashSet<>();
|
Set<BlockPos> logs = new HashSet<>();
|
||||||
Set<BlockPos> leaves = new HashSet<>();
|
Set<BlockPos> 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();
|
int logCount = logs.size();
|
||||||
|
|
||||||
|
|
|
@ -67,10 +67,9 @@ public class EarthPonyKickAbility implements Ability<Pos> {
|
||||||
TreeType tree = TreeType.get(player.getWorld().getBlockState(pos));
|
TreeType tree = TreeType.get(player.getWorld().getBlockState(pos));
|
||||||
|
|
||||||
if (tree != TreeType.NONE) {
|
if (tree != TreeType.NONE) {
|
||||||
pos = tree.findBase(player.getWorld(), pos);
|
return tree.findBase(player.getWorld(), pos).map(base -> {
|
||||||
if (tree.countBlocks(player.getWorld(), pos) > 0) {
|
return tree.countBlocks(player.getWorld(), pos) > 0 ? new Pos(base) : null;
|
||||||
return new Pos(pos);
|
}).orElse(null);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue