Skip to content

Commit

Permalink
warming food compat with farmers delight
Browse files Browse the repository at this point in the history
  • Loading branch information
TheDeathlyCow committed Dec 1, 2023
1 parent c44145c commit 5722263
Show file tree
Hide file tree
Showing 8 changed files with 211 additions and 1 deletion.
2 changes: 1 addition & 1 deletion 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 = 0.10
mod_version = 1.0.0-alpha.1
maven_group = com.github.thedeathlycow
archives_base_name = frostiful

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.github.thedeathlycow.frostiful.item;

import net.minecraft.item.FoodComponent;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;

public class FoodHelper {

@Contract("_->new")
@NotNull
public static FoodComponent copyFoodComponent(@NotNull FoodComponent other) {
var builder = new FoodComponent.Builder();
builder.hunger(other.getHunger());
builder.saturationModifier(other.getSaturationModifier());
other.getStatusEffects().forEach(effectAndChance -> {
builder.statusEffect(effectAndChance.getFirst(), effectAndChance.getSecond());
});
if (other.isAlwaysEdible()) {
builder.alwaysEdible();
}
if (other.isMeat()) {
builder.meat();
}
if (other.isSnack()) {
builder.snack();
}

return builder.build();
}

private FoodHelper() {

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

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.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;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.List;

@Mixin(Item.class)
public abstract class WarmFoodMixin {

@Shadow public abstract boolean isFood();

@Inject(
method = "finishUsing",
at = @At("HEAD")
)
private void addWarmthToWarmFoods(
ItemStack stack,
World world,
LivingEntity user,
CallbackInfoReturnable<ItemStack> cir
) {
if (this.isWarmingFood(stack)) {
user.addStatusEffect(new StatusEffectInstance(FStatusEffects.WARMTH, 30 * 20));
}
}

@Inject(
method = "appendTooltip",
at = @At("TAIL")
)
private void addToolTip(
ItemStack stack,
@Nullable World world,
List<Text> tooltip,
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);
}




}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public final class FItemTags {

public static final TagKey<Item> ICE_SKATES = register("ice_skates");

public static final TagKey<Item> WARM_FOODS = register("warm_foods");


private static TagKey<Item> register(String id) {
return TagKey.of(RegistryKeys.ITEM, new Identifier(Frostiful.MODID, id));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,12 @@ public class TextStyles {
public static final Style FROSTOLOGY_CLOAK_TOOLTIP = Style.EMPTY
.withItalic(true)
.withColor(TextColor.parse("blue"));

public static final Style WARMING_TOOLTIP = Style.EMPTY
.withItalic(false)
.withColor(TextColor.parse("gold"));

private TextStyles() {

}
}
1 change: 1 addition & 0 deletions src/main/resources/assets/frostiful/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"item.frostiful.ice_skates": "Ice Skates",
"item.frostiful.armored_ice_skates": "Armored Ice Skates",
"item.frostiful.frostology_cloak.tooltip": "Become Ice-like",
"item.frostiful.warming.tooltip": "Warming \uD83D\uDD25",

"item.minecraft.potion.effect.frostiful.freezing": "Potion of Freezing",
"item.minecraft.potion.effect.frostiful.freezing_long": "Potion of Freezing",
Expand Down
97 changes: 97 additions & 0 deletions src/main/resources/data/frostiful/tags/items/warm_foods.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
{
"replace": false,
"values": [
{
"id": "farmersdelight:hot_cocoa",
"required": false
},
{
"id": "frozenup:mug_of_truffle_hot_chocolate",
"required": false
},
{
"id": "farmersrespite:green_tea",
"required": false
},
{
"id": "farmersrespite:yellow_tea",
"required": false
},
{
"id": "farmersrespite:black_tea",
"required": false
},
{
"id": "farmersrespite:rose_hip_tea",
"required": false
},
{
"id": "farmersrespite:dandelion_tea",
"required": false
},
{
"id": "farmersrespite:purulent_tea",
"required": false
},
{
"id": "farmersrespite:coffee",
"required": false
},
{
"id": "farmersrespite:long_green_tea",
"required": false
},
{
"id": "farmersrespite:long_yellow_tea",
"required": false
},
{
"id": "farmersrespite:long_black_tea",
"required": false
},
{
"id": "farmersrespite:long_dandelion_tea",
"required": false
},
{
"id": "farmersrespite:long_coffee",
"required": false
},
{
"id": "farmersrespite:strong_green_tea",
"required": false
},
{
"id": "farmersrespite:strong_yellow_tea",
"required": false
},
{
"id": "farmersrespite:strong_black_tea",
"required": false
},
{
"id": "farmersrespite:strong_purulent_tea",
"required": false
},
{
"id": "farmersrespite:strong_rose_hip_tea",
"required": false
},
{
"id": "farmersrespite:strong_coffee",
"required": false
},
{
"id": "farmersrespite:tea_curry",
"required": false
},
{
"id": "farmersrespite:blazing_chili",
"required": false
},
{
"id": "festive_delight:christmas_tea",
"required": false
}
]
}
1 change: 1 addition & 0 deletions src/main/resources/frostiful.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"entity.shearing.MobShearingMixin",
"entity.shearing.PolarBearShearingMixin",
"entity.soaking.WaterPotionSoakingMixin",
"food.compat.WarmFoodMixin",
"item.ArmorItemMixin",
"item.ArmorTrimPatternsMixin",
"powder_snow_effects.EntityPowderSnowRedirect",
Expand Down

0 comments on commit 5722263

Please sign in to comment.