2

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?

marked as duplicate by Fabian Röling, Wondercricket, Virusbomb, arghtype, Lore Friendly May 1 at 12:07

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    Hm, sadly the experience command always succeeds, no matter if it can remove the experience or not. That's definitely a bug, I'll report it. Edit: It is already reported: bugs.mojang.com/browse/MC-121651 – Fabian Röling May 24 '18 at 19:34
  • You can use /experience query and execute store result. I'm so glad right now that this isn't a 1.12 question and I don't have to mess with /stats. :D – Fabian Röling May 24 '18 at 19:36
  • 2
    This one's older... – TQ1000 Apr 28 at 21:27
  • 2
    @FabianRöling Actually I think mine is technically a duplicate of this one because as TQ pointed out this one is older, but the name of this one is much different so I'd say leave both alone or mark mine as a duplicate. – Nik3141 Apr 28 at 22:12
  • 1
    Oh, I overlooked that yours was from 2019 and this one from 2018. Anyway, the other one has more and better answers, so it should be ok to backwards resolve. And that the name is different doesn't matter. The reason to not delete duplicates is so that people can find one and get directed to the other, so having a different wording in the duplicate question is actually a good thing. – Fabian Röling Apr 28 at 22:22
2

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
  • This will be useful to test for it, but you can still craft the item as it is basically a crafting recipe in a data pack. I still need a way to stop people from getting it, maybe by deleting the bottle once it's in the inventory but I don't know how to do that – TQ1000 May 24 '18 at 20:04
  • That's just the /take command. Or, if you want to completely prevent the crafting, you can turn the limited crafting gamerule on, give everyone all recipes and then take the XP bottle recipe from them. I'll edit the answer tomorrow when I'm on a PC again. – Fabian Röling May 24 '18 at 20:14
  • I take it you mean the /clear command? If so, I completely forgot about that one. Though the problem with that would be, how do I get it to wait till the item is in your inventory? And not execute right after you crafted the item? – TQ1000 May 24 '18 at 20:26
  • Ummm... Yeah, I don't know how I fantazised the "take" command, that never existed. Yes, I meant "clear". You could make an advancement that's triggered by an inventory change. But that doesn't prevent players from throwing out the item, maybe giving it to another player. So maybe you should actually prevent crafting it completely. – Fabian Röling May 25 '18 at 5:01
  • Query for the levels, not the points, because at 1 level you have 7 points. Points query gives points from the last integer level, so it might not let you craft it successfully if you have say 33 levels and 2 points. Also, like @FabianRöling said, crafting has too many loopholes. Use a system where throwing a bottle onto a cauldron or enchanting table kills the bottle and gives the closest player a bottle of enchanting while removing 7 xp points. It is cleaner, easier, and less prone to exploitation. – Nik3141 Apr 28 at 19:54

Not the answer you're looking for? Browse other questions tagged or ask your own question.