Skip to content

Commit

Permalink
Fixed a number of food related issues and did some changes-to-match-c…
Browse files Browse the repository at this point in the history
…lassic balancing:

 - transforming a food item doesn't copy traits. (fixes #670)
 - transforming a food item uses the inverse decay modifier to reset creation dates (fixes #662)
 - rebalanced a bunch of decay modifiers for meat and grains to match classic. All grain products have the same decay modifier, with the "grain" having half. Meats now gain a 0.75 modifier from cooking.
 - cooked meat has now slower decay, increased nutrition and saturation, fixes #694
  • Loading branch information
alcatrazEscapee committed Jan 8, 2020
1 parent 349c32b commit 9de8350
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 62 deletions.
Expand Up @@ -67,6 +67,7 @@ public static void applyTrait(IFood instance, FoodTrait trait)
{
if (!instance.isRotten())
{
// Applied decay DATE modifier = 1 / decay mod
instance.setCreationDate(calculateNewCreationDate(instance.getCreationDate(), 1f / trait.getDecayModifier()));
}
instance.getTraits().add(trait);
Expand All @@ -92,6 +93,7 @@ public static void removeTrait(IFood instance, FoodTrait trait)
{
if (!instance.isRotten())
{
// Removed trait = 1 / apply trait
instance.setCreationDate(calculateNewCreationDate(instance.getCreationDate(), trait.getDecayModifier()));
}
instance.getTraits().remove(trait);
Expand All @@ -116,22 +118,24 @@ public static void removeTrait(ItemStack stack, FoodTrait trait)
* @param newStack the new stack
* @return the modified stack, for chaining
*/
public static ItemStack updateFoodDecay(ItemStack oldStack, ItemStack newStack)
public static ItemStack updateFoodFromPrevious(ItemStack oldStack, ItemStack newStack)
{
IFood oldCap = oldStack.getCapability(CapabilityFood.CAPABILITY, null);
IFood newCap = newStack.getCapability(CapabilityFood.CAPABILITY, null);
if (oldCap != null && newCap != null)
{
// This is similar to the trait applied, except it's the inverse, since decay mod performs a 1 / x
float decayDelta = oldCap.getDecayModifier() / newCap.getDecayModifier();
// Copy traits from old stack to new stack
newCap.getTraits().addAll(oldCap.getTraits());
// Applied trait decay DATE modifier = new / old
float decayDelta = newCap.getDecayDateModifier() / oldCap.getDecayDateModifier();
newCap.setCreationDate(calculateNewCreationDate(oldCap.getCreationDate(), decayDelta));
}
return newStack;
}

/**
* Call this from any function that is meant to create a new item stack.
* In MOST cases, you should use {@link CapabilityFood#updateFoodDecay(ItemStack, ItemStack)}, as the decay should transfer from input -> output
* In MOST cases, you should use {@link CapabilityFood#updateFoodFromPrevious(ItemStack, ItemStack)}, as the decay should transfer from input -> output
* This is only for where there is no input. (i.e. on a direct {@code stack.copy()} from non-food inputs
*
* @param stack the new stack
Expand Down Expand Up @@ -234,11 +238,14 @@ public static ItemStack mergeStack(ItemStack inputStack, ItemStack mergeStack)
* = (1 - p) * T + p * (Ci + d)
* via 1. > (1 - p) * T + p * T = T
* QED
*
* @param ci The initial creation date
* @param p The decay date modifier (1 / standard decay modifier)
* @return cf the final creation date
*/
private static long calculateNewCreationDate(long ci, float p)
{
// Cf = (1 - p) * T + p * Ci
return (long) ((1 - p) * CalendarTFC.PLAYER_TIME.getTicks() + p * ci);
}

}
Expand Up @@ -43,7 +43,7 @@ public static void setNonDecaying(boolean markStacksNonDecaying)
private final float calories;

private long creationDate;
private boolean isNonDecaying;
private boolean isNonDecaying; // This is intentionally not serialized, as we don't want it to preserve over `ItemStack.copy()` operations

public FoodHandler()
{
Expand Down Expand Up @@ -130,7 +130,7 @@ public float getCalories()
}

@Override
public float getDecayModifier()
public float getDecayDateModifier()
{
// Decay modifiers are higher = shorter
float mod = decayModifier * (float) ConfigTFC.GENERAL.foodDecayModifier;
Expand Down Expand Up @@ -212,7 +212,7 @@ public void deserializeNBT(@Nullable NBTTagCompound nbt)

private long calculateRottenDate(long creationDateIn)
{
float decayMod = getDecayModifier();
float decayMod = getDecayDateModifier();
if (decayMod == Float.POSITIVE_INFINITY)
{
// Infinite decay modifier
Expand Down
Expand Up @@ -85,9 +85,9 @@ public float getCalories()
}

@Override
public float getDecayModifier()
public float getDecayDateModifier()
{
return internalFoodCap.getDecayModifier();
return internalFoodCap.getDecayDateModifier();
}

@Override
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/net/dries007/tfc/api/capability/food/IFood.java
Expand Up @@ -83,11 +83,12 @@ default boolean isRotten()
float getCalories();

/**
* Gets the current decay modifier, including traits
* Gets the current decay date modifier, including traits
* Note: there's a difference between the DECAY modifier, and the DECAY DATE modifier, in that they are reciprocals of eachother
*
* @return a value between 0 and infinity (0 = instant decay, infinity = never decay)
*/
float getDecayModifier();
float getDecayDateModifier();

/**
* Called from {@link net.dries007.tfc.CommonEventHandler#attachItemCapabilities(AttachCapabilitiesEvent)}
Expand Down
Expand Up @@ -60,7 +60,7 @@ public ItemStack getOutputStack(ItemStack input)
// Copy heat if possible
outputHeat.setTemperature(heat.getTemperature());
}
return CapabilityFood.updateFoodDecay(input, outputStack);
return CapabilityFood.updateFoodFromPrevious(input, outputStack);
}
return ItemStack.EMPTY;
}
Expand Down
Expand Up @@ -42,7 +42,7 @@ public QuernRecipe(IIngredient<ItemStack> input, ItemStack output)
@Nonnull
public ItemStack getOutputItem(ItemStack stack)
{
return CapabilityFood.updateFoodDecay(stack, outputItem.copy());
return CapabilityFood.updateFoodFromPrevious(stack, outputItem.copy());
}

@Override
Expand Down
Expand Up @@ -38,6 +38,7 @@
public class CTItemRegistry
{
@ZenMethod
@SuppressWarnings({"unchecked", "rawtypes"})
public static void registerItemSize(crafttweaker.api.item.IIngredient input, String inputSize, String inputWeight)
{
if (input == null) throw new IllegalArgumentException("Input not allowed to be empty!");
Expand All @@ -54,7 +55,6 @@ public static void registerItemSize(crafttweaker.api.item.IIngredient input, Str
{
CraftTweakerAPI.apply(new IAction()
{
@SuppressWarnings("unchecked")
@Override
public void apply()
{
Expand All @@ -71,6 +71,7 @@ public String describe()
}

@ZenMethod
@SuppressWarnings({"unchecked", "rawtypes"})
public static void registerItemMetal(crafttweaker.api.item.IIngredient input, String metalStr, int amount, boolean canMelt)
{
if (input == null) throw new IllegalArgumentException("Input not allowed to be empty!");
Expand All @@ -90,7 +91,6 @@ public static void registerItemMetal(crafttweaker.api.item.IIngredient input, St
{
CraftTweakerAPI.apply(new IAction()
{
@SuppressWarnings("unchecked")
@Override
public void apply()
{
Expand All @@ -107,6 +107,7 @@ public String describe()
}

@ZenMethod
@SuppressWarnings({"unchecked", "rawtypes"})
public static void registerItemHeat(crafttweaker.api.item.IIngredient input, float heatCapacity, float meltTemp, boolean forgeable)
{
if (input == null) throw new IllegalArgumentException("Input not allowed to be empty!");
Expand Down Expand Up @@ -147,6 +148,7 @@ public String describe()
}

@ZenMethod
@SuppressWarnings({"unchecked", "rawtypes"})
public static void registerFood(crafttweaker.api.item.IIngredient input, float[] nutrients, float calories, float water, float decay)
{
if (input == null) throw new IllegalArgumentException("Input not allowed to be empty!");
Expand All @@ -162,7 +164,6 @@ public static void registerFood(crafttweaker.api.item.IIngredient input, float[]
{
CraftTweakerAPI.apply(new IAction()
{
@SuppressWarnings("unchecked")
@Override
public void apply()
{
Expand All @@ -179,6 +180,7 @@ public String describe()
}

@ZenMethod
@SuppressWarnings({"unchecked", "rawtypes"})
public static void registerArmor(crafttweaker.api.item.IIngredient input, float crushingModifier, float piercingModifier, float slashingModifier)
{
if (input == null) throw new IllegalArgumentException("Input not allowed to be empty!");
Expand All @@ -193,7 +195,6 @@ public static void registerArmor(crafttweaker.api.item.IIngredient input, float
{
CraftTweakerAPI.apply(new IAction()
{
@SuppressWarnings("unchecked")
@Override
public void apply()
{
Expand Down
Expand Up @@ -53,7 +53,7 @@ public ItemStack getCraftingResult(InventoryCrafting inv)
}
}
}
return foodStack != null ? CapabilityFood.updateFoodDecay(foodStack, out) : ItemStack.EMPTY;
return foodStack != null ? CapabilityFood.updateFoodFromPrevious(foodStack, out) : ItemStack.EMPTY;
}

public static class Factory implements IRecipeFactory
Expand Down
Expand Up @@ -92,7 +92,7 @@ public ItemStack getCraftingResult(InventoryCrafting inv)
}
}
}
return foodStack != null ? CapabilityFood.updateFoodDecay(foodStack, out) : ItemStack.EMPTY;
return foodStack != null ? CapabilityFood.updateFoodFromPrevious(foodStack, out) : ItemStack.EMPTY;
}

public static class Factory implements IRecipeFactory
Expand Down
84 changes: 42 additions & 42 deletions src/main/java/net/dries007/tfc/util/agriculture/Food.java
Expand Up @@ -32,35 +32,35 @@ public enum Food
SNOW_BERRY(FRUIT, 0.4f, 5f, 0f, 0f, 0f, 0.5f, 0f, 4.5f),
STRAWBERRY(FRUIT, 0.4f, 8f, 0f, 0f, 0f, 1f, 0f, 4.5f),
WINTERGREEN_BERRY(FRUIT, 0.4f, 5f, 0f, 0f, 0f, 0.5f, 0f, 4.5f),
BARLEY(GRAIN, 0f, 0f, 0.2f, 0f, 0f, 0f, 0f, 1.8f, "barley"),
BARLEY_GRAIN(GRAIN, 0f, 0f, 0.2f, 0f, 0f, 0f, 0f, 1.2f, "grain_barley", "grain"),
BARLEY(GRAIN, 0f, 0f, 0.2f, 0f, 0f, 0f, 0f, 0.8f, "barley"),
BARLEY_GRAIN(GRAIN, 0f, 0f, 0.2f, 0f, 0f, 0f, 0f, 0.4f, "grain_barley", "grain"),
BARLEY_FLOUR(GRAIN, 0f, 0f, 0.2f, 0f, 0f, 0f, 0f, 0.8f, "flour_barley", "flour"),
BARLEY_DOUGH(GRAIN, 0f, 0f, 0.4f, 0f, 0f, 0f, 0f, 2.8f, 1f, 200f),
BARLEY_BREAD(GRAIN, 0.6f, 0f, 2f, 0.5f, 0f, 0f, 0f, 2.6f, 1f, 480f),
MAIZE(GRAIN, 0f, 0f, 0.2f, 0.1f, 0f, 0f, 0f, 1.8f, "maize", "grain"),
CORNBREAD(GRAIN, 0.6f, 0f, 2f, 1f, 0.5f, 0f, 0f, 2.6f, 1f, 480f),
BARLEY_DOUGH(GRAIN, 0f, 0f, 0.4f, 0f, 0f, 0f, 0f, 0.8f, 1f, 200f),
BARLEY_BREAD(GRAIN, 0.6f, 0f, 2f, 0.5f, 0f, 0f, 0f, 0.8f, 1f, 480f),
MAIZE(GRAIN, 0f, 0f, 0.2f, 0.1f, 0f, 0f, 0f, 0.8f, "maize", "grain"),
CORNBREAD(GRAIN, 0.6f, 0f, 2f, 1f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.4f, "grain_rice", "grain"),
RICE_FLOUR(GRAIN, 0f, 0f, 0.1f, 0f, 0f, 0f, 0f, 0.8f, "flour_rice", "flour"),
RICE_DOUGH(GRAIN, 0f, 0f, 0.1f, 0f, 0f, 0f, 0f, 2.8f, 1f, 200f),
RICE_BREAD(GRAIN, 0.4f, 0f, 1.5f, 0.5f, 0f, 0f, 0f, 2.6f, 1f, 480f),
RYE(GRAIN, 0f, 0f, 0.1f, 0f, 0f, 0f, 0f, 1.8f, "rye"),
RYE_GRAIN(GRAIN, 0f, 0f, 0.1f, 0f, 0f, 0f, 0f, 1.2f, "grain_rye", "grain"),
RICE_DOUGH(GRAIN, 0f, 0f, 0.1f, 0f, 0f, 0f, 0f, 0.8f, 1f, 200f),
RICE_BREAD(GRAIN, 0.4f, 0f, 1.5f, 0.5f, 0f, 0f, 0f, 0.8f, 1f, 480f),
RYE(GRAIN, 0f, 0f, 0.1f, 0f, 0f, 0f, 0f, 0.8f, "rye"),
RYE_GRAIN(GRAIN, 0f, 0f, 0.1f, 0f, 0f, 0f, 0f, 0.4f, "grain_rye", "grain"),
RYE_FLOUR(GRAIN, 0f, 0f, 0.1f, 0f, 0f, 0f, 0f, 0.8f, "flour_rye", "flour"),
RYE_DOUGH(GRAIN, 0f, 0f, 0.1f, 0f, 0f, 0f, 0f, 2.8f, 1f, 200f),
RYE_BREAD(GRAIN, 0.6f, 0f, 1.5f, 0.5f, 0f, 0f, 0f, 2.6f, 1f, 480f),
WHEAT(GRAIN, 0f, 0f, 0.2f, 0f, 0f, 0f, 0f, 1.8f, "wheat"),
WHEAT_GRAIN(GRAIN, 0f, 0f, 0.2f, 0f, 0f, 0f, 0f, 1.2f, "grain_wheat", "grain"),
RYE_DOUGH(GRAIN, 0f, 0f, 0.1f, 0f, 0f, 0f, 0f, 0.8f, 1f, 200f),
RYE_BREAD(GRAIN, 0.6f, 0f, 1.5f, 0.5f, 0f, 0f, 0f, 0.8f, 1f, 480f),
WHEAT(GRAIN, 0f, 0f, 0.2f, 0f, 0f, 0f, 0f, 0.8f, "wheat"),
WHEAT_GRAIN(GRAIN, 0f, 0f, 0.2f, 0f, 0f, 0f, 0f, 0.4f, "grain_wheat", "grain"),
WHEAT_FLOUR(GRAIN, 0f, 0f, 0.2f, 0f, 0f, 0f, 0f, 0.8f, "flour_wheat", "flour"),
WHEAT_DOUGH(GRAIN, 0f, 0f, 0.2f, 0f, 0f, 0f, 0f, 2.8f, 1f, 200f),
WHEAT_BREAD(GRAIN, 0.6f, 0f, 2f, 0.5f, 0.5f, 0f, 0f, 2.6f, 1f, 480f),
WHEAT_DOUGH(GRAIN, 0f, 0f, 0.2f, 0f, 0f, 0f, 0f, 0.8f, 1f, 200f),
WHEAT_BREAD(GRAIN, 0.6f, 0f, 2f, 0.5f, 0.5f, 0f, 0f, 0.8f, 1f, 480f),
BEET(VEGETABLE, 0.4f, 3f, 0f, 0f, 0f, 1f, 0f, 2.5f),
CABBAGE(VEGETABLE, 0.4f, 5f, 0f, 0f, 0f, 1f, 0f, 2.5f),
CARROT(VEGETABLE, 0.4f, 3f, 0f, 0f, 0f, 1f, 0f, 2.5f, "carrot"),
Expand All @@ -82,26 +82,26 @@ public enum Food
PORK(MEAT, 0.2f, 1f, 0f, 2f, 2.5f, 0f, 0f, 2f, 1f, 200f),
CHICKEN(MEAT, 0.2f, 1f, 0f, 0.5f, 2.5f, 0f, 0f, 3f, 1f, 200f),
MUTTON(MEAT, 0.2f, 1f, 0f, 1.5f, 2.5f, 0f, 0f, 3f, 1f, 200f),
FISH(MEAT, 0.2f, 1f, 0f, 0f, 2f, 0f, 0f, 3.5f, 1f, 200f),
BEAR(MEAT, 0.2f, 1f, 0f, 2f, 2.5f, 0.5f, 0f, 2.5f, 1f, 200f),
FISH(MEAT, 0.2f, 1f, 0f, 0f, 2f, 0f, 0f, 3f, 1f, 200f),
BEAR(MEAT, 0.2f, 1f, 0f, 2f, 2.5f, 0.5f, 0f, 2f, 1f, 200f),
CALAMARI(MEAT, 0.2f, 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, 0f, 0f, 2f, 1f, 200f),
PHEASANT(MEAT, 0.2f, 1f, 0f, 2f, 2.5f, 0f, 0f, 3f, 1f, 200f),
VENISON(MEAT, 0.2f, 1f, 0f, 0.5f, 2f, 0f, 0f, 2f, 1f, 200f),
WOLF(MEAT, 0.2f, 1f, 0f, 0.5f, 1f, 0f, 0f, 3f, 1f, 200f),
RABBIT(MEAT, 0.2f, 1f, 0f, 0.5f, 1f, 0f, 0f, 3f, 1f, 200f),
COOKED_BEEF(MEAT, 0.8f, 2f, 0f, 2f, 2.5f, 0f, 0f, 1.5f),
COOKED_PORK(MEAT, 0.8f, 2f, 0f, 2f, 2.5f, 0f, 0f, 1.5f),
COOKED_CHICKEN(MEAT, 0.6f, 2f, 0f, 0.5f, 2.5f, 0f, 0f, 2.25f),
COOKED_MUTTON(MEAT, 0.8f, 2f, 0f, 1.5f, 2.5f, 0f, 0f, 2.25f),
COOKED_FISH(MEAT, 0.6f, 2f, 0f, 0f, 2f, 0f, 0f, 2.25f),
COOKED_BEAR(MEAT, 0.8f, 2f, 0f, 2f, 2.5f, 0.5f, 0f, 1.5f),
COOKED_CALAMARI(MEAT, 0.4f, 2f, 0f, 0.5f, 1.5f, 0f, 0f, 2.25f),
COOKED_HORSE_MEAT(MEAT, 0.8f, 2f, 0f, 1f, 2.5f, 0f, 0f, 1.5f),
COOKED_PHEASANT(MEAT, 0.8f, 2f, 0f, 2f, 2.5f, 0f, 0f, 2.25f),
COOKED_VENISON(MEAT, 0.6f, 2f, 0f, 0.5f, 2f, 0f, 0f, 1.5f),
COOKED_WOLF(MEAT, 0.6f, 2f, 0f, 0.5f, 1.5f, 0f, 0f, 2.25f),
COOKED_RABBIT(MEAT, 0.6f, 2f, 0f, 0.5f, 1.5f, 0f, 0f, 2.25f);

private final Category category;
private final float calories;
Expand Down

0 comments on commit 9de8350

Please sign in to comment.