Skip to content

Commit

Permalink
Workaround for missing food properties in some modded food items
Browse files Browse the repository at this point in the history
(fixes #4783)
  • Loading branch information
TheRealWormbo committed Jan 27, 2025
1 parent 0daede4 commit db8d495
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.food.FoodProperties;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.gameevent.GameEvent;
Expand Down Expand Up @@ -152,15 +153,18 @@ public void tickFlower() {
}

private static int getCooldown(int foodValue) {
return foodValue * FOOD_COOLDOWN_FACTOR;
return Math.max(1, foodValue * FOOD_COOLDOWN_FACTOR);
}

private static int getDigestingMana(int foodValue, double streakFactor) {
return (int) (foodValue * foodValue * FOOD_MANA_FACTOR * streakFactor);
return Math.max(1, (int) (foodValue * foodValue * FOOD_MANA_FACTOR * streakFactor));
}

private static int getFoodValue(ItemStack stack) {
return Math.min(MAX_FOOD_VALUE, stack.getItem().getFoodProperties().getNutrition());
FoodProperties foodProperties = stack.getItem().getFoodProperties();
// greetings to GregTech's Purple Drink, which claims to be edible but does not have food properties
int nutrition = foodProperties != null ? foodProperties.getNutrition() : 0;
return Math.min(MAX_FOOD_VALUE, nutrition);
}

@Override
Expand Down
1 change: 1 addition & 0 deletions web/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ thanks to Wormbo for a lot of work on this feature!
* Fix: Redstone comparators no longer read signal strength 0 from special flowers other than the Thermalily
* Fix: A comparator reading from a Thermalily through a solid block no longer keeps outputting a value after breaking the Thermalily
* Fix: Potential crash issues in combination with mods that add colors have been resolved
* Fix: Workaround for missing food properties in some items that are nonetheless flagged as edible
* Language update:
* de_de completed (Wormbo, thanks to Kartabass and PssbleTrngle for reviewing)
* ko_kr updated (UnineVesiKass)
Expand Down

0 comments on commit db8d495

Please sign in to comment.