Advertisement
Corosus

install sounds from mods zip file

Nov 7th, 2012
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.17 KB | None | 0 0
  1. //usage: installSound("streaming/tornado/wind_far_2_.ogg");
  2.  
  3. private void installSound(String filename) {
  4.         File soundFile = new File(ModLoader.getMinecraftInstance().mcDataDir,
  5.                 "resources/" + filename);
  6.  
  7.         if (!soundFile.exists()) {
  8.             // Copy sound file from zip file to proper path
  9.             try {
  10.                 String srcPath = soundZipPath + filename;
  11.                 InputStream inStream = WeatherMod.class.getResourceAsStream(srcPath);
  12.                 if (inStream == null) {
  13.                     throw new IOException();
  14.                 }
  15.  
  16.                 if (!soundFile.getParentFile().exists()) {
  17.                     soundFile.getParentFile().mkdirs();
  18.                 }
  19.  
  20.                 BufferedInputStream fileIn = new BufferedInputStream(inStream);
  21.                 BufferedOutputStream fileOut = new BufferedOutputStream(new FileOutputStream(soundFile));
  22.                 byte[] buffer = new byte[1024];
  23.                 int n = 0;
  24.                 while (-1 != (n = fileIn.read(buffer))) {
  25.                     fileOut.write(buffer, 0, n);
  26.                 }
  27.                 fileIn.close();
  28.                 fileOut.close();
  29.  
  30.             } catch (IOException ex) {
  31.             }
  32.  
  33.         }
  34.  
  35.         if (soundFile.canRead() && soundFile.isFile()) {
  36.             ModLoader.getMinecraftInstance().installResource(filename, soundFile);
  37.         } else {
  38.             System.err.println("Could not load file: " + soundFile);
  39.         }
  40.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement