Carpet

Carpet

2M Downloads

Query 'xp' is not including levels when set with `/experience set` command

opsaaaaa opened this issue ยท 8 comments

commented

When set the players experience manually
Then I expect querying the players experience to include the adjustment.

/experience set @p 5 points
/experience set @p 25 levels
/script run player()~'xp'   => 5
/experience add @p 1 levels/experience add @p 1 levels
/script run player()~'xp'  => 5
/experience add @p 1 points
/script run player()~'xp'  => 6
/experience set @p 70 points
/script run player()~'xp' => 6
/script run player()~'xp_level' => 26

When collecting exp orbs naturally works then it works as expected.
when adding points it also works as expected.
When the experience set manually it is not included in the query.
When the 'points' are set it is does not include the adjustment

commented

Looking at this, I think I did actually implement it correctly, but didn't explain it in the docs.

commented

Sorry thought it said close as in close text window not close issue.

commented

I just got another weird result

/experience set @p 0 levels
/experience set @p 0 points
/script run query(player(), 'xp') => 1823
/experience add @p -30 points
/script run query(player(), 'xp') => 0
commented

Glancing at the code It looks solid.
Your are basically just reading the TotalExperience property.

However it is still showing odd behavior.

Starting with 0 xp, setting my xp points to 6 and then querying my xp with scarpet i get 0. querying my xp with mc i get 6.

/experience set @p 6 points
/script run query(player(), 'xp') => 0
/experience query @p points => 6

If i once again reset my xp with '/experience add @p -100' so both read 0 then i use add instead of set they both read 6 xp.

/experience add @p 6 points
/script run query(player(), 'xp') => 6
/experience query @p points => 6

I think the totalExperience is simply not updated when /experience set ... is used.
Or when '/experience add ... levels' is used.
however when /experince add ... points is used, or when experience is collected or used naturally it does something like totalExperience += val

It looks like the xp bar fetches two seprate properties experienceLevels and experienceProgress. one for the bar and the other for the levels.
I am also going to guess there is another property likeexperiencePoints that represents the points between each level.

The result being that totalExperience and the experiencePoints/ experienceLevel remain in sync during normal gameplay. And should they get out of sync i suspect the games experience system does not really use totalExperience.

Testing with an enchanting table i Set my levels to 20 and Added 100 points
/script run query(player(), 'xp') => 100 after enchanting i get the same number?? /script run query(player(), 'xp') => 100
Might be worse then i thought. I wonder if using the enchanting table updates totalExperience at all.

I wonder if total experience represents the total amount gathered during the entire game?

This time i am leaving them in sync

/experience add @p -1000 points
/experience add @p 1000 points
# enchant some stuff....
/script run query(player(), 'xp') => 1000

Yeah totalExperience is just not updated in enchanting....

New theory is that the totalExperience is either not used or represents the total xp gathered in a game.

Well that was fun.

commented

It appears that this a minecraft bug.

/experience set @p 20 levels
/experience query @p points => 8

Or perhaps intended behavior?

/experience add @p 600 points
/experience query @p points => 102
/script run player()~'xp' => 1805

It looks like points is getting the amount of xp between levels.
where as the 'xp' scarpet query is returning something else.

commented

Perhaps it would be better to be more explicit.

query(e, 'xp')
query(e, 'xp_levels')
query(e,'xp_progress')

vvv

query(e, 'xp_total')
query(e, 'xp_points')
query(e, 'xp_levels')
query(e,'xp_progress')

And you could keep query(e, 'xp') as an alias to either xp_total or xp_points for backwards compatibility.

commented

oh, boy...
This may be a vanilla bug, or maybe /experience command updates it right before showing? Will need to investigate this further.

commented

Workaround: Hardcode the experience formulas in the Scarpet app (or a library thereof) as given in the Minecraft Wiki page on Experience (scroll up to find the formulas), then use them to do whatever you wanted to with XP (e.g. an XP-banking app). Note that depending on the implementation, the formulas may not be perfectly accurate.