So I'm making a command that spawns a custom wolf, which, when killed, drops a custom sword. Now I want to get it so that when the sword is dropped or right clicked, it spawns the above custom wolf, removing the sword from the players inventory. I'm not sure how to go about it.
While it would be extremely difficult to get it to work with a right click, getting it to work on a dropped item is fairly simple. First, you'll just need your custom item to have some unique factor (in my example I used a sword with "DoggySword" as the lore tag). Then have a repeating command block run this command
/execute at @e[type=item,nbt={Item:{tag:{display:{Lore:["{\"text\":\"DoggySword\"}"]}}}}] run summon (Wolf data)
You can replace the display information with whatever you're using.
Then, have a chain command block connected to the repeating one that runs this command.
/kill @e[type=item,nbt={Item:{tag:{display:{Lore:["{\"text\":\"DoggySword\"}"]}}}}]
This will cause the sword to be destroyed immediately after summoning the wolf.
If you have any questions let me know.
The simple answer is, there is not a way to do this with commands without hindering other aspects of the game. Functionality like this cannot be detected by the game (especially with the removal of sword blocking) without external mods like Spigot or Forge.
The long answer is that it is technically possible, but it would be very complex and I am not qualified to go into details about it, but I know it would hinder gameplay.
Edit: Whoops, never mind, I missed the part about the dropped item
What you could do instead is test if the animal is alive. If it isnt alive, then it will summon the wolf beside you. So, as soon as it dies another one (duplicate) will spawn.
/execute at (PlayerName) unless entity @e[name=RangersPetWolf, distance=..500] run summon minecraft:wolf ~ ~ ~ {Owner:PlayerName,CustomName:"{\"text\":\"RangersPetWolf\"}"}
Run this on a command block repeat/always active.
It will test if the player has the pet alive and if it doesnt then it will summon the wolf. Careful, be sure the name matches the pet you summon as it will summon constant pets if you do not.
If so the command should be something like
/execute @e[type=item,nbt={Item:{tag:{display:{Lore:["{\"text\":\"DoggySword\"}"]}}}}] ~ ~ ~ summon (Wolf data)
Possibly, I'm not too familiar with Bedrock's /execute
I used the exact code you posted above, except with my username and the wolfs' name.
I just tested this out and it works perfectly fine. I went onto a different map and copied/pasted my own code. Changed player name to my own and it works perfectly fine. Make sure the code is in repeat/always active.
So I'm making a command that spawns a custom wolf, which, when killed, drops a custom sword. Now I want to get it so that when the sword is dropped or right clicked, it spawns the above custom wolf, removing the sword from the players inventory. I'm not sure how to go about it.
While it would be extremely difficult to get it to work with a right click, getting it to work on a dropped item is fairly simple. First, you'll just need your custom item to have some unique factor (in my example I used a sword with "DoggySword" as the lore tag). Then have a repeating command block run this command
/execute at @e[type=item,nbt={Item:{tag:{display:{Lore:["{\"text\":\"DoggySword\"}"]}}}}] run summon (Wolf data)
You can replace the display information with whatever you're using.
Then, have a chain command block connected to the repeating one that runs this command.
/kill @e[type=item,nbt={Item:{tag:{display:{Lore:["{\"text\":\"DoggySword\"}"]}}}}]
This will cause the sword to be destroyed immediately after summoning the wolf.
If you have any questions let me know.
The simple answer is, there is not a way to do this with commands without hindering other aspects of the game. Functionality like this cannot be detected by the game (especially with the removal of sword blocking) without external mods like Spigot or Forge.
The long answer is that it is technically possible, but it would be very complex and I am not qualified to go into details about it, but I know it would hinder gameplay.
Edit: Whoops, never mind, I missed the part about the dropped item
Check out my mod! You can find it on CurseForge here:
https://www.curseforge.com/minecraft/mc-mods/the-spookjams-mod
Doesn't seem to work for some reason. The error is "Entity "at" cannot be found" in command block one. I've tried tinkering with it but still no luck.
What you could do instead is test if the animal is alive. If it isnt alive, then it will summon the wolf beside you. So, as soon as it dies another one (duplicate) will spawn.
/execute at (PlayerName) unless entity @e[name=RangersPetWolf, distance=..500] run summon minecraft:wolf ~ ~ ~ {Owner:PlayerName,CustomName:"{\"text\":\"RangersPetWolf\"}"}
Run this on a command block repeat/always active.
It will test if the player has the pet alive and if it doesnt then it will summon the wolf. Careful, be sure the name matches the pet you summon as it will summon constant pets if you do not.
Let me know how this works.
Didn't work, "Unless is not a valid number". Also "Entity "at" cannot be found.
Can you write down the exact code you used for this?
I used the exact code you posted above, except with my username and the wolfs' name.
Are you playing Bedrock edition?
If so the command should be something like
/execute @e[type=item,nbt={Item:{tag:{display:{Lore:["{\"text\":\"DoggySword\"}"]}}}}] ~ ~ ~ summon (Wolf data)
Possibly, I'm not too familiar with Bedrock's /execute
Check out my mod! You can find it on CurseForge here:
https://www.curseforge.com/minecraft/mc-mods/the-spookjams-mod
Java Edition. What should I put for (Wolf data)?
I just tested this out and it works perfectly fine. I went onto a different map and copied/pasted my own code. Changed player name to my own and it works perfectly fine. Make sure the code is in repeat/always active.
wolf ~ ~ ~ {nbt}
but fill in the "nbt" with the nbt of the wolf you want to summon
Check out my mod! You can find it on CurseForge here:
https://www.curseforge.com/minecraft/mc-mods/the-spookjams-mod