From 0c2f713ab0292e370b421b5d70c5df714a3d5ced Mon Sep 17 00:00:00 2001 From: Petter Arvidsson Date: Sun, 15 May 2016 22:27:26 +0200 Subject: [PATCH 1/3] Adjust forest plugin to work better with grass - Make trees only plant seeds every n:th generation - Make less likely to randomly spawn - Make nicer birch leaves --- .../org/konstructs/forest/ForestConfig.java | 24 +++++----- .../org/konstructs/forest/ForestPlugin.java | 24 +++++----- src/main/java/org/konstructs/forest/Tree.java | 17 ++++--- src/main/resources/reference.conf | 42 +++++++++--------- .../org/konstructs/forest/birch/leaves.png | Bin 3549 -> 3528 bytes .../org/konstructs/forest/oak/leaves.png | Bin 0 -> 3558 bytes 6 files changed, 55 insertions(+), 52 deletions(-) create mode 100644 src/main/resources/textures/org/konstructs/forest/oak/leaves.png diff --git a/src/main/java/org/konstructs/forest/ForestConfig.java b/src/main/java/org/konstructs/forest/ForestConfig.java index 038b85a..840c360 100644 --- a/src/main/java/org/konstructs/forest/ForestConfig.java +++ b/src/main/java/org/konstructs/forest/ForestConfig.java @@ -8,9 +8,8 @@ public class ForestConfig { private final BlockTypeId thinLeaves; private final BlockTypeId sapling; private final BlockTypeId growsOn; + private final BlockTypeId seedsOn; private final int seedHeightDifference; - private final int maxSeedHeight; - private final int minSeedHeight; private final int maxGenerations; private final int minGenerations; private final int trunkRadi; @@ -21,6 +20,7 @@ public class ForestConfig { private final int minGrowthDelay; private final int randomGrowthDelay; private final int maxSeedsPerGeneration; + private final int seedEveryGeneration; private final int randomGrowth; ForestConfig(String wood, @@ -28,9 +28,8 @@ public class ForestConfig { String thinLeaves, String sapling, String growsOn, + String seedsOn, int seedHeightDifference, - int maxSeedHeight, - int minSeedHeight, int maxGenerations, int minGenerations, int trunkRadi, @@ -41,15 +40,15 @@ public class ForestConfig { int minGrowthDelay, int randomGrowthDelay, int maxSeedsPerGeneration, + int seedEveryGeneration, int randomGrowth) { this.wood = BlockTypeId.fromString(wood); this.leaves = BlockTypeId.fromString(leaves); this.thinLeaves = BlockTypeId.fromString(thinLeaves); this.sapling = BlockTypeId.fromString(sapling); this.growsOn = BlockTypeId.fromString(growsOn); + this.seedsOn = BlockTypeId.fromString(seedsOn); this.seedHeightDifference = seedHeightDifference; - this.maxSeedHeight = maxSeedHeight; - this.minSeedHeight = minSeedHeight; this.maxGenerations = maxGenerations; this.minGenerations = minGenerations; this.trunkRadi = trunkRadi; @@ -60,6 +59,7 @@ public class ForestConfig { this.minGrowthDelay = minGrowthDelay; this.randomGrowthDelay = randomGrowthDelay; this.maxSeedsPerGeneration = maxSeedsPerGeneration; + this.seedEveryGeneration = seedEveryGeneration; this.randomGrowth = randomGrowth; } @@ -78,15 +78,12 @@ public BlockTypeId getSapling() { public BlockTypeId getGrowsOn() { return growsOn; } + public BlockTypeId getSeedsOn() { + return seedsOn; + } public int getSeedHeightDifference() { return seedHeightDifference; } - public int getMaxSeedHeight() { - return maxSeedHeight; - } - public int getMinSeedHeight() { - return minSeedHeight; - } public int getMaxGenerations() { return maxGenerations; } @@ -117,6 +114,9 @@ public int getRandomGrowthDelay() { public int getMaxSeedsPerGeneration() { return maxSeedsPerGeneration; } + public int getSeedEveryGeneration() { + return seedEveryGeneration; + } public int getRandomGrowth() { return randomGrowth; } diff --git a/src/main/java/org/konstructs/forest/ForestPlugin.java b/src/main/java/org/konstructs/forest/ForestPlugin.java index d7823bb..9e7efb4 100644 --- a/src/main/java/org/konstructs/forest/ForestPlugin.java +++ b/src/main/java/org/konstructs/forest/ForestPlugin.java @@ -14,6 +14,7 @@ public class ForestPlugin extends KonstructsActor { private final ForestConfig config; private final BlockTypeId growsOn; + private final BlockTypeId seedsOn; private final BlockTypeId sapling; private final int randomGrowth; private final Random random = new Random(); @@ -23,22 +24,19 @@ public ForestPlugin(String name, ActorRef universe, ForestConfig config) { super(universe); this.config = config; this.growsOn = config.getGrowsOn(); + this.seedsOn = config.getSeedsOn(); this.sapling = config.getSapling(); this.randomGrowth = config.getRandomGrowth(); } void tryToSeed(Position pos) { Position start = - pos.withY(Math.max(pos.getY() - config.getSeedHeightDifference(), - config.getMinSeedHeight())); + pos.withY(pos.getY() - config.getSeedHeightDifference()); Position end = new Position(pos.getX() + 1, - Math.min(pos.getY() + config.getSeedHeightDifference(), - config.getMaxSeedHeight()), + pos.getY() + config.getSeedHeightDifference(), pos.getZ() + 1); - // Only run query if within the possible height band - if(start.getY() < end.getY()) - boxQuery(new Box(start, end)); + boxQuery(new Box(start, end)); } void seeded(Position pos) { @@ -58,7 +56,7 @@ void plant(Position pos) { public void onBoxQueryResult(BoxQueryResult result) { Map placed = result.getAsMap(); for(Map.Entry p: placed.entrySet()) { - if(p.getValue().equals(growsOn)) { + if(p.getValue().equals(growsOn) || p.getValue().equals(seedsOn)) { Position pos = p.getKey().addY(1); BlockTypeId above = placed.get(pos); if(above != null && above.equals(BlockTypeId.VACUUM)) { @@ -76,7 +74,7 @@ public void onBlockUpdateEvent(BlockUpdateEvent update) { if(after.equals(sapling)) { seeded(p.getKey()); } else if(after.equals(growsOn) && - random.nextInt(1000) <= randomGrowth) { + random.nextInt(10000) <= randomGrowth) { /* Try to seed a new tree */ scheduleSelfOnce(new TryToSeedTree(p.getKey()), (int)((float)(config.getMinGrowthDelay() * 1000 + @@ -116,9 +114,8 @@ public void onReceive(Object message) { @Config(key = "thin-leaves-block") String thinLeaves, @Config(key = "sapling-block") String sapling, @Config(key = "grows-on") String growsOn, + @Config(key = "seeds-on") String seedsOn, @Config(key = "max-seed-height-difference") int seedHeightDifference, - @Config(key = "max-seed-height") int maxSeedHeight, - @Config(key = "min-seed-height") int minSeedHeight, @Config(key = "max-generations") int maxGenerations, @Config(key = "min-generations") int minGenerations, @Config(key = "trunk-radi") int trunkRadi, @@ -129,6 +126,7 @@ public void onReceive(Object message) { @Config(key = "min-growth-delay") int minGrowthDelay, @Config(key = "random-growth-delay") int randomGrowthDelay, @Config(key = "max-seeds-per-generation") int maxSeedsPerGeneration, + @Config(key = "seed-every-generation") int seedEveryGeneration, @Config(key = "random-growth") int randomGrowth ) { Class currentClass = new Object() { }.getClass().getEnclosingClass(); @@ -139,9 +137,8 @@ public void onReceive(Object message) { thinLeaves, sapling, growsOn, + seedsOn, seedHeightDifference, - maxSeedHeight, - minSeedHeight, maxGenerations, minGenerations, trunkRadi, @@ -152,6 +149,7 @@ public void onReceive(Object message) { minGrowthDelay, randomGrowthDelay, maxSeedsPerGeneration, + seedEveryGeneration, randomGrowth); return Props.create(currentClass, pluginName, universe, config); } diff --git a/src/main/java/org/konstructs/forest/Tree.java b/src/main/java/org/konstructs/forest/Tree.java index 4139685..b358bb5 100644 --- a/src/main/java/org/konstructs/forest/Tree.java +++ b/src/main/java/org/konstructs/forest/Tree.java @@ -69,12 +69,15 @@ private void scheduleGrowth(int generation) { } } - private void seed() { - /* Plant seeds */ - int seeds = r.nextInt(config.getMaxSeedsPerGeneration() + 1); - for(int i = 0; i < seeds; i++) { - Position p = position.add(new Position(nextRandomSeedDistance(),0, nextRandomSeedDistance())); - getContext().parent().tell(new TryToSeedTree(p), getSelf()); + private void seed(int generation) { + /* Only try to seed every n:th generation */ + if(generation % config.getSeedEveryGeneration() == 0) { + /* Plant seeds */ + int seeds = r.nextInt(config.getMaxSeedsPerGeneration() + 1); + for(int i = 0; i < seeds; i++) { + Position p = position.add(new Position(nextRandomSeedDistance(),0, nextRandomSeedDistance())); + getContext().parent().tell(new TryToSeedTree(p), getSelf()); + } } } @@ -84,7 +87,7 @@ private void grow(int generation) { state = SYSTEM.iterate(state); removeOldBlocks.putAll(machine.interpret(state, position)); replaceBlocks(forestBlocks, removeOldBlocks); - seed(); + seed(generation); scheduleGrowth(generation + 1); } diff --git a/src/main/resources/reference.conf b/src/main/resources/reference.conf index 16126a4..b61e8f1 100644 --- a/src/main/resources/reference.conf +++ b/src/main/resources/reference.conf @@ -2,24 +2,24 @@ konstructs { org/konstructs/forest/oak { class = "org.konstructs.forest.ForestPlugin" wood-block = org/konstructs/wood - leaves-block = org/konstructs/leaves + leaves-block = org/konstructs/forest/oak/leaves thin-leaves-block = org/konstructs/leaves sapling-block = org/konstructs/forest/oak/sapling grows-on = org/konstructs/grass-dirt + seeds-on = org/konstructs/grass/warm max-seed-height-difference = 10 - max-seed-height = 48 - min-seed-height = 0 - max-generations = 9 + max-generations = 10 min-generations = 5 - trunk-radi = 3 + trunk-radi = 2 trunk-height = 10 crown-radi = 15 crown-height = 30 initial-state = "bba[&[c][-c][--c][+c]]c" - min-growth-delay = 300 + min-growth-delay = 180 random-growth-delay = 300 max-seeds-per-generation = 1 - random-growth = 2 + seed-every-generation = 4 + random-growth = 4 } org/konstructs/forest/beech { class = "org.konstructs.forest.ForestPlugin" @@ -28,19 +28,19 @@ konstructs { thin-leaves-block = org/konstructs/forest/beech/thin-leaves sapling-block = org/konstructs/forest/beech/sapling grows-on = org/konstructs/grass-dirt + seeds-on = org/konstructs/grass-dirt max-seed-height-difference = 4 - max-seed-height = 48 - min-seed-height = 8 - max-generations = 5 + max-generations = 6 min-generations = 3 - trunk-radi = 2 + trunk-radi = 1 trunk-height = 5 - crown-radi = 8 + crown-radi = 5 crown-height = 15 initial-state = "a[&[c][-c][--c][+c]]c" min-growth-delay = 180 random-growth-delay = 180 - max-seeds-per-generation = 2 + max-seeds-per-generation = 3 + seed-every-generation = 2 random-growth = 1 } org/konstructs/forest/birch { @@ -50,20 +50,20 @@ konstructs { thin-leaves-block = org/konstructs/forest/birch/leaves sapling-block = org/konstructs/forest/birch/sapling grows-on = org/konstructs/grass/autumn - max-seed-height-difference = 20 - max-seed-height = 128 - min-seed-height = 48 + seeds-on = org/konstructs/snow-dirt + max-seed-height-difference = 30 max-generations = 4 min-generations = 2 trunk-radi = 1 - trunk-height = 4 - crown-radi = 6 + trunk-height = 5 + crown-radi = 8 crown-height = 15 initial-state = "a[&[c][-c][--c][+c]]c" min-growth-delay = 180 random-growth-delay = 180 - max-seeds-per-generation = 0 - random-growth = 5 + max-seeds-per-generation = 1 + seed-every-generation = 3 + random-growth = 3 } org/konstructs/block-manager { blocks { @@ -71,6 +71,8 @@ konstructs { obstacle = false shape = "plant" } + org/konstructs/forest/oak/leaves { + } org/konstructs/forest/beech/sapling { obstacle = false shape = "plant" diff --git a/src/main/resources/textures/org/konstructs/forest/birch/leaves.png b/src/main/resources/textures/org/konstructs/forest/birch/leaves.png index 26a5810fb19e1114878039a45429ba091e0f4a14..b0290fd507ccf3bbd76820d227b685e8581ff023 100644 GIT binary patch delta 839 zcmV-N1GxO%8^{~5j|zVU5DN|q?L35R7dCK4}_C7yQClgSbj*2`3Zko>=CX*`C zo)JTJ$vr4z^lJ{rNBI z_&mYUvm|~=p+=Gb2mrnJ`>}Oep&%fS!~r?)zLZj^}_b9bKr zP!fvRKPYkXw1HQTGDL@E3~v|HNO#V`j*jB)9v}9#u=x8DPUi_0etwA*4p3T#^i+oE z56}7Pbbx?5j`jHsin$U14o_pb%8m}f0lV8d1SuTA8Ehjo*3HI? zErO$GF&XQsDJqG~b`x7mYfN6BMyS)sCi1kj>Jfj)mIGK1?BVbhh#*ZUPm5@v;NN}_3bs~ z5kEh__L&wPmI;k@lbTM`)P0!5=n{e*EG7%lVVMdmm`d0>t&Cs#0|0T*$A7NtN_qf5 RFVg@3002ovPDHLkV1gTfk1YTI delta 860 zcmV-i1Ec)N8{HeQj|zVS7ZMa11(~d00009mNkll(1*0zprV5JK!y2M6I)?imn;9xlP;6YN3Bt4M0qj5KTFv~JCF^h-AF1U`3nlx>Z zwQI}36sw>u{E3d~5JyXa-wq9R@AQ(F?|a|(ecz`L2yyC;g^7Q@5W8{w$}tZ2HnNgg z$7pOKcmFB32cw*sv;a`wpya0U9srd96MZ49w>kjGKiMQYlEAR4qpn#=?5`yn4QdP? z9Vy!^?s*rHv2b~qLLkJ&xy$USTp>NVM9^Jg;t1HOuB~9q?8gzX^Wu?=RIEnYF9=?E zfXS<;w(T7h?cRT*A~rgM)o0=5!y?IRQ}icKv-NK!kH();T;CyebryhuxRZxVX{-i2 zt8emrqx~A(sV_yhuS<0Mx`aRofe?C+ww!lfF^bQwbqKv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016 14:06:02 +0200 Subject: [PATCH 2/3] Even more birches --- src/main/resources/reference.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/reference.conf b/src/main/resources/reference.conf index b61e8f1..b59525e 100644 --- a/src/main/resources/reference.conf +++ b/src/main/resources/reference.conf @@ -63,7 +63,7 @@ konstructs { random-growth-delay = 180 max-seeds-per-generation = 1 seed-every-generation = 3 - random-growth = 3 + random-growth = 6 } org/konstructs/block-manager { blocks { From 702e9b81c2340758d75622e18933d5c95a287e18 Mon Sep 17 00:00:00 2001 From: Petter Arvidsson Date: Mon, 16 May 2016 14:09:26 +0200 Subject: [PATCH 3/3] Slightly less oak --- src/main/resources/reference.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/reference.conf b/src/main/resources/reference.conf index b59525e..d9cf65f 100644 --- a/src/main/resources/reference.conf +++ b/src/main/resources/reference.conf @@ -19,7 +19,7 @@ konstructs { random-growth-delay = 300 max-seeds-per-generation = 1 seed-every-generation = 4 - random-growth = 4 + random-growth = 2 } org/konstructs/forest/beech { class = "org.konstructs.forest.ForestPlugin"