1

I'm making a Minecraft map and I don't want the player to be able loose his bow. So I wrote this command into a repeating command block:

/replaceitem entity @p hotbar.0 bow{display:{Name:"{"text":"Bow of Shadows","color":"green","italic":"false","bold":"false"}"},"Enchantments":[{id:"minecraft:infinity",lvl:1}]} 1.

But if I try to shoot an arrow the bow reloads instantly because the command block gives me a new bow and I can't shoot. I have same problem with a shield.

I'm playing Vanilla 1.13.2

1
  • Why are you playing 1.13.2? That version has a lot of game-breaking and world-corrupting bugs and lag issues that were fixed in later versions. Sep 24, 2020 at 20:45

1 Answer 1

2

The problem is that the bow is being replaced every tick.

Instead of constantly replacing their first hotbar slot, simply give them a bow if they are missing one.

Instead of the nearest player, we're going to run this as all players for multiplayer support.

/execute as @a...

First, we need to check if the player has the bow in their inventory:

...unless entity @p[nbt={Inventory:[{id:"minecraft:bow", tag:{INSERT NBT}}]}]...

Then give them the bow.

...run give @p minecraft:bow{INSERT NBT} 1

Combine the three lines like this:

/execute as @a unless entity @s[nbt={Inventory:[{id:"minecraft:bow", tag:{INSERT NBT}}]}] run give @s minecraft:bow{INSERT NBT}]} 1

This will give every player a Bow of Shadows, if they do not already have a matching bow in their inventory. (replace "INSERT NBT" with the bow's display and enchantment data.)

Hope it helps!

3
  • 2
    You can use /execute as @a[nbt=!{...}] to simplify the command a bit.
    – pppery
    Jul 16, 2020 at 0:11
  • Thank you but it doesnt work. The command works but the bow get replaced also now. Did I something wrong? command is: /execute as @p[nbt=!{display:{Name:"{\"text\":\"Bow of Shadows\",\"color\":\"green\",\"italic\":\"false\",\"bold\":\"false\"}"},"Enchantments":[{id:"minecraft:infinity",lvl:1}]}] run replaceitem entity @p hotbar.0 bow{display:{Name:"{\"text\":\"Bow of Shadows\",\"color\":\"green\",\"italic\":\"false\",\"bold\":\"false\"}"},"Enchantments":[{id:"minecraft:infinity",lvl:1}]} 1 (Its a singelplayer map and there are four kits so it doesnt work in multiplayer because everyone would g
    – dedpunkrz
    Jul 16, 2020 at 7:54
  • With that command, you're executing it as the nearest player who isn't a Bow of Shadows, so, everyone. Either use the command in the original answer, or replace the @p[nbt=!{...}]. Instead of having the bow's NBT data replacing the ..., use the players NBT data, which can be found in the second code snippet within my original answer. Replace @p[nbt=!{...}] with @p[nbt=!{Inventory:[{id:"minecraft:bow", tag:{INSERT NBT}}]}], and replace INSERT NBT with the NBT of the bow.
    – Sam Hill
    Jul 16, 2020 at 17:22

You must log in to answer this question.

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