From e5f43d5ee321472aac1cbb7fce02876ed5b03c8e Mon Sep 17 00:00:00 2001 From: XxFran10xX <318299142+XxFran10xX@users.noreply.github.com> Date: Sun, 15 Nov 2026 15:08:58 +0100 Subject: [PATCH 1/2] tune: cooked food keeps three days, raw food lasts longer, faster horses Cooked food (cooked, boiled or burnt) now ages at most as slowly as config.yml cooked-freshness (3 days by default, 0 turns it off); a type's own cooked-freshness in types.yml replaces it (bread keeps 7 once baked). Raw and cooked food share a type, so this is the only way to give cooked food its own shelf life. The stored age is in units of the multiplier, so cooking keeps the share of freshness already used and never makes food fresher. Default configs follow fran's 2026-11-15 values: wheat, flour and dry ration 28 days; whole, cut and chopped vegetables, fruit, butter, dough and yeast 21; meat, sausage, egg, milk and seafood 14; bread 7; soup and sauce 3. Stale food keeps its full nutrition (0.8 -> 1.0) and food rots at 1.5 times its fresh days (108000 -> 129600). Horses (only) reach 0.31 speed (about 92% of vanilla's best), start from 0.11 and jump up to 0.93. Co-Authored-By: Claude Opus 5.5 --- .../tfminecraft/cooking/cache/ItemCache.java | 2 + .../tfminecraft/cooking/item/FoodItem.java | 33 +++++ .../cooking/loader/ConfigLoader.java | 1 + src/main/resources/config.yml | 4 + src/main/resources/husbandry.yml | 6 +- src/main/resources/tags.yml | 6 +- src/main/resources/types.yml | 64 ++++----- .../cooking/item/CookedFreshnessCapTest.java | 126 ++++++++++++++++++ .../cooking/item/ShelfLifeDefaultsTest.java | 49 ++++++- 9 files changed, 248 insertions(+), 43 deletions(-) create mode 100644 src/test/java/net/tfminecraft/cooking/item/CookedFreshnessCapTest.java diff --git a/src/main/java/net/tfminecraft/cooking/cache/ItemCache.java b/src/main/java/net/tfminecraft/cooking/cache/ItemCache.java index f95782c..a17f369 100644 --- a/src/main/java/net/tfminecraft/cooking/cache/ItemCache.java +++ b/src/main/java/net/tfminecraft/cooking/cache/ItemCache.java @@ -37,6 +37,8 @@ public class ItemCache { public static String potWaterInput; public static String potLiquidDisplay; public static int potSoupScoops = 3; + /** config.yml cooked-freshness: cooked food's freshness multiplier cap (days fresh); 0 or less turns it off. */ + public static double cookedFreshness = 3.0; public static int potSoupHeightDivisor = 4; public static String flour; diff --git a/src/main/java/net/tfminecraft/cooking/item/FoodItem.java b/src/main/java/net/tfminecraft/cooking/item/FoodItem.java index 81a0258..f4d3281 100644 --- a/src/main/java/net/tfminecraft/cooking/item/FoodItem.java +++ b/src/main/java/net/tfminecraft/cooking/item/FoodItem.java @@ -7,6 +7,7 @@ import org.bukkit.persistence.PersistentDataType; import net.tfminecraft.tlibs.objects.api.subapi.StringFormatter; +import net.tfminecraft.cooking.cache.ItemCache; import net.tfminecraft.cooking.item.data.CookData; import net.tfminecraft.cooking.item.data.OverrideData; import net.tfminecraft.cooking.item.model.FoodModel; @@ -28,6 +29,8 @@ import java.util.*; public class FoodItem { + private static final String FRESHNESS_TRACK = "freshness"; + private static final String COOKED_TRACK = "cooked"; private final String id; private final String name; @@ -64,6 +67,8 @@ public class FoodItem { private Map overrides = new HashMap<>(); private Map age = new HashMap<>(); private Map ageRemainder = new HashMap<>(); + /** types.yml cooked-freshness: this type's freshness once cooked, in place of config.yml's; null = use config.yml's. */ + private Double cookedFreshness; private Map> tagLabels = new HashMap<>(); private List ingredients = new ArrayList<>(); private IngredientLineage lineage = IngredientLineage.empty(); @@ -128,6 +133,9 @@ public FoodItem(String key, ConfigurationSection config) { } this.age.putAll(readAge(config.getConfigurationSection("age"))); + if (config.contains("cooked-freshness")) { + this.cookedFreshness = config.getDouble("cooked-freshness"); + } ConfigurationSection labelSec = config.getConfigurationSection("tag-labels"); if (labelSec != null) { @@ -184,6 +192,7 @@ public FoodItem(FoodItem other) { this.overrides = new HashMap<>(other.overrides); this.age = new HashMap<>(other.age); this.ageRemainder = new HashMap<>(other.ageRemainder); + this.cookedFreshness = other.cookedFreshness; this.tagLabels = new HashMap<>(); for (Map.Entry> entry : other.tagLabels.entrySet()) { this.tagLabels.put(entry.getKey(), new HashMap<>(entry.getValue())); @@ -417,7 +426,31 @@ public void addIngredient(String ingredient) { public void setOrigin(String o) { origin = o; } public String getOrigin() { return origin; } + /** + * How slowly this food ages on a track (types.yml age, an origin override first). Once the food is cooked (its cooked + * track is past Raw: cooked, boiled or burnt), freshness ages at most as slowly as the cooked cap, so cooked food + * lasts that many days however long its raw ingredient keeps. The stored age is in units of the multiplier, so + * switching to the cap keeps the share of freshness already used: cooking never makes food fresher. + */ public double resolveAgeMultiplier(String trackId) { + double base = resolveTypeAgeMultiplier(trackId); + if (!FRESHNESS_TRACK.equalsIgnoreCase(trackId) || !isCooked()) { + return base; + } + double cap = cookedFreshness != null ? cookedFreshness : ItemCache.cookedFreshness; + if (!Double.isFinite(cap) || cap <= 0) { + return base; + } + return Math.min(base, cap); + } + + /** True when the food carries a cooked track past its first (Raw) step. */ + public boolean isCooked() { + TagTrack cooked = tags.get(COOKED_TRACK); + return cooked != null && cooked.getValue() > 0; + } + + private double resolveTypeAgeMultiplier(String trackId) { if (trackId == null) { return AgeScale.DEFAULT; } diff --git a/src/main/java/net/tfminecraft/cooking/loader/ConfigLoader.java b/src/main/java/net/tfminecraft/cooking/loader/ConfigLoader.java index 7e8b69a..ffd6f73 100644 --- a/src/main/java/net/tfminecraft/cooking/loader/ConfigLoader.java +++ b/src/main/java/net/tfminecraft/cooking/loader/ConfigLoader.java @@ -70,6 +70,7 @@ public void loadConfig(File configFile) { ItemCache.potLiquidDisplay = config.getString("pot-liquid-display", "ia.tfmc_cooking:water"); ItemCache.potSoupScoops = Math.max(1, config.getInt("pot-soup-scoops", 3)); ItemCache.potSoupHeightDivisor = Math.max(1, config.getInt("pot-soup-height-divisor", 4)); + ItemCache.cookedFreshness = config.getDouble("cooked-freshness", 3.0); ItemCache.ladle = config.getString("ladle", "none"); ItemCache.masher = config.getString("masher", "none"); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index e6bd29b..45a9ab4 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -50,6 +50,10 @@ pot-liquid-display: ia.tfmc_cooking:water pot-soup-scoops: 3 pot-soup-height-divisor: 4 +# Cooked food (cooked, boiled or burnt) stays fresh at most this many days, however long the raw +# food keeps; a type's own cooked-freshness in types.yml replaces it. 0 turns the cap off. +cooked-freshness: 3 + ladle: ia.tfmc_cooking:ladle masher: ia.tfmc_cooking:masher diff --git a/src/main/resources/husbandry.yml b/src/main/resources/husbandry.yml index 8eebfc4..28ac777 100644 --- a/src/main/resources/husbandry.yml +++ b/src/main/resources/husbandry.yml @@ -399,10 +399,10 @@ mounts: HORSE: min-health: 10 max-health: 27 - min-speed: 0.0675 - max-speed: 0.27 + min-speed: 0.11 + max-speed: 0.31 min-jump: 0.24 - max-jump: 0.8 + max-jump: 0.93 DONKEY: min-health: 10 max-health: 20 diff --git a/src/main/resources/tags.yml b/src/main/resources/tags.yml index 1d701d3..2c0021b 100644 --- a/src/main/resources/tags.yml +++ b/src/main/resources/tags.yml @@ -4,7 +4,7 @@ # stars: added to inherited quality while this step is active. Negative lowers the star rating. # effects: status effects eating a food at this step gives, as " [level]" (Minecraft effect ids, # level 1 = I), e.g. - "poison 10 1". They apply even when the track is hidden. -# Age values are seconds at age.freshness 1.0 (stale = 1 day, rotten = 1.25 days). +# Age values are seconds at age.freshness 1.0 (stale = 1 day, rotten = 1.5 days). # Per-type duration is types.yml age.freshness (higher = lasts longer). freshness: ageable: true @@ -15,11 +15,11 @@ freshness: stale: name: "#c3db81Stale" value: 86400 - nutrition-mult: 0.8 + nutrition-mult: 1.0 quality-reduce: 0.25 rotten: name: "#0a6935Rotten" - value: 108000 + value: 129600 nutrition-mult: 0.05 food-mult: 0.6 quality-reduce: 0.75 diff --git a/src/main/resources/types.yml b/src/main/resources/types.yml index 05af395..3e3cea6 100644 --- a/src/main/resources/types.yml +++ b/src/main/resources/types.yml @@ -4,7 +4,7 @@ roast: age: warmth: 450 - freshness: 7 + freshness: 14 name: "#d9baa5{inherit}" overrides: CHICKEN: @@ -63,7 +63,7 @@ roast: meat_poultry: age: warmth: 450 - freshness: 7 + freshness: 14 name: "#d9baa5{inherit}" overrides: CHICKEN: @@ -86,7 +86,7 @@ meat_poultry: meat_poultry_leg: age: warmth: 450 - freshness: 7 + freshness: 14 name: "#d9baa5{inherit} Leg" overrides: CHICKEN: @@ -104,7 +104,7 @@ meat_poultry_leg: meat_red_meat: age: warmth: 450 - freshness: 7 + freshness: 14 name: "#d9baa5Steak" overrides: BEEF: @@ -130,7 +130,7 @@ meat_red_meat: meat_pork: age: warmth: 450 - freshness: 7 + freshness: 14 name: "#d9baa5Pork" model: meat_pork food: 20 @@ -144,7 +144,7 @@ meat_pork: sausage: age: warmth: 450 - freshness: 7 + freshness: 14 name: "#d9baa5Sausage" model: sausage food: 20 @@ -158,7 +158,7 @@ sausage: sausage_chain: age: warmth: 450 - freshness: 7 + freshness: 14 name: "#d9baa5Sausage Chain" model: sausage_chain food: 20 @@ -182,7 +182,7 @@ vegetable_1: nutrition: 4.5 age: warmth: 450 - freshness: 14 + freshness: 21 ###Veggies — raw CustomCrops vegetable_2: @@ -204,7 +204,7 @@ vegetable_2: nutrition: 7.5 age: warmth: 450 - freshness: 14 + freshness: 21 ###Veggies — raw (chop only, no cut step; excludes from cut_vegetables recipe) vegetable_chop_only: @@ -223,7 +223,7 @@ vegetable_chop_only: nutrition: 6 age: warmth: 450 - freshness: 14 + freshness: 21 ###Veggies — cut vanilla (pan + pot) vegetable_cut: @@ -252,7 +252,7 @@ vegetable_cut: burn: 30 age: warmth: 450 - freshness: 10 + freshness: 21 ###Veggies — cut CustomCrops (pan + pot) vegetable_cut_2: @@ -284,7 +284,7 @@ vegetable_cut_2: burn: 30 age: warmth: 450 - freshness: 10 + freshness: 21 ###Veggies — chopped garnish vanilla (no cooking; cook on cut stage) vegetable_chopped: @@ -303,7 +303,7 @@ vegetable_chopped: nutrition: 4.5 age: warmth: 450 - freshness: 8 + freshness: 21 ###Veggies — chopped garnish CustomCrops (chopped corn pops into popcorn in the frying pan) vegetable_chopped_2: @@ -336,7 +336,7 @@ vegetable_chopped_2: output: snack(type=popcorn;origin=Corn) age: warmth: 450 - freshness: 8 + freshness: 21 ###Seasoning — does not spoil seasoning_1: @@ -416,13 +416,15 @@ garnish_chopped: nutrition: 6 age: warmth: 450 - freshness: 8 + freshness: 21 ###Baked goods bread: + # Bread keeps its own days once baked (config.yml cooked-freshness is for cooked dishes). + cooked-freshness: 7 age: warmth: 450 - freshness: 14 + freshness: 7 name: "#d9c4a5{prefixes}{fillers}Bread" model: bread food: 26 @@ -438,7 +440,7 @@ dry_ration: nutrition: 5 age: warmth: 450 - freshness: 20 + freshness: 28 ###Fruits — raw vanilla (no cut step) fruit_1: @@ -457,7 +459,7 @@ fruit_1: nutrition: 5.25 age: warmth: 450 - freshness: 14 + freshness: 21 ###Fruits — raw CustomCrops fruit_2: @@ -489,7 +491,7 @@ fruit_2: nutrition: 8.75 age: warmth: 450 - freshness: 14 + freshness: 21 ##Crops wheat: @@ -499,7 +501,7 @@ wheat: nutrition: 4 age: warmth: 450 - freshness: 20 + freshness: 28 flour: name: "#f5f0e8Flour" @@ -518,7 +520,7 @@ flour: output: thickener(type=roux;origin=Roux;tags=processed.0) age: warmth: 450 - freshness: 20 + freshness: 28 tag-labels: freshness: rotten: "#8B7355Musty" @@ -530,7 +532,7 @@ yeast: nutrition: 4 age: warmth: 450 - freshness: 7 + freshness: 21 tag-labels: freshness: rotten: "#8B7355Mouldy" @@ -542,7 +544,7 @@ dough: nutrition: 4 age: warmth: 450 - freshness: 7 + freshness: 21 rising: 1 tag-labels: freshness: @@ -663,7 +665,7 @@ cup_of_milk: nutrition: 6 age: warmth: 450 - freshness: 7 + freshness: 14 tag-labels: freshness: stale: "#c3db81Sour" @@ -676,7 +678,7 @@ milk_bucket: nutrition: 6 age: warmth: 450 - freshness: 7 + freshness: 14 tag-labels: freshness: stale: "#c3db81Sour" @@ -688,7 +690,7 @@ seafood_whole: nutrition: 6 age: warmth: 450 - freshness: 9.33 + freshness: 14 seafood_fish_filet: name: "#6fa8dc{inherit} Filet" @@ -707,7 +709,7 @@ seafood_fish_filet: burn: 30 age: warmth: 450 - freshness: 9.33 + freshness: 14 tag-labels: freshness: stale: "#c3db81Stale" @@ -730,7 +732,7 @@ seafood_jellyfish: burn: 30 age: warmth: 450 - freshness: 9.33 + freshness: 14 tag-labels: freshness: stale: "#c3db81Stale" @@ -755,7 +757,7 @@ seafood_octopus: burn: 30 age: warmth: 450 - freshness: 9.33 + freshness: 14 tag-labels: freshness: stale: "#c3db81Stale" @@ -798,7 +800,7 @@ butter: nutrition: 6 age: warmth: 450 - freshness: 14 + freshness: 21 tag-labels: freshness: stale: "#c3db81Rancid" @@ -817,7 +819,7 @@ egg: burn: 25 age: warmth: 450 - freshness: 7 + freshness: 14 tag-labels: freshness: stale: "#c3db81Stale" diff --git a/src/test/java/net/tfminecraft/cooking/item/CookedFreshnessCapTest.java b/src/test/java/net/tfminecraft/cooking/item/CookedFreshnessCapTest.java new file mode 100644 index 0000000..28ae2f5 --- /dev/null +++ b/src/test/java/net/tfminecraft/cooking/item/CookedFreshnessCapTest.java @@ -0,0 +1,126 @@ +package net.tfminecraft.cooking.item; + +import static org.junit.jupiter.api.Assertions.*; + +import java.io.File; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; +import org.bukkit.configuration.MemoryConfiguration; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; +import org.mockbukkit.mockbukkit.MockBukkit; +import net.tfminecraft.cooking.cache.ItemCache; +import net.tfminecraft.cooking.item.tag.TagTrack; +import net.tfminecraft.cooking.loader.ConfigLoader; +import net.tfminecraft.cooking.loader.TrackLoader; + +/** config.yml cooked-freshness: cooked food ages at most as slowly as the cap, raw food keeps its type's pace. */ +class CookedFreshnessCapTest { + List tracks; + double previousCap; + + @BeforeEach void setup() { + MockBukkit.mock(); + tracks = new ArrayList<>(TrackLoader.oList); + previousCap = ItemCache.cookedFreshness; + TrackLoader.oList.clear(); + TrackLoader.oList.add(FoodItemCoverageTest.track("cooked", false, 0, "raw", "cooked", "burnt")); + MemoryConfiguration freshness = new MemoryConfiguration(); freshness.set("ageable", true); + freshness.set("fresh.value", 0); freshness.set("stale.value", 86400); freshness.set("rotten.value", 129600); + TrackLoader.oList.add(new TagTrack("freshness", 2, freshness)); + TrackLoader.oList.add(FoodItemCoverageTest.track("warmth", true, 1, "hot", "warm", "cold")); + ItemCache.cookedFreshness = 3.0; + } + + @AfterEach void cleanup() { + TrackLoader.oList.clear(); TrackLoader.oList.addAll(tracks); + ItemCache.cookedFreshness = previousCap; + MockBukkit.unmock(); + } + + static FoodItem meat(MemoryConfiguration extra) { + MemoryConfiguration config = FoodItemCoverageTest.config(); + config.set("age.freshness", 14); config.set("age.warmth", 450); + config.set("overrides.chicken.age.freshness", 10); + if (extra != null) for (String key : extra.getKeys(true)) if (!extra.isConfigurationSection(key)) config.set(key, extra.get(key)); + FoodItem food = new FoodItem("meat", config); + food.addTagTrack("freshness"); food.addTagTrack("cooked"); + return food; + } + + @Test void rawFoodKeepsItsOwnShelfLife() { + FoodItem food = meat(null); + assertFalse(food.isCooked()); + assertEquals(14, food.resolveAgeMultiplier("freshness")); + food.setOrigin("chicken"); assertEquals(10, food.resolveAgeMultiplier("freshness")); + } + + @Test void cookedBoiledOrBurntFoodIsCappedOnFreshnessOnly() { + FoodItem food = meat(null); + for (int step : new int[] {10, 20, 30}) { + food.getTagTrack("cooked").setValue(step); + assertTrue(food.isCooked()); + assertEquals(3, food.resolveAgeMultiplier("FRESHNESS")); + assertEquals(450, food.resolveAgeMultiplier("warmth")); + } + food.setOrigin("chicken"); assertEquals(3, food.resolveAgeMultiplier("freshness")); + } + + @Test void shorterLivedFoodIsNeverStretchedByTheCap() { + MemoryConfiguration extra = new MemoryConfiguration(); extra.set("age.freshness", 2); + FoodItem food = meat(extra); + food.getTagTrack("cooked").setValue(10); + assertEquals(2, food.resolveAgeMultiplier("freshness")); + } + + @Test void foodWithoutACookedTrackIsNotCapped() { + MemoryConfiguration config = FoodItemCoverageTest.config(); config.set("age.freshness", 21); + FoodItem veg = new FoodItem("veg", config); veg.addTagTrack("freshness"); + assertFalse(veg.isCooked()); + assertEquals(21, veg.resolveAgeMultiplier("freshness")); + } + + @Test void typeCookedFreshnessReplacesTheConfigCapAndCopiesKeepIt() { + MemoryConfiguration extra = new MemoryConfiguration(); extra.set("cooked-freshness", 7); + FoodItem bread = meat(extra); + bread.getTagTrack("cooked").setValue(10); + assertEquals(7, bread.resolveAgeMultiplier("freshness")); + assertEquals(7, new FoodItem(bread).resolveAgeMultiplier("freshness")); + extra.set("cooked-freshness", 0); + FoodItem uncapped = meat(extra); uncapped.getTagTrack("cooked").setValue(10); + assertEquals(14, uncapped.resolveAgeMultiplier("freshness")); + } + + @Test void zeroOrInvalidConfigCapTurnsItOff() { + FoodItem food = meat(null); food.getTagTrack("cooked").setValue(10); + for (double cap : new double[] {0, -1, Double.NaN, Double.POSITIVE_INFINITY}) { + ItemCache.cookedFreshness = cap; + assertEquals(14, food.resolveAgeMultiplier("freshness")); + } + } + + @Test void cookingKeepsTheShareOfFreshnessUsedSoFoodNeverGetsFresher() { + FoodItem food = meat(null); + // half way through its raw fresh days: 7 of 14 days, stored as 43200 age units at multiplier 1 + food.getTagTrack("freshness").forceSetValue(43200); + food.getTagTrack("cooked").setValue(10); + food.setLastUpdate(System.currentTimeMillis() - 3L * 3600_000L); // 3 hours later + food.updateAge(); + // 3 h at multiplier 3 = 10800 / 3 = 3600 units: the stored value only grows, now at the cooked pace + assertEquals(43200 + 3600, food.getTagTrack("freshness").getValue()); + } + + @Test void configLoaderReadsTheCapAndDefaultsToThreeDays(@TempDir Path dir) throws Exception { + File file = dir.resolve("config.yml").toFile(); + Files.writeString(file.toPath(), "cooked-freshness: 4.5\n"); + new ConfigLoader().loadConfig(file); + assertEquals(4.5, ItemCache.cookedFreshness); + Files.writeString(file.toPath(), "logging: true\n"); + new ConfigLoader().loadConfig(file); + assertEquals(3.0, ItemCache.cookedFreshness); + } +} diff --git a/src/test/java/net/tfminecraft/cooking/item/ShelfLifeDefaultsTest.java b/src/test/java/net/tfminecraft/cooking/item/ShelfLifeDefaultsTest.java index 27274dc..e111755 100644 --- a/src/test/java/net/tfminecraft/cooking/item/ShelfLifeDefaultsTest.java +++ b/src/test/java/net/tfminecraft/cooking/item/ShelfLifeDefaultsTest.java @@ -8,27 +8,64 @@ import org.junit.jupiter.api.Test; /** - * Bundled shelf lives (age.freshness = days until Stale; Rotten comes at 1.25 times that, see tags.yml). - * Owner rule 2026-11-13: ingredients last at least a week, cooked soup and sauce three days. + * Bundled shelf lives (age.freshness = days until Stale; Rotten comes at 1.5 times that, see tags.yml). + * Owner rules 2026-11-15: grains a month, produce three weeks, meat, fish, eggs and milk two weeks, bread a week; + * cooked food three days (config.yml cooked-freshness), so there is always a reason to cook. */ class ShelfLifeDefaultsTest { private static final YamlConfiguration TYPES = YamlConfiguration.loadConfiguration(new File("src/main/resources/types.yml")); + private static final YamlConfiguration TAGS = + YamlConfiguration.loadConfiguration(new File("src/main/resources/tags.yml")); + private static final YamlConfiguration CONFIG = + YamlConfiguration.loadConfiguration(new File("src/main/resources/config.yml")); @Test - void ingredientsLastAWeek() { - for (String id : new String[] {"milk_bucket", "cup_of_milk", "dough", "yeast", "egg"}) { - assertEquals(7.0, freshness(id), id); + void grainsLastAMonth() { + for (String id : new String[] {"wheat", "flour", "dry_ration"}) { + assertEquals(28.0, freshness(id), id); } } @Test - void soupAndSauceLastThreeDays() { + void produceDoughAndYeastLastThreeWeeks() { + for (String id : new String[] {"vegetable_1", "vegetable_2", "vegetable_chop_only", "vegetable_cut", + "vegetable_cut_2", "vegetable_chopped", "vegetable_chopped_2", "garnish_chopped", "fruit_1", "fruit_2", + "butter", "dough", "yeast"}) { + assertEquals(21.0, freshness(id), id); + } + } + + @Test + void meatFishEggsAndMilkLastTwoWeeks() { + for (String id : new String[] {"roast", "meat_poultry", "meat_poultry_leg", "meat_red_meat", "meat_pork", + "sausage", "sausage_chain", "egg", "cup_of_milk", "milk_bucket", "seafood_whole", "seafood_fish_filet", + "seafood_jellyfish", "seafood_octopus"}) { + assertEquals(14.0, freshness(id), id); + } + } + + @Test + void breadLastsAWeekEvenOnceBaked() { + assertEquals(7.0, freshness("bread")); + assertEquals(7.0, TYPES.getDouble("bread.cooked-freshness", -1)); + } + + @Test + void cookedFoodSoupAndSauceLastThreeDays() { + assertEquals(3.0, CONFIG.getDouble("cooked-freshness", -1)); assertEquals(3.0, freshness("soup")); assertEquals(3.0, freshness("sauce")); } + @Test + void staleFoodKeepsItsNutritionAndRotsAtOneAndAHalfTimesItsFreshDays() { + assertEquals(86400, TAGS.getInt("freshness.stale.value")); + assertEquals(1.0, TAGS.getDouble("freshness.stale.nutrition-mult")); + assertEquals(129600, TAGS.getInt("freshness.rotten.value")); + } + private static double freshness(String id) { return TYPES.getDouble(id + ".age.freshness", -1); } From 3424fa2b1cc3c405bdf73f4d2b1cb477c8f907f5 Mon Sep 17 00:00:00 2001 From: XxFran10xX <318299142+XxFran10xX@users.noreply.github.com> Date: Sun, 15 Nov 2026 15:35:44 +0100 Subject: [PATCH 2/2] fix: age food to now at its raw pace before it cooks, boils or burns CookData.check, the baking tray and the pot's markBoiled changed the cooked track without settling the age first, so the next ageing charged the whole time since the last update at the cooked cap: raw meat a week behind its clock used 201600 units instead of 43200 and rotted as it cooked. They now call updateAge() first. Main's bundled roux (14 days) and roasted cocoa beans (28), ingredients that keep their cooked track, keep their own days with cooked-freshness; the popcorn comment now says it keeps the 3-day cap. Co-Authored-By: Claude Opus 5.5 --- .../cooking/baking/BakingTrayBakeApplier.java | 2 + .../cooking/cooking/PotReference.java | 2 + .../cooking/item/data/CookData.java | 4 ++ src/main/resources/types.yml | 7 ++- .../cooking/item/CookedFreshnessCapTest.java | 49 +++++++++++++++++++ .../cooking/item/ShelfLifeDefaultsTest.java | 6 +++ 6 files changed, 69 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/tfminecraft/cooking/baking/BakingTrayBakeApplier.java b/src/main/java/net/tfminecraft/cooking/baking/BakingTrayBakeApplier.java index e736108..66262ee 100644 --- a/src/main/java/net/tfminecraft/cooking/baking/BakingTrayBakeApplier.java +++ b/src/main/java/net/tfminecraft/cooking/baking/BakingTrayBakeApplier.java @@ -75,6 +75,8 @@ private static boolean applyToSlot(Furniture tray, String slotId, int fromValue, return false; } + // Age it to now at the pace it had before the bake (cooked-freshness), then change its step. + foodItem.updateAge(); cookedTrack.setValue(toValue); foodItem.addOrModifyTrack(cookedTrack); ItemStack updated = ItemUpdater.applyItemUpdate(item, foodItem, tray.getId()); diff --git a/src/main/java/net/tfminecraft/cooking/cooking/PotReference.java b/src/main/java/net/tfminecraft/cooking/cooking/PotReference.java index d958e96..9c41816 100644 --- a/src/main/java/net/tfminecraft/cooking/cooking/PotReference.java +++ b/src/main/java/net/tfminecraft/cooking/cooking/PotReference.java @@ -414,6 +414,8 @@ public static void markBoiled(FoodItem item) { item.addOrModifyTrack(cooked); return; } + // Age it to now at its pace before boiling (cooked-freshness), then mark it boiled. + item.updateAge(); cooked.forceSetValue(3); } diff --git a/src/main/java/net/tfminecraft/cooking/item/data/CookData.java b/src/main/java/net/tfminecraft/cooking/item/data/CookData.java index d438c6d..03ad792 100644 --- a/src/main/java/net/tfminecraft/cooking/item/data/CookData.java +++ b/src/main/java/net/tfminecraft/cooking/item/data/CookData.java @@ -107,9 +107,13 @@ public boolean check() { boolean changed = false; if(currentTime == p.getTime()) { changed = true; + // Age it to now at the raw pace first: cooked food ages faster (config.yml cooked-freshness), and the + // time before this moment was spent raw. + item.updateAge(); item.getTagTrack("cooked").setValue(p.getTag()); } else if(currentTime == p.getBurnTime()) { changed = true; + item.updateAge(); item.getTagTrack("cooked").setValue(2); } return changed; diff --git a/src/main/resources/types.yml b/src/main/resources/types.yml index 3e3cea6..5e0cf14 100644 --- a/src/main/resources/types.yml +++ b/src/main/resources/types.yml @@ -636,6 +636,8 @@ sauce: # name the sauce; the Thick tag does: Thick Garlic Sauce. roux: name: "#d9a95bRoux" + # An ingredient, not a dish: keeps its own 14 days once cooked (config.yml cooked-freshness is for cooked dishes). + cooked-freshness: 14 model: roux category: thickener food: 6 @@ -866,7 +868,8 @@ grilled_mushroom: freshness: 14 ###Popcorn: chopped corn popped in the frying pan (vegetable_chopped_2 output). Burnt, it stays popcorn. -# A light snack, a little less filling than the chopped corn it came from; dry, it keeps three times as long. +# A light snack, a little less filling than the chopped corn it came from. Popped, it is cooked food and keeps +# config.yml cooked-freshness (3 days). # Toppings put in a popcorn machine (popcorn-machines.yml) name it: Salted Caramel Popcorn (naming.yml prefix-tracks). popcorn: name: "#f3e3a6{prefixes}Popcorn" @@ -914,6 +917,8 @@ cocoa_beans: roasted_cocoa_beans: name: "#5c3a21Roasted Cocoa Beans" + # An ingredient, not a dish: keeps its own 28 days once roasted (config.yml cooked-freshness is for cooked dishes). + cooked-freshness: 28 model: roasted_cocoa_beans food: 3 nutrition: 3 diff --git a/src/test/java/net/tfminecraft/cooking/item/CookedFreshnessCapTest.java b/src/test/java/net/tfminecraft/cooking/item/CookedFreshnessCapTest.java index 28ae2f5..826629c 100644 --- a/src/test/java/net/tfminecraft/cooking/item/CookedFreshnessCapTest.java +++ b/src/test/java/net/tfminecraft/cooking/item/CookedFreshnessCapTest.java @@ -14,6 +14,8 @@ import org.junit.jupiter.api.io.TempDir; import org.mockbukkit.mockbukkit.MockBukkit; import net.tfminecraft.cooking.cache.ItemCache; +import net.tfminecraft.cooking.cooking.PotReference; +import net.tfminecraft.cooking.enums.Method; import net.tfminecraft.cooking.item.tag.TagTrack; import net.tfminecraft.cooking.loader.ConfigLoader; import net.tfminecraft.cooking.loader.TrackLoader; @@ -114,6 +116,53 @@ static FoodItem meat(MemoryConfiguration extra) { assertEquals(43200 + 3600, food.getTagTrack("freshness").getValue()); } + static final long WEEK_MS = 7L * 86400_000L; + + /** Raw meat (14 days) on a frying pan, cooked after 2 ticks, with its clock a week behind. */ + static FoodItem panMeatAWeekBehind() { + MemoryConfiguration extra = new MemoryConfiguration(); + extra.set("cooking-options.frying_pan.tag", 1); + extra.set("cooking-options.frying_pan.time", 2); + extra.set("cooking-options.frying_pan.burn", 4); + FoodItem food = new FoodItem(meat(extra)); + food.getTagTrack("freshness").forceSetValue(0); + food.setAgeRemainder("freshness", 0); + food.setLastUpdate(System.currentTimeMillis() - WEEK_MS); + return food; + } + + @Test void timeSpentRawIsChargedAtTheRawPaceWhenTheFoodCooks() { + FoodItem food = panMeatAWeekBehind(); + food.getCookData().start(Method.FRYING_PAN); + food.getCookData().tick(); + assertFalse(food.isCooked()); + food.getCookData().tick(); + assertTrue(food.isCooked()); + // a week at 14 days = 604800 / 14 = 43200 units (half way to Stale), not 604800 / 3 = 201600 (past Rotten) + int value = food.getTagTrack("freshness").getValue(); + assertTrue(value >= 43200 && value <= 43201, "freshness " + value); + assertEquals(3, food.resolveAgeMultiplier("freshness")); + } + + @Test void burningAlsoSettlesTheTimeBeforeIt() { + FoodItem food = panMeatAWeekBehind(); + food.getCookData().start(Method.FRYING_PAN); + food.getCookData().tick(); food.getCookData().tick(); + food.setLastUpdate(System.currentTimeMillis() - 3L * 3600_000L); // 3 hours cooked, unsettled + int before = food.getTagTrack("freshness").getValue(); + food.getCookData().tick(); food.getCookData().tick(); + assertEquals(2, food.getTagTrack("cooked").getValue()); // CookData burns to value 2 + assertEquals(before + 3600, food.getTagTrack("freshness").getValue()); // 10800 s at the cooked pace 3 + } + + @Test void boilingInThePotSettlesTheRawTimeFirst() { + FoodItem food = panMeatAWeekBehind(); + PotReference.markBoiled(food); + assertTrue(food.isCooked()); + int value = food.getTagTrack("freshness").getValue(); + assertTrue(value >= 43200 && value <= 43201, "freshness " + value); + } + @Test void configLoaderReadsTheCapAndDefaultsToThreeDays(@TempDir Path dir) throws Exception { File file = dir.resolve("config.yml").toFile(); Files.writeString(file.toPath(), "cooked-freshness: 4.5\n"); diff --git a/src/test/java/net/tfminecraft/cooking/item/ShelfLifeDefaultsTest.java b/src/test/java/net/tfminecraft/cooking/item/ShelfLifeDefaultsTest.java index e111755..8841583 100644 --- a/src/test/java/net/tfminecraft/cooking/item/ShelfLifeDefaultsTest.java +++ b/src/test/java/net/tfminecraft/cooking/item/ShelfLifeDefaultsTest.java @@ -52,6 +52,12 @@ void breadLastsAWeekEvenOnceBaked() { assertEquals(7.0, TYPES.getDouble("bread.cooked-freshness", -1)); } + @Test + void cookedIngredientsKeepTheirOwnDays() { + assertEquals(14.0, TYPES.getDouble("roux.cooked-freshness", -1)); + assertEquals(28.0, TYPES.getDouble("roasted_cocoa_beans.cooked-freshness", -1)); + } + @Test void cookedFoodSoupAndSauceLastThreeDays() { assertEquals(3.0, CONFIG.getDouble("cooked-freshness", -1));