Advertisement
Guest User

Minecraft assets extraction script

a guest
Dec 10th, 2016
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.98 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * Minecraft assets extraction script. Put this script into .minecraft/assets
  5.  * and run it from command line. See minecraft folder in .minecraft/assets for
  6.  * your exported resources.
  7.  *
  8.  * @author McHorse
  9.  */
  10.  
  11. $json = json_decode(file_get_contents(__DIR__ . '/indexes/1.11.json'), true);
  12.  
  13. /* Iterate over objects */
  14. foreach ($json['objects'] as $key => $value)
  15. {
  16.     /* Setup variables */
  17.     $hash = $value['hash'];
  18.     $two = substr($hash, 0, 2);
  19.     $path = __DIR__ . "/objects/$two/$hash";
  20.     $dest = __DIR__ . '/' . pathinfo($key, PATHINFO_DIRNAME);
  21.    
  22.     /* If given file exists, then extract this iterated asset */
  23.     if (file_exists($path))
  24.     {
  25.         if (!file_exists($dest))
  26.         {
  27.             mkdir($dest, 0777, true);
  28.         }
  29.        
  30.         /* Copy file */
  31.         copy($path, __DIR__ . '/' . $key);
  32.        
  33.         echo "File by key '$key' was saved!\n";
  34.     }
  35.     else
  36.     {
  37.         echo "Not found '$key'!";
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement