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/ diff --git a/src/main/java/randommcsomethin/fallingleaves/config/FallingLeavesConfig.java b/src/main/java/randommcsomethin/fallingleaves/config/FallingLeavesConfig.java index 81d59d3..8a7422f 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,16 @@ public double getBaseLeafSpawnChance() { double actualSpawnRate = leafSpawnRate / 10.0; return actualSpawnRate / 75.0; } + + @ConfigEntry.Category("fallingleaves.general") + @ConfigEntry.Gui.Tooltip + @ConfigEntry.BoundedDiscrete(min = 0, max = 2) + public float leafWindySpawnCoefficient = 1.0f; + + @ConfigEntry.Category("fallingleaves.general") + @ConfigEntry.Gui.Tooltip + @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 4f9820d..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")) { @@ -56,6 +56,12 @@ public static double getModifiedSpawnChance(BlockState state, LeafSettingsEntry } } + // 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 spawnChance *= CONFIG.decaySpawnRateFactor; @@ -76,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 c3db372..77bf058 100644 --- a/src/main/java/randommcsomethin/fallingleaves/util/Wind.java +++ b/src/main/java/randommcsomethin/fallingleaves/util/Wind.java @@ -61,6 +61,10 @@ public static void init() { return (2f * rng.nextFloat() - 1f) * TAU / 8f; }); } + + public static double windMagnitute() { + return velocityNoise.getNoise(); + } 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..7ac4678 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.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",