Skip to content

Instantly share code, notes, and snippets.

@bellflower2015
Last active March 19, 2018 20:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bellflower2015/b989bc79ba0174f8d493dc6d5f0603c9 to your computer and use it in GitHub Desktop.
Save bellflower2015/b989bc79ba0174f8d493dc6d5f0603c9 to your computer and use it in GitHub Desktop.
Minecraft Sound Extractor for PHP
<?php
// $ curl -fsSL https://gist.github.com/bellflower2015/b989bc79ba0174f8d493dc6d5f0603c9/raw/minecraft_sound_extractor.php | php
$version = '1.12';
$outputDir = 'minecraft_sounds_' . preg_replace('/[^A-Za-z0-9]/', '_', $version);
@mkdir($outputDir, 0755, true);
$outputDir = realpath($outputDir);
if (substr(getenv('OS'), 0, 7) == 'Windows') {
$minecraftDir = getenv('APPDATA').'/.minecraft';
} elseif (substr(`uname`, 0, 6) == 'Darwin') {
$minecraftDir = getenv('HOME').'/Library/Application Support/minecraft';
} else {
$minecraftDir = getenv('HOME').'/.minecraft';
}
$indexFile = "{$minecraftDir}/assets/indexes/{$version}.json";
$data = json_decode(file_get_contents($indexFile), true);
foreach ($data['objects'] as $key => $val) {
if (preg_match('|^minecraft/sounds/|', $key)) {
$dir = dirname($key);
$file = basename($key);
$dir = preg_replace('|^minecraft/sounds/|', '', $dir);
if (!file_exists("{$outputDir}/{$dir}")) {
@mkdir("{$outputDir}/{$dir}", 0755, true);
}
$prefix = substr($val['hash'], 0, 2);
@copy(
"{$minecraftDir}/assets/objects/{$prefix}/{$val['hash']}",
"{$outputDir}/{$dir}/{$file}"
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment