Testfor movement after Eating
I'm having trouble with commandblocks, so here is what I want to do: I want to create a system that teleports you away upon eating bread. I know how to test for a player who is eating the bread using:
/scoreboard objectives add Eat stat.useItem.minecraft.bread
/testfor @a[score_Eat_min=1]
/scoreboard players set @a[score_Eat_min=1] Eat 0
That part for me is easy, but I also want to add a feature that you won't be teleported away if you are moving, or moving after you have eaten the bread. This part I do not know how to create with commandblocks. I want this only to happen for the player who ate the bread and not that it will count the movements of other players.
Solution 1:
First, follow the steps in this answer:
Create the scoreboard:
/scoreboard objectives add Moving stat.walkOneCm
Create a 20Hz clock or use repeat/chain command blocks and run the following two commands:
/scoreboard players remove @a[score_Moving_min=1] Moving 1 {OnGround:1b}
/scoreboard players set @a[score_Moving_min=1] Moving 1
The first command will reduce the Moving score by one for every player on the ground, if it is at least 1 (I.e. the score will not go below 0). The second command limits the Moving score to at most 1 by setting it to one if it is greater.
Moving will be 1 for people that are moving, or were moving prior to jumping (jumping in place does not work), and 0 otherwise.
Now from me: Next hook up this command block to the system that detects the player eating bread:
tp @a[score_Moving=0,score_Moving_min=0] x y z
Basically, this tests if the score Moving
(Remember, 0
is not moving, and 1
is) is 0
. If it is 0
, that means the player is not moving, and hence teleports them.
TIP: Maybe, you should run the previous command a few times after the player eats the bread, to make sure that don't move at all after they eat the bread.
Hope I helped!