Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
*.iml
*.ipr
*.iws
/bin/
.project
*.prefs

# IntelliJ
out/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/randommcsomethin/fallingleaves/util/LeafUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand All @@ -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;
Expand All @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/randommcsomethin/fallingleaves/util/Wind.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/assets/fallingleaves/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down