mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-23 21:38:00 +01:00
Damage the tree with each kick and only break it when destruction reaches 100%
This commit is contained in:
parent
d1f6679882
commit
52f643bba9
2 changed files with 25 additions and 3 deletions
|
@ -118,6 +118,18 @@ public class TreeTraverser {
|
||||||
return logs.size() <= (leaves.size() / 2) ? logs.size() + leaves.size() : 0;
|
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<BlockPos> getParts(World w, BlockState log, BlockPos pos) {
|
||||||
|
Set<BlockPos> parts = new HashSet<>();
|
||||||
|
|
||||||
|
countParts(parts, parts, w, log, pos);
|
||||||
|
|
||||||
|
return parts;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private static void countParts(Set<BlockPos> logs, Set<BlockPos> leaves, World w, BlockState log, BlockPos pos) {
|
private static void countParts(Set<BlockPos> logs, Set<BlockPos> leaves, World w, BlockState log, BlockPos pos) {
|
||||||
if (logs.contains(pos) || leaves.contains(pos)) {
|
if (logs.contains(pos) || leaves.contains(pos)) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -7,6 +7,7 @@ import java.util.Optional;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
import com.minelittlepony.unicopia.BlockDestructionManager;
|
||||||
import com.minelittlepony.unicopia.Race;
|
import com.minelittlepony.unicopia.Race;
|
||||||
import com.minelittlepony.unicopia.TreeTraverser;
|
import com.minelittlepony.unicopia.TreeTraverser;
|
||||||
import com.minelittlepony.unicopia.TreeType;
|
import com.minelittlepony.unicopia.TreeType;
|
||||||
|
@ -93,15 +94,19 @@ public class EarthPonyKickAbility implements Ability<Pos> {
|
||||||
return;
|
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) {
|
if (!harmed || player.world.random.nextInt(30) == 0) {
|
||||||
TreeTraverser.Remover.removeTree(player.world, data.pos());
|
TreeTraverser.Remover.removeTree(player.world, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
iplayer.subtractEnergyCost(3);
|
iplayer.subtractEnergyCost(3);
|
||||||
} else {
|
} else {
|
||||||
int cost = dropApples(player.world, data.pos());
|
int cost = dropApples(player.world, pos);
|
||||||
|
|
||||||
if (cost > 0) {
|
if (cost > 0) {
|
||||||
iplayer.subtractEnergyCost(cost * 3);
|
iplayer.subtractEnergyCost(cost * 3);
|
||||||
|
@ -147,7 +152,12 @@ public class EarthPonyKickAbility implements Ability<Pos> {
|
||||||
private int dropApples(World w, BlockPos pos) {
|
private int dropApples(World w, BlockPos pos) {
|
||||||
BlockState log = w.getBlockState(pos);
|
BlockState log = w.getBlockState(pos);
|
||||||
int size = TreeTraverser.Measurer.measureTree(w, log, pos);
|
int size = TreeTraverser.Measurer.measureTree(w, log, pos);
|
||||||
|
|
||||||
if (size > 0) {
|
if (size > 0) {
|
||||||
|
BlockDestructionManager destr = ((BlockDestructionManager.Source)w).getDestructionManager();
|
||||||
|
TreeTraverser.Measurer.getParts(w, log, pos).forEach(position -> {
|
||||||
|
destr.damageBlock(position, 4);
|
||||||
|
});
|
||||||
|
|
||||||
List<ItemEntity> capturedDrops = Lists.newArrayList();
|
List<ItemEntity> capturedDrops = Lists.newArrayList();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue