Autonomous Lightning Turret

Build an automated defense turret in vanilla Minecraft that rotates toward wandering mobs, locks on with a targeting laser, and strikes them with lightning.

Java EditionWands, Weapons & ToolsMedium26 commandsTested on a real 26.2 & 26.3 server
A custom copper and prismarine turret aims and fires blue energy particles at a glowing skeleton. Download the GIF Video & GIF © www.9minecraft.net

Lasers & BeamsLightningTechnologyCyanBlueOrangePvPAdventure MapBoss FightBlock displaysArmor standsRiding & passengersSummoned mobsBlock building (fill/setblock/clone)Lightning boltsRotation math21+ commands

The Autonomous Lightning Turret is a self-aiming defense tower built with command blocks and display entities. A copper and prismarine base sits at the center of the arena while a floating conduit core rotates smoothly to face the nearest hostile target.

As the turret charges up, electric sparks and a cyan laser beam lock onto the incoming enemy. Once the charge reaches maximum, a custom laser pulse shoots out from the muzzle and calls down a direct lightning strike, obliterating the target before switching to the next threat.

1. Setup - type these once 10 commands

  1. /scoreboard objectives add c9_t dummy
  2. /scoreboard players set #fire c9_t 0
  3. /scoreboard players set #spawn c9_t 70
  4. /fill ~-1 ~ ~-1 ~1 ~ ~1 polished_deepslate_slab[type=bottom]
  5. /setblock ~ ~ ~ chiseled_copper
  6. /setblock ~ ~1 ~ waxed_copper_bulb[lit=true]
  7. /setblock ~ ~2 ~ deepslate_tile_wall
  8. /summon armor_stand ~ ~3.1 ~ {Tags:["c9_turret"],Invisible:1b,NoGravity:1b,Marker:1b,Passengers:[{id:"minecraft:block_display",Tags:["c9_part"],block_state:{Name:"minecraft:conduit"},Brightness:{sky:15,block:15},transformation:{left_rotation:[0f,0f,0f,1f],right_rotation:[0f,0f,0f,1f],scale:[1.3f,1.3f,1.3f],translation:[-0.65f,-0.65f,-0.65f]}},{id:"minecraft:block_display",Tags:["c9_part"],block_state:{Name:"minecraft:lightning_rod",Properties:{facing:"south"}},Brightness:{sky:15,block:15},transformation:{left_rotation:[0f,0f,0f,1f],right_rotation:[0f,0f,0f,1f],scale:[1.0f,1.0f,1.8f],translation:[-0.5f,-0.5f,0.1f]}},{id:"minecraft:block_display",Tags:["c9_part"],block_state:{Name:"minecraft:dark_prismarine"},transformation:{left_rotation:[0f,0f,0f,1f],right_rotation:[0f,0f,0f,1f],scale:[0.7f,0.7f,0.9f],translation:[-0.35f,-0.35f,-0.45f]}}]}
  9. /summon husk ~7 ~ ~4 {Tags:["c9_target"],CustomName:{"text":"Target","color":"red"},Glowing:1b,Attributes:[{id:"minecraft:movement_speed",base:0.15d}]}
  10. /summon husk ~-6 ~ ~6 {Tags:["c9_target"],CustomName:{"text":"Target","color":"red"},Glowing:1b,Attributes:[{id:"minecraft:movement_speed",base:0.15d}]}

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

  1. /scoreboard players add #spawn c9_t 1
  2. /execute if score #spawn c9_t matches 80.. unless entity @e[tag=c9_target,distance=..16,limit=4] run summon husk ~6 ~ ~-6 {Tags:["c9_target"],CustomName:{"text":"Target","color":"red"},Glowing:1b,Attributes:[{id:"minecraft:movement_speed",base:0.15d}]}
  3. /execute if score #spawn c9_t matches 160.. unless entity @e[tag=c9_target,distance=..16,limit=4] run summon stray ~-7 ~ ~-4 {Tags:["c9_target"],CustomName:{"text":"Target","color":"aqua"},Glowing:1b,HandItems:[{id:"minecraft:stone_sword",count:1},{}]}
  4. /execute if score #spawn c9_t matches 160.. run scoreboard players set #spawn c9_t 0
  5. /execute as @e[tag=c9_target] at @s facing ~ ~ ~ run tp @s ^ ^ ^0.06 facing ~ ~ ~
  6. /execute as @e[tag=c9_turret] at @s if entity @e[tag=c9_target,distance=..16] facing entity @e[tag=c9_target,distance=..16,sort=nearest,limit=1] feet run tp @s ~ ~ ~ ~ ~
  7. /execute as @e[tag=c9_turret] at @s unless entity @e[tag=c9_target,distance=..16] run tp @s ~ ~ ~ ~4 ~
  8. /execute at @e[tag=c9_turret] run particle electric_spark ^ ^ ^1.2 0.15 0.15 0.15 0.05 3 force
  9. /execute at @e[tag=c9_turret] if entity @e[tag=c9_target,distance=..16] run scoreboard players add #fire c9_t 1
  10. /execute at @e[tag=c9_turret] if score #fire c9_t matches 20..39 run particle dust{color:[0.2,0.9,1.0],scale:1.0} ^ ^ ^1.5 0.05 0.05 0.05 0 4 force
  11. /execute at @e[tag=c9_turret] if score #fire c9_t matches 40.. run summon area_effect_cloud ^ ^ ^1.2 {Tags:["c9_ray"],Duration:3,Radius:0f}
  12. /execute as @e[tag=c9_ray] at @s facing entity @e[tag=c9_target,distance=..16,sort=nearest,limit=1] eyes run tp @s ^ ^ ^2.2
  13. /execute at @e[tag=c9_ray] run particle soul_fire_flame ~ ~ ~ 0.05 0.05 0.05 0.01 5 force
  14. /execute if score #fire c9_t matches 42.. at @e[tag=c9_target,distance=..16,sort=nearest,limit=1] run summon lightning_bolt ~ ~ ~
  15. /execute if score #fire c9_t matches 42.. at @e[tag=c9_target,distance=..16,sort=nearest,limit=1] run kill @e[tag=c9_target,distance=..2,limit=1]
  16. /execute if score #fire c9_t matches 42.. run scoreboard players set #fire c9_t 0

How it works

Frames from the test run

Autonomous Lightning Turret - frame 1Autonomous Lightning Turret - frame 2Autonomous Lightning Turret - frame 3

Recorded on our own test server: 60 frames at about 9.9 fps. Our image check saw: A turret made of a copper bulb, deepslate base, prismarine block, and lightning rod rotates and fires blue flame particles at a glowing skeleton.

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. Create a flat area and stand where you want your turret tower to be built.
  2. Run each command from the Setup list once in chat to build the copper base, summon the turret head, and spawn initial targets.
  3. Place a chain of 16 command blocks nearby: the first one set to Repeat and Always Active, and the remaining 15 chained to it set to Chain, Unconditional, and Always Active.
  4. Paste the Loop commands in order into the 16 command blocks.
  5. Watch the turret automatically rotate toward the glowing targets, charge up its barrel, and strike them with lightning.

Use it with real players

To make the turret defend you against any real hostile mob in your world instead of only tagged targets, replace tag=c9_target in the loop commands with type=#minecraft:raiders or type=!player,type=!armor_stand,type=!block_display,type=!area_effect_cloud,type=!lightning_bolt,type=!item, and remove the first five loop commands that spawn the demo mobs.

Remove it again 6 commands

  1. /kill @e[tag=c9_turret]
  2. /kill @e[tag=c9_part]
  3. /kill @e[tag=c9_target]
  4. /kill @e[tag=c9_ray]
  5. /fill ~-1 ~ ~-1 ~1 ~3 ~1 air
  6. /scoreboard objectives remove c9_t

FAQ

Why doesn't the barrel rotate up and down when the turret turns?

Block display passengers inherit the yaw rotation of the vehicle armor stand in Java Edition, keeping the turret base level while aiming horizontally toward targets.

Can I change how fast the turret fires?

Yes. Lower the numbers 40 and 42 in the last six loop commands to make the turret charge and strike faster, or raise them for a slower cooldown.

Commands used

/execute/fill/kill/particle/scoreboard/setblock/summon/tp

Similar creations

Join 9Minecraft News & Guides