Pretty satisfactory implentation now, approaching point of being able to merge into 8.0.

This commit is contained in:
Ben Spiers 2014-08-29 05:15:00 +01:00
parent be3120800f
commit 9db096f9bf
20 changed files with 468 additions and 1078 deletions

View file

@ -1,7 +1,6 @@
package mekanism.client; package mekanism.client;
import java.io.File; import java.io.File;
import java.util.HashMap;
import mekanism.api.Coord4D; import mekanism.api.Coord4D;
import mekanism.api.MekanismConfig.client; import mekanism.api.MekanismConfig.client;
@ -90,7 +89,6 @@ import mekanism.client.render.tileentity.RenderSalinationController;
import mekanism.client.render.tileentity.RenderSeismicVibrator; import mekanism.client.render.tileentity.RenderSeismicVibrator;
import mekanism.client.render.tileentity.RenderTeleporter; import mekanism.client.render.tileentity.RenderTeleporter;
import mekanism.client.sound.SoundHandler; import mekanism.client.sound.SoundHandler;
import mekanism.client.sound.SoundMap;
import mekanism.common.CommonProxy; import mekanism.common.CommonProxy;
import mekanism.common.Mekanism; import mekanism.common.Mekanism;
import mekanism.common.MekanismBlocks; import mekanism.common.MekanismBlocks;
@ -493,29 +491,6 @@ public class ClientProxy extends CommonProxy
} }
} }
@Override
public void unloadSoundHandler()
{
if(client.enableSounds)
{
if(MekanismClient.audioHandler != null)
{
synchronized(MekanismClient.audioHandler.soundMaps)
{
HashMap<Object, SoundMap> mapsCopy = new HashMap<Object, SoundMap>();
mapsCopy.putAll(MekanismClient.audioHandler.soundMaps);
for(SoundMap map : mapsCopy.values())
{
map.kill();
}
MekanismClient.audioHandler.soundMaps.clear();
}
}
}
}
@Override @Override
public void preInit() public void preInit()
{ {

View file

@ -7,45 +7,30 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import mekanism.api.EnumColor;
import mekanism.api.IClientTicker; import mekanism.api.IClientTicker;
import mekanism.api.MekanismConfig.client;
import mekanism.api.gas.GasStack; import mekanism.api.gas.GasStack;
import mekanism.client.sound.FlamethrowerSound; import mekanism.client.sound.FlamethrowerSound;
import mekanism.client.sound.GasMaskSound; import mekanism.client.sound.GasMaskSound;
import mekanism.client.sound.JetpackSound; import mekanism.client.sound.JetpackSound;
import mekanism.client.sound.SoundHandler;
import mekanism.common.KeySync; import mekanism.common.KeySync;
import mekanism.common.Mekanism; import mekanism.common.Mekanism;
import mekanism.common.ObfuscatedNames; import mekanism.common.ObfuscatedNames;
import mekanism.common.block.BlockMachine.MachineType;
import mekanism.common.item.ItemBlockMachine;
import mekanism.common.item.ItemConfigurator;
import mekanism.common.item.ItemElectricBow;
import mekanism.common.item.ItemFlamethrower; import mekanism.common.item.ItemFlamethrower;
import mekanism.common.item.ItemFreeRunners; import mekanism.common.item.ItemFreeRunners;
import mekanism.common.item.ItemGasMask; import mekanism.common.item.ItemGasMask;
import mekanism.common.item.ItemJetpack; import mekanism.common.item.ItemJetpack;
import mekanism.common.item.ItemJetpack.JetpackMode; import mekanism.common.item.ItemJetpack.JetpackMode;
import mekanism.common.item.ItemScubaTank; import mekanism.common.item.ItemScubaTank;
import mekanism.common.item.ItemWalkieTalkie;
import mekanism.common.network.PacketConfiguratorState.ConfiguratorStateMessage;
import mekanism.common.network.PacketElectricBowState.ElectricBowStateMessage;
import mekanism.common.network.PacketFlamethrowerActive.FlamethrowerActiveMessage; import mekanism.common.network.PacketFlamethrowerActive.FlamethrowerActiveMessage;
import mekanism.common.network.PacketJetpackData.JetpackDataMessage; import mekanism.common.network.PacketJetpackData.JetpackDataMessage;
import mekanism.common.network.PacketJetpackData.JetpackPacket; import mekanism.common.network.PacketJetpackData.JetpackPacket;
import mekanism.common.network.PacketPortableTankState.PortableTankStateMessage;
import mekanism.common.network.PacketScubaTankData.ScubaTankDataMessage; import mekanism.common.network.PacketScubaTankData.ScubaTankDataMessage;
import mekanism.common.network.PacketScubaTankData.ScubaTankPacket; import mekanism.common.network.PacketScubaTankData.ScubaTankPacket;
import mekanism.common.network.PacketWalkieTalkieState.WalkieTalkieStateMessage;
import mekanism.common.util.LangUtils;
import mekanism.common.util.MekanismUtils; import mekanism.common.util.MekanismUtils;
import mekanism.api.util.StackUtils;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.AbstractClientPlayer; import net.minecraft.client.entity.AbstractClientPlayer;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.StringUtils; import net.minecraft.util.StringUtils;
import cpw.mods.fml.client.FMLClientHandler; import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.eventhandler.SubscribeEvent;
@ -54,6 +39,10 @@ import cpw.mods.fml.common.gameevent.TickEvent.Phase;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
import static mekanism.client.sound.SoundHandler.Channel.FLAMETHROWER;
import static mekanism.client.sound.SoundHandler.Channel.GASMASK;
import static mekanism.client.sound.SoundHandler.Channel.JETPACK;
/** /**
* Client-side tick handler for Mekanism. Used mainly for the update check upon startup. * Client-side tick handler for Mekanism. Used mainly for the update check upon startup.
* @author AidanBrady * @author AidanBrady
@ -90,27 +79,10 @@ public class ClientTickHandler
{ {
tickStart(); tickStart();
} }
else if(event.phase == Phase.END)
{
tickEnd();
}
} }
public void tickStart() public void tickStart()
{ {
if(!preloadedSounds && client.enableSounds && MekanismClient.audioHandler != null && MekanismClient.audioHandler.isSystemLoaded())
{
preloadedSounds = true;
new Thread(new Runnable() {
@Override
public void run()
{
MekanismClient.audioHandler.preloadSounds();
}
}).start();
}
MekanismClient.ticksPassed++; MekanismClient.ticksPassed++;
if(!hasNotified && mc.theWorld != null && Mekanism.latestVersionNumber != null && Mekanism.recentNews != null) if(!hasNotified && mc.theWorld != null && Mekanism.latestVersionNumber != null && Mekanism.recentNews != null)
@ -286,12 +258,11 @@ public class ClientTickHandler
if(player != null) if(player != null)
{ {
if(MekanismClient.audioHandler.getSound(player, SoundHandler.CHANNEL_JETPACK) == null) if(!MekanismClient.audioHandler.hasSound(player, JETPACK))
{ {
//player.worldObj.playSoundAtEntity(player, "mekanism:item.jetpack", 1F, 1F); MekanismClient.audioHandler.addSound(player, JETPACK, new JetpackSound(player), false);
player.worldObj.playSound(player.posX, player.posY, player.posZ, "mekanism:item.jetpack", 1, 1, false);
//new JetpackSound(MekanismClient.audioHandler.getIdentifier(player), player);
} }
MekanismClient.audioHandler.playSound(player, JETPACK);
} }
} }
@ -301,10 +272,11 @@ public class ClientTickHandler
if(player != null) if(player != null)
{ {
if(MekanismClient.audioHandler.getSound(player, SoundHandler.CHANNEL_GASMASK) == null) if(!MekanismClient.audioHandler.hasSound(player, GASMASK))
{ {
new GasMaskSound(MekanismClient.audioHandler.getIdentifier(player), player); MekanismClient.audioHandler.addSound(player, GASMASK, new GasMaskSound(player), false);
} }
MekanismClient.audioHandler.playSound(player, GASMASK);
} }
} }
@ -312,10 +284,11 @@ public class ClientTickHandler
{ {
if(hasFlamethrower(player)) if(hasFlamethrower(player))
{ {
if(MekanismClient.audioHandler.getSound(player, SoundHandler.CHANNEL_FLAMETHROWER) == null) if(!MekanismClient.audioHandler.hasSound(player, FLAMETHROWER))
{ {
new FlamethrowerSound(MekanismClient.audioHandler.getIdentifier(player), player); MekanismClient.audioHandler.addSound(player, FLAMETHROWER, new FlamethrowerSound(player), false);
} }
MekanismClient.audioHandler.playSound(player, FLAMETHROWER);
} }
} }
} }
@ -486,15 +459,4 @@ public class ClientTickHandler
return false; return false;
} }
public void tickEnd()
{
if(MekanismClient.audioHandler != null)
{
synchronized(MekanismClient.audioHandler.soundMaps)
{
MekanismClient.audioHandler.onTick();
}
}
}
} }

View file

@ -34,7 +34,7 @@ public class ThreadMultiblockSparkle extends Thread
try { try {
if(general.dynamicTankEasterEgg) if(general.dynamicTankEasterEgg)
{ {
MekanismClient.audioHandler.quickPlay("cj/CJ_" + (random.nextInt(8)+1) + ".ogg", pointer.getWorldObj(), Coord4D.get(pointer)); pointer.getWorldObj().playSound(pointer.xCoord, pointer.yCoord, pointer.zCoord, "mekanism:etc.cj", 1F, 1F, false);
} }
loop(pointer); loop(pointer);

View file

@ -1,60 +1,58 @@
package mekanism.client.sound; package mekanism.client.sound;
import mekanism.client.ClientTickHandler; import mekanism.client.ClientTickHandler;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World; import net.minecraft.util.ResourceLocation;
public class FlamethrowerSound extends PlayerSound public class FlamethrowerSound extends PlayerSound
{ {
public boolean inUse = false; public boolean inUse;
public FlamethrowerSound(String id, EntityPlayer entity) public ResourceLocation onSound;
public ResourceLocation offSound;
public FlamethrowerSound(EntityPlayer player)
{ {
super(id, getSound(ClientTickHandler.isFlamethrowerOn(entity)), SoundHandler.CHANNEL_FLAMETHROWER, entity); super(player, new ResourceLocation("mekanism", "item.flamethrower.idle"));
onSound = new ResourceLocation("mekanism", "item.flamethrower.active");
inUse = ClientTickHandler.isFlamethrowerOn(entity); offSound = new ResourceLocation("mekanism", "item.flamethrower.idle");
setFadeIn(0);
setFadeOut(0);
} }
@Override @Override
public boolean update(World world) public boolean isDonePlaying()
{ {
if(!super.update(world)) return donePlaying;
{
return false;
}
else if(!ClientTickHandler.hasFlamethrower(player))
{
return false;
}
else if(inUse != ClientTickHandler.isFlamethrowerOn(player))
{
return false;
} }
if(!isPlaying) @Override
public boolean shouldPlaySound()
{ {
play();
}
ticksSincePlay++;
return true; return true;
} }
@Override @Override
public float getMultiplier() public float getVolume()
{ {
return super.getMultiplier() * (inUse ? 2 : 1); return super.getVolume() * (inUse ? 2 : 1);
} }
@Override @Override
public boolean doGradualEffect() public void update()
{ {
return false; if(!ClientTickHandler.hasFlamethrower(player))
} {
donePlaying = true;
private static String getSound(boolean inUse) return;
}
if(inUse != ClientTickHandler.isFlamethrowerOn(player))
{ {
return inUse ? "FlamethrowerActive.ogg" : "FlamethrowerIdle.ogg"; inUse = ClientTickHandler.isFlamethrowerOn(player);
sound = inUse ? onSound : offSound;
donePlaying = true;
}
} }
} }

View file

@ -2,46 +2,29 @@ package mekanism.client.sound;
import mekanism.client.ClientTickHandler; import mekanism.client.ClientTickHandler;
import mekanism.common.item.ItemGasMask; import mekanism.common.item.ItemGasMask;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World; import net.minecraft.util.ResourceLocation;
public class GasMaskSound extends PlayerSound public class GasMaskSound extends PlayerSound
{ {
public GasMaskSound(String id, EntityPlayer entity) public GasMaskSound(EntityPlayer player)
{ {
super(id, "GasMask.ogg", SoundHandler.CHANNEL_GASMASK, entity); super(player, new ResourceLocation("mekanism", "item.gasMask"));
setFadeIn(0);
setFadeOut(0);
} }
@Override @Override
public boolean update(World world) public boolean isDonePlaying()
{ {
if(!super.update(world)) return donePlaying;
{
return false;
}
else if(!hasGasMask(player))
{
return false;
}
else {
if(ClientTickHandler.isGasMaskOn(player) != isPlaying)
{
if(ClientTickHandler.isGasMaskOn(player))
{
play();
}
else {
stopLoop();
}
}
} }
if(isPlaying) @Override
public boolean shouldPlaySound()
{ {
ticksSincePlay++; return hasGasMask(player) && ClientTickHandler.isGasMaskOn(player);
}
return true;
} }
private boolean hasGasMask(EntityPlayer player) private boolean hasGasMask(EntityPlayer player)

View file

@ -0,0 +1,8 @@
package mekanism.client.sound;
import net.minecraft.client.audio.ITickableSound;
public interface IResettableSound extends ITickableSound
{
public void reset();
}

View file

@ -2,46 +2,29 @@ package mekanism.client.sound;
import mekanism.client.ClientTickHandler; import mekanism.client.ClientTickHandler;
import mekanism.common.item.ItemJetpack; import mekanism.common.item.ItemJetpack;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World; import net.minecraft.util.ResourceLocation;
public class JetpackSound extends PlayerSound public class JetpackSound extends PlayerSound
{ {
public JetpackSound(String id, EntityPlayer entity) public JetpackSound(EntityPlayer player)
{ {
super(id, "Jetpack.ogg", SoundHandler.CHANNEL_JETPACK, entity); super(player, new ResourceLocation("mekanism", "item.jetpack"));
setFadeIn(0);
setFadeOut(0);
} }
@Override @Override
public boolean update(World world) public boolean isDonePlaying()
{ {
if(!super.update(world)) return donePlaying;
{
return false;
}
else if(!hasJetpack(player))
{
return false;
}
else {
if(ClientTickHandler.isJetpackOn(player) != isPlaying)
{
if(ClientTickHandler.isJetpackOn(player))
{
play();
}
else {
stopLoop();
}
}
} }
if(isPlaying) @Override
public boolean shouldPlaySound()
{ {
ticksSincePlay++; return hasJetpack(player) && ClientTickHandler.isJetpackOn(player);
}
return true;
} }
private boolean hasJetpack(EntityPlayer player) private boolean hasJetpack(EntityPlayer player)

View file

@ -1,53 +1,114 @@
package mekanism.client.sound; package mekanism.client.sound;
import mekanism.api.Pos3D; import mekanism.common.Mekanism;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
public abstract class PlayerSound extends Sound import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ResourceLocation;
public abstract class PlayerSound extends Sound implements IResettableSound
{ {
/** The TileEntity this sound is associated with. */
public EntityPlayer player; public EntityPlayer player;
public PlayerSound(String id, String sound, String chan, EntityPlayer entity) boolean beginFadeOut;
{ boolean donePlaying = true;
super(id, sound, chan, entity, new Pos3D(entity)); int ticks = 0;
int fadeIn = 50;
int fadeOut = 50;
float baseVolume = 0.3F;
player = entity;
public PlayerSound(EntityPlayer player, ResourceLocation location)
{
super(location, 0.3F, 1, true, 0, (float) player.posX, (float) player.posY, (float) player.posZ, AttenuationType.LINEAR);
this.player = player;
} }
@Override @Override
public float getMultiplier() public float getXPosF()
{ {
return super.getMultiplier()*0.3F;
return (float) player.posX;
} }
@Override @Override
public boolean update(World world) public float getYPosF()
{ {
if(!super.update(world))
{
return false;
}
else if(player.isDead)
{
return false;
}
else if(player.worldObj != world)
{
return false;
}
else if(!world.loadedEntityList.contains(player))
{
return false;
}
return true; return (float) player.posY;
} }
@Override @Override
public Pos3D getLocation() public float getZPosF()
{ {
return new Pos3D(player);
return (float) player.posZ;
}
public PlayerSound setFadeIn(int fadeIn) {
this.fadeIn = Math.min(0, fadeIn);
return this;
}
public PlayerSound setFadeOut(int fadeOut) {
this.fadeOut = Math.min(0, fadeOut);
return this;
}
public float getFadeInMultiplier() {
return ticks >= fadeIn ? 1 : (float) (ticks / (float) fadeIn);
}
public float getFadeOutMultiplier() {
return ticks >= fadeOut ? 0 : (float) ((fadeOut - ticks) / (float) fadeOut);
}
@Override
public void update()
{
if(!beginFadeOut)
{
if(ticks < fadeIn)
{
ticks++;
}
if(!shouldPlaySound())
{
beginFadeOut = true;
ticks = 0;
}
} else
{
ticks++;
}
float multiplier = beginFadeOut ? getFadeOutMultiplier() : getFadeInMultiplier();
volume = baseVolume * multiplier;
if(multiplier <= 0)
{
Mekanism.logger.info("Sound Stopping. " + this);
donePlaying = true;
}
}
@Override
public boolean isDonePlaying()
{
return donePlaying;
}
public abstract boolean shouldPlaySound();
@Override
public void reset()
{
donePlaying = false;
beginFadeOut = false;
volume = baseVolume;
ticks = 0;
} }
} }

View file

@ -1,251 +1,178 @@
package mekanism.client.sound; package mekanism.client.sound;
import java.net.URL; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import mekanism.api.MekanismConfig.client;
import mekanism.api.Pos3D;
import mekanism.client.MekanismClient;
import mekanism.common.Mekanism;
import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.ISound; import net.minecraft.client.audio.ISound;
import net.minecraft.client.audio.ISound.AttenuationType;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.client.ForgeHooksClient;
public abstract class Sound
{
/** The bundled path where the sound is */
public String prevSoundPath;
/** A unique identifier for this sound */
public String identifier;
/** Whether or not this sound is playing */
public boolean isPlaying = false;
public int ticksSincePlay = 0;
private Object objRef;
public String channel;
protected Minecraft mc = Minecraft.getMinecraft();
/** /**
* A sound that runs off of the PaulsCode sound system. * Generic ISound class with lots of constructor functionality.
* @param id - unique identifier * Required because - of course - Mojang has no generic that
* @param sound - bundled path to the sound * lets you specify *any* arguments for this.
* @param tileentity - the tile this sound is playing from. *
* Taken from CoFHLib
*
* @author skyboy
*
*/ */
public Sound(String id, String sound, String chan, Object obj, Pos3D loc) @SideOnly(Side.CLIENT)
{ public class Sound implements ISound {
if(MekanismClient.audioHandler.getSound(obj, chan) != null)
{ protected AttenuationType attenuation;
return; protected ResourceLocation sound;
protected float volume;
protected float pitch;
protected float x;
protected float y;
protected float z;
protected boolean repeat;
protected int repeatDelay;
public Sound(String sound) {
this(sound, 0);
} }
synchronized(MekanismClient.audioHandler.soundMaps) public Sound(String sound, float volume) {
{
prevSoundPath = sound;
identifier = id;
objRef = obj;
channel = chan;
URL url = getClass().getClassLoader().getResource("assets/mekanism/sounds/" + sound); this(sound, volume, 0);
if(url == null)
{
Mekanism.logger.error("Invalid sound file: " + sound);
} }
if(SoundHandler.getSoundSystem() != null) public Sound(String sound, float volume, float pitch) {
{
SoundHandler.getSoundSystem().newSource(false, id, url, sound, true, (float)loc.xPos, (float)loc.yPos, (float)loc.zPos, 0, 16F); this(sound, volume, pitch, false, 0);
updateVolume();
SoundHandler.getSoundSystem().activate(id);
} }
MekanismClient.audioHandler.registerSound(objRef, channel, this); public Sound(String sound, float volume, float pitch, boolean repeat, int repeatDelay) {
}
this(sound, volume, pitch, repeat, repeatDelay, 0, 0, 0, AttenuationType.NONE);
} }
/** public Sound(String sound, float volume, float pitch, double x, double y, double z) {
* Start looping the sound effect
*/ this(sound, volume, pitch, false, 0, x, y, z);
public void play()
{
synchronized(MekanismClient.audioHandler.soundMaps)
{
if(isPlaying)
{
return;
} }
ISound sound = ForgeHooksClient.playSound(SoundHandler.getSoundManager(), new DummySound()); public Sound(String sound, float volume, float pitch, boolean repeat, int repeatDelay, double x, double y, double z) {
if (!(sound instanceof DummySound)) return;
ticksSincePlay = 0; this(sound, volume, pitch, repeat, repeatDelay, x, y, z, AttenuationType.LINEAR);
if(SoundHandler.getSoundSystem() != null)
{
updateVolume();
SoundHandler.getSoundSystem().play(identifier);
} }
isPlaying = true; public Sound(String sound, float volume, float pitch, boolean repeat, int repeatDelay, double x, double y, double z, AttenuationType attenuation) {
}
this(new ResourceLocation(sound), volume, pitch, repeat, repeatDelay, x, y, z, attenuation);
} }
/** public Sound(ResourceLocation sound) {
* Stop looping the sound effect
*/ this(sound, 0);
public void stopLoop()
{
synchronized(MekanismClient.audioHandler.soundMaps)
{
if(!isPlaying)
{
return;
} }
if(SoundHandler.getSoundSystem() != null) public Sound(ResourceLocation sound, float volume) {
{
updateVolume(); this(sound, volume, 0);
SoundHandler.getSoundSystem().stop(identifier);
} }
isPlaying = false; public Sound(ResourceLocation sound, float volume, float pitch) {
}
this(sound, volume, pitch, false, 0);
} }
/** public Sound(ResourceLocation sound, float volume, float pitch, boolean repeat, int repeatDelay) {
* Remove the sound effect from the PaulsCode SoundSystem and the Mekanism SoundHandler
*/ this(sound, volume, pitch, repeat, repeatDelay, 0, 0, 0, AttenuationType.NONE);
public void remove()
{
synchronized(MekanismClient.audioHandler.soundMaps)
{
if(isPlaying)
{
stopLoop();
} }
MekanismClient.audioHandler.removeSound(objRef, channel); public Sound(ResourceLocation sound, float volume, float pitch, double x, double y, double z) {
if(SoundHandler.getSoundSystem() != null) this(sound, volume, pitch, false, 0, x, y, z);
{
updateVolume();
SoundHandler.getSoundSystem().removeSource(identifier);
}
}
} }
public String getSoundPath() public Sound(ResourceLocation sound, float volume, float pitch, boolean repeat, int repeatDelay, double x, double y, double z) {
{
return prevSoundPath; this(sound, volume, pitch, repeat, repeatDelay, x, y, z, AttenuationType.LINEAR);
} }
public boolean update(World world) public Sound(ResourceLocation sound, float volume, float pitch, boolean repeat, int repeatDelay, double x, double y, double z,
{ AttenuationType attenuation) {
if(!getSoundPath().equals(prevSoundPath))
{ this.attenuation = attenuation;
return false; this.sound = sound;
this.volume = volume;
this.pitch = pitch;
this.x = (float) x;
this.y = (float) y;
this.z = (float) z;
this.repeat = repeat;
this.repeatDelay = repeatDelay;
} }
return true; public Sound(Sound other) {
}
public abstract Pos3D getLocation(); this.attenuation = other.attenuation;
this.sound = other.sound;
public float getMultiplier() this.volume = other.volume;
{ this.pitch = other.pitch;
return doGradualEffect() ? Math.min(1, ((float)ticksSincePlay/30F)) : 1; this.x = other.x;
} this.y = other.y;
this.z = other.z;
public boolean doGradualEffect() this.repeat = other.repeat;
{ this.repeatDelay = other.repeatDelay;
return true;
}
/**
* Updates the volume based on how far away the player is from the machine.
* @param entityplayer - player who is near the machine, always Minecraft.thePlayer
*/
public void updateVolume()
{
synchronized(MekanismClient.audioHandler.soundMaps)
{
try {
float multiplier = getMultiplier();
float volume = 0;
float masterVolume = MekanismClient.audioHandler.getMasterVolume();
double distance = mc.thePlayer.getDistance(getLocation().xPos, getLocation().yPos, getLocation().zPos);
volume = (float)Math.min(Math.max(masterVolume-((distance*.08F)*masterVolume), 0)*multiplier, 1);
volume *= Math.max(0, Math.min(1, client.baseSoundVolume));
if(SoundHandler.getSoundSystem() != null)
{
SoundHandler.getSoundSystem().setVolume(identifier, volume);
}
} catch(Exception e) {}
}
}
public class DummySound implements ISound
{
@Override
public ResourceLocation getPositionedSoundLocation()
{
return new ResourceLocation("mekanism", "sound.ogg");
} }
@Override @Override
public boolean canRepeat() public AttenuationType getAttenuationType() {
{
return false; return attenuation;
} }
@Override @Override
public int getRepeatDelay() public ResourceLocation getPositionedSoundLocation() {
{
return 0; return sound;
} }
@Override @Override
public float getVolume() public float getVolume() {
{
return 1; return volume;
} }
@Override @Override
public float getPitch() public float getPitch() {
{
return 0; return pitch;
} }
@Override @Override
public float getXPosF() public float getXPosF() {
{
return (float)getLocation().xPos; return x;
} }
@Override @Override
public float getYPosF() public float getYPosF() {
{
return (float)getLocation().yPos; return y;
} }
@Override @Override
public float getZPosF() public float getZPosF() {
{
return (float)getLocation().zPos; return z;
} }
@Override @Override
public AttenuationType getAttenuationType() public boolean canRepeat() {
{
return AttenuationType.LINEAR; return repeat;
} }
@Override
public int getRepeatDelay() {
return repeatDelay;
} }
} }

View file

@ -1,178 +0,0 @@
package mekanism.client.sound;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.audio.ISound;
import net.minecraft.util.ResourceLocation;
/**
* Generic ISound class with lots of constructor functionality.
* Required because - of course - Mojang has no generic that
* lets you specify *any* arguments for this.
*
* Taken from CoFHLib
*
* @author skyboy
*
*/
@SideOnly(Side.CLIENT)
public class SoundBase implements ISound {
protected AttenuationType attenuation;
protected final ResourceLocation sound;
protected float volume;
protected float pitch;
protected float x;
protected float y;
protected float z;
protected boolean repeat;
protected int repeatDelay;
public SoundBase(String sound) {
this(sound, 0);
}
public SoundBase(String sound, float volume) {
this(sound, volume, 0);
}
public SoundBase(String sound, float volume, float pitch) {
this(sound, volume, pitch, false, 0);
}
public SoundBase(String sound, float volume, float pitch, boolean repeat, int repeatDelay) {
this(sound, volume, pitch, repeat, repeatDelay, 0, 0, 0, AttenuationType.NONE);
}
public SoundBase(String sound, float volume, float pitch, double x, double y, double z) {
this(sound, volume, pitch, false, 0, x, y, z);
}
public SoundBase(String sound, float volume, float pitch, boolean repeat, int repeatDelay, double x, double y, double z) {
this(sound, volume, pitch, repeat, repeatDelay, x, y, z, AttenuationType.LINEAR);
}
public SoundBase(String sound, float volume, float pitch, boolean repeat, int repeatDelay, double x, double y, double z, AttenuationType attenuation) {
this(new ResourceLocation(sound), volume, pitch, repeat, repeatDelay, x, y, z, attenuation);
}
public SoundBase(ResourceLocation sound) {
this(sound, 0);
}
public SoundBase(ResourceLocation sound, float volume) {
this(sound, volume, 0);
}
public SoundBase(ResourceLocation sound, float volume, float pitch) {
this(sound, volume, pitch, false, 0);
}
public SoundBase(ResourceLocation sound, float volume, float pitch, boolean repeat, int repeatDelay) {
this(sound, volume, pitch, repeat, repeatDelay, 0, 0, 0, AttenuationType.NONE);
}
public SoundBase(ResourceLocation sound, float volume, float pitch, double x, double y, double z) {
this(sound, volume, pitch, false, 0, x, y, z);
}
public SoundBase(ResourceLocation sound, float volume, float pitch, boolean repeat, int repeatDelay, double x, double y, double z) {
this(sound, volume, pitch, repeat, repeatDelay, x, y, z, AttenuationType.LINEAR);
}
public SoundBase(ResourceLocation sound, float volume, float pitch, boolean repeat, int repeatDelay, double x, double y, double z,
AttenuationType attenuation) {
this.attenuation = attenuation;
this.sound = sound;
this.volume = volume;
this.pitch = pitch;
this.x = (float) x;
this.y = (float) y;
this.z = (float) z;
this.repeat = repeat;
this.repeatDelay = repeatDelay;
}
public SoundBase(SoundBase other) {
this.attenuation = other.attenuation;
this.sound = other.sound;
this.volume = other.volume;
this.pitch = other.pitch;
this.x = other.x;
this.y = other.y;
this.z = other.z;
this.repeat = other.repeat;
this.repeatDelay = other.repeatDelay;
}
@Override
public AttenuationType getAttenuationType() {
return attenuation;
}
@Override
public ResourceLocation getPositionedSoundLocation() {
return sound;
}
@Override
public float getVolume() {
return volume;
}
@Override
public float getPitch() {
return pitch;
}
@Override
public float getXPosF() {
return x;
}
@Override
public float getYPosF() {
return y;
}
@Override
public float getZPosF() {
return z;
}
@Override
public boolean canRepeat() {
return repeat;
}
@Override
public int getRepeatDelay() {
return repeatDelay;
}
}

View file

@ -1,36 +1,18 @@
package mekanism.client.sound; package mekanism.client.sound;
import java.io.File;
import java.io.FileInputStream;
import java.net.URL;
import java.security.CodeSource;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Random;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import mekanism.api.Coord4D;
import mekanism.api.MekanismConfig.client;
import mekanism.client.HolidayManager;
import mekanism.common.Mekanism; import mekanism.common.Mekanism;
import mekanism.common.ObfuscatedNames; import mekanism.common.ObfuscatedNames;
import mekanism.common.util.MekanismUtils; import mekanism.common.util.MekanismUtils;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.ISound;
import net.minecraft.client.audio.ITickableSound;
import net.minecraft.client.audio.PositionedSoundRecord; import net.minecraft.client.audio.PositionedSoundRecord;
import net.minecraft.client.audio.SoundCategory;
import net.minecraft.client.audio.SoundManager; import net.minecraft.client.audio.SoundManager;
import net.minecraft.tileentity.TileEntity; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.world.ChunkEvent;
import paulscode.sound.SoundSystem;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
@ -43,296 +25,78 @@ import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public class SoundHandler public class SoundHandler
{ {
/** All the sound references in the Minecraft game. */ public Map<String, Map<String, IResettableSound>> soundMaps = new HashMap<String, Map<String, IResettableSound>>();
public Map<Object, SoundMap> soundMaps = Collections.synchronizedMap(new HashMap<Object, SoundMap>());
public static Map<ISound, String> invPlayingSounds;
public static Minecraft mc = Minecraft.getMinecraft(); public static Minecraft mc = Minecraft.getMinecraft();
public static final String CHANNEL_TILE_DEFAULT = "tile"; public enum Channel
public static final String CHANNEL_JETPACK = "jetpack";
public static final String CHANNEL_GASMASK = "gasMask";
public static final String CHANNEL_FLAMETHROWER = "flamethrower";
/**
* SoundHandler -- a class that handles all Sounds used by Mekanism.
*/
public SoundHandler()
{ {
MinecraftForge.EVENT_BUS.register(this); JETPACK("jetpack"),
GASMASK("gasMask"),
FLAMETHROWER("flamethrower");
Mekanism.logger.info("Successfully set up SoundHandler."); String channelName;
private Channel(String name)
{
channelName = name;
} }
public void preloadSounds() public String getName()
{ {
CodeSource src = getClass().getProtectionDomain().getCodeSource(); return channelName;
String corePath = src.getLocation().getFile().split("/mekanism/client")[0];
List<String> listings = listFiles(corePath.replace("%20", " ").replace(".jar!", ".jar").replace("file:", ""), "assets/mekanism/sounds");
for(String s : listings)
{
if(s.contains("etc") || s.contains("holiday"))
{
continue;
}
if(s.contains("/mekanism/sounds/"))
{
s = s.split("/mekanism/sounds/")[1];
}
preloadSound(s);
}
Mekanism.logger.info("Preloaded " + listings.size() + " object sounds.");
if(client.holidays)
{
listings = listFiles(corePath.replace("%20", " ").replace(".jar!", ".jar").replace("file:", ""), "assets/mekanism/sounds/holiday");
for(String s : listings)
{
if(s.contains("/mekanism/sounds/"))
{
s = s.split("/mekanism/sounds/")[1];
}
if(!s.contains("holiday"))
{
s = "holiday/" + s;
}
preloadSound(s);
}
} }
} }
private List<String> listFiles(String path, String s) public boolean hasSound(EntityPlayer player, Channel channel)
{ {
List<String> names = new ArrayList<String>(); String name = player.getCommandSenderName();
Map<String, IResettableSound> map = getMap(name);
IResettableSound sound = map.get(channel.getName());
File f = new File(path); return sound != null;
if(!f.exists())
{
return names;
} }
if(!f.isDirectory()) public void addSound(EntityPlayer player, Channel channel, IResettableSound newSound, boolean replace)
{ {
try { String name = player.getCommandSenderName();
ZipInputStream zip = new ZipInputStream(new FileInputStream(path)); Map<String, IResettableSound> map = getMap(name);
IResettableSound sound = map.get(channel.getName());
while(true) if(sound == null || replace)
{ {
ZipEntry e = zip.getNextEntry(); map.put(channel.getName(), newSound);
if(e == null)
{
break;
}
String name = e.getName();
if(name.contains(s) && name.endsWith(".ogg"))
{
names.add(name);
} }
} }
zip.close(); public boolean playSound(EntityPlayer player, Channel channel)
} catch(Exception e) {
e.printStackTrace();
}
}
else {
f = new File(path + "/" + s);
for(File file : f.listFiles())
{ {
if(file.getPath().contains(s) && file.getName().endsWith(".ogg")) String name = player.getCommandSenderName();
Map<String, IResettableSound> map = getMap(name);
IResettableSound sound = map.get(channel.getName());
if(sound != null)
{ {
names.add(file.getName()); if(sound.isDonePlaying() && !getSoundMap().containsKey(sound))
{
sound.reset();
Mekanism.logger.info("Playing sound " + sound);
playSound(sound);
} }
return true;
} }
return false;
} }
return names; public Map<String, IResettableSound> getMap(String name)
}
private void preloadSound(String sound)
{ {
String id = "pre_" + sound; Map<String, IResettableSound> map = soundMaps.get(name);
URL url = getClass().getClassLoader().getResource("assets/mekanism/sounds/" + sound); if(map == null)
if(getSoundSystem() != null)
{ {
getSoundSystem().newSource(false, id, url, sound, true, 0, 0, 0, 0, 16F); map = new HashMap<String, IResettableSound>();
getSoundSystem().activate(id); soundMaps.put(name, map);
getSoundSystem().removeSource(id);
}
}
/**
* Ticks the sound handler. Should be called every Minecraft tick, or 20 times per second.
*/
public void onTick()
{
synchronized(soundMaps)
{
if(getSoundSystem() != null)
{
if(!Mekanism.proxy.isPaused())
{
ArrayList<Sound> soundsToRemove = new ArrayList<Sound>();
World world = FMLClientHandler.instance().getClient().theWorld;
if(FMLClientHandler.instance().getClient().thePlayer != null && world != null)
{
for(SoundMap map : soundMaps.values())
{
for(Sound sound : map)
{
if(!sound.update(world))
{
soundsToRemove.add(sound);
continue;
}
if(sound.isPlaying)
{
sound.updateVolume();
}
}
}
for(Sound sound : soundsToRemove)
{
sound.remove();
}
}
}
else {
for(SoundMap map : soundMaps.values())
{
map.stopLoops();
}
}
}
else {
Mekanism.proxy.unloadSoundHandler();
}
}
}
public void removeSound(Object ref, String channel)
{
if(soundMaps.get(ref) == null)
{
return;
}
soundMaps.get(ref).remove(channel);
if(soundMaps.get(ref).isEmpty())
{
soundMaps.remove(ref);
}
}
public void registerSound(Object ref, String channel, Sound sound)
{
if(soundMaps.get(ref) == null)
{
soundMaps.put(ref, new SoundMap(ref, channel, sound));
return;
}
soundMaps.get(ref).add(channel, sound);
}
/**
* Gets a sound object from a specific TileEntity, null if there is none.
* @param tileEntity - the holder of the sound
* @return Sound instance
*/
public SoundMap getMap(Object ref)
{
synchronized(soundMaps)
{
return soundMaps.get(ref);
}
}
public Sound getSound(Object ref, String channel)
{
if(soundMaps.get(ref) == null)
{
return null;
}
return soundMaps.get(ref).getSound(channel);
}
/**
* Get a unique identifier for a sound effect instance by combining the mod's name,
* Mekanism, the new sound's unique position on the 'sounds' ArrayList, and a random
* number between 0 and 10,000. Example: "Mekanism_6_6123"
* @return unique identifier
*/
public String getIdentifier(Object obj)
{
synchronized(soundMaps)
{
String toReturn = "Mekanism_" + getActiveSize() + "_" + new Random().nextInt(10000);
return toReturn;
}
}
public int getActiveSize()
{
int count = 0;
for(SoundMap map : soundMaps.values())
{
count += map.size();
}
return count;
}
/**
* Plays a sound in a specific location.
* @param soundPath - sound path to play
* @param world - world to play in
* @param object - location to play
*/
public void quickPlay(String soundPath, World world, Coord4D object)
{
URL url = getClass().getClassLoader().getResource("assets/mekanism/sounds/" + soundPath);
if(url == null)
{
Mekanism.logger.info("Invalid sound file: " + soundPath);
}
String s = getSoundSystem().quickPlay(false, url, soundPath, false, object.xCoord, object.yCoord, object.zCoord, 0, 16F);
getSoundSystem().setVolume(s, getMasterVolume());
}
public float getMasterVolume()
{
return FMLClientHandler.instance().getClient().gameSettings.getSoundLevel(SoundCategory.MASTER);
}
public static SoundSystem getSoundSystem()
{
try {
return (SoundSystem)MekanismUtils.getPrivateValue(getSoundManager(), SoundManager.class, ObfuscatedNames.SoundManager_sndSystem);
} catch(Exception e) {
return null;
} }
return map;
} }
public static SoundManager getSoundManager() public static SoundManager getSoundManager()
@ -344,43 +108,31 @@ public class SoundHandler
} }
} }
public static boolean isSystemLoaded() //Fudge required because sound thread gets behind and the biMap crashes when rapidly toggling sounds.
public static Map<ISound, String> getSoundMap()
{ {
if(invPlayingSounds == null)
try { try {
return (Boolean)MekanismUtils.getPrivateValue(getSoundManager(), net.minecraft.client.audio.SoundManager.class, new String[] {"loaded"}); invPlayingSounds = (Map<ISound, String>)MekanismUtils.getPrivateValue(getSoundManager(), net.minecraft.client.audio.SoundManager.class, ObfuscatedNames.SoundManager_invPlayingSounds);
} catch(Exception e) { } catch(Exception e) {
return false; invPlayingSounds = null;
} }
return invPlayingSounds;
}
public static boolean canRestartSound(ITickableSound sound)
{
return sound.isDonePlaying() && !getSoundMap().containsKey(sound);
} }
public static void playSound(String sound) public static void playSound(String sound)
{ {
mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation(sound), 1.0F)); playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation(sound), 1.0F));
} }
@SubscribeEvent public static void playSound(ISound sound)
public void onChunkUnload(ChunkEvent.Unload event)
{ {
if(event.getChunk() != null) mc.getSoundHandler().playSound(sound);
{
for(Object obj : event.getChunk().chunkTileEntityMap.values())
{
if(obj instanceof TileEntity)
{
TileEntity tileEntity = (TileEntity)obj;
if(tileEntity instanceof IHasSound)
{
if(getMap(tileEntity) != null)
{
if(soundMaps.containsKey(tileEntity))
{
getMap(tileEntity).kill();
}
}
}
}
}
}
} }
} }

View file

@ -1,83 +0,0 @@
package mekanism.client.sound;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import mekanism.client.MekanismClient;
public class SoundMap implements Iterable<Sound>
{
public Map<String, Sound> soundMap = new HashMap<String, Sound>();
public Object objRef;
public SoundMap(Object obj)
{
objRef = obj;
}
public SoundMap(Object obj, String channel, Sound sound)
{
this(obj);
soundMap.put(channel, sound);
}
@Override
public Iterator<Sound> iterator()
{
return soundMap.values().iterator();
}
public Sound getSound(String channel)
{
return soundMap.get(channel);
}
public boolean hasSound(String channel)
{
return soundMap.containsKey(channel);
}
public void remove(String channel)
{
soundMap.remove(channel);
}
public void add(String channel, Sound sound)
{
soundMap.put(channel, sound);
}
public void stopLoops()
{
for(Sound sound : soundMap.values())
{
if(sound.isPlaying)
{
sound.stopLoop();
}
}
}
public void kill()
{
for(Sound sound : soundMap.values())
{
sound.remove();
}
MekanismClient.audioHandler.soundMaps.remove(objRef);
}
public boolean isEmpty()
{
return soundMap.isEmpty();
}
public int size()
{
return soundMap.size();
}
}

View file

@ -1,9 +1,8 @@
package mekanism.client.sound; package mekanism.client.sound;
import net.minecraft.client.audio.ITickableSound;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
public class SoundTile extends SoundBase implements ITickableSound { public class TileSound extends Sound implements IResettableSound {
IHasSound source; IHasSound source;
boolean beginFadeOut; boolean beginFadeOut;
@ -13,28 +12,28 @@ public class SoundTile extends SoundBase implements ITickableSound {
int fadeOut = 50; int fadeOut = 50;
float baseVolume = 1.0F; float baseVolume = 1.0F;
public SoundTile(IHasSound source, ISoundSource values) public TileSound(IHasSound source, ISoundSource values)
{ {
this(source, values.getSoundLocation(), values.getVolume(), values.getPitch(), values.shouldRepeat(), values.getRepeatDelay(), values.getSoundPosition().xPos, values.getSoundPosition().yPos, values.getSoundPosition().zPos); this(source, values.getSoundLocation(), values.getVolume(), values.getPitch(), values.shouldRepeat(), values.getRepeatDelay(), values.getSoundPosition().xPos, values.getSoundPosition().yPos, values.getSoundPosition().zPos);
} }
public SoundTile(IHasSound source, String sound, float volume, float pitch, boolean repeat, int repeatDelay, double x, double y, double z) { public TileSound(IHasSound source, String sound, float volume, float pitch, boolean repeat, int repeatDelay, double x, double y, double z) {
this(source, sound, volume, pitch, repeat, repeatDelay, x, y, z, AttenuationType.LINEAR); this(source, sound, volume, pitch, repeat, repeatDelay, x, y, z, AttenuationType.LINEAR);
} }
public SoundTile(IHasSound source, String sound, float volume, float pitch, boolean repeat, int repeatDelay, double x, double y, double z, public TileSound(IHasSound source, String sound, float volume, float pitch, boolean repeat, int repeatDelay, double x, double y, double z,
AttenuationType attenuation) { AttenuationType attenuation) {
this(source, new ResourceLocation(sound), volume, pitch, repeat, repeatDelay, x, y, z, attenuation); this(source, new ResourceLocation(sound), volume, pitch, repeat, repeatDelay, x, y, z, attenuation);
} }
public SoundTile(IHasSound source, ResourceLocation sound, float volume, float pitch, boolean repeat, int repeatDelay, double x, double y, double z) { public TileSound(IHasSound source, ResourceLocation sound, float volume, float pitch, boolean repeat, int repeatDelay, double x, double y, double z) {
this(source, sound, volume, pitch, repeat, repeatDelay, x, y, z, AttenuationType.LINEAR); this(source, sound, volume, pitch, repeat, repeatDelay, x, y, z, AttenuationType.LINEAR);
} }
public SoundTile(IHasSound source, ResourceLocation sound, float volume, float pitch, boolean repeat, int repeatDelay, double x, double y, double z, public TileSound(IHasSound source, ResourceLocation sound, float volume, float pitch, boolean repeat, int repeatDelay, double x, double y, double z,
AttenuationType attenuation) { AttenuationType attenuation) {
super(sound, volume, pitch, repeat, repeatDelay, x, y, z, attenuation); super(sound, volume, pitch, repeat, repeatDelay, x, y, z, attenuation);
@ -42,13 +41,13 @@ public class SoundTile extends SoundBase implements ITickableSound {
this.baseVolume = volume; this.baseVolume = volume;
} }
public SoundTile setFadeIn(int fadeIn) { public TileSound setFadeIn(int fadeIn) {
this.fadeIn = Math.min(0, fadeIn); this.fadeIn = Math.min(0, fadeIn);
return this; return this;
} }
public SoundTile setFadeOut(int fadeOut) { public TileSound setFadeOut(int fadeOut) {
this.fadeOut = Math.min(0, fadeOut); this.fadeOut = Math.min(0, fadeOut);
return this; return this;
@ -93,10 +92,12 @@ public class SoundTile extends SoundBase implements ITickableSound {
return donePlaying; return donePlaying;
} }
@Override
public void reset() public void reset()
{ {
donePlaying = false; donePlaying = false;
beginFadeOut = false; beginFadeOut = false;
volume = baseVolume;
ticks = 0; ticks = 0;
} }
} }

View file

@ -14,4 +14,5 @@ public final class ObfuscatedNames
public static String[] NetHandlerPlayServer_floatingTickCount = new String[] {"floatingTickCount", "field_147365_f"}; public static String[] NetHandlerPlayServer_floatingTickCount = new String[] {"floatingTickCount", "field_147365_f"};
public static String[] SoundHandler_sndManager = new String[] {"sndManager", "field_147694_f"}; public static String[] SoundHandler_sndManager = new String[] {"sndManager", "field_147694_f"};
public static String[] SoundManager_sndSystem = new String[] {"sndSystem", "field_148620_e"}; public static String[] SoundManager_sndSystem = new String[] {"sndSystem", "field_148620_e"};
public static String[] SoundManager_invPlayingSounds = new String[] {"invPlayingSounds", "field_148630_i"};
} }

View file

@ -8,10 +8,6 @@ import mekanism.api.Coord4D;
import mekanism.api.Pos3D; import mekanism.api.Pos3D;
import mekanism.api.Range4D; import mekanism.api.Range4D;
import mekanism.api.MekanismConfig.general; import mekanism.api.MekanismConfig.general;
import mekanism.client.sound.IHasSound;
import mekanism.client.sound.ISoundSource;
import mekanism.client.sound.SoundTile;
import mekanism.client.sound.TestSound;
import mekanism.common.Mekanism; import mekanism.common.Mekanism;
import mekanism.common.SideData; import mekanism.common.SideData;
import mekanism.common.base.IActiveState; import mekanism.common.base.IActiveState;

View file

@ -3,17 +3,9 @@ package mekanism.common.tile;
import java.util.Map; import java.util.Map;
import mekanism.api.MekanismConfig.usage; import mekanism.api.MekanismConfig.usage;
import mekanism.client.sound.TestSound;
import mekanism.common.Mekanism;
import mekanism.common.block.BlockMachine.MachineType; import mekanism.common.block.BlockMachine.MachineType;
import mekanism.common.recipe.RecipeHandler.Recipe; import mekanism.common.recipe.RecipeHandler.Recipe;
import net.minecraft.client.audio.ISound.AttenuationType;
import net.minecraft.client.audio.PositionedSound;
import net.minecraft.client.audio.PositionedSoundRecord;
import net.minecraft.util.ResourceLocation;
import cpw.mods.fml.client.FMLClientHandler;
public class TileEntityCrusher extends TileEntityElectricMachine public class TileEntityCrusher extends TileEntityElectricMachine
{ {
public TileEntityCrusher() public TileEntityCrusher()

View file

@ -2,15 +2,17 @@ package mekanism.common.tile;
import mekanism.api.Pos3D; import mekanism.api.Pos3D;
import mekanism.client.sound.IHasSound; import mekanism.client.sound.IHasSound;
import mekanism.client.sound.IResettableSound;
import mekanism.client.sound.ISoundSource; import mekanism.client.sound.ISoundSource;
import mekanism.client.sound.SoundTile; import mekanism.client.sound.SoundHandler;
import mekanism.common.Mekanism; import mekanism.client.sound.TileSound;
import mekanism.common.Upgrade;
import mekanism.common.base.IActiveState; import mekanism.common.base.IActiveState;
import mekanism.common.base.IUpgradeTile;
import net.minecraft.client.audio.ISound; import net.minecraft.client.audio.ISound;
import net.minecraft.client.audio.ISound.AttenuationType; import net.minecraft.client.audio.ISound.AttenuationType;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import cpw.mods.fml.client.FMLClientHandler;
public abstract class TileEntityNoisyElectricBlock extends TileEntityElectricBlock implements IHasSound, ISoundSource, IActiveState public abstract class TileEntityNoisyElectricBlock extends TileEntityElectricBlock implements IHasSound, ISoundSource, IActiveState
{ {
@ -18,7 +20,7 @@ public abstract class TileEntityNoisyElectricBlock extends TileEntityElectricBlo
public ResourceLocation soundURL; public ResourceLocation soundURL;
/** The bundled URL of this machine's sound effect */ /** The bundled URL of this machine's sound effect */
public SoundTile sound; public IResettableSound sound;
/** /**
* The base of all blocks that deal with electricity and make noise. * The base of all blocks that deal with electricity and make noise.
@ -60,6 +62,11 @@ public abstract class TileEntityNoisyElectricBlock extends TileEntityElectricBlo
@Override @Override
public float getPitch() public float getPitch()
{ {
if(this instanceof IUpgradeTile)
{
float speedUpgrades = ((IUpgradeTile)this).getComponent().getUpgrades(Upgrade.SPEED);
return 1F + 20 * speedUpgrades / (float)Upgrade.SPEED.getMax();
}
return 1F; return 1F;
} }
@ -91,17 +98,16 @@ public abstract class TileEntityNoisyElectricBlock extends TileEntityElectricBlo
public void validate() public void validate()
{ {
super.validate(); super.validate();
sound = new SoundTile(this, this); sound = new TileSound(this, this);
} }
@Override @Override
public void onUpdate() public void onUpdate()
{ {
if(worldObj.isRemote && shouldPlaySound() && sound.isDonePlaying()) if(worldObj.isRemote && shouldPlaySound() && SoundHandler.canRestartSound(sound))
{ {
Mekanism.logger.info("Playing " + this.fullName + " noise");
sound.reset(); sound.reset();
FMLClientHandler.instance().getClient().getSoundHandler().playSound(sound); SoundHandler.playSound(sound);
} }
} }
} }

View file

@ -608,7 +608,7 @@ public final class MekanismUtils
*/ */
public static int getTicks(IUpgradeTile mgmt, int def) public static int getTicks(IUpgradeTile mgmt, int def)
{ {
return def * (int)Math.pow(general.maxUpgradeMultiplier, (float)-mgmt.getComponent().getUpgrades(Upgrade.SPEED)/(float)Upgrade.SPEED.getMax()); return (int)(def * Math.pow(general.maxUpgradeMultiplier, (float)-mgmt.getComponent().getUpgrades(Upgrade.SPEED)/(float)Upgrade.SPEED.getMax()));
} }
/** /**

View file

@ -6,26 +6,21 @@ import java.util.ArrayList;
import java.util.EnumSet; import java.util.EnumSet;
import mekanism.api.Coord4D; import mekanism.api.Coord4D;
import mekanism.api.Pos3D;
import mekanism.api.Range4D; import mekanism.api.Range4D;
import mekanism.api.MekanismConfig.general; import mekanism.api.MekanismConfig.general;
import mekanism.client.sound.IHasSound; import mekanism.client.sound.IHasSound;
import mekanism.client.sound.ISoundSource; import mekanism.client.sound.ISoundSource;
import mekanism.client.sound.SoundTile; import mekanism.client.sound.TileSound;
import mekanism.common.Mekanism; import mekanism.common.Mekanism;
import mekanism.common.base.IActiveState; import mekanism.common.base.IActiveState;
import mekanism.common.base.IRedstoneControl; import mekanism.common.base.IRedstoneControl;
import mekanism.common.network.PacketTileEntity.TileEntityMessage; import mekanism.common.network.PacketTileEntity.TileEntityMessage;
import mekanism.common.tile.TileEntityElectricBlock;
import mekanism.common.tile.TileEntityNoisyElectricBlock; import mekanism.common.tile.TileEntityNoisyElectricBlock;
import mekanism.common.util.CableUtils; import mekanism.common.util.CableUtils;
import mekanism.common.util.MekanismUtils; import mekanism.common.util.MekanismUtils;
import net.minecraft.client.audio.ISound;
import net.minecraft.client.audio.ISound.AttenuationType;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
import cpw.mods.fml.common.Optional.Interface; import cpw.mods.fml.common.Optional.Interface;
import cpw.mods.fml.common.Optional.Method; import cpw.mods.fml.common.Optional.Method;
@ -130,7 +125,7 @@ public abstract class TileEntityGenerator extends TileEntityNoisyElectricBlock i
{ {
super.validate(); super.validate();
sound = new SoundTile(this, this); sound = new TileSound(this, this);
} }
/** /**

View file

@ -7,6 +7,17 @@
"etc.Hydraulic": {"category": "master", "sounds": [{"name": "etc/Hydraulic", "stream": false}]}, "etc.Hydraulic": {"category": "master", "sounds": [{"name": "etc/Hydraulic", "stream": false}]},
"etc.Pop": {"category": "master", "sounds": [{"name": "etc/Pop", "stream": false}]}, "etc.Pop": {"category": "master", "sounds": [{"name": "etc/Pop", "stream": false}]},
"etc.Success": {"category": "master", "sounds": [{"name": "etc/Success", "stream": false}]}, "etc.Success": {"category": "master", "sounds": [{"name": "etc/Success", "stream": false}]},
"etc.cj": {"category": "block", "sounds": [
{"name": "cj/CJ_1", "stream": false},
{"name": "cj/CJ_2", "stream": false},
{"name": "cj/CJ_3", "stream": false},
{"name": "cj/CJ_4", "stream": false},
{"name": "cj/CJ_5", "stream": false},
{"name": "cj/CJ_6", "stream": false},
{"name": "cj/CJ_7", "stream": false},
{"name": "cj/CJ_8", "stream": false}
]
},
"tile.machine.chargepad": {"category": "block", "sounds": [{"name": "Chargepad", "stream": false}]}, "tile.machine.chargepad": {"category": "block", "sounds": [{"name": "Chargepad", "stream": false}]},
"tile.machine.crystallizer": {"category": "block", "sounds": [{"name": "ChemicalCrystallizer", "stream": false}]}, "tile.machine.crystallizer": {"category": "block", "sounds": [{"name": "ChemicalCrystallizer", "stream": false}]},
@ -33,6 +44,6 @@
"item.flamethrower.idle": {"category": "player", "sounds": [{"name": "FlamethrowerIdle", "stream": false}]}, "item.flamethrower.idle": {"category": "player", "sounds": [{"name": "FlamethrowerIdle", "stream": false}]},
"item.flamethrower.active": {"category": "player", "sounds": [{"name": "FlamethrowerActive", "stream": false}]}, "item.flamethrower.active": {"category": "player", "sounds": [{"name": "FlamethrowerActive", "stream": false}]},
"item.gasmask": {"category": "player", "sounds": [{"name": "GasMask","stream": false}]}, "item.gasMask": {"category": "player", "sounds": [{"name": "GasMask", "stream": false}]},
"item.jetpack": {"category": "player", "sounds": [{"name": "Jetpack", "stream": false}]} "item.jetpack": {"category": "player", "sounds": [{"name": "Jetpack", "stream": false}]}
} }