oddlama / vane

Immersive and lore friendly enhancements for vanilla Minecraft
MIT License
272 stars 33 forks source link

Empty experience bottle giving larger variant than expected #56

Closed CosmicCaterpillar closed 2 years ago

CosmicCaterpillar commented 2 years ago

v1.3.0 (pretty sure it was happening in v1.2.3 also) loss_percentage: 0.0 (have not tested at other percentages) All other xp bottle related configurations are default. No other plugins installed.

Expected: At 0 experience, drink large experience bottle to hit level 30, anvil/enchant down to lower level (say 27), use empty xp bottle and get medium experience bottle and some leftover experience/levels.

Actual: At 0 experience, drink large experience bottle to hit level 30, anvil/enchant down to any level (went down to 9 for one of my tests), use empty xp bottle and still get large experience bottle and no leftover experience/levels.

This seems to happen for any variant of experience bottle. If I die to reset my experience to 0, I am not able to store any experience unexpectedly regardless of actions before death. Then, once I get to level 10, even if I spend 2 levels enchanting an item and go down to level 8, I can still bottle a small experience bottle and drink it back up to level 10.

Same results regardless of gaining experience using regular xp (villager trading, killing mobs, mining, bottles o' enchanting, etc) or Vane experience bottles, and losing experience from anvil or enchanting table. Additionally, gaining a small amount of experience or levels does not prevent this from happening (E.g., start at level 10, enchant down to 8, level up to 9, I am still able to get a small experience bottle). Losing experience from death or bottling experience seems to prevent the issue temporarily until you gain back to a variant level.

https://github.com/oddlama/vane/blob/26e53758c00af43d1c3d3c13b243fc0f14ae2c8f/vane-trifles/src/main/java/org/oddlama/vane/trifles/items/EmptyXpBottle.java#L97

I'm not really familiar at all with Vane code or Paper API but did some quick poking around and this might be the issue. [player.getTotalExperience()](https://papermc.io/javadocs/paper/1.17/org/bukkit/entity/Player.html#getTotalExperience()) is apparently the players "score" (the one that displays on the death screen), not their actual xp. I'm guessing your approach of subtracting xp might also be subtracting from the score (and death resets your score iirc), but subtracting levels (anvil, enchanting table) does not and that is the disconnect. Seems in line with the current behavior I am experiencing. Found a few threads similar to this. Sounds like there isn't a simple way to get the desired value and need to do a few calculations instead.

We have been loving Vane, thanks for your hard work!

oddlama commented 2 years ago

Wow thanks for the detailed report and the kind words! You are absolutely right, I wrongly assumed that [player.getTotalExperience()](https://papermc.io/javadocs/paper/1.17/org/bukkit/entity/Player.html#getTotalExperience()) returns the current amount of experience points when instead it does something slightly different than what the name suggests - as you already pointed out correctly.

Funnily enough, the utility functions by "Jikoo" which were posted to the thread you linked to, also miscalculate the experience due to a formula simplification mistake :P. I notified the owner, and implemented the correct formulas for vane.

Thanks again for the report, the issue is fixed in vane v1.3.1.