Skip to content

fix: keep health and mana when the nutrition attribute updates - #68

Merged
XxFran10xX merged 1 commit into
mainfrom
fix/nutrition-keeps-health
Oct 10, 2026
Merged

XxFran10xX merged 1 commit into
mainfrom
fix/nutrition-keeps-health

Conversation

@XxFran10xX

Copy link
Copy Markdown
Contributor

Summary

  • Bug: players lost health every time they ate. Reported on Main by EuryOnIce on 2026-10-10: a plum cost about 3 HP at full health, and the diet didn't change.
  • Cause: after each meal Cooking writes the diet score into the MMOCore nutrition attribute (NutritionAttributeBridge.apply). MMOCore's AttributeInstance.setBase always calls updateStats(), even when the value is unchanged. That removes the attribute's stat buffs from every stat, then adds them back. Removing a buff triggers MMOCore's MaxResourceStatUpdateListener, which straight away lowers health and mana to the reduced maximum (ResourceUpdateReason.CLAMPING). When the buffs come back, the maximum is restored but the lost health and mana are not. Main gives max_health: 0.1 and max_mana: 0.25 per nutrition point, so at diet 36 each bite at full health cost 3.6 HP and 9 mana.
  • Fix, part 1: apply now returns early when the attribute already equals the diet score. Most bites take this path.
  • Fix, part 2: when the diet does change, health and MMOCore mana, stamina and stellium are read before setBase. Afterwards anything the clamp removed is restored, capped at the new maximum. So a lower diet still lowers max health, but players lose only that difference, not the whole nutrition share.
  • Event choice: mana, stamina and stellium are restored with ResourceUpdateReason.CLAMPING, which fires no update event. That's the same reason MMOCore used when it removed them.
  • Health: health goes through the Bukkit API, because MMOCore's PlayerResource.HEALTH loads MythicLib's Attributes class, which can't load in unit tests.
  • Soft dependency: MMOCore classes are only loaded after the existing isPluginEnabled("MMOCore") check, because MMOCore is a softdepend.

Documentation impact

Contract

  • Affected behavior: eating, and activating a character, no longer cost health or mana. When the diet changes, current health and mana follow only the new maximum.
  • Tests run: mvn -B clean verify passes all tests, with the JaCoCo 100% line gate. The bridge tests now cover:
    • skipping the update when the attribute is unchanged;
    • giving back health and mana after a simulated clamp;
    • leaving stamina and stellium alone when nothing was lost;
    • capping health at a lower new maximum.
  • Dev bot test (~/challenge-test/nutri-test.js): a seeded character with diet 36 eats a Cooking fruit at full health. With the old jar it went 24.8 → 21.43 HP, and 24.7 → 21.43 on the next bite. With this build:
    • Diet unchanged: 24.8 → 24.8.
    • Diet 36 → 34: 24.8 → 24.6, matching the new max of 24.6.
  • Player wiki (ProvinceSystem /wiki/cooking or related pages): no change.

Notes

  • Config source is src/main/resources. Do not edit target/.
  • cookware.yml is not loaded.
  • MMOCore does the same strip-then-re-add for any attribute setBase or addModifier call. Other plugins that change MMOCore attributes on players at full health would cause the same loss.

🤖 Generated with Claude Code

MMOCore's AttributeInstance.setBase strips the attribute's stat buffs and
adds them back, and its max-resource listener clamps health and mana to the
stripped maximums in between. Every meal reset the nutrition attribute, so a
player at full health lost the nutrition share of max health (0.1 per diet
point) and of max mana on each bite, even when the diet did not change.

Skip the update when the attribute already matches the diet score, and when
it does change, give back what the clamp took, up to the new maximums.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@XxFran10xX

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d67b6599-d605-429e-8404-c569e7015468

📥 Commits

Reviewing files that changed from the base of the PR and between e2cb9db and 5358b0e.


📒 Files selected for processing (2)
  • src/main/java/net/tfminecraft/cooking/nutrition/NutritionAttributeBridge.java
  • src/test/java/net/tfminecraft/cooking/nutrition/NutritionRuntimeCoverageTest.java

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.



📝 Summary

Summary by CodeRabbit

  • Bug Fixes
    • Changing a diet attribute now preserves health and resource levels where possible, without exceeding their updated maximums.
    • Reduced maximum health is respected when restoring health.

Walkthrough

The nutrition attribute bridge now preserves health, mana, stamina and stellium when a diet attribute base changes, within the new maximum values. Runtime coverage tests check restoration, clamping, unchanged resources and repeated application of the same base.

Changes

Nutrition attribute restoration

Layer / File(s) Summary
Preserve health and resources during attribute changes
src/main/java/net/tfminecraft/cooking/nutrition/NutritionAttributeBridge.java, src/test/java/net/tfminecraft/cooking/nutrition/NutritionRuntimeCoverageTest.java
The bridge records health and resource values before changing the diet attribute base. It restores values only when they are below the recorded values capped at the new maximums. Tests check health and mana restoration, clamping, unchanged stamina and stellium, and repeated application of the same base.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: ryanbarlow97


Merge Risk: ⚪ Minimal · up to 5358b

No confirmed issue blocks merging. The tests cover the intended restoration calls, though behavior with the real MMOCore implementation remains unverified.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai

coderabbitai Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@XxFran10xX

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@XxFran10xX
XxFran10xX merged commit 24c2ddb into main Oct 10, 2026
2 checks passed
@XxFran10xX
XxFran10xX deleted the fix/nutrition-keeps-health branch October 10, 2026 16:09
@coderabbitai

coderabbitai Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
⚠️ Action not completed

Pull request is closed.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant