Bottle 'o enchanting recipe using commands? [duplicate]

I'm trying to make a crafting recipe for xp bottles in Minecraft 1.13. I've made the recipe, and I've got a command block that removes xp when you craft it:

/experience add @a[scores={xp=1}] -7 points
  • The xp objective is simply minecraft.crafted:minecraft.experience_bottle

  • Another command block removes the score afterwards

  • I'm removing 7 points because 1 bottle gives between 3 and 11 points so I took the rough average as a compromise

Now I'm trying to figure out how to stop people from doing it when they have no xp. I was thinking a system that removes the xp bottle from your inventory after crafting if you don't have any xp, but I don't know how to go about it. Any suggestions?


Solution 1:

There's an xp scoreboard type. So you just have to create a scoreboard like this:

/scoreboard objectives add scoreboardName xp {"text":"scoreboardDisplayName"}

Then you can query for the score being 7 or more like this: @a[scores={scoreboardName=7..}]


If you already have players with XP when you set up this command system, then you can put their current XP value into the scoreboard like this:

/execute as @a store result score @s xp run experience query @s points