From cb1c50d473e90f07c002d32ffcd4fe1420091536 Mon Sep 17 00:00:00 2001 From: Cameron Hetzler Date: Fri, 31 Mar 2023 13:26:53 -0400 Subject: [PATCH 1/7] Add ability for weather to affect spawn rate Adding ability for wind strength to affect the spawn rate of leaves. Weather events in Wind can now also affect spawn rate in a compounded fashion. --- .../config/FallingLeavesConfig.java | 30 +++++++++++++++++++ .../fallingleaves/util/LeafUtil.java | 2 ++ .../fallingleaves/util/Wind.java | 8 +++++ .../assets/fallingleaves/lang/en_us.json | 4 +++ 4 files changed, 44 insertions(+) diff --git a/src/main/java/randommcsomethin/fallingleaves/config/FallingLeavesConfig.java b/src/main/java/randommcsomethin/fallingleaves/config/FallingLeavesConfig.java index 81d59d3..400cc0f 100644 --- a/src/main/java/randommcsomethin/fallingleaves/config/FallingLeavesConfig.java +++ b/src/main/java/randommcsomethin/fallingleaves/config/FallingLeavesConfig.java @@ -9,6 +9,7 @@ import net.minecraft.state.property.Property; import net.minecraft.util.Identifier; import randommcsomethin.fallingleaves.FallingLeavesClient; +import randommcsomethin.fallingleaves.util.Wind; import java.util.*; import java.util.function.Consumer; @@ -55,6 +56,35 @@ public double getBaseLeafSpawnChance() { double actualSpawnRate = leafSpawnRate / 10.0; return actualSpawnRate / 75.0; } + + @ConfigEntry.Category("fallingleaves.general") + @ConfigEntry.Gui.Tooltip + @ConfigEntry.BoundedDiscrete(max = 10) + private int leafWindySpawnRate = 2; + + @ConfigEntry.Category("fallingleaves.general") + @ConfigEntry.Gui.Tooltip + @ConfigEntry.BoundedDiscrete(max = 8) + public int leafWeatherSpawnCoeficient = 4; + + // leaf spawn rate can be affected slightly by the magnitude + // of the current wind speed. + // when weather events are in effect, spawn rate will be + // compounded based on the event with "Thunder" being + // the most intensive. + public double getWindyLeafSpawnCoeficient() { + + double actualSpawnCoeficient = 1 + (Wind.windMagnitute() * leafWindySpawnRate); + switch (Wind.getState()) { + case STORMY: + actualSpawnCoeficient *= leafWeatherSpawnCoeficient; + case WINDY: + actualSpawnCoeficient *= leafWeatherSpawnCoeficient; + default: + break; + } + return actualSpawnCoeficient; + } @ConfigEntry.Category("fallingleaves.general") @ConfigEntry.Gui.Tooltip diff --git a/src/main/java/randommcsomethin/fallingleaves/util/LeafUtil.java b/src/main/java/randommcsomethin/fallingleaves/util/LeafUtil.java index 4f9820d..2749859 100644 --- a/src/main/java/randommcsomethin/fallingleaves/util/LeafUtil.java +++ b/src/main/java/randommcsomethin/fallingleaves/util/LeafUtil.java @@ -55,6 +55,8 @@ public static double getModifiedSpawnChance(BlockState state, LeafSettingsEntry spawnChance *= CONFIG.winterSpawnRateFactor; } } + + spawnChance *= CONFIG.getWindyLeafSpawnCoeficient(); if (CONFIG.decaySpawnRateFactor != 1.0f) { if (isLeafBlock(state.getBlock(), true) && state.getBlock().hasRandomTicks(state)) { // decaying leaves have random ticks diff --git a/src/main/java/randommcsomethin/fallingleaves/util/Wind.java b/src/main/java/randommcsomethin/fallingleaves/util/Wind.java index c3db372..6ff4b48 100644 --- a/src/main/java/randommcsomethin/fallingleaves/util/Wind.java +++ b/src/main/java/randommcsomethin/fallingleaves/util/Wind.java @@ -61,6 +61,14 @@ public static void init() { return (2f * rng.nextFloat() - 1f) * TAU / 8f; }); } + + public static double windMagnitute() { + return Math.sqrt(Math.pow(windX, 2)+Math.pow(windZ, 2)); + } + + public static State getState() { + return state; + } protected static void tickState(ClientWorld world) { --stateDuration; diff --git a/src/main/resources/assets/fallingleaves/lang/en_us.json b/src/main/resources/assets/fallingleaves/lang/en_us.json index 54e83ea..a6e86cb 100644 --- a/src/main/resources/assets/fallingleaves/lang/en_us.json +++ b/src/main/resources/assets/fallingleaves/lang/en_us.json @@ -6,6 +6,10 @@ "text.autoconfig.fallingleaves.option.leafLifespan.@Tooltip": "20 ticks are roughly 1 second", "text.autoconfig.fallingleaves.option.leafSpawnRate": "Leaf Spawn Rate", "text.autoconfig.fallingleaves.option.leafSpawnRate.@Tooltip": "How many leaves spawn over time", + "text.autoconfig.fallingleaves.option.leafWindySpawnCoeficient": "Leaf Spawn Coeficient from Wind", + "text.autoconfig.fallingleaves.option.leafWindySpawnCoeficient.@Tooltip": "How strongly can wind magnitude affect spawn rate", + "text.autoconfig.fallingleaves.option.leafWeatherSpawnCoeficient": "Leaf Spawn Coeficient from Weather", + "text.autoconfig.fallingleaves.option.leafWeatherSpawnCoeficient.@Tooltip": "How strongly can weather (rain, wind, calm) affect spawn rate", "text.autoconfig.fallingleaves.option.coniferLeafSpawnRate": "Conifer Leaf Spawn Rate", "text.autoconfig.fallingleaves.option.coniferLeafSpawnRate.@Tooltip": "How many conifer leaves spawn over time", "text.autoconfig.fallingleaves.option.snowflakeSpawnRate": "Snowflake Spawn Rate", From 22aab75596844d2c32fef40bad093f301ef69257 Mon Sep 17 00:00:00 2001 From: Cameron Hetzler Date: Fri, 31 Mar 2023 13:28:09 -0400 Subject: [PATCH 2/7] Update FallingLeavesConfig.java Need to make sure no funny business happens with bad user input. --- .../fallingleaves/config/FallingLeavesConfig.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/randommcsomethin/fallingleaves/config/FallingLeavesConfig.java b/src/main/java/randommcsomethin/fallingleaves/config/FallingLeavesConfig.java index 400cc0f..9a2586e 100644 --- a/src/main/java/randommcsomethin/fallingleaves/config/FallingLeavesConfig.java +++ b/src/main/java/randommcsomethin/fallingleaves/config/FallingLeavesConfig.java @@ -59,12 +59,12 @@ public double getBaseLeafSpawnChance() { @ConfigEntry.Category("fallingleaves.general") @ConfigEntry.Gui.Tooltip - @ConfigEntry.BoundedDiscrete(max = 10) + @ConfigEntry.BoundedDiscrete(min = 0, max = 10) private int leafWindySpawnRate = 2; @ConfigEntry.Category("fallingleaves.general") @ConfigEntry.Gui.Tooltip - @ConfigEntry.BoundedDiscrete(max = 8) + @ConfigEntry.BoundedDiscrete(min = 1, max = 8) public int leafWeatherSpawnCoeficient = 4; // leaf spawn rate can be affected slightly by the magnitude From acbf983d18c600ee4776366e27885d05be3cd4d7 Mon Sep 17 00:00:00 2001 From: Cameron Hetzler Date: Fri, 31 Mar 2023 13:42:39 -0400 Subject: [PATCH 3/7] Update .gitignore eclipse support --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index f8c9ac5..d31e783 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,9 @@ *.iml *.ipr *.iws +/bin/ +.project +*.prefs # IntelliJ out/ From 64eca52a16a7c9174f70b62e59edec4738ea908d Mon Sep 17 00:00:00 2001 From: Cameron Hetzler Date: Fri, 31 Mar 2023 13:26:53 -0400 Subject: [PATCH 4/7] Add ability for weather to affect spawn rate Adding ability for wind strength to affect the spawn rate of leaves. Weather events in Wind can now also affect spawn rate in a compounded fashion. Signed-off-by: Cameron Hetzler --- .../config/FallingLeavesConfig.java | 30 +++++++++++++++++++ .../fallingleaves/util/LeafUtil.java | 2 ++ .../fallingleaves/util/Wind.java | 8 +++++ .../assets/fallingleaves/lang/en_us.json | 4 +++ 4 files changed, 44 insertions(+) diff --git a/src/main/java/randommcsomethin/fallingleaves/config/FallingLeavesConfig.java b/src/main/java/randommcsomethin/fallingleaves/config/FallingLeavesConfig.java index 81d59d3..400cc0f 100644 --- a/src/main/java/randommcsomethin/fallingleaves/config/FallingLeavesConfig.java +++ b/src/main/java/randommcsomethin/fallingleaves/config/FallingLeavesConfig.java @@ -9,6 +9,7 @@ import net.minecraft.state.property.Property; import net.minecraft.util.Identifier; import randommcsomethin.fallingleaves.FallingLeavesClient; +import randommcsomethin.fallingleaves.util.Wind; import java.util.*; import java.util.function.Consumer; @@ -55,6 +56,35 @@ public double getBaseLeafSpawnChance() { double actualSpawnRate = leafSpawnRate / 10.0; return actualSpawnRate / 75.0; } + + @ConfigEntry.Category("fallingleaves.general") + @ConfigEntry.Gui.Tooltip + @ConfigEntry.BoundedDiscrete(max = 10) + private int leafWindySpawnRate = 2; + + @ConfigEntry.Category("fallingleaves.general") + @ConfigEntry.Gui.Tooltip + @ConfigEntry.BoundedDiscrete(max = 8) + public int leafWeatherSpawnCoeficient = 4; + + // leaf spawn rate can be affected slightly by the magnitude + // of the current wind speed. + // when weather events are in effect, spawn rate will be + // compounded based on the event with "Thunder" being + // the most intensive. + public double getWindyLeafSpawnCoeficient() { + + double actualSpawnCoeficient = 1 + (Wind.windMagnitute() * leafWindySpawnRate); + switch (Wind.getState()) { + case STORMY: + actualSpawnCoeficient *= leafWeatherSpawnCoeficient; + case WINDY: + actualSpawnCoeficient *= leafWeatherSpawnCoeficient; + default: + break; + } + return actualSpawnCoeficient; + } @ConfigEntry.Category("fallingleaves.general") @ConfigEntry.Gui.Tooltip diff --git a/src/main/java/randommcsomethin/fallingleaves/util/LeafUtil.java b/src/main/java/randommcsomethin/fallingleaves/util/LeafUtil.java index 4f9820d..2749859 100644 --- a/src/main/java/randommcsomethin/fallingleaves/util/LeafUtil.java +++ b/src/main/java/randommcsomethin/fallingleaves/util/LeafUtil.java @@ -55,6 +55,8 @@ public static double getModifiedSpawnChance(BlockState state, LeafSettingsEntry spawnChance *= CONFIG.winterSpawnRateFactor; } } + + spawnChance *= CONFIG.getWindyLeafSpawnCoeficient(); if (CONFIG.decaySpawnRateFactor != 1.0f) { if (isLeafBlock(state.getBlock(), true) && state.getBlock().hasRandomTicks(state)) { // decaying leaves have random ticks diff --git a/src/main/java/randommcsomethin/fallingleaves/util/Wind.java b/src/main/java/randommcsomethin/fallingleaves/util/Wind.java index c3db372..6ff4b48 100644 --- a/src/main/java/randommcsomethin/fallingleaves/util/Wind.java +++ b/src/main/java/randommcsomethin/fallingleaves/util/Wind.java @@ -61,6 +61,14 @@ public static void init() { return (2f * rng.nextFloat() - 1f) * TAU / 8f; }); } + + public static double windMagnitute() { + return Math.sqrt(Math.pow(windX, 2)+Math.pow(windZ, 2)); + } + + public static State getState() { + return state; + } protected static void tickState(ClientWorld world) { --stateDuration; diff --git a/src/main/resources/assets/fallingleaves/lang/en_us.json b/src/main/resources/assets/fallingleaves/lang/en_us.json index 54e83ea..a6e86cb 100644 --- a/src/main/resources/assets/fallingleaves/lang/en_us.json +++ b/src/main/resources/assets/fallingleaves/lang/en_us.json @@ -6,6 +6,10 @@ "text.autoconfig.fallingleaves.option.leafLifespan.@Tooltip": "20 ticks are roughly 1 second", "text.autoconfig.fallingleaves.option.leafSpawnRate": "Leaf Spawn Rate", "text.autoconfig.fallingleaves.option.leafSpawnRate.@Tooltip": "How many leaves spawn over time", + "text.autoconfig.fallingleaves.option.leafWindySpawnCoeficient": "Leaf Spawn Coeficient from Wind", + "text.autoconfig.fallingleaves.option.leafWindySpawnCoeficient.@Tooltip": "How strongly can wind magnitude affect spawn rate", + "text.autoconfig.fallingleaves.option.leafWeatherSpawnCoeficient": "Leaf Spawn Coeficient from Weather", + "text.autoconfig.fallingleaves.option.leafWeatherSpawnCoeficient.@Tooltip": "How strongly can weather (rain, wind, calm) affect spawn rate", "text.autoconfig.fallingleaves.option.coniferLeafSpawnRate": "Conifer Leaf Spawn Rate", "text.autoconfig.fallingleaves.option.coniferLeafSpawnRate.@Tooltip": "How many conifer leaves spawn over time", "text.autoconfig.fallingleaves.option.snowflakeSpawnRate": "Snowflake Spawn Rate", From edfc8f57c523ae98dfd79a413827bf218e3d7734 Mon Sep 17 00:00:00 2001 From: Cameron Hetzler Date: Fri, 31 Mar 2023 13:28:09 -0400 Subject: [PATCH 5/7] Update FallingLeavesConfig.java Need to make sure no funny business happens with bad user input. Signed-off-by: Cameron Hetzler --- .../fallingleaves/config/FallingLeavesConfig.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/randommcsomethin/fallingleaves/config/FallingLeavesConfig.java b/src/main/java/randommcsomethin/fallingleaves/config/FallingLeavesConfig.java index 400cc0f..9a2586e 100644 --- a/src/main/java/randommcsomethin/fallingleaves/config/FallingLeavesConfig.java +++ b/src/main/java/randommcsomethin/fallingleaves/config/FallingLeavesConfig.java @@ -59,12 +59,12 @@ public double getBaseLeafSpawnChance() { @ConfigEntry.Category("fallingleaves.general") @ConfigEntry.Gui.Tooltip - @ConfigEntry.BoundedDiscrete(max = 10) + @ConfigEntry.BoundedDiscrete(min = 0, max = 10) private int leafWindySpawnRate = 2; @ConfigEntry.Category("fallingleaves.general") @ConfigEntry.Gui.Tooltip - @ConfigEntry.BoundedDiscrete(max = 8) + @ConfigEntry.BoundedDiscrete(min = 1, max = 8) public int leafWeatherSpawnCoeficient = 4; // leaf spawn rate can be affected slightly by the magnitude From 46baabf9523dc0cd7ad78df6bd67aa10e8a0c706 Mon Sep 17 00:00:00 2001 From: Cameron Hetzler Date: Fri, 31 Mar 2023 13:42:39 -0400 Subject: [PATCH 6/7] Update .gitignore eclipse support Signed-off-by: Cameron Hetzler --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index f8c9ac5..d31e783 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,9 @@ *.iml *.ipr *.iws +/bin/ +.project +*.prefs # IntelliJ out/ From fee59b1d1ba47e06bc58a47d826e74d06b33e32c Mon Sep 17 00:00:00 2001 From: Cameron Hetzler Date: Sat, 1 Apr 2023 03:21:23 -0400 Subject: [PATCH 7/7] Changed rain to simple multiplication coefficient instead of any compounding. Wind is now heavily weighted around a multiplier of 1. To turn off with effect, set to 0. To turn off rain effect, set to 1. --- .../config/FallingLeavesConfig.java | 27 +++---------------- .../fallingleaves/util/LeafUtil.java | 12 ++++++--- .../fallingleaves/util/Wind.java | 6 +---- .../assets/fallingleaves/lang/en_us.json | 8 +++--- 4 files changed, 17 insertions(+), 36 deletions(-) diff --git a/src/main/java/randommcsomethin/fallingleaves/config/FallingLeavesConfig.java b/src/main/java/randommcsomethin/fallingleaves/config/FallingLeavesConfig.java index 9a2586e..8a7422f 100644 --- a/src/main/java/randommcsomethin/fallingleaves/config/FallingLeavesConfig.java +++ b/src/main/java/randommcsomethin/fallingleaves/config/FallingLeavesConfig.java @@ -59,32 +59,13 @@ public double getBaseLeafSpawnChance() { @ConfigEntry.Category("fallingleaves.general") @ConfigEntry.Gui.Tooltip - @ConfigEntry.BoundedDiscrete(min = 0, max = 10) - private int leafWindySpawnRate = 2; + @ConfigEntry.BoundedDiscrete(min = 0, max = 2) + public float leafWindySpawnCoefficient = 1.0f; @ConfigEntry.Category("fallingleaves.general") @ConfigEntry.Gui.Tooltip - @ConfigEntry.BoundedDiscrete(min = 1, max = 8) - public int leafWeatherSpawnCoeficient = 4; - - // leaf spawn rate can be affected slightly by the magnitude - // of the current wind speed. - // when weather events are in effect, spawn rate will be - // compounded based on the event with "Thunder" being - // the most intensive. - public double getWindyLeafSpawnCoeficient() { - - double actualSpawnCoeficient = 1 + (Wind.windMagnitute() * leafWindySpawnRate); - switch (Wind.getState()) { - case STORMY: - actualSpawnCoeficient *= leafWeatherSpawnCoeficient; - case WINDY: - actualSpawnCoeficient *= leafWeatherSpawnCoeficient; - default: - break; - } - return actualSpawnCoeficient; - } + @ConfigEntry.BoundedDiscrete(min = 1, max = 4) + public float leafRainSpawnCoefficient = 2.0f; @ConfigEntry.Category("fallingleaves.general") @ConfigEntry.Gui.Tooltip diff --git a/src/main/java/randommcsomethin/fallingleaves/util/LeafUtil.java b/src/main/java/randommcsomethin/fallingleaves/util/LeafUtil.java index 2749859..61a74da 100644 --- a/src/main/java/randommcsomethin/fallingleaves/util/LeafUtil.java +++ b/src/main/java/randommcsomethin/fallingleaves/util/LeafUtil.java @@ -43,7 +43,7 @@ public class LeafUtil { private static final Random renderRandom = Random.createLocal(); - public static double getModifiedSpawnChance(BlockState state, LeafSettingsEntry leafSettings) { + public static double getModifiedSpawnChance(BlockState state, World world, LeafSettingsEntry leafSettings) { double spawnChance = leafSettings.getSpawnChance(); if (FabricLoader.getInstance().isModLoaded("seasons")) { @@ -55,8 +55,12 @@ public static double getModifiedSpawnChance(BlockState state, LeafSettingsEntry spawnChance *= CONFIG.winterSpawnRateFactor; } } - - spawnChance *= CONFIG.getWindyLeafSpawnCoeficient(); + + // Compress the variability of wind speed to a number between .87 and 1.61, multiply this by coefficient + spawnChance *= Math.pow(Wind.windMagnitute() * 10, 0.2f * CONFIG.leafWindySpawnCoefficient); + + if (world.isRaining()) + spawnChance *= CONFIG.leafRainSpawnCoefficient; if (CONFIG.decaySpawnRateFactor != 1.0f) { if (isLeafBlock(state.getBlock(), true) && state.getBlock().hasRandomTicks(state)) { // decaying leaves have random ticks @@ -78,7 +82,7 @@ public static void trySpawnLeafAndSnowParticle(BlockState state, World world, Bl // every leaf block or leaf spawner should have a settings entry LeafSettingsEntry leafSettings = Objects.requireNonNull(getLeafSettingsEntry(state)); - double spawnChance = LeafUtil.getModifiedSpawnChance(state, leafSettings); + double spawnChance = LeafUtil.getModifiedSpawnChance(state, world, leafSettings); if (spawnChance != 0 && random.nextDouble() < spawnChance) { spawnLeafParticles(1, false, state, world, pos, random, leafSettings); diff --git a/src/main/java/randommcsomethin/fallingleaves/util/Wind.java b/src/main/java/randommcsomethin/fallingleaves/util/Wind.java index 6ff4b48..77bf058 100644 --- a/src/main/java/randommcsomethin/fallingleaves/util/Wind.java +++ b/src/main/java/randommcsomethin/fallingleaves/util/Wind.java @@ -63,11 +63,7 @@ public static void init() { } public static double windMagnitute() { - return Math.sqrt(Math.pow(windX, 2)+Math.pow(windZ, 2)); - } - - public static State getState() { - return state; + return velocityNoise.getNoise(); } protected static void tickState(ClientWorld world) { diff --git a/src/main/resources/assets/fallingleaves/lang/en_us.json b/src/main/resources/assets/fallingleaves/lang/en_us.json index a6e86cb..7ac4678 100644 --- a/src/main/resources/assets/fallingleaves/lang/en_us.json +++ b/src/main/resources/assets/fallingleaves/lang/en_us.json @@ -6,10 +6,10 @@ "text.autoconfig.fallingleaves.option.leafLifespan.@Tooltip": "20 ticks are roughly 1 second", "text.autoconfig.fallingleaves.option.leafSpawnRate": "Leaf Spawn Rate", "text.autoconfig.fallingleaves.option.leafSpawnRate.@Tooltip": "How many leaves spawn over time", - "text.autoconfig.fallingleaves.option.leafWindySpawnCoeficient": "Leaf Spawn Coeficient from Wind", - "text.autoconfig.fallingleaves.option.leafWindySpawnCoeficient.@Tooltip": "How strongly can wind magnitude affect spawn rate", - "text.autoconfig.fallingleaves.option.leafWeatherSpawnCoeficient": "Leaf Spawn Coeficient from Weather", - "text.autoconfig.fallingleaves.option.leafWeatherSpawnCoeficient.@Tooltip": "How strongly can weather (rain, wind, calm) affect spawn rate", + "text.autoconfig.fallingleaves.option.leafWindySpawnCoefficient": "Leaf Spawn Coeficient from Wind", + "text.autoconfig.fallingleaves.option.leafWindySpawnCoefficient.@Tooltip": "How strongly can wind affect spawn rate", + "text.autoconfig.fallingleaves.option.leafRainSpawnCoefficient": "Leaf Spawn Coeficient from Rain", + "text.autoconfig.fallingleaves.option.leafRainSpawnCoefficient.@Tooltip": "By what multiple should rain affect leaf rate", "text.autoconfig.fallingleaves.option.coniferLeafSpawnRate": "Conifer Leaf Spawn Rate", "text.autoconfig.fallingleaves.option.coniferLeafSpawnRate.@Tooltip": "How many conifer leaves spawn over time", "text.autoconfig.fallingleaves.option.snowflakeSpawnRate": "Snowflake Spawn Rate",