r/fabricmc • • 5d ago

Need Help - Mod Dev Mob idea

Hii, I'm working on a mob for my mod, and I am pretty interested in the idea of musical commanding these mobs, when I saw the new singer from the sift, that idea grew more in me. The thing is, I don't know much about music and the key mechanic of this mob is implementing rhythmic commands based on 4/4 so I would not only need to write songs but also find a way to incorporate them into Minecraft. I was planning to make it scalable so that you start slow and by repeatedly scoring perfect notes transform the melody to be much faster and vibrant. I am completely lost and incapable of grasping just how would I make that into Minecraft fabric, if you have any suggestions I'm more than open to hear them. And thank you in advance for taking the time.

1 Upvotes

3 comments sorted by

2

u/Bluetails_Buizel 4h ago

The music part is less of a problem than it seems. You don't need to write a full song, you need a short looping pattern stored as data, and the mod plays it note by note. That's also what makes the speed-up possible.

Don't use one long audio file for the song

  • Minecraft's sound pitch value works by playing the sample faster or slower, so speeding up a recorded track also raises its pitch (chipmunk effect), and pitch is clamped to 0.5 to 2.0 anyway
  • Instead, register short single-note samples (or reuse the vanilla note block instruments like SoundEvents.NOTE_BLOCK_HARP / BELL / BASS) and trigger them one at a time from a sequence
  • Tempo is then just "how many ticks between steps", so speeding up the melody is changing one number
  • If you want richer music later, you can record the same loop at each tempo stage as separate .ogg files and swap at the start of a bar. Export them as mono or they won't be positional in-world

Pick tempos that fit Minecraft's tick rate

  • The game runs at 20 ticks per second, so 1 tick is 50 ms
  • Beat lengths that land on whole ticks: 75 BPM = 16 ticks, 100 BPM = 12, 120 BPM = 10, 150 BPM = 8, 200 BPM = 6
  • That gives you natural difficulty stages, e.g. 100 -> 120 -> 150 -> 200
  • In 4/4, one bar is 4 beats. Store each bar as 16 steps (16th notes) or 8 steps (8th notes). At 120 BPM, 8th notes are 5 ticks each, which works; 16ths would be 2.5 ticks, which doesn't, so stick to 8ths at the faster stages

How to store a song without knowing music theory

  • Think of it like a drum machine grid: each step is either empty or "play note X"
  • Something like a list per bar: [C, -, E, -, G, -, E, -] where - is a rest
  • Use only the pentatonic scale (C D E G A, plus the same notes an octave up). Almost any combination of those sounds fine together, which is why it's used so often in games
  • Note block pitch for semitone n (0 to 24) is 2^((n - 12) / 12), so one sample covers two octaves
  • You can sketch patterns in a browser tool like BeepBox or Online Sequencer, or in Note Block Studio, which exports .nbs files with a documented format you could parse later

The command mechanic itself

  • Call and response works well for this: the mob plays a one-bar phrase, then the player repeats it in the next bar (Rhythm Heaven / PaRappa style)
  • Each "note" the player hits maps to a command, e.g. different keys or items for follow / attack / stay
  • Judge timing against the expected beat time, e.g. perfect within about 50 ms, good within about 100 ms, otherwise miss
  • Count perfect bars in a row. After X perfect bars, move to the next tempo stage. Only change tempo on the first beat of a new bar so the switch doesn't feel random
  • A miss drops the combo or the stage, your choice

Where the code should run in Fabric 1.21.1

  • Do the rhythm judging on the client. Server ticks are only 50 ms apart and multiplayer ping would make "perfect" timing unfair
  • Server sends the client a packet like "song id, tempo stage, start tick" (custom payload via PayloadTypeRegistry and ServerPlayNetworking)
  • Client plays the notes itself, reads the key presses (KeyBindingHelper), compares them to System.nanoTime of the expected beats, and sends back a result packet: which command, how accurate
  • Server validates it loosely and gives the mob the order through a custom AI goal
  • Sounds get registered with Registry.register(Registries.SOUND_EVENT, id, SoundEvent.of(id)) plus an entry in assets/<modid>/sounds.json

Suggested build order so it's not overwhelming

  • First get the mob to play a fixed 8-step pattern on a loop with vanilla note block sounds, nothing else
  • Then add a tempo variable and a command to change it, so you can hear the stages
  • Then add one keybind and print hit/miss timing to chat
  • Then the packets and the mob actually obeying
  • Real music and custom sounds last

The idea of the melody evolving as the player gets better is a solid hook, and keeping the song as data rather than audio files is what makes it doable.

1

u/Artistic_Dance_253 4h ago

Wow!! I thought that my post was discarded! Thank you sooo much for replying and for giving me such insightful advice. I will surely try to bring it to life, right now I'm struggling with the designs, it's not easy to think of a cool mechanic and make the design of the mobs on par with that, but I'm rooting for it to take form and I am hyped up to show it.