Repository navigation
fix: keep health and mana when the nutrition attribute updates - #68
Conversation
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>
|
@coderabbitai review |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Summary
Merge Risk: ⚪ Minimal · up to No confirmed issue blocks merging. The tests cover the intended restoration calls, though behavior with the real MMOCore implementation remains unverified.
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. Comment |
✅ Action performedReview finished.
|
|
@coderabbitai review |
|
Summary
nutritionattribute (NutritionAttributeBridge.apply). MMOCore'sAttributeInstance.setBasealways callsupdateStats(), 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'sMaxResourceStatUpdateListener, 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 givesmax_health: 0.1andmax_mana: 0.25per nutrition point, so at diet 36 each bite at full health cost 3.6 HP and 9 mana.applynow returns early when the attribute already equals the diet score. Most bites take this path.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.ResourceUpdateReason.CLAMPING, which fires no update event. That's the same reason MMOCore used when it removed them.PlayerResource.HEALTHloads MythicLib'sAttributesclass, which can't load in unit tests.isPluginEnabled("MMOCore")check, because MMOCore is asoftdepend.Documentation impact
Contract
mvn -B clean verifypasses all tests, with the JaCoCo 100% line gate. The bridge tests now cover:~/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:ProvinceSystem/wiki/cookingor related pages): no change.Notes
src/main/resources. Do not edittarget/.cookware.ymlis not loaded.setBaseoraddModifiercall. Other plugins that change MMOCore attributes on players at full health would cause the same loss.🤖 Generated with Claude Code