Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better compats #57

Merged
merged 8 commits into from
Dec 12, 2023
Merged
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: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ Basically everything about this mod is documented extensively on the [wiki](http
* [Farmer's Respite](https://www.curseforge.com/minecraft/mc-mods/farmers-respite): Teas and warm foods provide the Warmth effect
* [Festive Delight](https://www.curseforge.com/minecraft/mc-mods/festive-delight): Christmas Tea provides the Warmth effect
* [Frozen Up](https://www.curseforge.com/minecraft/mc-mods/frozen-up): Truffle Hot Chocolate provides the Warmth effect
* [Fabric Seasons](https://modrinth.com/mod/fabric-seasons): Winters in snowy and freezing biomes are *even colder* than normal
* [Spectrum](https://modrinth.com/mod/spectrum): Hot Chocolate, Demon Tea, Restoration Tea, and Glistering Jelly Tea provide the Warmth effect
* [Fabric Seasons](https://modrinth.com/mod/fabric-seasons): Winters in snowy and freezing biomes are *even colder* than normal. Freezing biomes are slightly warmer in Summer.

# Additional Credits

Expand Down
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ dependencies {
// Fabric Seasons https://modrinth.com/mod/fabric-seasons
modCompileOnly("maven.modrinth:fabric-seasons:${project.fabric_seasons_version}") { transitive = false }

// Farmer's Delight and add ons
modCompileOnly("maven.modrinth:farmers-delight-fabric:${project.farmers_delight_version}") { transitive = false }

modImplementation "dev.onyxstudios.cardinal-components-api:cardinal-components-base:${project.cardinal_components_version}"
modImplementation "dev.onyxstudios.cardinal-components-api:cardinal-components-entity:${project.cardinal_components_version}"
// Includes Cardinal Components API as a Jar-in-Jar dependency (optional but recommended)
Expand Down
7 changes: 5 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ loader_version=0.14.21


# Mod Properties
mod_version = 1.0.0
mod_version = 1.0.1
maven_group = com.github.thedeathlycow
archives_base_name = frostiful

Expand Down Expand Up @@ -39,4 +39,7 @@ cardinal_components_version=5.2.1
trinkets_version=3.7.0

# Fabric Seasons
fabric_seasons_version=2.3+1.20
fabric_seasons_version=2.3+1.20

# Farmer's Delight and addons
farmers_delight_version=1.4.3
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.github.thedeathlycow.frostiful.compat;

import com.github.thedeathlycow.frostiful.survival.BiomeCategory;
import io.github.lucaargolo.seasons.FabricSeasons;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;

/**
* Used as a mod-neutral adapter for different possible seasons from other mods.
*/
public enum AdaptedSeason {

SPRING,
SUMMER,
AUTUMN,
WINTER,
WET_SEASON,
DRY_SEASON;


/**
* Gets the current season in the world. Returns null if no season mod is enabled.
*
* @param world The world to get the season for.
* @return Returns the current season. Returns null if no season mod is enabled.
*/
@Nullable
public static AdaptedSeason getCurrentSeason(World world) {
if (FrostifulIntegrations.isModLoaded(FrostifulIntegrations.FABRIC_SEASONS_ID)) {
return switch (FabricSeasons.getCurrentSeason(world)) {
case SUMMER -> AdaptedSeason.SUMMER;
case WINTER -> AdaptedSeason.WINTER;
case FALL -> AdaptedSeason.AUTUMN;
case SPRING -> AdaptedSeason.SPRING;
};
} else {
return null;
}
}

/**
* Adjusts biome categories for their season.
*
* @param season The current season
* @param normalCategory The normal category of the biome if no season mod was enabled.
* @return Returns the biome category, adjusted for the season.
*/
public static BiomeCategory getSeasonallyShiftedBiomeCategory(
@Nullable AdaptedSeason season,
BiomeCategory normalCategory
) {
if (isSummer(season) && normalCategory == BiomeCategory.FREEZING) {
return BiomeCategory.COLD;
}
return normalCategory;
}

/**
* Checks if the current season is one of the two possible summer seasons.
*
* @param season The current season
* @return Returns true if the season is {@link #SUMMER} or {@link #DRY_SEASON}
*/
public static boolean isSummer(@Nullable AdaptedSeason season) {
return season == SUMMER || season == DRY_SEASON;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.github.thedeathlycow.frostiful.compat;

import com.github.thedeathlycow.frostiful.Frostiful;
import com.github.thedeathlycow.frostiful.entity.effect.FStatusEffects;
import com.github.thedeathlycow.frostiful.tag.FItemTags;
import com.github.thedeathlycow.frostiful.util.TextStyles;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.text.Text;

import java.util.List;

public class FoodIntegration {

public static void onConsumeFood(Item item, ItemStack stack, LivingEntity user) {
if (isWarmingFood(item, stack)) {
applyWarmthFromFood(user);
}
}

public static void appendWarmthTooltip(Item item, ItemStack stack, List<Text> tooltip) {
if (isWarmingFood(item, stack)) {
tooltip.add(Text.translatable("item.frostiful.warming.tooltip")
.setStyle(TextStyles.WARMING_TOOLTIP));
}
}

private static boolean isWarmingFood(Item item, ItemStack stack) {
return stack.isIn(FItemTags.WARM_FOODS);
}

private static void applyWarmthFromFood(LivingEntity user) {
int duration = Frostiful.getConfig().freezingConfig.getWarmFoodWarmthTime();
user.addStatusEffect(new StatusEffectInstance(FStatusEffects.WARMTH, duration));
}

private FoodIntegration() {

}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.github.thedeathlycow.frostiful.compat;

import io.github.lucaargolo.seasons.FabricSeasons;
import io.github.lucaargolo.seasons.utils.Season;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.world.World;

public class FrostifulIntegrations {

Expand All @@ -24,12 +21,4 @@ public static boolean isHeartsRenderOverridden() {
public static boolean isModLoaded(String id) {
return FabricLoader.getInstance().isModLoaded(id);
}

public static boolean isWinter(World world) {
if (isModLoaded(FABRIC_SEASONS_ID)) {
return Season.WINTER == FabricSeasons.getCurrentSeason(world);
} else {
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class EnvironmentConfigGroup implements ConfigData {
int ultrawarmWarmRate = 15;

int winterTemperatureShift = -1;
boolean isNightColdInSummer = false;

public boolean doDryBiomeNightFreezing() {
return doDryBiomeNightFreezing;
Expand Down Expand Up @@ -84,4 +85,8 @@ public int getUltrawarmWarmRate() {
public int getWinterTemperatureShift() {
return winterTemperatureShift;
}

public boolean isNightColdInSummer() {
return isNightColdInSummer;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.github.thedeathlycow.frostiful.mixins.compat.farmersdelight.present;

import com.github.thedeathlycow.frostiful.compat.FoodIntegration;
import com.nhoryzon.mc.farmersdelight.item.HotCocoaItem;
import com.nhoryzon.mc.farmersdelight.item.MilkBottleItem;
import net.minecraft.client.item.TooltipContext;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.text.Text;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.List;

@Mixin(HotCocoaItem.class)
public abstract class HotCocoaItemMixin extends MilkBottleItem {

@Inject(
method = "affectConsumer",
at = @At("HEAD")
)
private void onConsume(ItemStack stack, World world, LivingEntity user, CallbackInfo ci) {
FoodIntegration.onConsumeFood(this, stack, user);
}

@Inject(
method = "appendTooltip",
at = @At("HEAD")
)
private void appendWarmthToolTip(ItemStack stack, @Nullable World world, List<Text> tooltip, TooltipContext context, CallbackInfo ci) {
FoodIntegration.appendWarmthTooltip(this, stack, tooltip);
}

}
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
package com.github.thedeathlycow.frostiful.mixins.food.compat;

import com.github.thedeathlycow.frostiful.Frostiful;
import com.github.thedeathlycow.frostiful.entity.effect.FStatusEffects;
import com.github.thedeathlycow.frostiful.tag.FItemTags;
import com.github.thedeathlycow.frostiful.util.TextStyles;
import com.github.thedeathlycow.frostiful.compat.FoodIntegration;
import net.minecraft.client.item.TooltipContext;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.text.Text;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
Expand All @@ -24,8 +19,6 @@
@Mixin(Item.class)
public abstract class WarmFoodMixin {

@Shadow public abstract boolean isFood();

@Inject(
method = "finishUsing",
at = @At("HEAD")
Expand All @@ -36,10 +29,7 @@ private void addWarmthToWarmFoods(
LivingEntity user,
CallbackInfoReturnable<ItemStack> cir
) {
if (this.isWarmingFood(stack)) {
int duration = Frostiful.getConfig().freezingConfig.getWarmFoodWarmthTime();
user.addStatusEffect(new StatusEffectInstance(FStatusEffects.WARMTH, duration));
}
FoodIntegration.onConsumeFood((Item) (Object) this, stack, user);
}

@Inject(
Expand All @@ -53,17 +43,6 @@ private void addToolTip(
TooltipContext context,
CallbackInfo ci
) {
if (this.isWarmingFood(stack)) {
tooltip.add(Text.translatable("item.frostiful.warming.tooltip")
.setStyle(TextStyles.WARMING_TOOLTIP));
}
}

private boolean isWarmingFood(ItemStack stack) {
return this.isFood() && stack.isIn(FItemTags.WARM_FOODS);
FoodIntegration.appendWarmthTooltip((Item) (Object) this, stack, tooltip);
}




}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.github.thedeathlycow.frostiful.survival;

import com.github.thedeathlycow.frostiful.Frostiful;
import com.github.thedeathlycow.frostiful.compat.FrostifulIntegrations;
import com.github.thedeathlycow.frostiful.compat.AdaptedSeason;
import com.github.thedeathlycow.frostiful.config.FrostifulConfig;
import com.github.thedeathlycow.frostiful.tag.FBlockTags;
import com.github.thedeathlycow.thermoo.api.temperature.EnvironmentController;
Expand All @@ -14,6 +14,7 @@
import net.minecraft.world.LightType;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
import org.jetbrains.annotations.Nullable;

public class AmbientTemperatureController extends EnvironmentControllerDecorator {

Expand Down Expand Up @@ -79,12 +80,10 @@ public boolean isAreaHeated(World world, BlockPos pos) {
private int getNaturalWorldTemperatureChange(World world, BlockPos pos) {
RegistryEntry<Biome> biome = world.getBiome(pos);

BiomeCategory category = BiomeCategory.fromBiome(biome);
int temp = category.getTemperatureChange(world);
@Nullable AdaptedSeason season = AdaptedSeason.getCurrentSeason(world);
BiomeCategory category = BiomeCategory.fromBiome(biome, season);
int temp = category.getTemperatureChange(world, season);
if (temp < 0) {
if (FrostifulIntegrations.isWinter(world)) {
temp += Frostiful.getConfig().environmentConfig.getWinterTemperatureShift();
}
return temp;
}

Expand Down
Loading
Loading