Skip to content

Commit

Permalink
If a tree cannot grow, saplings will not be consumed.
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Dec 15, 2019
1 parent bd74366 commit d8536c5
Showing 1 changed file with 27 additions and 20 deletions.
47 changes: 27 additions & 20 deletions src/main/java/world/bentobox/twerk/listeners/TreeGrowListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,23 +97,27 @@ private void runChecker() {
}

private void growTree(Block b) {
if (!Tag.SAPLINGS.isTagged(b.getType())) {
Material t = b.getType();
if (!Tag.SAPLINGS.isTagged(t)) {
return;
}
// Try to grow big tree if possible
if (SAPLING_TO_BIG_TREE_TYPE.containsKey(b.getType()) && bigTreeSaplings(b)) {
if (SAPLING_TO_BIG_TREE_TYPE.containsKey(t) && bigTreeSaplings(b)) {
return;
} else if (SAPLING_TO_TREE_TYPE.containsKey(b.getType())) {
} else if (SAPLING_TO_TREE_TYPE.containsKey(t)) {
TreeType type = SAPLING_TO_TREE_TYPE.getOrDefault(b.getType(), TreeType.TREE);
b.setType(Material.AIR);
b.getWorld().generateTree(b.getLocation(), type);
if (addon.getSettings().isEffectsEnabled()) {
showSparkles(b);
}
addon.getPlugin().logDebug("Growing 1x1 tree " + type);
if (addon.getSettings().isSoundsEnabled()) {
b.getWorld().playSound(b.getLocation(), addon.getSettings().getSoundsGrowingSmallTreeSound(),
addon.getSettings().getSoundsGrowingSmallTreeVolume(), addon.getSettings().getSoundsGrowingSmallTreePitch());
if (b.getWorld().generateTree(b.getLocation(), type)) {
if (addon.getSettings().isEffectsEnabled()) {
showSparkles(b);
}
if (addon.getSettings().isSoundsEnabled()) {
b.getWorld().playSound(b.getLocation(), addon.getSettings().getSoundsGrowingSmallTreeSound(),
addon.getSettings().getSoundsGrowingSmallTreeVolume(), addon.getSettings().getSoundsGrowingSmallTreePitch());
}
} else {
// Tree generation failed, so reset block
b.setType(t);
}
}
}
Expand All @@ -124,18 +128,21 @@ private boolean bigTreeSaplings(Block b) {
if (q.stream().map(b::getRelative).allMatch(c -> c.getType().equals(b.getType()))) {
// All the same sapling type found in this quad
q.stream().map(b::getRelative).forEach(c -> c.setType(Material.AIR));
addon.getPlugin().logDebug("Growing big tree");
// Get the tree planting location
Location l = b.getRelative(q.get(0)).getLocation();
b.getWorld().generateTree(l, type);
if (addon.getSettings().isEffectsEnabled()) {
showSparkles(b);
}
if (addon.getSettings().isSoundsEnabled()) {
b.getWorld().playSound(b.getLocation(), addon.getSettings().getSoundsGrowingBigTreeSound(),
addon.getSettings().getSoundsGrowingBigTreeVolume(), addon.getSettings().getSoundsGrowingBigTreePitch());
if (b.getWorld().generateTree(l, type)) {
if (addon.getSettings().isEffectsEnabled()) {
showSparkles(b);
}
if (addon.getSettings().isSoundsEnabled()) {
b.getWorld().playSound(b.getLocation(), addon.getSettings().getSoundsGrowingBigTreeSound(),
addon.getSettings().getSoundsGrowingBigTreeVolume(), addon.getSettings().getSoundsGrowingBigTreePitch());
}
return true;
} else {
// Generation failed, reset saplings
q.stream().map(b::getRelative).forEach(c -> c.setType(b.getType()));
}
return true;
}
}
return false;
Expand Down

0 comments on commit d8536c5

Please sign in to comment.