3

I'm currently working on a data pack the reworks the leveling system in Minecraft. One of the things that I'm currently struggling with is putting the XP orb into a scoreboard instead of your XP bar. I have tried multiple different variations of commands but it is not working for some reason.

What I have currently have tried is: execute as @a at @s unless score @s p_lvl = @s pm_lvl if entity @e[type=experience_orb,nbt={Value:1s},distance=..1.5] run scoreboard players add @s reserve 1

Breaking down the command:

  • If A and B are not equal & experience orb is 0-1.5 blocks away
  • then add 1 to C
2
  • 1
    Have you tried draining XP from players as they gain it, and adding it to their score? Apr 1, 2021 at 2:03
  • I can't touch the xp bar because its being used by other scripts, which is why i have a place holder variable. Apr 2, 2021 at 7:05

1 Answer 1

2

For anyone else who is looking for an answer to this question, this is what I came up with and it works quite well.

First, it is recommended that you tag your xp orbs mostly to make the commands look less scary. ex. execute as @e[nbt={Value:1s},tag=] run tag @s add xp.1 You are gonna have to do this for every naturally spawned xp orb [1–11, 17, 37, 73, 149, 307, 617, 1237, 2477].

Next, we need to find the xp orbs in the world that are close to the player, add them to the scoreboard, and (optional) kill them off. Here is my code for doing this:

execute as @a at @s if entity @e[tag=xp.1,distance=..2.5] run scoreboard players add @s xp 1
execute as @a at @s as @e[tag=xp.1,distance=..2.5] run kill @s

This seems to be working 100% (or 99% if your killing them) of the time. Due to Minecraft commands running at 1/20th of a second, there is a very small chance that xp orbs at very close range will make it into your xp bar, without killing itself or being added to the scoreboard.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .