/replaceitem
has a target selector. Just use /replaceitem
instead of /testfor
.
/replaceitem entity @a[score_health=19,score_health_min=1] slot.armor.head minecraft:diamond_helmet 1 0
Relying on physical redstone logic when dealing with multi-target situations will make it difficult or impossible to support it. For example, you mechanism appears to turn on and stay on as long as a player has that health, which means any future players that meet those requirements will not be affected because the mechanism is locked due to the first detection. Removing physical logic and using /replaceitem
on the clock will allow it to support multiplayer.
/execute @a ~ ~ ~ detect ~ ~-1 ~ minecraft:stonebrick 1 /tp @p @e{type=Villager]
When ANY player steps on mossy stonebrick (minecraft:stonebirck 1) it teleports the nearest player to the command block to the villager regardless if he step on the mossy cobble.
The /execute
command modifies the sender of the command to that of its target. Any subsequent selectors in commands being run are going to use the executor as the sender.
This comes into play with sender bias, which forces a target selector to target the entity that ran the command. The command you've presented already uses it. The executing player will be the one to be teleported, so long as they are alive.
The @a
selector is the only target selector capable of targeting dead players. If a player dies while on top of stonebrick, they will teleport the nearest living player to them rather than themselves, because @p
cannot target dead players.
The fix for that in particular is to use the @a
selector while reducing the count (via c
parameter) to 1, which also enforces a sender bias. The command itself is still functional as you need it without having to have changed anything else.
/execute @a ~ ~ ~ detect ~ ~-1 ~ minecraft:stonebrick 1 /tp @a[c=1] @e[type=Villager,c=1]
/execute
is used to change the sender and origin of commands to run. /tp
is being run through the player, not by the command block. @p
will be in reference to the executing player's location, and due to sender bias, @p
will always target that player so long as that player is alive. Your command was originally working fine apart from the dead targeting flaw.
Best Answer
teleport
works relative to the executioner, no matter if~ ~ ~
or^ ^ ^
.So you want:
Note that this will neither redirect the arrow towards you (it has a
Motion
tag and to change that properly you need sinus calculation), nor will it actually rotate the tip of the arrow towards you, because facing directions of arrows are always a bit weird.