Fix for issue #1218 (journal restoring XP spent in an enchanting table) #1237
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue #1218 (journal restoring all spent XP instead of storing more) arises from the combination of enchantment tables working strangely (a flat level deduction, not a flat XP deduction) and that the "experienceTotal" variable in EntityPlayer isn't actually decreased when levels are removed - it appears to be some kind of lifetime sum.
This means that when someone used an enchanting table, the journal was looking at the lifetime sum of XP and then setting the player's XP value to (that - 10). I've changed the deductXP function in EntityUtilities.java so that it re-calculates an effective total from the player's level and "fill factor", subtracts (amount) from that to get a new total, zeros out the player's experience level and fill factor (the experience total gets (amount) subtracted from it, seeing as how it's some kind of lifetime accumulation) and then gives the player (new total) XP. It is kinda roundabout, but it guarantees that there will be no overflow.
Secondly, the "getXPFromLevel" function in EntityUtilities.java seemed to have an off by one error, meaning that if I used it in the calculations here, it kept increasing your XP even when you were trying to put it away. I've fixed that here.
Finally, I noticed that all of the XP-related variables in EntityPlayer which you accessed are now public, so I took out the reflection helper. There was also another non-localised chat message when looking at journals which didn't belong to you, so I fixed that as well.