Autonomous Defense Turret

Build a rotating mechanical laser turret in vanilla Minecraft that automatically tracks nearby monsters and blasts them with glowing plasma beams.

Java EditionWands, Weapons & ToolsMedium24 commandsTested on a real 26.2 & 26.3 server
An autonomous turret swivels and fires a glowing cyan laser beam at a nearby monster at night. Download the GIF Video & GIF © www.9minecraft.net

Lasers & BeamsTechnologyFireCyanOrangeWhitePvPAdventure MapDecorationBlock displaysSmooth animation (interpolation)Summoned mobsBlock building (fill/setblock/clone)SoundsGlowing outlinesRotation math21+ commands

This command creation builds a custom mechanical turret out of block display entities at the center of your base. It swivels smoothly on its pedestal, automatically locking onto the nearest wandering monster and firing high-speed cyan plasma beams that zap targets with fiery impacts.

Everything runs purely on vanilla display entities and scoreboards. In this self-running demo, armored husks spawn around the perimeter and try to approach the turret, only to get tracked and taken down by the automated defense system.

1. Setup - type these once 10 commands

  1. /scoreboard objectives add c9_timer dummy
  2. /fill ~-1 ~-1 ~-1 ~1 ~-1 ~1 polished_deepslate
  3. /setblock ~ ~ ~ chiseled_polished_blackstone
  4. /setblock ~ ~1 ~ lodestone
  5. /summon block_display ~ ~1.8 ~ {tags:["c9_turret","c9_part"],transformation:{translation:[-0.35f,-0.35f,-0.35f],scale:[0.7f,0.7f,0.7f],left_rotation:[0f,0f,0f,1f],right_rotation:[0f,0f,0f,1f]},block_state:{Name:"minecraft:iron_block"},teleport_duration:2}
  6. /summon block_display ~ ~1.8 ~ {tags:["c9_part"],transformation:{translation:[-0.15f,-0.1f,0.1f],scale:[0.3f,0.3f,1.2f],left_rotation:[0f,0f,0f,1f],right_rotation:[0f,0f,0f,1f]},block_state:{Name:"minecraft:polished_deepslate"},teleport_duration:2}
  7. /summon block_display ~ ~1.8 ~ {tags:["c9_part"],transformation:{translation:[-0.2f,-0.15f,1.1f],scale:[0.4f,0.4f,0.3f],left_rotation:[0f,0f,0f,1f],right_rotation:[0f,0f,0f,1f]},block_state:{Name:"minecraft:sea_lantern"},teleport_duration:2}
  8. /summon block_display ~ ~1.8 ~ {tags:["c9_part"],transformation:{translation:[-0.1f,0.2f,-0.2f],scale:[0.2f,0.3f,0.6f],left_rotation:[0f,0f,0f,1f],right_rotation:[0f,0f,0f,1f]},block_state:{Name:"minecraft:redstone_block"},teleport_duration:2}
  9. /summon husk ~7 ~ ~7 {Tags:["c9_mob"],CustomName:'{"text":"Target","color":"red"}',Glowing:1b,ArmorItems:[{},{},{},{id:"minecraft:iron_helmet",count:1}]}
  10. /summon husk ~-7 ~ ~6 {Tags:["c9_mob"],CustomName:'{"text":"Target","color":"red"}',Glowing:1b,ArmorItems:[{},{},{},{id:"minecraft:iron_helmet",count:1}]}

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

  1. /scoreboard players add #tick c9_timer 1
  2. /scoreboard players add #spawn c9_timer 1
  3. /execute if score #tick c9_timer matches 20.. run scoreboard players set #tick c9_timer 0
  4. /execute if score #spawn c9_timer matches 45.. run scoreboard players set #spawn c9_timer 0
  5. /execute if score #spawn c9_timer matches 1 unless entity @e[tag=c9_mob,limit=5] run summon husk ~8 ~ ~-6 {Tags:["c9_mob"],CustomName:'{"text":"Target","color":"red"}',Glowing:1b,ArmorItems:[{},{},{},{id:"minecraft:iron_helmet",count:1}]}
  6. /execute if score #spawn c9_timer matches 23 unless entity @e[tag=c9_mob,limit=5] run summon husk ~-8 ~ ~-5 {Tags:["c9_mob"],CustomName:'{"text":"Target","color":"red"}',Glowing:1b,ArmorItems:[{},{},{},{id:"minecraft:iron_helmet",count:1}]}
  7. /execute as @e[tag=c9_turret] at @s if entity @e[tag=c9_mob,distance=..18] facing entity @e[tag=c9_mob,distance=..18,sort=nearest,limit=1] feet run tp @s ~ ~ ~ ~ ~
  8. /execute as @e[tag=c9_turret] at @s unless entity @e[tag=c9_mob,distance=..18] run tp @s ~ ~ ~ ~4 ~
  9. /execute at @e[tag=c9_turret] as @e[tag=c9_part,tag=!c9_turret] run tp @s ~ ~ ~ ~ ~
  10. /execute at @e[tag=c9_turret] run particle electric_spark ^ ^ ^1.3 0.1 0.1 0.1 0.02 1 force
  11. /execute if score #tick c9_timer matches 1 at @e[tag=c9_turret] if entity @e[tag=c9_mob,distance=..18] run summon area_effect_cloud ^ ^ ^1.3 {Tags:["c9_beam"],Duration:16,Radius:0f}
  12. /execute if score #tick c9_timer matches 1 at @e[tag=c9_turret] if entity @e[tag=c9_mob,distance=..18] run playsound block.beacon.deactivate master @a ~ ~ ~ 1 2
  13. /execute as @e[tag=c9_beam] at @s facing entity @e[tag=c9_mob,distance=..20,sort=nearest,limit=1] eyes run tp @s ^ ^ ^0.9
  14. /execute at @e[tag=c9_beam] run particle dust{color:[0.0,1.0,1.0],scale:1.5} ~ ~ ~ 0.05 0.05 0.05 0 4 force

How it works

Frames from the test run

Autonomous Defense Turret - frame 1Autonomous Defense Turret - frame 2Autonomous Defense Turret - frame 3

Recorded on our own test server: 60 frames at about 9.8 fps. Our image check saw: A custom block display turret swivels on a pedestal at night, tracking a glowing armored husk in the bottom-left and firing a cyan plasma beam that hits the ground with fire.

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 at the center of a flat area where you want the turret built.
  2. Run each command from the Setup list in chat one by one to build the pedestal, assemble the turret display parts, and spawn the first test targets.
  3. Place a line of 14 Repeating Command Blocks nearby, set them all to Always Active, and paste one Loop command into each block.
  4. To make the laser beams actually damage monsters on impact, add one more Always Active repeating command block with: <code>/execute as @e[tag=c9_beam] at @s if entity @e[tag=c9_mob,distance=..1.5] run damage @e[tag=c9_mob,distance=..1.5,limit=1] 6 magic</code>
  5. Watch the turret automatically swivel toward the glowing husks and fire cyan particle beams at them.

Use it with real players

To make the turret defend you against all natural survival monsters instead of just the demo husks, replace tag=c9_mob in the loop commands with type=#minecraft:raiders or type=zombie, and remove the four husk spawning commands. Add a repeating command block running /execute at @e[tag=c9_beam] run damage @e[type=!player,type=!block_display,type=!area_effect_cloud,distance=..1.5,limit=1] 8 magic so the beam damages any hostile mob it touches.

Remove it again 6 commands

  1. /kill @e[tag=c9_part]
  2. /kill @e[tag=c9_beam]
  3. /kill @e[tag=c9_mob]
  4. /scoreboard objectives remove c9_timer
  5. /fill ~-1 ~-1 ~-1 ~1 ~-1 ~1 grass_block
  6. /fill ~ ~ ~ ~ ~1 ~ air

FAQ

Why does the turret look so smooth when it turns?

The block display entities use the teleport_duration NBT tag set to 2 ticks, which tells Minecraft to smoothly interpolate their rotation between every command tick.

Can I change the range of the turret?

Yes. Change distance=..18 in the loop commands to a larger number like distance=..30, and increase the Duration tag on the area_effect_cloud projectile so the beam can travel further before disappearing.

Commands used

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

Similar creations

Join 9Minecraft News & Guides