1414import org .bukkit .Tag ;
1515import org .bukkit .TreeType ;
1616import org .bukkit .Bukkit ;
17+ import org .bukkit .Effect ;
1718import org .bukkit .Location ;
1819import org .bukkit .Material ;
1920import org .bukkit .Particle ;
2829
2930import java .util .Collections ;
3031import java .util .concurrent .ThreadLocalRandom ;
31- import java .util .logging .Level ;
3232
3333/**
3434 * The {@link WaterSprinkler} speeds up the growth of nearby crops
3939 */
4040public class WaterSprinkler extends AbstractGrowthAccelerator {
4141
42- public final ItemSetting <Double > successChance = new ItemSetting <>(this , "success-chance" , 0.5 );
42+ public final ItemSetting <Double > cropSuccessChance = new ItemSetting <>(this , "crop-success-chance" , 0.5 );
43+ public final ItemSetting <Double > sugarCaneSuccessChance = new ItemSetting <>(this , "sugar-cane-success-chance" , 0.5 );
44+ public final ItemSetting <Double > treeSuccessChance = new ItemSetting <>(this , "tree-success-chance" , 0.5 );
45+ public final ItemSetting <Double > exoticGardenSuccessChance = new ItemSetting <>(this , "exotic-garden-success-chance" , 0.5 );
46+
4347 public static final int ENERGY_CONSUMPTION = 16 ;
4448 public static final int CAPACITY = 128 ;
4549 private static final int RADIUS = 2 ;
@@ -65,7 +69,13 @@ public WaterSprinkler(ItemGroup category, SlimefunItemStack item, RecipeType rec
6569 blockMenuPreset .addItem (PROGRESS_SLOT , noWaterItem );
6670 });
6771
68- addItemSetting (successChance , particles );
72+ addItemSetting (
73+ cropSuccessChance ,
74+ sugarCaneSuccessChance ,
75+ treeSuccessChance ,
76+ exoticGardenSuccessChance ,
77+ particles
78+ );
6979 }
7080
7181 public int getEnergyConsumption () {
@@ -123,12 +133,7 @@ protected void tick(@Nonnull Block b) {
123133
124134 BlockData blockData = block .getBlockData ();
125135
126- if (blockData instanceof Ageable ) {
127- grow (block );
128- removeCharge (b .getLocation (), getEnergyConsumption ());
129- }
130-
131- if (Tag .SAPLINGS .isTagged (block .getType ())) {
136+ if (blockData instanceof Ageable || Tag .SAPLINGS .isTagged (block .getType ())) {
132137 grow (block );
133138 removeCharge (b .getLocation (), getEnergyConsumption ());
134139 }
@@ -138,27 +143,36 @@ protected void tick(@Nonnull Block b) {
138143 }
139144
140145 private void grow (@ Nonnull Block crop ) {
146+ final double random = ThreadLocalRandom .current ().nextDouble ();
141147
142148 if (Tag .SAPLINGS .isTagged (crop .getType ())) {
143- Material saplingMaterial = crop .getType ();
144- Location blockLocation = crop .getLocation ();
149+ final Material saplingMaterial = crop .getType ();
150+ final Location blockLocation = crop .getLocation ();
145151
146152 if (BlockStorage .hasBlockInfo (crop )) {
147- Bukkit .getPluginManager ().callEvent (
148- new StructureGrowEvent (
149- blockLocation ,
150- getTreeFromSapling (saplingMaterial ),
151- false ,
152- null ,
153- Collections .singletonList (crop .getState ())
154- )
155- );
153+ if (random < exoticGardenSuccessChance .getValue ()) {
154+ Bukkit .getPluginManager ().callEvent (
155+ new StructureGrowEvent (
156+ blockLocation ,
157+ getTreeFromSapling (saplingMaterial ),
158+ false ,
159+ null ,
160+ Collections .singletonList (crop .getState ())
161+ )
162+ );
163+
164+ blockLocation .getWorld ().playEffect (blockLocation , Effect .VILLAGER_PLANT_GROW , 0 );
165+ }
156166 } else {
157167 if (Constants .SERVER_VERSION < 1163 ) {
158- crop .setType (Material .AIR );
168+ if (random < treeSuccessChance .getValue ()) {
169+ crop .setType (Material .AIR );
159170
160- if (!blockLocation .getWorld ().generateTree (blockLocation , getTreeFromSapling (saplingMaterial ))) {
161- crop .setType (saplingMaterial );
171+ if (!blockLocation .getWorld ().generateTree (blockLocation , getTreeFromSapling (saplingMaterial ))) {
172+ crop .setType (saplingMaterial );
173+ }
174+
175+ blockLocation .getWorld ().playEffect (blockLocation , Effect .VILLAGER_PLANT_GROW , 0 );
162176 }
163177 } else {
164178 crop .applyBoneMeal (BlockFace .UP );
@@ -168,8 +182,7 @@ private void grow(@Nonnull Block crop) {
168182 return ;
169183 }
170184
171- final double random = ThreadLocalRandom .current ().nextDouble ();
172- if (successChance .getValue () >= random ) {
185+ if (cropSuccessChance .getValue () >= random ) {
173186 if (crop .getType () == Material .SUGAR_CANE ) {
174187 for (int i = 1 ; i < 3 ; i ++) {
175188 final Block above = crop .getRelative (BlockFace .UP , i );
0 commit comments