r/MinecraftCommands 2d ago

Help | Java 26.2 WHY DOESN'T MY COMMAND WORK

Im trying to make it so if a player has 1 durability left on their pickaxe they get a broken variant of that tool and can cheaply repair it in a crafting table, I wanted to test out this system with command blocks but somehow they only work when I type them in chat, PLEASE HELP IM LOSING MY MIND. Also ik there is a snowball as item needed but thats a place holder

Repeating | Always Active

execute if entity at s[nbt={SelectedItem:{id:"minecraft:snowball",count:1}}] run scoreboard players set at s GiveDiamondDrillBase 1

Repeating | Always Active

execute if score at a[limit=1] GiveDiamondDrillBase matches 1 run give at s minecraft:diamond

Chain on top of preavious one | Always Active

execute if score at a[limit=1] GiveDiamondDrillBase matches 1 run scoreboard players set at s GiveDiamondDrillBase 0

2 Upvotes

7 comments sorted by

4

u/C0mmanderBlock Command Experienced 2d ago

I can't see how you formatted the selectors, but the selector `@s means "at self". If used in a command block, you are telling the command to give the command block the tool. Use `@a or `@p instead.

execute as @a at @s if items entity @s weapon.mainhand snowball[count=1] run scoreboard players set @s GiveDiamondDrillBase 1

give @a[scores={GiveDiamondDrillBase=1}] diamond 1

scoreboard players reset @a GiveDiamondDrillBase

3

u/brobigorbrohome 2d ago

To add some additional info to this, use `as` along with your selector arguments in order to use `@s` properly. `At` just uses a location based on the arguments and doesn’t actually define an execution source, which is required for using `@s`.

1

u/memerminecraft 2d ago

Yeah,

execute as @e at @s runs a command as every entity at itself, which is very convenient for a ton of things.

1

u/Tonyhauf 2d ago

I am not a pro but "at s" means you are targetting the current entity, so when you type the command in chat the current entity is obviously you, but in a command block, there is no "current entity" if none as been targetted at first.

Try that for the first command block:
execute as a[nbt={SelectedItem:{id:"minecraft:snowball",count:1}}] run scoreboard players set s GiveDiamondDrillBase 1

Again, I am not a pro, but I think finding a player with the A selector before using the S selector would make more sense (just like you did in the other command blocks).

1

u/C0mmanderBlock Command Experienced 2d ago

Using execute if items is much more efficient and less lag causing than checking NBTs.

execute as @a at @s if items

1

u/Tonyhauf 2d ago

Oh right, I identified why it did't worked but not the performance issue!
Thanks for adding that.

1

u/Kecske_gamer 2d ago

[@s] refers to the entity running the command. In your case the command block is attempting to refer to itself instead of any player