mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-23 13:37:58 +01:00
Fixed incorrect percentage breakdown for pony diets in tooltips
This commit is contained in:
parent
5acebc270c
commit
a5132859ab
3 changed files with 21 additions and 4 deletions
|
@ -10,6 +10,7 @@ import java.util.stream.Collectors;
|
|||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import com.minelittlepony.unicopia.entity.player.Pony;
|
||||
import com.minelittlepony.unicopia.item.ItemDuck;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import com.mojang.serialization.Codec;
|
||||
|
@ -104,6 +105,7 @@ public record DietProfile(
|
|||
|
||||
public void appendTooltip(ItemStack stack, @Nullable PlayerEntity user, List<Text> tooltip, TooltipContext context) {
|
||||
var food = stack.getItem().getFoodComponent();
|
||||
|
||||
var ratios = getRatios(stack);
|
||||
if (food == null || isInedible(ratios)) {
|
||||
if (stack.getUseAction() != UseAction.DRINK) {
|
||||
|
@ -115,15 +117,30 @@ public record DietProfile(
|
|||
float baseMultiplier = (isForaged(stack) ? foragingMultiplier() : defaultMultiplier());
|
||||
|
||||
if (context.isAdvanced()) {
|
||||
var nonAdjustedFood = getNonAdjustedFoodComponent(stack, user).orElse(food);
|
||||
tooltip.add(Text.literal(" ").append(Text.translatable("unicopia.diet.base_multiplier", baseMultiplier).formatted(Formatting.DARK_GRAY)));
|
||||
tooltip.add(Text.literal(" ").append(Text.translatable("unicopia.diet.hunger.detailed", Math.max(1, (int)(ratios.getFirst() * food.getHunger())), food.getHunger(), (int)(ratios.getFirst() * 100))).formatted(Formatting.DARK_GRAY));
|
||||
tooltip.add(Text.literal(" ").append(Text.translatable("unicopia.diet.saturation.detailed", String.format("%.2f", ratios.getSecond() * food.getSaturationModifier()), (int)(ratios.getSecond() * 100))).formatted(Formatting.DARK_GRAY));
|
||||
tooltip.add(Text.literal(" ").append(Text.translatable("unicopia.diet.hunger.detailed", food.getHunger(), nonAdjustedFood.getHunger(), (int)(ratios.getFirst() * 100))).formatted(Formatting.DARK_GRAY));
|
||||
tooltip.add(Text.literal(" ").append(Text.translatable("unicopia.diet.saturation.detailed", food.getSaturationModifier(), nonAdjustedFood.getSaturationModifier(), (int)(ratios.getSecond() * 100))).formatted(Formatting.DARK_GRAY));
|
||||
} else {
|
||||
tooltip.add(Text.literal(" ").append(Text.translatable("unicopia.diet.hunger", (int)(ratios.getFirst() * 100))).formatted(Formatting.DARK_GRAY));
|
||||
tooltip.add(Text.literal(" ").append(Text.translatable("unicopia.diet.saturation", (int)(ratios.getSecond() * 100))).formatted(Formatting.DARK_GRAY));
|
||||
}
|
||||
}
|
||||
|
||||
private Optional<FoodComponent> getNonAdjustedFoodComponent(ItemStack stack, @Nullable PlayerEntity user) {
|
||||
@Nullable
|
||||
Pony pony = Pony.of(user);
|
||||
Optional<FoodComponent> food = ((ItemDuck)stack.getItem()).getOriginalFoodComponent();
|
||||
|
||||
if (food.isEmpty() && pony.getObservedSpecies().hasIronGut()) {
|
||||
return findEffect(stack)
|
||||
.flatMap(Effect::foodComponent)
|
||||
.or(() -> PonyDiets.getInstance().getEffects(stack).foodComponent());
|
||||
}
|
||||
|
||||
return food;
|
||||
}
|
||||
|
||||
public record Multiplier(
|
||||
Set<TagKey<Item>> tags,
|
||||
float hunger,
|
||||
|
|
|
@ -53,7 +53,7 @@ public class PonyDiets implements DietView {
|
|||
return Optional.ofNullable(diets.get(pony.getObservedSpecies())).orElse(DietProfile.EMPTY);
|
||||
}
|
||||
|
||||
private Effect getEffects(ItemStack stack) {
|
||||
Effect getEffects(ItemStack stack) {
|
||||
return effects.stream().filter(effect -> effect.test(stack)).findFirst().orElse(Effect.EMPTY);
|
||||
}
|
||||
|
||||
|
|
|
@ -594,7 +594,7 @@
|
|||
"unicopia.diet.not_edible": "Item is not edible",
|
||||
"unicopia.diet.base_multiplier": "Base Multiplier: %s%%",
|
||||
"unicopia.diet.hunger.detailed": "Hunger gained: %s of %s (%s%%)",
|
||||
"unicopia.diet.saturation.detailed": "Saturation gained: %s (%s%%)",
|
||||
"unicopia.diet.saturation.detailed": "Saturation gained: %s of %s (%s%%)",
|
||||
"unicopia.diet.hunger": "Hunger Ratio: %s%%",
|
||||
"unicopia.diet.saturation": "Saturation Ratio: %s%%",
|
||||
|
||||
|
|
Loading…
Reference in a new issue