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
Best Answer
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.
First, we need to check if the player has the bow in their inventory:
Then give them the bow.
Combine the three lines like this:
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!