Skip to content

Commit

Permalink
Merge remote-tracking branch 'Midnight145/master' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Dream-Master committed Jul 30, 2024
2 parents 3abee67 + 9d67302 commit d3b8e44
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 7 deletions.
16 changes: 16 additions & 0 deletions src/main/java/squeek/spiceoflife/ModConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,17 @@ public class ModConfig implements IPackable, IPacketProcessor {
+ "Note: If this is set to 0 and "
+ ModConfig.FOOD_EATING_SPEED_MODIFIER_NAME
+ " is > 0, a food with 0% nutrtional value will take nearly infinite time to eat";
private static final String USE_HUNGER_QUEUE_NAME = "use.hunger.restored.for.food.history.length";
private static final boolean USE_HUNGER_QUEUE_DEFAULT = false;
private static final String USE_HUNGER_QUEUE_COMMENT = "If true, " + FOOD_HISTORY_LENGTH_NAME
+ " will use amount of hunger restored instead of number of foods eaten for its maximum length\n"
+ "For example, a "
+ FOOD_HISTORY_LENGTH_NAME
+ " length of 12 will store a max of 2 foods that restored 6 hunger each, \n"
+ "3 foods that restored 4 hunger each, 12 foods that restored 1 hunger each, etc\n"
+ "NOTE: "
+ FOOD_HISTORY_LENGTH_NAME
+ " uses hunger units, where 1 hunger unit = 1/2 hunger bar";
private static final String FOOD_MODIFIER_FORMULA_STRING_NAME = "food.modifier.formula";
private static final String FOOD_MODIFIER_FORMULA_STRING_DEFAULT = "MAX(0, (1 - count/12))^MIN(8, food_hunger_value)";
private static final String FOOD_MODIFIER_FORMULA_STRING_COMMENT = "Uses the EvalEx expression parser\n"
Expand Down Expand Up @@ -168,6 +179,7 @@ public class ModConfig implements IPackable, IPacketProcessor {
private static final String FOOD_CONTAINERS_MAX_STACKSIZE_NAME = "food.containers.max.stacksize";
private static final int FOOD_CONTAINERS_MAX_STACKSIZE_DEFAULT = 2;
private static final String FOOD_CONTAINERS_MAX_STACKSIZE_COMMENT = "The maximum stacksize per slot in a food container";

/*
* CLIENT
*/
Expand Down Expand Up @@ -201,6 +213,7 @@ public class ModConfig implements IPackable, IPacketProcessor {
public static boolean AFFECT_NEGATIVE_FOOD_SATURATION_MODIFIERS = ModConfig.AFFECT_NEGATIVE_FOOD_SATURATION_MODIFIERS_DEFAULT;
public static float FOOD_EATING_SPEED_MODIFIER = ModConfig.FOOD_EATING_SPEED_MODIFIER_DEFAULT;
public static int FOOD_EATING_DURATION_MAX = ModConfig.FOOD_EATING_DURATION_MAX_DEFAULT;
public static boolean USE_HUNGER_QUEUE = USE_HUNGER_QUEUE_DEFAULT;
public static String FOOD_MODIFIER_FORMULA = ModConfig.FOOD_MODIFIER_FORMULA_STRING_DEFAULT;
public static boolean GIVE_FOOD_JOURNAL_ON_START = ModConfig.GIVE_FOOD_JOURNAL_ON_START_DEFAULT;

Expand Down Expand Up @@ -357,6 +370,9 @@ public static void init(File file) {
FOOD_EATING_DURATION_MAX_DEFAULT,
FOOD_EATING_DURATION_MAX_COMMENT)
.getInt(FOOD_EATING_DURATION_MAX_DEFAULT);
USE_HUNGER_QUEUE = config
.get(CATEGORY_SERVER, USE_HUNGER_QUEUE_NAME, USE_HUNGER_QUEUE_DEFAULT, USE_HUNGER_QUEUE_COMMENT)
.getBoolean(USE_HUNGER_QUEUE_DEFAULT);
GIVE_FOOD_JOURNAL_ON_START = config
.get(
CATEGORY_SERVER,
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/squeek/spiceoflife/foodtracker/FoodHistory.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import squeek.spiceoflife.compat.IByteIO;
import squeek.spiceoflife.foodtracker.foodgroups.FoodGroup;
import squeek.spiceoflife.foodtracker.foodgroups.FoodGroupRegistry;
import squeek.spiceoflife.foodtracker.foodqueue.FixedHungerQueue;
import squeek.spiceoflife.foodtracker.foodqueue.FixedSizeQueue;
import squeek.spiceoflife.foodtracker.foodqueue.FoodQueue;
import squeek.spiceoflife.helpers.FoodHelper;
Expand Down Expand Up @@ -90,7 +91,8 @@ public int getFoodCountForFoodGroup(ItemStack food, FoodGroup foodGroup) {
}

public static FoodQueue getNewFoodQueue() {
return new FixedSizeQueue(ModConfig.FOOD_HISTORY_LENGTH);
return ModConfig.USE_HUNGER_QUEUE ? new FixedHungerQueue(ModConfig.FOOD_HISTORY_LENGTH)
: new FixedSizeQueue(ModConfig.FOOD_HISTORY_LENGTH);
}

public void deltaTicksActive(long delta) {
Expand Down Expand Up @@ -144,7 +146,7 @@ public FoodValues getTotalFoodValuesIgnoringFoodGroups(ItemStack food) {
}

public int getHistoryLength() {
return recentHistory.size();
return ModConfig.USE_HUNGER_QUEUE ? ((FixedHungerQueue) recentHistory).hunger() : recentHistory.size();
}

public FoodEaten getLastEatenFood() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package squeek.spiceoflife.foodtracker.foodqueue;

import squeek.spiceoflife.foodtracker.FoodEaten;

public class FixedHungerQueue extends FixedSizeQueue {

protected int hunger;
protected int hungerOverflow;

public FixedHungerQueue(int limit) {
super(limit);
}

@Override
public boolean add(FoodEaten foodEaten) {
boolean added = super.add(foodEaten);
if (added) {
hunger += foodEaten.foodValues.hunger;
trimToMaxSize();
}
return added;
}

@Override
public void clear() {
super.clear();
hunger = hungerOverflow = 0;
}

public int hunger() {
return hunger;
}

@Override
protected void trimToMaxSize() {
while (hunger > limit && peekFirst() != null) {
hunger -= 1;
hungerOverflow += 1;

while (hungerOverflow >= peekFirst().foodValues.hunger) {
hungerOverflow -= removeFirst().foodValues.hunger;
}
}
}
}
18 changes: 13 additions & 5 deletions src/main/java/squeek/spiceoflife/gui/TooltipHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,19 @@ public String getEatenRecentlyTooltip(FoodHistory foodHistory, ItemStack itemSta
+ EnumChatFormatting.DARK_GRAY
+ "]"
: "";
if (count > 0) eatenRecently = StatCollector.translateToLocalFormatted(
"spiceoflife.tooltip.eaten.recently",
StringHelper.getQuantityDescriptor(count),
ModConfig.FOOD_HISTORY_LENGTH);
else eatenRecently = StatCollector.translateToLocal("spiceoflife.tooltip.not.eaten.recently");
if (count > 0) {
if (ModConfig.USE_HUNGER_QUEUE) {
eatenRecently = StatCollector.translateToLocalFormatted(
"spiceoflife.tooltip.eaten.recently.hunger",
StringHelper.getQuantityDescriptor(count),
StringHelper.hungerHistoryLength(ModConfig.FOOD_HISTORY_LENGTH));
} else {
eatenRecently = StatCollector.translateToLocalFormatted(
"spiceoflife.tooltip.eaten.recently",
StringHelper.getQuantityDescriptor(count),
ModConfig.FOOD_HISTORY_LENGTH);
}
} else eatenRecently = StatCollector.translateToLocal("spiceoflife.tooltip.not.eaten.recently");
return prefix + (foodGroup != null ? StringHelper.decapitalize(eatenRecently, StringHelper.getMinecraftLocale())
: eatenRecently) + nutritionalValue;
}
Expand Down

0 comments on commit d3b8e44

Please sign in to comment.