Infinite Procedural Melody

Build a self-playing command contraption that uses random numbers to compose and visualize a non-stop musical performance in F# major.

Java EditionComplex Contraptions & CinematicsMedium24 commandsTested on a real 26.2 & 26.3 server
Glowing colored pillars and floating music notes surround a central amethyst cluster on a dark stone platform. Download the GIF Video & GIF © www.9minecraft.net

SimulationsMusicMysticRainbowPurpleBlackDecorationServer LobbyLearningBlock displaysSummoned mobsBlock building (fill/setblock/clone)Sounds21+ commands

This command creation builds an automated musical gazebo that generates an endless, non-repeating melody in F# major. Every quarter second, a random number generator picks a note from the F# major pentatonic scale and plays it on a bell, supported by a warm bass chord and a rhythmic drum beat.

Each note is visualized in real time. A floating amethyst core hovers at the center of the stage, sending out colorful note particles and rising glowing crystals from a ring of six tuned pillars whenever their specific pitch is chosen.

1. Setup - type these once 10 commands

  1. /scoreboard objectives add c9_tick dummy
  2. /scoreboard objectives add c9_note dummy
  3. /scoreboard objectives add c9_beat dummy
  4. /fill ~-4 ~ ~-4 ~4 ~ ~4 minecraft:polished_blackstone_bricks
  5. /fill ~-2 ~ ~-2 ~2 ~ ~2 minecraft:chiseled_polished_blackstone
  6. /setblock ~ ~ ~ minecraft:jukebox
  7. /summon minecraft:block_display ~ ~1.8 ~ {Tags:["c9_gen","c9_core"],Glowing:1b,glow_color_override:16755200,block_state:{Name:"minecraft:amethyst_cluster"},transformation:{left_rotation:[0f,0f,0f,1f],right_rotation:[0f,0f,0f,1f],scale:[1.2f,1.2f,1.2f],translation:[-0.6f,-0.5f,-0.6f]}}
  8. /summon minecraft:block_display ~3 ~0.5 ~ {Tags:["c9_gen","c9_p0"],Glowing:1b,glow_color_override:16724787,block_state:{Name:"minecraft:red_stained_glass"},transformation:{left_rotation:[0f,0f,0f,1f],right_rotation:[0f,0f,0f,1f],scale:[0.8f,1.5f,0.8f],translation:[-0.4f,0f,-0.4f]}}
  9. /execute positioned ~1.5 ~0.5 ~2.6 run summon minecraft:block_display ~ ~ ~ {Tags:["c9_gen","c9_p1"],Glowing:1b,glow_color_override:16755200,block_state:{Name:"minecraft:orange_stained_glass"},transformation:{left_rotation:[0f,0f,0f,1f],right_rotation:[0f,0f,0f,1f],scale:[0.8f,1.7f,0.8f],translation:[-0.4f,0f,-0.4f]}}
  10. /execute positioned ~-1.5 ~0.5 ~2.6 run summon minecraft:block_display ~ ~ ~ {Tags:["c9_gen","c9_p2"],Glowing:1b,glow_color_override:16777045,block_state:{Name:"minecraft:yellow_stained_glass"},transformation:{left_rotation:[0f,0f,0f,1f],right_rotation:[0f,0f,0f,1f],scale:[0.8f,1.9f,0.8f],translation:[-0.4f,0f,-0.4f]}}

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

  1. /execute unless entity @e[tag=c9_p3] run summon minecraft:block_display ~-3 ~0.5 ~ {Tags:["c9_gen","c9_p3"],Glowing:1b,glow_color_override:5635925,block_state:{Name:"minecraft:lime_stained_glass"},transformation:{left_rotation:[0f,0f,0f,1f],right_rotation:[0f,0f,0f,1f],scale:[0.8f,2.1f,0.8f],translation:[-0.4f,0f,-0.4f]}}
  2. /execute unless entity @e[tag=c9_p4] run summon minecraft:block_display ~-1.5 ~0.5 ~-2.6 {Tags:["c9_gen","c9_p4"],Glowing:1b,glow_color_override:5636095,block_state:{Name:"minecraft:cyan_stained_glass"},transformation:{left_rotation:[0f,0f,0f,1f],right_rotation:[0f,0f,0f,1f],scale:[0.8f,2.3f,0.8f],translation:[-0.4f,0f,-0.4f]}}
  3. /execute unless entity @e[tag=c9_p5] run summon minecraft:block_display ~1.5 ~0.5 ~-2.6 {Tags:["c9_gen","c9_p5"],Glowing:1b,glow_color_override:11141290,block_state:{Name:"minecraft:purple_stained_glass"},transformation:{left_rotation:[0f,0f,0f,1f],right_rotation:[0f,0f,0f,1f],scale:[0.8f,2.5f,0.8f],translation:[-0.4f,0f,-0.4f]}}
  4. /scoreboard players add @e[tag=c9_core] c9_tick 1
  5. /execute as @e[tag=c9_core,scores={c9_tick=5..}] run scoreboard players add @s c9_beat 1
  6. /execute as @e[tag=c9_core,scores={c9_tick=5..}] store result score @s c9_note run random value 0..5
  7. /execute as @e[tag=c9_core,scores={c9_tick=5..,c9_note=0}] at @e[tag=c9_p0] run playsound minecraft:block.note_block.bell master @a ~ ~ ~ 2 0.5
  8. /execute as @e[tag=c9_core,scores={c9_tick=5..,c9_note=1}] at @e[tag=c9_p1] run playsound minecraft:block.note_block.bell master @a ~ ~ ~ 2 0.561231
  9. /execute as @e[tag=c9_core,scores={c9_tick=5..,c9_note=2}] at @e[tag=c9_p2] run playsound minecraft:block.note_block.bell master @a ~ ~ ~ 2 0.629961
  10. /execute as @e[tag=c9_core,scores={c9_tick=5..,c9_note=3}] at @e[tag=c9_p3] run playsound minecraft:block.note_block.bell master @a ~ ~ ~ 2 0.749154
  11. /execute as @e[tag=c9_core,scores={c9_tick=5..,c9_note=4}] at @e[tag=c9_p4] run playsound minecraft:block.note_block.bell master @a ~ ~ ~ 2 0.840896
  12. /execute as @e[tag=c9_core,scores={c9_tick=5..,c9_note=5}] at @e[tag=c9_p5] run playsound minecraft:block.note_block.bell master @a ~ ~ ~ 2 1.0
  13. /execute as @e[tag=c9_core,scores={c9_tick=5..}] at @s run particle minecraft:note ~ ~0.4 ~ 1.8 0.8 1.8 1 12 force
  14. /execute as @e[tag=c9_core,scores={c9_tick=5..}] at @s run playsound minecraft:block.note_block.basedrum master @a ~ ~ ~ 0.8 1.0

How it works

Frames from the test run

Infinite Procedural Melody - frame 1Infinite Procedural Melody - frame 2Infinite Procedural Melody - frame 3

Recorded on our own test server: 59 frames at about 9.8 fps. Our image check saw: A blackstone platform with glowing rainbow-outlined pillars, a central glowing amethyst cluster, and colorful music note particles floating around.

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 open area and run the 10 setup commands in chat to create the scoreboards, the blackstone platform, the central amethyst core, and the first three stained glass pillars.
  2. Place a repeating command block under the stage and connect 13 chain command blocks to it (all set to Always Active).
  3. Paste each of the 14 loop commands into the command block chain in order.
  4. To keep the 5-tick clock cycling continuously in your world, replace or append to the end of the chain: /scoreboard players set @e[tag=c9_core,scores={c9_tick=5..}] c9_tick 0
  5. Turn up your game sound and watch the contraption compose a non-stop F# major melody.

Use it with real players

This contraption works automatically as an ambient musical fountain, so no player stand-in is needed. If you want to let players control the tempo, change the c9_tick=5.. condition in the loop commands to a higher number like 8.. for a slower song, or 4.. for a fast upbeat melody.

Remove it again 5 commands

  1. /kill @e[tag=c9_gen]
  2. /fill ~-4 ~ ~-4 ~4 ~ ~4 minecraft:air
  3. /scoreboard objectives remove c9_tick
  4. /scoreboard objectives remove c9_note
  5. /scoreboard objectives remove c9_beat

FAQ

Why does every random note sound good together?

The six pitches are tuned to the F# major pentatonic scale (F#, G#, A#, C#, D#, and high F#). Because a pentatonic scale removes the half-step intervals that cause dissonance, any random order of notes forms a pleasant melody.

Can I change the instrument sound?

Yes! Replace minecraft:block.note_block.bell in the loop commands with another instrument like minecraft:block.note_block.chime, flute, harp, or bit.

Commands used

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

Similar creations

Join 9Minecraft News & Guides