Build an automated defense turret in vanilla Minecraft that rotates toward wandering mobs, locks on with a targeting laser, and strikes them with lightning.
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.
/scoreboard objectives add c9_t dummy/scoreboard players set #fire c9_t 0/scoreboard players set #spawn c9_t 70/fill ~-1 ~ ~-1 ~1 ~ ~1 polished_deepslate_slab[type=bottom]/setblock ~ ~ ~ chiseled_copper/setblock ~ ~1 ~ waxed_copper_bulb[lit=true]/setblock ~ ~2 ~ deepslate_tile_wall/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]}}]}/summon husk ~7 ~ ~4 {Tags:["c9_target"],CustomName:{"text":"Target","color":"red"},Glowing:1b,Attributes:[{id:"minecraft:movement_speed",base:0.15d}]}/summon husk ~-6 ~ ~6 {Tags:["c9_target"],CustomName:{"text":"Target","color":"red"},Glowing:1b,Attributes:[{id:"minecraft:movement_speed",base:0.15d}]}/scoreboard players add #spawn c9_t 1/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}]}/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},{}]}/execute if score #spawn c9_t matches 160.. run scoreboard players set #spawn c9_t 0/execute as @e[tag=c9_target] at @s facing ~ ~ ~ run tp @s ^ ^ ^0.06 facing ~ ~ ~/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 ~ ~ ~ ~ ~/execute as @e[tag=c9_turret] at @s unless entity @e[tag=c9_target,distance=..16] run tp @s ~ ~ ~ ~4 ~/execute at @e[tag=c9_turret] run particle electric_spark ^ ^ ^1.2 0.15 0.15 0.15 0.05 3 force/execute at @e[tag=c9_turret] if entity @e[tag=c9_target,distance=..16] run scoreboard players add #fire c9_t 1/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/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}/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/execute at @e[tag=c9_ray] run particle soul_fire_flame ~ ~ ~ 0.05 0.05 0.05 0.01 5 force/execute if score #fire c9_t matches 42.. at @e[tag=c9_target,distance=..16,sort=nearest,limit=1] run summon lightning_bolt ~ ~ ~/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]/execute if score #fire c9_t matches 42.. run scoreboard players set #fire c9_t 0setup #8 Summons an invisible marker armor stand tagged <code>c9_turret</code> at the top of the tower with three <code>block_display</code> passengers (a conduit, a stretched lightning rod barrel, and a dark prismarine housing) that rotate together with the stand.loop #6 Rotates the turret armor stand every tick to face the nearest target entity within 16 blocks using <code>facing entity ... feet</code>.loop #11 When the <code>#fire</code> charge timer reaches 40 ticks (2 seconds), spawns a short-lived tracer cloud at the tip of the barrel using local coordinates <code>^ ^ ^1.2</code>.loop #14 At 42 ticks, summons a lightning bolt directly on the nearest target and resets the firing cycle.


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.
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.
/kill @e[tag=c9_turret]/kill @e[tag=c9_part]/kill @e[tag=c9_target]/kill @e[tag=c9_ray]/fill ~-1 ~ ~-1 ~1 ~3 ~1 air/scoreboard objectives remove c9_tBlock display passengers inherit the yaw rotation of the vehicle armor stand in Java Edition, keeping the turret base level while aiming horizontally toward targets.
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.
▶Automated Defense TurretsLasers & BeamsMedium26 cmds
▶Overcharged Railgun Multi-Wall PiercerLasers & BeamsHard24 cmds
▶Automated Sentinel TurretLasers & BeamsMedium24 cmds
▶Autonomous Defense TurretLasers & BeamsMedium24 cmds
▶Barbershop Pole Helical Blood-Letting LanceLasers & BeamsHard22 cmds
▶Cyber-Grid Laser Wireframe Slicer CubeLasers & BeamsExpert24 cmds