Skip to content

Instantly share code, notes, and snippets.

@insin
Last active February 13, 2024 21:59
Show Gist options
  • Save insin/b1a294e440548e0d5860 to your computer and use it in GitHub Desktop.
Save insin/b1a294e440548e0d5860 to your computer and use it in GitHub Desktop.
Extract Minecraft music

Extract Minecraft music

As of 1.8, assets are stored by hash, which makes it fiddly to listen to Minecraft's amazing ambient soundtrack outside the game.

This script can be used to copy music files to appopriately-named and organised .ogg files for easier listening.

1. Install Node.js or io.js

2. Save extract-music.js to your Minecraft assets directory:

  • Windows: %AppData%\.minecraft\assets
  • Linux: ~/.minecraft/assets
  • OS X: ~/Library/Application Support/minecraft/assets

3. Install dependencies

npm install fs-extra

4. Run the script

node extract-music.js

You should see output similar to this, after which .ogg files will be available in a new sounds/ directory:

./objects/87/87722a59c8d488370f3d430cd4c97a3161081785 -> ./sounds/music/menu/menu3.ogg
./objects/df/df1ff11b79757432c5c3f279e5ecde7b63ceda64 -> ./sounds/music/game/hal1.ogg
./objects/62/6254527d626a2c7d80901cc2e62dce3ba4bd81f6 -> ./sounds/music/game/creative/creative6.ogg
...

5. Listen!

var fs = require('fs-extra')
var objects = require('./indexes/1.8.json').objects
for (var filePath in objects) {
if (!/\/(?:music|records)\//.test(filePath)) continue
var copyPath = filePath.replace('minecraft/', './')
var hash = objects[filePath].hash
var objectPath = './objects/' + hash.substring(0, 2) + '/' + hash
console.log(objectPath, '->', copyPath)
fs.copySync(objectPath, copyPath)
}
@TheWildNooblet
Copy link

Ummmmmmm...... If i wanted the ambience too what changes would i have to make to the extract-music.js code?

@DatrixTHLK
Copy link

DatrixTHLK commented Dec 24, 2019

No changes need to be made since all music and sounds are extracted from the assets file, but it depends on what version you want to extract the music from, If you need it from a specific version of minecraft such as 1.7 just change the line with 1.12.json to 1.7.json or if you want the sounds from 1.8+ then substitute that for 1.12.json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment