From 52f643bba9293c8d9fb18b0787c73f5e6f0eae98 Mon Sep 17 00:00:00 2001 From: Sollace Date: Tue, 26 Jan 2021 22:33:26 +0200 Subject: [PATCH] Damage the tree with each kick and only break it when destruction reaches 100% --- .../minelittlepony/unicopia/TreeTraverser.java | 12 ++++++++++++ .../unicopia/ability/EarthPonyKickAbility.java | 16 +++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/minelittlepony/unicopia/TreeTraverser.java b/src/main/java/com/minelittlepony/unicopia/TreeTraverser.java index 4ef9645f..ef7ebb6a 100644 --- a/src/main/java/com/minelittlepony/unicopia/TreeTraverser.java +++ b/src/main/java/com/minelittlepony/unicopia/TreeTraverser.java @@ -118,6 +118,18 @@ public class TreeTraverser { return logs.size() <= (leaves.size() / 2) ? logs.size() + leaves.size() : 0; } + /** + * Counts the number of logs and leaves present in the targeted tree. + */ + public static Set getParts(World w, BlockState log, BlockPos pos) { + Set parts = new HashSet<>(); + + countParts(parts, parts, w, log, pos); + + return parts; + } + + private static void countParts(Set logs, Set leaves, World w, BlockState log, BlockPos pos) { if (logs.contains(pos) || leaves.contains(pos)) { return; diff --git a/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyKickAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyKickAbility.java index 77f9cfa8..29b35b1b 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyKickAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyKickAbility.java @@ -7,6 +7,7 @@ import java.util.Optional; import javax.annotation.Nullable; import com.google.common.collect.Lists; +import com.minelittlepony.unicopia.BlockDestructionManager; import com.minelittlepony.unicopia.Race; import com.minelittlepony.unicopia.TreeTraverser; import com.minelittlepony.unicopia.TreeType; @@ -93,15 +94,19 @@ public class EarthPonyKickAbility implements Ability { return; } - if (harmed || player.world.random.nextInt(5) == 0) { + BlockPos pos = data.pos(); + + BlockDestructionManager destr = ((BlockDestructionManager.Source)player.world).getDestructionManager(); + + if (destr.getBlockDestruction(pos) + 4 >= BlockDestructionManager.MAX_DAMAGE) { if (!harmed || player.world.random.nextInt(30) == 0) { - TreeTraverser.Remover.removeTree(player.world, data.pos()); + TreeTraverser.Remover.removeTree(player.world, pos); } iplayer.subtractEnergyCost(3); } else { - int cost = dropApples(player.world, data.pos()); + int cost = dropApples(player.world, pos); if (cost > 0) { iplayer.subtractEnergyCost(cost * 3); @@ -147,7 +152,12 @@ public class EarthPonyKickAbility implements Ability { private int dropApples(World w, BlockPos pos) { BlockState log = w.getBlockState(pos); int size = TreeTraverser.Measurer.measureTree(w, log, pos); + if (size > 0) { + BlockDestructionManager destr = ((BlockDestructionManager.Source)w).getDestructionManager(); + TreeTraverser.Measurer.getParts(w, log, pos).forEach(position -> { + destr.damageBlock(position, 4); + }); List capturedDrops = Lists.newArrayList();