Skip to content

Commit

Permalink
add compatibility for serene seasons
Browse files Browse the repository at this point in the history
  • Loading branch information
Fourmisain committed Nov 27, 2024
1 parent 51cd97c commit 74c2213
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 13 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ dependencies {
}

modCompileOnly "maven.modrinth:fabric-seasons:${project.fabric_seasons_version}"
modCompileOnly "maven.modrinth:serene-seasons:${project.serene_seasons_version}"
}

processResources {
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ fabric_api_version=0.106.1+1.21.2
cloth_config_version=16.0.141
modmenu_version=12.0.0-beta.1
fabric_seasons_version=2.4.2-BETA+1.21
serene_seasons_version=S5y2NO2L

# Publishing
modrinth_id=WhbRG4iK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import randommcsomethin.fallingleaves.init.Leaves;
import randommcsomethin.fallingleaves.particle.FallingLeafParticle;
import randommcsomethin.fallingleaves.seasons.Seasons;
import randommcsomethin.fallingleaves.util.Wind;

import java.util.Map;
Expand Down Expand Up @@ -57,10 +58,11 @@ public void registerLeafFactories(CallbackInfo ci) {
}

@Inject(method = "tick", at = @At("HEAD"))
public void tickWind(CallbackInfo ci) {
public void tick(CallbackInfo ci) {
if (!CONFIG.enabled)
return;

Seasons.tick(world);
Wind.tick(world);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package randommcsomethin.fallingleaves.seasons;

public class FabricSeasonsCompat {
public static Season convertSeason(io.github.lucaargolo.seasons.utils.Season season) {
return switch (season) {
case SPRING -> Season.SPRING;
case SUMMER -> Season.SUMMER;
case FALL -> Season.FALL;
case WINTER -> Season.WINTER;
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package randommcsomethin.fallingleaves.seasons;

// abstract over Fabric Seasons and Serene Seasons
public enum Season {
SPRING,
SUMMER,
FALL,
WINTER
}
29 changes: 29 additions & 0 deletions src/main/java/randommcsomethin/fallingleaves/seasons/Seasons.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package randommcsomethin.fallingleaves.seasons;

import io.github.lucaargolo.seasons.FabricSeasons;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.world.ClientWorld;
import org.jetbrains.annotations.Nullable;
import randommcsomethin.fallingleaves.FallingLeavesClient;
import sereneseasons.api.season.SeasonHelper;

public class Seasons {
@Nullable
public static Season currentSeason = null;

public static void tick(ClientWorld world) {
Season newSeason = null;

if (FabricLoader.getInstance().isModLoaded("seasons")) {
newSeason = FabricSeasonsCompat.convertSeason(FabricSeasons.getCurrentSeason());
} else if (FabricLoader.getInstance().isModLoaded("sereneseasons")) {
newSeason = SereneSeasonsCompat.convertSeason(SeasonHelper.getSeasonState(world).getSeason());
}

if (currentSeason != newSeason) {
FallingLeavesClient.LOGGER.debug("changed season {} -> {}", currentSeason, newSeason);
}

currentSeason = newSeason;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package randommcsomethin.fallingleaves.seasons;

public class SereneSeasonsCompat {
public static Season convertSeason(sereneseasons.api.season.Season season) {
return switch (season) {
case SPRING -> Season.SPRING;
case SUMMER -> Season.SUMMER;
case AUTUMN -> Season.FALL;
case WINTER -> Season.WINTER;
};
}
}
21 changes: 9 additions & 12 deletions src/main/java/randommcsomethin/fallingleaves/util/LeafUtil.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package randommcsomethin.fallingleaves.util;

import io.github.lucaargolo.seasons.FabricSeasons;
import io.github.lucaargolo.seasons.utils.Season;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.block.*;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.particle.Particle;
Expand All @@ -29,6 +26,8 @@
import randommcsomethin.fallingleaves.init.Leaves;
import randommcsomethin.fallingleaves.mixin.NativeImageAccessor;
import randommcsomethin.fallingleaves.mixin.SpriteContentsAccessor;
import randommcsomethin.fallingleaves.seasons.Season;
import randommcsomethin.fallingleaves.seasons.Seasons;

import java.util.List;
import java.util.Map;
Expand All @@ -46,14 +45,12 @@ public class LeafUtil {
public static double getModifiedSpawnChance(BlockState state, LeafSettingsEntry leafSettings) {
double spawnChance = leafSettings.getSpawnChance();

if (FabricLoader.getInstance().isModLoaded("seasons")) {
if (FabricSeasons.getCurrentSeason() == Season.FALL) {
// TODO this is a bit weird because some trees like Traverse's autumnal leaves already have boosted values
// double autumn, what does it mean?
spawnChance *= CONFIG.fallSpawnRateFactor;
} else if (FabricSeasons.getCurrentSeason() == Season.WINTER) {
spawnChance *= CONFIG.winterSpawnRateFactor;
}
if (Seasons.currentSeason == Season.FALL) {
// TODO this is a bit weird because some trees like Traverse's autumnal leaves already have boosted values
// double autumn, what does it mean?
spawnChance *= CONFIG.fallSpawnRateFactor;
} else if (Seasons.currentSeason == Season.WINTER) {
spawnChance *= CONFIG.winterSpawnRateFactor;
}

if (CONFIG.decaySpawnRateFactor != 1.0f) {
Expand Down Expand Up @@ -103,7 +100,7 @@ public static void spawnSnowParticles(int count, boolean spawnInsideBlock, Block
boolean snowy = false;

boolean snowyVillagers = VillagerType.forBiome(world.getBiome(pos)) == VillagerType.SNOW;
boolean isSummer = FabricLoader.getInstance().isModLoaded("seasons") && FabricSeasons.getCurrentSeason() == Season.SUMMER;
boolean isSummer = Seasons.currentSeason == Season.SUMMER;

// matches all snowy vanilla biomes
if (!isSummer && snowyVillagers) {
Expand Down

0 comments on commit 74c2213

Please sign in to comment.