mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
Fix door audio issue where the open/close loop would sometimes play endlessly due to being dereferenced without being stopped
This commit is contained in:
parent
07610a603d
commit
b5b3131d04
@ -104,7 +104,6 @@ import com.hbm.render.util.RenderOverhead;
|
||||
import com.hbm.render.util.RenderOverhead.Marker;
|
||||
import com.hbm.sound.AudioWrapper;
|
||||
import com.hbm.sound.AudioWrapperClient;
|
||||
import com.hbm.sound.AudioWrapperClientStartStop;
|
||||
import com.hbm.tileentity.TileEntityDoorGeneric;
|
||||
import com.hbm.tileentity.bomb.*;
|
||||
import com.hbm.tileentity.conductor.*;
|
||||
@ -2009,14 +2008,6 @@ public class ClientProxy extends ServerProxy {
|
||||
audio.setKeepAlive(keepAlive);
|
||||
return audio;
|
||||
}
|
||||
|
||||
/** Only used for doors */
|
||||
@Override
|
||||
public AudioWrapper getLoopedSoundStartStop(World world, String sound, String start, String stop, float x, float y, float z, float volume, float pitch) {
|
||||
AudioWrapperClientStartStop audio = new AudioWrapperClientStartStop(world, sound == null ? null : new ResourceLocation(sound), start, stop, volume * 5);
|
||||
audio.updatePosition(x, y, z);
|
||||
return audio;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playSound(String sound, Object data) { }
|
||||
|
||||
@ -45,7 +45,6 @@ public class ServerProxy {
|
||||
|
||||
public AudioWrapper getLoopedSound(String sound, float x, float y, float z, float volume, float range, float pitch) { return null; }
|
||||
public AudioWrapper getLoopedSound(String sound, float x, float y, float z, float volume, float range, float pitch, int keepAlive) { return null; }
|
||||
public AudioWrapper getLoopedSoundStartStop(World world, String sound, String start, String stop, float x, float y, float z, float volume, float pitch) { return null; }
|
||||
|
||||
public void playSound(String sound, Object data) { }
|
||||
|
||||
|
||||
@ -1,54 +0,0 @@
|
||||
package com.hbm.sound;
|
||||
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/** Only used for doors */
|
||||
public class AudioWrapperClientStartStop extends AudioWrapperClient {
|
||||
|
||||
public String start;
|
||||
public String stop;
|
||||
public World world;
|
||||
public float ssVol;
|
||||
public float x, y, z;
|
||||
|
||||
public AudioWrapperClientStartStop(World world, ResourceLocation source, String start, String stop, float vol){
|
||||
super(source);
|
||||
if(sound != null){
|
||||
sound.setVolume(vol);
|
||||
}
|
||||
this.ssVol = vol;
|
||||
this.world = world;
|
||||
this.start = start;
|
||||
this.stop = stop;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePosition(float x, float y, float z){
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
super.updatePosition(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startSound(){
|
||||
if(start != null){
|
||||
world.playSound(x, y, z, start, ssVol * 0.2F, 1, false);
|
||||
}
|
||||
super.startSound();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopSound(){
|
||||
if(stop != null){
|
||||
world.playSound(x, y, z, stop, ssVol * 0.2F, 1, false);
|
||||
}
|
||||
super.stopSound();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getVolume(){
|
||||
return ssVol;
|
||||
}
|
||||
}
|
||||
@ -243,27 +243,49 @@ public class TileEntityDoorGeneric extends TileEntityLockableBase implements IAn
|
||||
public void handleNewState(byte state){
|
||||
|
||||
if(this.state != state) {
|
||||
if(this.state == 0 && state == 3){
|
||||
if(audio == null){
|
||||
audio = MainRegistry.proxy.getLoopedSoundStartStop(worldObj, getDoorType().getOpenSoundLoop(), getDoorType().getOpenSoundStart(), getDoorType().getOpenSoundEnd(), xCoord, yCoord, zCoord, getDoorType().getSoundVolume(), 1);
|
||||
DoorDecl doorType = getDoorType();
|
||||
|
||||
if(this.state == 0 && state == 3){ // Door transitioning to open
|
||||
if(audio != null) audio.stopSound();
|
||||
|
||||
if(doorType.getOpenSoundLoop() != null){
|
||||
audio = MainRegistry.proxy.getLoopedSound(doorType.getOpenSoundLoop(), xCoord, yCoord, zCoord, doorType.getSoundVolume(), 10F, 1F);
|
||||
audio.startSound();
|
||||
}
|
||||
if(audio2 == null && getDoorType().getSoundLoop2() != null){
|
||||
audio2 = MainRegistry.proxy.getLoopedSoundStartStop(worldObj, getDoorType().getSoundLoop2(), null, null, xCoord, yCoord, zCoord, getDoorType().getSoundVolume(), 1);
|
||||
|
||||
if(doorType.getOpenSoundStart() != null){
|
||||
worldObj.playSound(xCoord, yCoord, zCoord, doorType.getOpenSoundStart(), doorType.getSoundVolume(), 1F, false);
|
||||
}
|
||||
|
||||
if(doorType.getSoundLoop2() != null){
|
||||
if(audio2 != null) audio2.stopSound();
|
||||
|
||||
audio2 = MainRegistry.proxy.getLoopedSound(doorType.getSoundLoop2(), xCoord, yCoord, zCoord, doorType.getSoundVolume(), 10F, 1F);
|
||||
audio2.startSound();
|
||||
}
|
||||
}
|
||||
if(this.state == 1 && state == 2){
|
||||
if(audio == null){
|
||||
audio = MainRegistry.proxy.getLoopedSoundStartStop(worldObj, getDoorType().getCloseSoundLoop(), getDoorType().getCloseSoundStart(), getDoorType().getCloseSoundEnd(), xCoord, yCoord, zCoord, getDoorType().getSoundVolume(), 1);
|
||||
|
||||
if(this.state == 1 && state == 2){ // Door transitioning to closed
|
||||
if(audio != null) audio.stopSound();
|
||||
|
||||
if(doorType.getCloseSoundLoop() != null){
|
||||
audio = MainRegistry.proxy.getLoopedSound(doorType.getCloseSoundLoop(), xCoord, yCoord, zCoord, doorType.getSoundVolume(), 10F, 1F);
|
||||
audio.startSound();
|
||||
}
|
||||
if(audio2 == null && getDoorType().getSoundLoop2() != null){
|
||||
audio2 = MainRegistry.proxy.getLoopedSoundStartStop(worldObj, getDoorType().getSoundLoop2(), null, null, xCoord, yCoord, zCoord, getDoorType().getSoundVolume(), 1);
|
||||
|
||||
if(doorType.getCloseSoundStart() != null){
|
||||
worldObj.playSound(xCoord, yCoord, zCoord, doorType.getCloseSoundStart(), doorType.getSoundVolume(), 1F, false);
|
||||
}
|
||||
|
||||
if(doorType.getSoundLoop2() != null){
|
||||
if(audio2 != null) audio2.stopSound();
|
||||
|
||||
audio2 = MainRegistry.proxy.getLoopedSound(doorType.getSoundLoop2(), xCoord, yCoord, zCoord, doorType.getSoundVolume(), 10F, 1F);
|
||||
audio2.startSound();
|
||||
}
|
||||
}
|
||||
if((this.state == 3 && state == 1) || (this.state == 2 && state == 0)){
|
||||
|
||||
if((this.state == 3 && state == 1) || (this.state == 2 && state == 0)){ // Door finished any transition
|
||||
if(audio != null){
|
||||
audio.stopSound();
|
||||
audio = null;
|
||||
@ -273,6 +295,18 @@ public class TileEntityDoorGeneric extends TileEntityLockableBase implements IAn
|
||||
audio2 = null;
|
||||
}
|
||||
}
|
||||
|
||||
if(this.state == 3 && state == 1){ // Door finished transitioning to open
|
||||
if(doorType.getOpenSoundEnd() != null){
|
||||
worldObj.playSound(xCoord, yCoord, zCoord, doorType.getOpenSoundEnd(), doorType.getSoundVolume(), 1F, false);
|
||||
}
|
||||
}
|
||||
|
||||
if(this.state == 2 && state == 0){ // Door finished transitioning to closed
|
||||
if(doorType.getCloseSoundEnd() != null){
|
||||
worldObj.playSound(xCoord, yCoord, zCoord, doorType.getCloseSoundEnd(), doorType.getSoundVolume(), 1F, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
this.state = state;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user