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.render.util.MissilePart;
import com.hbm.sound.AudioWrapper; import com.hbm.sound.AudioWrapper;
import com.hbm.sound.AudioWrapperClient; 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.TileEntityDoorGeneric;
import com.hbm.tileentity.bomb.*; import com.hbm.tileentity.bomb.*;
import com.hbm.tileentity.conductor.*; import com.hbm.tileentity.conductor.*;
@ -1555,10 +1557,14 @@ public class ClientProxy extends ServerProxy {
} }
@Override @Override
public void playSound(String sound, Object data) { public SoundWrapper getTileSound(String sound) {
SoundWrapperClient wrapper = new SoundWrapperClient(sound);
return wrapper;
} }
@Override
public void playSound(String sound, Object data) { }
@Override @Override
public void displayTooltip(String msg) { public void displayTooltip(String msg) {

View File

@ -2,6 +2,8 @@ package com.hbm.main;
import com.hbm.handler.HbmKeybinds.EnumKeybind; import com.hbm.handler.HbmKeybinds.EnumKeybind;
import com.hbm.sound.AudioWrapper; 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.Entity;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
@ -41,4 +43,8 @@ public class ServerProxy {
} }
public void openLink(String url) { } 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) { public float func(float f, float v) {
return (f / v) * -2 + 2; return (f / v) * -2 + 2;
} }
} }

View File

@ -1,12 +1,17 @@
package com.hbm.sound.nt; package com.hbm.sound.nt;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Vec3; import net.minecraft.util.Vec3;
public interface ISoundSourceTE { public interface ISoundSourceTE {
public Vec3 getSoundLocation();
public boolean isPlaying(); 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() { public default float getVolume() {
return 1F; return 1F;
} }

View File

@ -1,25 +1,49 @@
package com.hbm.sound.nt; 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.ResourceLocation;
import net.minecraft.util.Vec3; 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; ISoundSourceTE source;
private ResourceLocation sound; private ResourceLocation sound;
private boolean canRepeat = true; private boolean canRepeat = true;
private int repeatDelay = 0; private int repeatDelay = 0;
private boolean donePlaying = true;
private float soundX; private float soundX;
private float soundY; private float soundY;
private float soundZ; private float soundZ;
private float volume; private float volume;
private float pitch; private float pitch;
public SoundTE(String sound) { public SoundTE(String sound, ISoundSourceTE source) {
this.sound = new ResourceLocation(sound); this.sound = new ResourceLocation(sound);
this.source = source;
} }
@Override @Override
@ -67,11 +91,21 @@ public class SoundTE implements ITickableSound {
return AttenuationType.LINEAR; 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; return;
}
if(!handler.isSoundPlaying(this)) {
handler.playSound(this);
}
this.volume = this.source.getVolume(); this.volume = this.source.getVolume();
this.pitch = this.source.getPitch(); this.pitch = this.source.getPitch();
@ -82,9 +116,4 @@ public class SoundTE implements ITickableSound {
this.soundZ = (float) pos.zCoord; 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.items.machine.ItemMachineUpgrade.UpgradeType;
import com.hbm.lib.Library; import com.hbm.lib.Library;
import com.hbm.main.MainRegistry; 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.tileentity.TileEntityMachineBase;
import com.hbm.util.InventoryUtil; import com.hbm.util.InventoryUtil;
@ -29,7 +30,7 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.AxisAlignedBB;
import net.minecraftforge.common.util.ForgeDirection; 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 long power;
public static final long maxPower = 100000; public static final long maxPower = 100000;
@ -37,7 +38,7 @@ public class TileEntityMachineChemplant extends TileEntityMachineBase implements
public int maxProgress = 100; public int maxProgress = 100;
public boolean isProgressing; public boolean isProgressing;
private AudioWrapper audio; private SoundWrapper audio;
public FluidTank[] tanks; 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); worldObj.spawnParticle("cloud", x, y, z, 0.0, 0.1, 0.0);
} }
float volume = this.getVolume(2); if(this.audio == null) {
this.audio = MainRegistry.proxy.getTileSound("hbm:block.chemplantOperate", this);
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;
}
} }
this.audio.updateSound();
} }
} }
@ -172,26 +162,6 @@ public class TileEntityMachineChemplant extends TileEntityMachineBase implements
} }
} }
@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() { private void updateConnections() {
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset).getOpposite(); ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset).getOpposite();
@ -556,4 +526,9 @@ public class TileEntityMachineChemplant extends TileEntityMachineBase implements
return bb; return bb;
} }
@Override
public boolean isPlaying() {
return !this.isInvalid() && this.isProgressing;
}
} }