1414public class ForestPlugin extends KonstructsActor {
1515 private final ForestConfig config ;
1616 private final BlockTypeId growsOn ;
17+ private final BlockTypeId seedsOn ;
1718 private final BlockTypeId sapling ;
1819 private final int randomGrowth ;
1920 private final Random random = new Random ();
@@ -23,22 +24,19 @@ public ForestPlugin(String name, ActorRef universe, ForestConfig config) {
2324 super (universe );
2425 this .config = config ;
2526 this .growsOn = config .getGrowsOn ();
27+ this .seedsOn = config .getSeedsOn ();
2628 this .sapling = config .getSapling ();
2729 this .randomGrowth = config .getRandomGrowth ();
2830 }
2931
3032 void tryToSeed (Position pos ) {
3133 Position start =
32- pos .withY (Math .max (pos .getY () - config .getSeedHeightDifference (),
33- config .getMinSeedHeight ()));
34+ pos .withY (pos .getY () - config .getSeedHeightDifference ());
3435 Position end =
3536 new Position (pos .getX () + 1 ,
36- Math .min (pos .getY () + config .getSeedHeightDifference (),
37- config .getMaxSeedHeight ()),
37+ pos .getY () + config .getSeedHeightDifference (),
3838 pos .getZ () + 1 );
39- // Only run query if within the possible height band
40- if (start .getY () < end .getY ())
41- boxQuery (new Box (start , end ));
39+ boxQuery (new Box (start , end ));
4240 }
4341
4442 void seeded (Position pos ) {
@@ -58,7 +56,7 @@ void plant(Position pos) {
5856 public void onBoxQueryResult (BoxQueryResult result ) {
5957 Map <Position , BlockTypeId > placed = result .getAsMap ();
6058 for (Map .Entry <Position , BlockTypeId > p : placed .entrySet ()) {
61- if (p .getValue ().equals (growsOn )) {
59+ if (p .getValue ().equals (growsOn ) || p . getValue (). equals ( seedsOn ) ) {
6260 Position pos = p .getKey ().addY (1 );
6361 BlockTypeId above = placed .get (pos );
6462 if (above != null && above .equals (BlockTypeId .VACUUM )) {
@@ -76,7 +74,7 @@ public void onBlockUpdateEvent(BlockUpdateEvent update) {
7674 if (after .equals (sapling )) {
7775 seeded (p .getKey ());
7876 } else if (after .equals (growsOn ) &&
79- random .nextInt (1000 ) <= randomGrowth ) {
77+ random .nextInt (10000 ) <= randomGrowth ) {
8078 /* Try to seed a new tree */
8179 scheduleSelfOnce (new TryToSeedTree (p .getKey ()),
8280 (int )((float )(config .getMinGrowthDelay () * 1000 +
@@ -116,9 +114,8 @@ public void onReceive(Object message) {
116114 @ Config (key = "thin-leaves-block" ) String thinLeaves ,
117115 @ Config (key = "sapling-block" ) String sapling ,
118116 @ Config (key = "grows-on" ) String growsOn ,
117+ @ Config (key = "seeds-on" ) String seedsOn ,
119118 @ Config (key = "max-seed-height-difference" ) int seedHeightDifference ,
120- @ Config (key = "max-seed-height" ) int maxSeedHeight ,
121- @ Config (key = "min-seed-height" ) int minSeedHeight ,
122119 @ Config (key = "max-generations" ) int maxGenerations ,
123120 @ Config (key = "min-generations" ) int minGenerations ,
124121 @ Config (key = "trunk-radi" ) int trunkRadi ,
@@ -129,6 +126,7 @@ public void onReceive(Object message) {
129126 @ Config (key = "min-growth-delay" ) int minGrowthDelay ,
130127 @ Config (key = "random-growth-delay" ) int randomGrowthDelay ,
131128 @ Config (key = "max-seeds-per-generation" ) int maxSeedsPerGeneration ,
129+ @ Config (key = "seed-every-generation" ) int seedEveryGeneration ,
132130 @ Config (key = "random-growth" ) int randomGrowth
133131 ) {
134132 Class currentClass = new Object () { }.getClass ().getEnclosingClass ();
@@ -139,9 +137,8 @@ public void onReceive(Object message) {
139137 thinLeaves ,
140138 sapling ,
141139 growsOn ,
140+ seedsOn ,
142141 seedHeightDifference ,
143- maxSeedHeight ,
144- minSeedHeight ,
145142 maxGenerations ,
146143 minGenerations ,
147144 trunkRadi ,
@@ -152,6 +149,7 @@ public void onReceive(Object message) {
152149 minGrowthDelay ,
153150 randomGrowthDelay ,
154151 maxSeedsPerGeneration ,
152+ seedEveryGeneration ,
155153 randomGrowth );
156154 return Props .create (currentClass , pluginName , universe , config );
157155 }
0 commit comments