diff --git a/src/main/java/com/hbm/main/ClientProxy.java b/src/main/java/com/hbm/main/ClientProxy.java index 6a79eb4d9..3edad4671 100644 --- a/src/main/java/com/hbm/main/ClientProxy.java +++ b/src/main/java/com/hbm/main/ClientProxy.java @@ -71,6 +71,8 @@ import com.hbm.render.tileentity.*; import com.hbm.render.util.MissilePart; import com.hbm.sound.AudioWrapper; import com.hbm.sound.AudioWrapperClient; +import com.hbm.sound.nt.SoundWrapper; +import com.hbm.sound.nt.SoundWrapperClient; import com.hbm.tileentity.TileEntityDoorGeneric; import com.hbm.tileentity.bomb.*; import com.hbm.tileentity.conductor.*; @@ -1553,11 +1555,15 @@ public class ClientProxy extends ServerProxy { audio.updatePosition(x, y, z); return audio; } + + @Override + public SoundWrapper getTileSound(String sound) { + SoundWrapperClient wrapper = new SoundWrapperClient(sound); + return wrapper; + } @Override - public void playSound(String sound, Object data) { - - } + public void playSound(String sound, Object data) { } @Override public void displayTooltip(String msg) { diff --git a/src/main/java/com/hbm/main/ServerProxy.java b/src/main/java/com/hbm/main/ServerProxy.java index 38ac20e0c..8dfa85cbb 100644 --- a/src/main/java/com/hbm/main/ServerProxy.java +++ b/src/main/java/com/hbm/main/ServerProxy.java @@ -2,6 +2,8 @@ package com.hbm.main; import com.hbm.handler.HbmKeybinds.EnumKeybind; import com.hbm.sound.AudioWrapper; +import com.hbm.sound.nt.ISoundSourceTE; +import com.hbm.sound.nt.SoundWrapper; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; @@ -41,4 +43,8 @@ public class ServerProxy { } public void openLink(String url) { } + + public SoundWrapper getTileSound(String sound, ISoundSourceTE source) { + return new SoundWrapper(); + } } \ No newline at end of file diff --git a/src/main/java/com/hbm/sound/AudioDynamic.java b/src/main/java/com/hbm/sound/AudioDynamic.java index 787e63b24..6666ee9e5 100644 --- a/src/main/java/com/hbm/sound/AudioDynamic.java +++ b/src/main/java/com/hbm/sound/AudioDynamic.java @@ -59,5 +59,4 @@ public class AudioDynamic extends MovingSound { public float func(float f, float v) { return (f / v) * -2 + 2; } - } diff --git a/src/main/java/com/hbm/sound/nt/ISoundSourceTE.java b/src/main/java/com/hbm/sound/nt/ISoundSourceTE.java index a3aa01260..c5f1eacee 100644 --- a/src/main/java/com/hbm/sound/nt/ISoundSourceTE.java +++ b/src/main/java/com/hbm/sound/nt/ISoundSourceTE.java @@ -1,11 +1,16 @@ package com.hbm.sound.nt; +import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Vec3; public interface ISoundSourceTE { - - public Vec3 getSoundLocation(); + public boolean isPlaying(); + + public default Vec3 getSoundLocation() { + TileEntity te = (TileEntity) this; + return Vec3.createVectorHelper(te.xCoord + 0.5, te.yCoord + 0.5, te.zCoord + 0.5); + } public default float getVolume() { return 1F; diff --git a/src/main/java/com/hbm/sound/nt/SoundTE.java b/src/main/java/com/hbm/sound/nt/SoundTE.java index d6cc4b345..4729d3079 100644 --- a/src/main/java/com/hbm/sound/nt/SoundTE.java +++ b/src/main/java/com/hbm/sound/nt/SoundTE.java @@ -1,25 +1,49 @@ package com.hbm.sound.nt; -import net.minecraft.client.audio.ITickableSound; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.client.Minecraft; +import net.minecraft.client.audio.ISound; +import net.minecraft.client.audio.SoundHandler; import net.minecraft.util.ResourceLocation; import net.minecraft.util.Vec3; -public class SoundTE implements ITickableSound { +/** + * I have a dream. That one day every tile entity in this codebase will control their + * own sounds. A codebase of the truly free, dammit. A codebase of functionality, not + * patterns, ruled by necessity, not chance! Where the code changes to suit the use + * case, not the other way around. Where methods and fields are back where they belong: + * in the hands of the tile entities! Where every object is free to think - to calcilate + * - for itself! Fuck all these limp-dick programmers and chickenshit coders. Fuck this + * 24-hour Internet spew of design classes and Stack Overflow bullshit! Fuck duct tape + * pride! Fuck the patterns! FUCK ALL OF IT! NTM is diseased. Rotten to the core. + * There's no saving it - we need to pull it out by the classroot. Wipe the slate clean. + * BURN IT DOWN! And from the ashes, the mother of all omelettes will be born. Evolved, + * but unconventional! The broken will be purged and the cleanest will thrive - free to + * function as they see fit, they'll make NTM great again! ...in my new NTM, tile + * entities will expire and invalidate for what they BELIEVE! Not for memory space, not + * for compatibility! Not for what they're told is professional. Every tile will be free + * to load its own chunks! + * @author hbm + * + */ +@SideOnly(Side.CLIENT) +public class SoundTE implements ISound { ISoundSourceTE source; private ResourceLocation sound; private boolean canRepeat = true; private int repeatDelay = 0; - private boolean donePlaying = true; private float soundX; private float soundY; private float soundZ; private float volume; private float pitch; - public SoundTE(String sound) { + public SoundTE(String sound, ISoundSourceTE source) { this.sound = new ResourceLocation(sound); + this.source = source; } @Override @@ -67,11 +91,21 @@ public class SoundTE implements ITickableSound { return AttenuationType.LINEAR; } - @Override - public void update() { + /** + * Called by proxy of the SoundWrapper from the holding tile entity, once per tick. + */ + public void updateExternally() { - if(this.source == null) + SoundHandler handler = Minecraft.getMinecraft().getSoundHandler(); + + if(!this.source.isPlaying() && handler.isSoundPlaying(this)) { + handler.stopSound(this); return; + } + + if(!handler.isSoundPlaying(this)) { + handler.playSound(this); + } this.volume = this.source.getVolume(); this.pitch = this.source.getPitch(); @@ -82,9 +116,4 @@ public class SoundTE implements ITickableSound { this.soundZ = (float) pos.zCoord; } - - @Override - public boolean isDonePlaying() { - return this.donePlaying; - } } diff --git a/src/main/java/com/hbm/sound/nt/SoundWrapper.java b/src/main/java/com/hbm/sound/nt/SoundWrapper.java new file mode 100644 index 000000000..bbb6964cf --- /dev/null +++ b/src/main/java/com/hbm/sound/nt/SoundWrapper.java @@ -0,0 +1,6 @@ +package com.hbm.sound.nt; + +public class SoundWrapper { + + public void updateSound() { } +} diff --git a/src/main/java/com/hbm/sound/nt/SoundWrapperClient.java b/src/main/java/com/hbm/sound/nt/SoundWrapperClient.java new file mode 100644 index 000000000..5f5fa1e3b --- /dev/null +++ b/src/main/java/com/hbm/sound/nt/SoundWrapperClient.java @@ -0,0 +1,19 @@ +package com.hbm.sound.nt; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +@SideOnly(Side.CLIENT) +public class SoundWrapperClient extends SoundWrapper { + + private SoundTE sound; + + public SoundWrapperClient(String sound, ISoundSourceTE source) { + this.sound = new SoundTE(sound, source); + } + + @Override + public void updateSound() { + this.sound.updateExternally(); + } +} diff --git a/src/main/java/com/hbm/tileentity/machine/TileEntityMachineChemplant.java b/src/main/java/com/hbm/tileentity/machine/TileEntityMachineChemplant.java index dbe67b482..59fb4b457 100644 --- a/src/main/java/com/hbm/tileentity/machine/TileEntityMachineChemplant.java +++ b/src/main/java/com/hbm/tileentity/machine/TileEntityMachineChemplant.java @@ -17,7 +17,8 @@ import com.hbm.items.ModItems; import com.hbm.items.machine.ItemMachineUpgrade.UpgradeType; import com.hbm.lib.Library; import com.hbm.main.MainRegistry; -import com.hbm.sound.AudioWrapper; +import com.hbm.sound.nt.ISoundSourceTE; +import com.hbm.sound.nt.SoundWrapper; import com.hbm.tileentity.TileEntityMachineBase; import com.hbm.util.InventoryUtil; @@ -29,7 +30,7 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; import net.minecraftforge.common.util.ForgeDirection; -public class TileEntityMachineChemplant extends TileEntityMachineBase implements IEnergyUser, IFluidSource, IFluidAcceptor { +public class TileEntityMachineChemplant extends TileEntityMachineBase implements IEnergyUser, IFluidSource, IFluidAcceptor, ISoundSourceTE { public long power; public static final long maxPower = 100000; @@ -37,7 +38,7 @@ public class TileEntityMachineChemplant extends TileEntityMachineBase implements public int maxProgress = 100; public boolean isProgressing; - private AudioWrapper audio; + private SoundWrapper audio; public FluidTank[] tanks; @@ -141,22 +142,11 @@ public class TileEntityMachineChemplant extends TileEntityMachineBase implements worldObj.spawnParticle("cloud", x, y, z, 0.0, 0.1, 0.0); } - float volume = this.getVolume(2); - - if(isProgressing && volume > 0) { - - if(audio == null) { - audio = MainRegistry.proxy.getLoopedSound("hbm:block.chemplantOperate", xCoord, yCoord, zCoord, volume, 1.0F); - audio.startSound(); - } - - } else { - - if(audio != null) { - audio.stopSound(); - audio = null; - } + if(this.audio == null) { + this.audio = MainRegistry.proxy.getTileSound("hbm:block.chemplantOperate", this); } + + this.audio.updateSound(); } } @@ -171,26 +161,6 @@ public class TileEntityMachineChemplant extends TileEntityMachineBase implements tanks[i].readFromNBT(nbt, "t" + i); } } - - @Override - public void onChunkUnload() { - - if(audio != null) { - audio.stopSound(); - audio = null; - } - } - - @Override - public void invalidate() { - - super.invalidate(); - - if(audio != null) { - audio.stopSound(); - audio = null; - } - } private void updateConnections() { @@ -556,4 +526,9 @@ public class TileEntityMachineChemplant extends TileEntityMachineBase implements return bb; } + + @Override + public boolean isPlaying() { + return !this.isInvalid() && this.isProgressing; + } }