Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class SoundboardSound extends AbstractSoundInstance {
- public static final ResourceLocation SOUND_LOC = new ResourceLocation(SoundboardMod.MODID, "soundboard_sound");
- private final Path soundPath;
- public SoundboardSound(Path soundPath, Vec3 position, float volume, float pitch) {
- super(SOUND_LOC, SoundSource.MASTER, SoundInstance.createUnseededRandom());
- this.soundPath = soundPath;
- this.x = position.x;
- this.y = position.y;
- this.z = position.z;
- this.volume = volume;
- this.pitch = pitch;
- }
- @Override
- public CompletableFuture<AudioStream> getStream(SoundBufferLibrary soundBuffers, Sound sound, boolean looping) {
- try {
- return CompletableFuture.completedFuture(new SoundboardStream(this.soundPath));
- } catch (IOException exception) {
- return CompletableFuture.failedFuture(exception);
- }
- }
- public static class SoundboardStream implements AudioStream {
- private static final AudioFormat AUDIO_FORMAT = new AudioFormat(44100, 16, 2, true, false);
- private final byte[] bytes;
- public SoundboardStream(Path soundPath) throws IOException {
- this.bytes = Files.readAllBytes(soundPath);
- }
- @Override
- public AudioFormat getFormat() {
- return AUDIO_FORMAT;
- }
- @Override
- public ByteBuffer read(int pSize) {
- ByteBuffer buffer = ByteBuffer.allocate(pSize);
- for (int index = 0; index < pSize; index++) {
- buffer.put(this.bytes[index % this.bytes.length]);
- }
- return buffer;
- }
- @Override
- public void close() {}
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement