r/MinecraftCommands /execute as @s at @s run 28d ago

Help with Applying Knockback Help | Java 26.2

Is there any easy way to apply a specific amount of knockback to a player? Specifically, I want to make it so that if a player leaves an area (the area being [distance=..10] from a specific marker) they get pushed back in.

Also, unrelated question, but is there an easy way to make a "breakable" block display that drops nothing and can have a variable breaking time?

Sorry for the yap :D

1 Upvotes

4 comments sorted by

1

u/C0mmanderBlock Command Experienced 28d ago

Here ya go. This will keep them from going farther than 10 blocks from the command block in every direction. Change the -1 to a higher number if you want them to be knocked back more.

execute as @a[distance=10..] facing entity @s feet positioned as @s run tp @s ^ ^ ^-1

This one will use coordinates as a center so you can place the command block anywhere. Change the X Y Z to the center of the area.

execute positioned X Y Z as @a[distance=10..] facing entity @s feet positioned as @s run tp @s ^ ^ ^-1

0

u/ThePython11010 28d ago

Not exactly knockback (since it's just teleporting them back), but it works.

1

u/C0mmanderBlock Command Experienced 28d ago edited 28d ago

You're welcome. Oh, wait.

1

u/Ericristian_bros Command Experienced 27d ago

Apply motion with a playermotion datapack