How to execute at a player holding a specific item in Minecraft? [duplicate]
![How to execute at a player holding a specific item in Minecraft? [duplicate] - Hand Holding Fishing Baits How to execute at a player holding a specific item in Minecraft? [duplicate] - Hand Holding Fishing Baits](/assets/images/how_to_execute_at_a_player_holding_a_specific_item_in_minecraft_duplicate_0.jpeg)
I'm trying to direct /execute to the location of a player who is holding a specific item. In this case, an item with the name "Gun". This is the script I'm trying to use:
/execute @e {SelectedItem:{tag:{display:{Name:"Firestarter"}}}} ~ ~ ~
/summon Fireball ~ ~ ~ {ExplosionPower:0,direction:[0.0,0.0,0.0]}
Unfortunately, this doesn't work. I've compiled the script from two working scripts:
/execute @p ~ ~ ~
/summon Fireball ~ ~ ~ {ExplosionPower:0,direction:[0.0,0.0,0.0]}
and
/testfor @e {SelectedItem:{tag:{display:{Name:"Gun"}}}}
Does anyone know how to put these together? The output of the command block is "that entity cannot be found"
Best Answer
I know I'm a little late to the party, but I would use snowballs as a gun, retexture them to look like a weapon, then instantly summon a snowball at that snowball's location- the snowball will give the fireball it's exact momentum before being deleted. First off, put into the chat this command:
/scoreboard objectives add holding.gun dummy
Then, attach these commands to a repeating/chain command block string (in order)
/scoreboard players set @a holding.gun 2 {SelectedItem:{id:snowball,tag:{put any other NBT tags in here}}}
/scoreboard player remove @a[score_holding.gun_min=1] holding.gun 1
/execute @a[score_holding.gun_min=1] ~ ~ ~ execute @e[type=Snowball,tag=!snowball,r=2] ~ ~ ~ summon Fireball ~ ~ ~ {ExplosionPower:0,direction:[0.0,0.0,0.0]}
/scoreboard players tag @e[type=Snowball] add snowball
Pictures about "How to execute at a player holding a specific item in Minecraft? [duplicate]"
![How to execute at a player holding a specific item in Minecraft? [duplicate] - Man Holding a Ball Beside a Net How to execute at a player holding a specific item in Minecraft? [duplicate] - Man Holding a Ball Beside a Net](/assets/images/how_to_execute_at_a_player_holding_a_specific_item_in_minecraft_duplicate_1.jpeg)
![How to execute at a player holding a specific item in Minecraft? [duplicate] - Woman Holding a Ball Beside The Volleyball Net How to execute at a player holding a specific item in Minecraft? [duplicate] - Woman Holding a Ball Beside The Volleyball Net](/assets/images/how_to_execute_at_a_player_holding_a_specific_item_in_minecraft_duplicate_2.jpeg)
![How to execute at a player holding a specific item in Minecraft? [duplicate] - Handsome Man Holding a Ball How to execute at a player holding a specific item in Minecraft? [duplicate] - Handsome Man Holding a Ball](/assets/images/how_to_execute_at_a_player_holding_a_specific_item_in_minecraft_duplicate_3.jpeg)
How do you execute a command if a player is holding an item?
You can clear items from a player's inventory using the /clear command in Minecraft....Supported Platforms.PlatformSupported (Version*)Java Edition (PC/Mac)Yes (1.4.2)Pocket Edition (PE)Yes (1.0.5)Xbox 360NoXbox OneYes (1.2)6 more rowsMinecraft 1.18.2: How To Run a Command When a Player Holds a Certain Item
More answers regarding how to execute at a player holding a specific item in Minecraft? [duplicate]
Answer 2
Actually, to testfor
yourself holding a certain item, all you need is one command block with the following command (for example, we can test for ourself holding an arrow)
/testfor @e[type=Player] {SelectedItem:{id:"minecraft:arrow"}}
Answer 3
The execute command sadly does not support data tags, but can be matched up with a test for command block on a repeater clock with a secondary command of /summon
, or so put as
/testfor @a {SelectedItem:{tag:{display:{Name:"Firestarter"}}}}
, then do
/summon Fireball ~ ~ ~ {ExplosionPower:0,direction:[0.0,0.0,0.0]}
You can also add particles to make it more detailed, or setblock to fire like this:
/setblock ~1 ~ ~ fire
with the /testfor
command, and do this:
/execute @e[type=Fireball] ~ ~ ~ /particle <Particle Name> ~ ~ ~ 0.25 0.25 0.25 <Speed> <Count>
,although 0.25 can be replaced with how many blocks away from the fireball the particles can reach. You can also do:
/execute @e[type=Fireball] ~ ~ ~ /setblock ~ ~-1 ~ fire
to set the block below the fire charge on fire.
Answer 4
This is what you need to do...
/testfor @e {SelectedItem:{tag:{Display{Name: "Firestarter"}}}}
/execute @e {SelectedItem:{tag:{Display{Name: "Firestarter"}}}} ~ ~ ~
/summon Fireball ~ ~ ~ {ExplosionPower0,direction:[0.0,0.0,0.0]}
That should work :)
Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.
Images: Karolina Grabowska, cottonbro, Kampus Production, cottonbro