-1

I've spent a few hours on this and looked around on the minecraft wiki and I cannot work out how to go about this. The aim is to add motion to a minecart a player is riding in when looking in a certain direction.

The following two commands work as intended:

execute as @e[type=minecart,distance=..18] run data merge entity @s {Motion:[-1.0d, 0.0d, 0.0d]}
execute if entity @p[team=red,distance=..20,y_rotation=0..90]

But I can't merge the two together to work as one.

Previous version command that used to work:

execute @a[team=red,r=200,rym=-64,ry=-26] ~ ~ ~ entitydata @e[type=minecart,r=1] {Motion:[4.5,0.04,4.5]}

Command so far, not working:

execute as @p if entity @p[distance=..20,y_rotation=0..359] run data merge entity @s[distance=..20] {Motion:[0.0,0.04,5.0]}

Apologies if I've missed something simple, I have learning difficulties that can make certain tasks difficult.

  • You're only using "as", never "at" does everything work like you want if you use your "as" part, then "at @s", then the "if" part? – Fabian Röling Oct 15 at 23:42
  • I've tried using 'at' a few times now but I cannot figure out how to make the command work. Do you have any suggestions as to how it should be formed? I followed your suggestion as well as possible and in that order and re-aranged things a few times but the command block just stops responding Another possible solution is to use two command blocks but I cannot apply motion to a team or even a named minecart – Blaze the Fox Oct 16 at 8:03
0

Instead of trying to fix your commands, I rewrote it completely, I hope this helps and can be applied to your case. This command works for me, it sets a minecart in motion whenever I'm in it:

/execute if data entity @s RootVehicle run data merge entity @e[type=minecart,distance=..0.4,limit=1] {Motion:[0.0,0.0,10.0]}

If you need to be absolutely, 100% sure that you move the minecart that you're riding, even if there's another one at the exact same position, then it gets complicated. I think the easiest way would be to loop over all minecarts in the area, each time copying the tag UUIDMost and UUIDLeast of the minecart that the player is riding (RootVehicle.UUIDMost, …) over to an arbitrary temporary storage (for example inside the tag tag of an item entity, or, in 1.15, the "storage" of the player, then trying to copy over the UUID parts of the current minecart in the loop, if that returns false (meaning that the same value was already stored there), then you found the minecart and apply motion to it.
I told you it's complicated. Sometimes being 99% sure is enough.

  • This command does not seem suitable, but thanks anyway – Blaze the Fox Oct 20 at 17:04
-1

If you wanna modify player data, I need to say you that this isn't possible anyway.
You can easily modify entity data, but playerdata can't be.
If you tell us what you're trying to do, maybe we could come up with another solution
for your problem.
I hope this helped you.

  • I'm not trying to modify player data, I'm trying to modify an entity based on player data. The old command is part of a set of 8 or more and it's purpose is stated in the OP. Thanks – Blaze the Fox Oct 20 at 23:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.