Repulsion Forcefield Mobs

Wandering mobs carry invisible kinetic barriers that automatically push them away from each other with glowing particles whenever they get too close.

Java EditionMagic & SpellsEasy22 commandsTested on a real 26.2 & 26.3 server
Glowing sheep and cows with particle effects surround a cyan pillar at night in Minecraft. Download the GIF Video & GIF © www.9minecraft.net

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.

1. Setup - type these once 10 commands

  1. /scoreboard objectives add c9_timer dummy
  2. /summon marker ~ ~ ~ {Tags:["c9_center","c9_ent"]}
  3. /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]}}
  4. /summon sheep ~3 ~ ~2 {Tags:["c9_repel","c9_ent"],Color:3b,Glowing:1b,PersistenceRequired:1b,Invulnerable:1b}
  5. /summon sheep ~-3 ~ ~2 {Tags:["c9_repel","c9_ent"],Color:1b,Glowing:1b,PersistenceRequired:1b,Invulnerable:1b}
  6. /summon sheep ~2 ~ ~-3 {Tags:["c9_repel","c9_ent"],Color:2b,Glowing:1b,PersistenceRequired:1b,Invulnerable:1b}
  7. /summon sheep ~-2 ~ ~-3 {Tags:["c9_repel","c9_ent"],Color:4b,Glowing:1b,PersistenceRequired:1b,Invulnerable:1b}
  8. /summon cow ~4 ~ ~ {Tags:["c9_repel","c9_ent"],Glowing:1b,PersistenceRequired:1b,Invulnerable:1b}
  9. /summon cow ~-4 ~ ~ {Tags:["c9_repel","c9_ent"],Glowing:1b,PersistenceRequired:1b,Invulnerable:1b}
  10. /summon mooshroom ~ ~ ~4 {Tags:["c9_repel","c9_ent"],Glowing:1b,PersistenceRequired:1b,Invulnerable:1b}

2. Loop - one repeating command block each (Always Active) 12 commands

  1. /scoreboard players add @e[tag=c9_center] c9_timer 1
  2. /execute as @e[tag=c9_center,scores={c9_timer=40..}] run scoreboard players set @s c9_timer 0
  3. /execute at @e[tag=c9_center] run particle end_rod ~ ~1.2 ~ 0.4 1.0 0.4 0.02 2 force
  4. /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
  5. /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 ~ ~ ~
  6. /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
  7. /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
  8. /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 ~ ~ ~
  9. /execute as @e[tag=c9_pushing] at @s run particle electric_spark ~ ~0.7 ~ 0.35 0.35 0.35 0.15 4 force
  10. /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
  11. /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
  12. /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 force

How it works

Frames from the test run

Repulsion Forcefield Mobs - frame 1Repulsion Forcefield Mobs - frame 2Repulsion Forcefield Mobs - frame 3

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.

Build it in your world

  1. Stand in the center of a flat grass area and run each of the setup commands in chat once to create the scoreboard, central pillar, and glowing mobs.
  2. Place a Repeating Command Block set to Always Active and paste in the first loop command.
  3. Attach 11 Chain Command Blocks (all set to Always Active and Unconditional) in a line pointing away from the repeating block.
  4. Paste the remaining loop commands in order into the chain command blocks.
  5. Watch the mobs glide toward the center beacon and bounce off each other whenever their invisible 3-block forcefields touch.

Use it with real players

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 ~ ~ ~.

Remove it again 3 commands

  1. /tp @e[tag=c9_repel] ~ ~-200 ~
  2. /kill @e[tag=c9_ent]
  3. /scoreboard objectives remove c9_timer

FAQ

How do I change the size of the repulsion forcefield?

Change 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.

Why does the teleport command check for a grass block below?

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.

Commands used

/execute/particle/playsound/scoreboard/summon/tag/tp

Similar creations

Join 9Minecraft News & Guides