Is it possible to test when a player gets hit by a minecart, then inflict damage on the person hit by the minecart based on the speed of the minecart? If testing for the speed of the minecart isn't possible, that's okay. This is as far as I got with this:

/testfor @e[type=MinecartRideable]

Obviously, this command block would be running on a constant redstone loop, and would feed into the command block testing for the player, then into the command block that does damage to the player, unfortunately, I just can't figure out how to test for the player in the same location as the minecart. Does anyone know how to do this? Is it possible? As always, any help is appreciated, thanks!

1 Answer 1


First, the name of a normal minecart entity is actually "MinecartRideable".

Rather than just testing for a minecart being existent, we should make the minecart do something. The /execute command allows another command to be run as a specific entity. What we want the minecart to do is /execute an /effect command that damages nearby players:

/execute @e[type=MinecartRideable] ~ ~ ~ /effect @p[r=0] 7 10 0 true

Hook that up to a clock and all minecarts will constantly be giving damage to players that they touch. It doesn't need to check if it is actually touching anyone first, because if it isn't then nobody (@p[r=0]) will be hurt so it doesn't matter.

There's no real way to test for how fast a minecart is going, so be warned that it will always give the same amount of damage, even if you are the one pushing it away from you.

(We can technically test the speed of a minecart, but only in single values rather than a range, and its momentum tag can be decimal values.)

  • What do you mean by We can technically test the speed of a minecart, but only in single values rather than a range, and its momentum tag can be decimal values. Could you give an example? If possible? May 30, 2014 at 20:41
  • 2
    @DatEpicCoderGuyWhoPrograms The motion NBTag is a list of doubles. Doubles can have 15 decimal places, and you can only test for a single value. For example "/testfor @e[type=MinecartRideable] {Motion:[1.0,0.0,0.0]}" would test for a minecart with EXACTLY 1m/s velocity in the direction of positive X, but it's more likely to be something like 0.8292260 which the command would not detect. Furthermore, AFAIK, you can only test for all three of the values at once, and all have to match. So there'd be no way to test speed on diagonals without billions of command blocks.
    – SirBenet
    May 31, 2014 at 11:58
  • It would be nice if it was possible to test ranges of speeds, instead of the actual speed itself. Jun 3, 2014 at 12:10
  • It's kinda funny, while it makes minecarts more realistic, players are now killed when they enter the minecart. Jun 3, 2014 at 12:12
  • 1
    @jc3833 To test for one direction, you'd need roughly 200000000000 command blocks. To test for all direction combinations you'd need 200000000000^3 command blocks, or about 8*10^33. That's more blocks than there are in the entire minecraft world (by a very long way). So yes, it probably would take a long time (several million millennia) and a lot of space (just under 10000000000000000 worlds) to set up.
    – SirBenet
    Jun 5, 2014 at 6:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .