After much client code isolation, there should be no more issues on the server side with sounds

This commit is contained in:
Aidan C. Brady 2015-03-18 13:26:12 -04:00
parent 12b6b4610b
commit 339e048a4e
9 changed files with 103 additions and 41 deletions

View file

@ -1,7 +1,10 @@
package mekanism.client.sound;
import net.minecraft.client.audio.ITickableSound;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public interface IResettableSound extends ITickableSound
{
public void reset();

View file

@ -1,9 +1,10 @@
package mekanism.client.sound;
import mekanism.api.Pos3D;
import net.minecraft.client.audio.ISound.AttenuationType;
import net.minecraft.util.ResourceLocation;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public interface ISoundSource
{
@ -19,5 +20,6 @@ public interface ISoundSource
public int getRepeatDelay();
@SideOnly(Side.CLIENT)
public AttenuationType getAttenuation();
}

View file

@ -1,9 +1,10 @@
package mekanism.client.sound;
import mekanism.common.base.IHasSound;
import net.minecraft.util.ResourceLocation;
public class TileSound extends Sound implements IResettableSound {
public class TileSound extends Sound implements IResettableSound
{
IHasSound source;
boolean beginFadeOut;
@ -85,7 +86,7 @@ public class TileSound extends Sound implements IResettableSound {
ticks++;
}
if(!(source.shouldPlaySound() && source.getSound() == this))
if(!(source.shouldPlaySound() && source.getSound().sound == this))
{
beginFadeOut = true;
ticks = 0;

View file

@ -1,6 +1,8 @@
package mekanism.client.sound;
package mekanism.common.base;
import net.minecraft.client.audio.ISound;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/**
* Implement this if your TileEntity has a specific sound.
@ -9,7 +11,7 @@ import net.minecraft.client.audio.ISound;
*/
public interface IHasSound
{
public ISound getSound();
public SoundWrapper getSound();
public boolean shouldPlaySound();
}

View file

@ -0,0 +1,47 @@
package mekanism.common.base;
import net.minecraft.util.ResourceLocation;
import mekanism.client.sound.IResettableSound;
import mekanism.client.sound.ISoundSource;
import mekanism.client.sound.SoundHandler;
import mekanism.client.sound.TileSound;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class SoundWrapper
{
@SideOnly(Side.CLIENT)
public IResettableSound sound;
public SoundWrapper(IHasSound tile, ISoundSource source)
{
try {
sound = new TileSound(tile, source);
} catch(Throwable t) {}
}
public SoundWrapper(IHasSound tile, ISoundSource source, ResourceLocation location)
{
try {
sound = new TileSound(tile, source, location);
} catch(Throwable t) {}
}
@SideOnly(Side.CLIENT)
public void reset()
{
sound.reset();
}
@SideOnly(Side.CLIENT)
public void play()
{
SoundHandler.playSound(sound);
}
@SideOnly(Side.CLIENT)
public boolean canRestart()
{
return SoundHandler.canRestartSound(sound);
}
}

View file

@ -20,8 +20,6 @@ import mekanism.api.gas.IGasItem;
import mekanism.api.gas.ITubeConnection;
import mekanism.api.transmitters.TransmissionType;
import mekanism.api.util.StackUtils;
import mekanism.client.sound.IResettableSound;
import mekanism.client.sound.TileSound;
import mekanism.common.Mekanism;
import mekanism.common.MekanismBlocks;
import mekanism.common.MekanismItems;
@ -33,6 +31,7 @@ import mekanism.common.base.IFactory.RecipeType;
import mekanism.common.base.IRedstoneControl;
import mekanism.common.base.ISideConfiguration;
import mekanism.common.base.IUpgradeTile;
import mekanism.common.base.SoundWrapper;
import mekanism.common.block.BlockMachine.MachineType;
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
import mekanism.common.recipe.machines.AdvancedMachineRecipe;
@ -106,7 +105,7 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I
public boolean upgraded;
public IResettableSound[] sounds = new IResettableSound[RecipeType.values().length];
public SoundWrapper[] sounds = new SoundWrapper[RecipeType.values().length];
/** This machine's current RedstoneControl type. */
public RedstoneControl controlType = RedstoneControl.DISABLED;
@ -923,7 +922,7 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I
}
@Override
public IResettableSound getSound()
public SoundWrapper getSound()
{
return sounds[recipeType.ordinal()];
}
@ -933,7 +932,7 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I
{
for(RecipeType type : RecipeType.values())
{
sounds[type.ordinal()] = new TileSound(this, this, type.getSound());
sounds[type.ordinal()] = new SoundWrapper(this, this, type.getSound());
}
}

View file

@ -2,23 +2,25 @@ package mekanism.common.tile;
import mekanism.api.MekanismConfig.client;
import mekanism.api.Pos3D;
import mekanism.client.sound.IHasSound;
import mekanism.client.sound.IResettableSound;
import mekanism.client.sound.ISoundSource;
import mekanism.client.sound.SoundHandler;
import mekanism.client.sound.TileSound;
import mekanism.common.base.IActiveState;
import mekanism.common.base.IHasSound;
import mekanism.common.base.SoundWrapper;
import net.minecraft.client.audio.ISound.AttenuationType;
import net.minecraft.util.ResourceLocation;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public abstract class TileEntityNoisyElectricBlock extends TileEntityElectricBlock implements IHasSound, ISoundSource, IActiveState
{
/** The ResourceLocation of the machine's sound */
public ResourceLocation soundURL;
/** The bundled URL of this machine's sound effect */
public IResettableSound sound;
/** The SoundWrapper containing this machine's sound object */
@SideOnly(Side.CLIENT)
public SoundWrapper sound;
/**
* The base of all blocks that deal with electricity and make noise.
@ -34,7 +36,8 @@ public abstract class TileEntityNoisyElectricBlock extends TileEntityElectricBlo
}
@Override
public IResettableSound getSound()
@SideOnly(Side.CLIENT)
public SoundWrapper getSound()
{
return sound;
}
@ -82,6 +85,7 @@ public abstract class TileEntityNoisyElectricBlock extends TileEntityElectricBlo
}
@Override
@SideOnly(Side.CLIENT)
public AttenuationType getAttenuation()
{
return AttenuationType.LINEAR;
@ -92,12 +96,18 @@ public abstract class TileEntityNoisyElectricBlock extends TileEntityElectricBlo
{
super.validate();
try {
if(worldObj.isRemote)
{
initSounds();
}
} catch(Throwable t) {}
}
@SideOnly(Side.CLIENT)
public void initSounds()
{
sound = new TileSound(this, this);
sound = new SoundWrapper(this, this);
}
@Override
@ -105,10 +115,12 @@ public abstract class TileEntityNoisyElectricBlock extends TileEntityElectricBlo
{
super.onUpdate();
if(worldObj.isRemote && shouldPlaySound() && SoundHandler.canRestartSound(getSound()) && client.enableMachineSounds)
try {
if(worldObj.isRemote && shouldPlaySound() && getSound().canRestart() && client.enableMachineSounds)
{
getSound().reset();
SoundHandler.playSound(getSound());
}
getSound().play();
}
} catch(Throwable t) {}
}
}

View file

@ -1,22 +1,23 @@
package mekanism.generators.common.tile;
import io.netty.buffer.ByteBuf;
import java.util.ArrayList;
import java.util.EnumSet;
import mekanism.api.Coord4D;
import mekanism.api.MekanismConfig.general;
import mekanism.api.Range4D;
import mekanism.client.sound.IHasSound;
import mekanism.client.sound.ISoundSource;
import mekanism.client.sound.TileSound;
import mekanism.common.Mekanism;
import mekanism.common.base.IActiveState;
import mekanism.common.base.IHasSound;
import mekanism.common.base.IRedstoneControl;
import mekanism.common.base.SoundWrapper;
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
import mekanism.common.tile.TileEntityNoisyElectricBlock;
import mekanism.common.util.CableUtils;
import mekanism.common.util.MekanismUtils;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.AxisAlignedBB;
import net.minecraftforge.common.util.ForgeDirection;
@ -24,9 +25,6 @@ import cpw.mods.fml.common.Optional.Interface;
import cpw.mods.fml.common.Optional.Method;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import io.netty.buffer.ByteBuf;
import dan200.computercraft.api.peripheral.IComputerAccess;
import dan200.computercraft.api.peripheral.IPeripheral;
@ -121,7 +119,7 @@ public abstract class TileEntityGenerator extends TileEntityNoisyElectricBlock i
{
super.validate();
sound = new TileSound(this, this);
sound = new SoundWrapper(this, this);
}
/**

View file

@ -11,13 +11,11 @@ import mekanism.api.gas.GasRegistry;
import mekanism.api.gas.GasStack;
import mekanism.api.gas.GasTank;
import mekanism.client.ThreadSparkle.INodeChecker;
import mekanism.client.sound.IHasSound;
import mekanism.client.sound.IResettableSound;
import mekanism.client.sound.ISoundSource;
import mekanism.client.sound.SoundHandler;
import mekanism.client.sound.TileSound;
import mekanism.common.Mekanism;
import mekanism.common.base.IActiveState;
import mekanism.common.base.IHasSound;
import mekanism.common.base.SoundWrapper;
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
import mekanism.common.util.MekanismUtils;
import mekanism.generators.common.FusionReactor;
@ -52,7 +50,7 @@ public class TileEntityReactorController extends TileEntityReactorBlock implemen
public ResourceLocation soundURL = new ResourceLocation("mekanism", "tile.machine.fusionreactor");
public IResettableSound sound;
public SoundWrapper sound;
public double clientTemp = 0;
public boolean clientBurning = false;
@ -106,10 +104,10 @@ public class TileEntityReactorController extends TileEntityReactorBlock implemen
{
super.onUpdate();
if(worldObj.isRemote && shouldPlaySound() && SoundHandler.canRestartSound(getSound()) && client.enableMachineSounds)
if(worldObj.isRemote && shouldPlaySound() && getSound().canRestart() && client.enableMachineSounds)
{
getSound().reset();
SoundHandler.playSound(getSound());
getSound().play();
}
if(isFormed())
@ -324,7 +322,7 @@ public class TileEntityReactorController extends TileEntityReactorBlock implemen
}
@Override
public IResettableSound getSound()
public SoundWrapper getSound()
{
return sound;
}
@ -387,6 +385,6 @@ public class TileEntityReactorController extends TileEntityReactorBlock implemen
public void initSounds()
{
sound = new TileSound(this, this);
sound = new SoundWrapper(this, this);
}
}