test for new sound loop system

This commit is contained in:
Boblet 2022-03-07 13:47:06 +01:00
parent 9471d66c6e
commit d3cf2cb43d
8 changed files with 101 additions and 56 deletions

View File

@ -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) {

View File

@ -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();
}
}

View File

@ -59,5 +59,4 @@ public class AudioDynamic extends MovingSound {
public float func(float f, float v) {
return (f / v) * -2 + 2;
}
}

View File

@ -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;

View File

@ -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;
}
}

View File

@ -0,0 +1,6 @@
package com.hbm.sound.nt;
public class SoundWrapper {
public void updateSound() { }
}

View File

@ -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();
}
}

View File

@ -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;
}
}