Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //usage: installSound("streaming/tornado/wind_far_2_.ogg");
- private void installSound(String filename) {
- File soundFile = new File(ModLoader.getMinecraftInstance().mcDataDir,
- "resources/" + filename);
- if (!soundFile.exists()) {
- // Copy sound file from zip file to proper path
- try {
- String srcPath = soundZipPath + filename;
- InputStream inStream = WeatherMod.class.getResourceAsStream(srcPath);
- if (inStream == null) {
- throw new IOException();
- }
- if (!soundFile.getParentFile().exists()) {
- soundFile.getParentFile().mkdirs();
- }
- BufferedInputStream fileIn = new BufferedInputStream(inStream);
- BufferedOutputStream fileOut = new BufferedOutputStream(new FileOutputStream(soundFile));
- byte[] buffer = new byte[1024];
- int n = 0;
- while (-1 != (n = fileIn.read(buffer))) {
- fileOut.write(buffer, 0, n);
- }
- fileIn.close();
- fileOut.close();
- } catch (IOException ex) {
- }
- }
- if (soundFile.canRead() && soundFile.isFile()) {
- ModLoader.getMinecraftInstance().installResource(filename, soundFile);
- } else {
- System.err.println("Could not load file: " + soundFile);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment