My thought is to use a structure block, to clone the entity.
So this is what I'd do it:
- First, spawn an armor stand (as a marker) in the location of the entity to be cloned.
- Move the entity to a predefined location.
- Clone it with the structure blocks.
- Then move the entity back to the marker, and the new one where you want it.
- Finally remove the marker.
I'll just show how to set up the structure blocks. I'll assume you know what your doing with the teleportation of the entities.
So the cloning device should look like this:
(The command block in the second picture removes the stone block when a red stone block is placed there.)
So the structure block on the left is the saving block, you place the entities to be cloned on top of it.
You must have "Include Entities" set to on, or it won't clone entities.
The block on the right loads the entities. (If you use red stone to save, it will only save to RAM, not your disk, which is good.)
(The structure name doesn't have to be "cloner", but it just has to be the same in both blocks.)
When you have the cloning device set up, you just have to teleport an entity on top of the structure block on the left, place a red stone block in place of the stone one, then one red stone tick later, you'll have two identical entities.
Necro edit: I though I'd clarify why there has to be a red stone tick between them, its because structure blocks are "slow" (compared to command blocks) and require time to save the structure data. A single red stone tick is simply easy to do, but it can be any amount of time, as long as it gives the structure blocks time to do their thing.
You can use the caret notation (^
) in execute positioned
, which removes the need for the x
, y
and z
target selectors entirely (except in some really niche cases). The command you need is this one:
execute at @e[type=villager] positioned ^ ^ ^2 run tellraw @a[distance=..2] "Hey!"
As a bonus, you can get rid of the comparator (and also prevent that players why enter the radius multiple times get the message multiple times) by putting this command after the first:
execute at @e[type=villager] positioned ^ ^ ^2 run tag @a[distance=..2] add heardVillagerTalk
and modifying the first command to:
execute at @e[type=villager] positioned ^ ^ ^2 run tellraw @a[distance=..2,tag=!heardVillagerTalk] "Hey!"
This will prevent the issue the comparator had that players could walk in and out of the area and get the message every time.
If you're using a state scoreboard in your map, you can of course do the same with that. Let's say that state 0 is before having "heard" the "villager" "talk" and state 1 is afterwards. Make this command the second command in the row:
execute at @e[type=villager] positioned ^ ^ ^2 if entity @a[distance=..2] run scoreboard players set $game state 1
And make both only activate in state 0. This assumes that your state scoreboard is called "state" and the holder "$game".
Best Answer
/execute
is not what you are looking for. Even in Java Edition, you can only run one command with it.You can consider creating a command chain. Please consider visiting this post for info on how you can create a command chain. With a command chain, all the commands that are part of it will execute at the same time, but in order. I hope that this will suffice for running multiple commands at once.
If a command chain is not satisfactory, there's not much else you can do.