Last active
March 19, 2018 20:38
-
-
Save bellflower2015/b989bc79ba0174f8d493dc6d5f0603c9 to your computer and use it in GitHub Desktop.
Minecraft Sound Extractor for PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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