Skip to content

Commit ac4eec5

Browse files
committed
feat(manager): added recursion to log identifier algorithm.
1 parent d1b4e87 commit ac4eec5

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

src/main/java/com/github/pozzoo/quicktree/Listeners/BlockListener.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public void onBlockBreak(BlockBreakEvent event) {
2424

2525
QuickTree.getInstance().getWoodManager().checkAround(location);
2626

27+
QuickTree.getInstance().getWoodManager().createTree();
28+
2729
event.getPlayer().getInventory().getItemInMainHand().damage(QuickTree.getInstance().getWoodManager().getTreeModelSet().size(), event.getPlayer());
2830

2931
QuickTree.getInstance().getWoodManager().destroyTree();

src/main/java/com/github/pozzoo/quicktree/WoodManager.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,23 @@ public void checkAround(Location location) {
7777

7878
Location location1 = location.clone();
7979

80-
while (!location1.getBlock().getType().equals(Material.AIR)) {
80+
while (woods.contains(location1.getBlock().getType())) {
8181

8282
for (int i = 0; i < coordsVector.size(); i++) {
83-
if (isWoodenLogs(location1.getBlock().getType())) {
83+
if (isWoodenLogs(location1.getBlock().getType()) && !treeModel.contains(location1)) {
8484
addBlockLocation(location1.getBlock().getLocation());
85+
86+
if (treeModel.size() <= 30) {
87+
checkAround(location1);
88+
}
8589
}
8690
location1.add(getCoordsVector(i));
8791
}
8892
location1.add(0, 1, 0);
8993
}
90-
91-
createTree();
9294
}
9395

94-
private void createTree() {
96+
public void createTree() {
9597
for (Location location : treeModel) {
9698
BlockDisplay blockDisplay = location.getWorld().spawn(location, BlockDisplay.class);
9799
blockDisplay.setBlock(location.getBlock().getBlockData());
@@ -129,7 +131,7 @@ public void run() {
129131
}
130132
iterations++;
131133

132-
if (iterations == 10) {
134+
if (iterations >= 10) {
133135
this.cancel();
134136
explodeBlocks();
135137
}
@@ -145,7 +147,7 @@ public void run() {
145147

146148
for (BlockDisplay blockDisplay : treeDisplay) {
147149
blockDisplay.remove();
148-
blockDisplay.getWorld().spawnParticle(Particle.BLOCK_CRACK, blockDisplay.getLocation(), 50, 1, 5, 0, Material.SPRUCE_LOG.createBlockData());
150+
blockDisplay.getWorld().spawnParticle(Particle.BLOCK_CRACK, blockDisplay.getLocation(), 20, 1, 5, 0, Material.SPRUCE_LOG.createBlockData());
149151

150152
}
151153
treeDisplay.clear();

0 commit comments

Comments
 (0)