TransWikia.com

Java Minecraft 1.16.5 - How do I put an experience orb into a scoreboard?

Arqade Asked by Peter Davies-Crandley on May 31, 2021

So i’m currently working on a datapack 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

If anyone has any suggestions on how to make this work, that would be great.

One Answer

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.

Answered by Peter Davies-Crandley on May 31, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP