Wandering mobs carry invisible kinetic barriers that automatically push them away from each other with glowing particles whenever they get too close.
Time & Space MagicMysticTechnologyCyanGoldWhiteMini-gameLearningMap MakingBlock displaysSummoned mobsSoundsRotation math21+ commands
This command creation gives every tagged mob a personal magnetic forcefield. As sheep and cows wander around the central beacon, they glow with a soft cyan aura. The moment any two creatures step within three blocks of each other, their barriers collide and push them smoothly in opposite directions with a burst of golden sparks and electric trails.
It uses directional teleportation with the facing syntax to calculate the exact angle away from the nearest neighbor, combined with a gentle pull toward the center so the herd stays together and keeps bouncing.
/scoreboard objectives add c9_timer dummy/summon marker ~ ~ ~ {Tags:["c9_center","c9_ent"]}/summon block_display ~-0.3 ~ ~-0.3 {Tags:["c9_ent"],Glowing:1b,glow_color_override:65535,block_state:{Name:"minecraft:sea_lantern"},transformation:{left_rotation:[0f,0f,0f,1f],right_rotation:[0f,0f,0f,1f],translation:[0f,0f,0f],scale:[0.6f,2.5f,0.6f]}}/summon sheep ~3 ~ ~2 {Tags:["c9_repel","c9_ent"],Color:3b,Glowing:1b,PersistenceRequired:1b,Invulnerable:1b}/summon sheep ~-3 ~ ~2 {Tags:["c9_repel","c9_ent"],Color:1b,Glowing:1b,PersistenceRequired:1b,Invulnerable:1b}/summon sheep ~2 ~ ~-3 {Tags:["c9_repel","c9_ent"],Color:2b,Glowing:1b,PersistenceRequired:1b,Invulnerable:1b}/summon sheep ~-2 ~ ~-3 {Tags:["c9_repel","c9_ent"],Color:4b,Glowing:1b,PersistenceRequired:1b,Invulnerable:1b}/summon cow ~4 ~ ~ {Tags:["c9_repel","c9_ent"],Glowing:1b,PersistenceRequired:1b,Invulnerable:1b}/summon cow ~-4 ~ ~ {Tags:["c9_repel","c9_ent"],Glowing:1b,PersistenceRequired:1b,Invulnerable:1b}/summon mooshroom ~ ~ ~4 {Tags:["c9_repel","c9_ent"],Glowing:1b,PersistenceRequired:1b,Invulnerable:1b}/scoreboard players add @e[tag=c9_center] c9_timer 1/execute as @e[tag=c9_center,scores={c9_timer=40..}] run scoreboard players set @s c9_timer 0/execute at @e[tag=c9_center] run particle end_rod ~ ~1.2 ~ 0.4 1.0 0.4 0.02 2 force/execute as @e[tag=c9_repel] at @s run particle dust{color:[0.2,0.9,1.0],scale:1.2} ~ ~0.6 ~ 0.4 0.3 0.4 0 2 force/execute as @e[tag=c9_repel] at @s unless entity @e[tag=c9_center,distance=..2.2] facing entity @e[tag=c9_center,limit=1] feet positioned ^ ^ ^0.09 if block ~ ~-1 ~ grass_block run tp @s ~ ~ ~/execute as @e[tag=c9_repel] at @s if entity @e[tag=c9_repel,distance=0.1..3.2] run tag @s add c9_pushing/execute as @e[tag=c9_repel] at @s unless entity @e[tag=c9_repel,distance=0.1..3.2] run tag @s remove c9_pushing/execute as @e[tag=c9_pushing] at @s facing entity @e[tag=c9_repel,distance=0.1..3.2,sort=nearest,limit=1] feet positioned ^ ^ ^-0.24 if block ~ ~-1 ~ grass_block run tp @s ~ ~ ~/execute as @e[tag=c9_pushing] at @s run particle electric_spark ~ ~0.7 ~ 0.35 0.35 0.35 0.15 4 force/execute as @e[tag=c9_pushing] at @s run particle dust{color:[1.0,0.8,0.1],scale:1.5} ~ ~0.7 ~ 0.4 0.2 0.4 0 2 force/execute if entity @e[tag=c9_center,scores={c9_timer=1}] as @e[tag=c9_pushing] at @s run playsound minecraft:block.amethyst_block.chime master @a ~ ~ ~ 0.6 1.5/execute if entity @e[tag=c9_center,scores={c9_timer=20}] as @e[tag=c9_pushing,limit=3] at @s run particle flash{color:[0.3,1.0,1.0,1.0]} ~ ~0.8 ~ 0 0 0 0 1 forceloop #5 Gently pulls every forcefield mob 0.09 blocks per tick toward the central marker using <code>facing entity</code> and local coordinates <code>^ ^ ^0.09</code>, keeping them gathered near the middle so they continually interact.loop #6 Checks if another <code>c9_repel</code> mob is within 0.1 to 3.2 blocks. Using <code>0.1..</code> ignores the mob checking itself and adds the <code>c9_pushing</code> tag when a neighbor enters the barrier range.loop #8 Faces the nearest neighboring mob and steps backward by <code>^ ^ ^-0.24</code> blocks if there is grass underneath. Because it teleports to <code>~ ~ ~</code> without rotation arguments, the mob slides away smoothly without snapping its head.loop #9 Spawns electric sparks and golden dust around any mob currently repelling another creature to visualize the barrier collision.


Recorded on our own test server: 59 frames at about 9.7 fps. Our image check saw: Glowing sheep and cows surround a glowing cyan beacon pillar at night, emitting blue, gold, and white spark particles while maintaining distance from each other.
Commands, video and screenshots: tested and recorded by www.9minecraft.net © 9Minecraft. Sharing a video or screenshot? Please credit www.9minecraft.net.
To give yourself this repulsion barrier so nearby mobs are pushed away from you, skip the center pull command (Loop #5) and run a repeating command that pushes mobs away from players: /execute as @e[type=!player,distance=..3.5] at @s if entity @a[distance=..3.2] facing entity @p feet positioned ^ ^ ^-0.25 run tp @s ~ ~ ~.
/tp @e[tag=c9_repel] ~ ~-200 ~/kill @e[tag=c9_ent]/scoreboard objectives remove c9_timerChange the distance range <code>0.1..3.2</code> in Loop commands 6, 7, and 8 to a larger number like <code>0.1..5.0</code> for a wider barrier.
The <code>if block ~ ~-1 ~ grass_block</code> check ensures mobs only slide onto valid ground and never get pushed off the edge of the platform or into walls.
▶Steampunk Aether-Core Piston EngineTime & Space MagicExpert26 cmds
▶Arcane Metronome Tempo DistortionTime & Space MagicHard24 cmds
▶Celestial Astrolabe Gyroscopic AlignmentTime & Space MagicExpert24 cmds
▶Celestial Da Vinci Ornithopter FlightTime & Space MagicExpert24 cmds
▶Materializing Time MachineTime & Space MagicMedium24 cmds
▶Chrono-Stasis ArenaTime & Space MagicMedium23 cmds