Implemented the SoundWrapper system again - for some reason dedicated servers won't behave without it on OS X

This commit is contained in:
Aidan C. Brady 2015-03-19 23:16:27 -04:00
parent 6bae353118
commit c3ef938166
7 changed files with 72 additions and 32 deletions

View file

@ -1,5 +1,6 @@
package mekanism.client.sound;
import mekanism.common.base.IHasSound;
import net.minecraft.util.ResourceLocation;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@ -88,7 +89,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,5 @@
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;
@ -12,7 +11,7 @@ import cpw.mods.fml.relauncher.SideOnly;
public interface IHasSound
{
@SideOnly(Side.CLIENT)
public ISound getSound();
public SoundWrapper getSound();
@SideOnly(Side.CLIENT)
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;
@ -52,7 +51,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 dan200.computercraft.api.lua.ILuaContext;
import dan200.computercraft.api.lua.LuaException;
import dan200.computercraft.api.peripheral.IComputerAccess;
@ -110,7 +108,7 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I
public boolean upgraded;
@SideOnly(Side.CLIENT)
public IResettableSound[] sounds;
public SoundWrapper[] sounds;
/** This machine's current RedstoneControl type. */
public RedstoneControl controlType = RedstoneControl.DISABLED;
@ -926,7 +924,7 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I
@Override
@SideOnly(Side.CLIENT)
public IResettableSound getSound()
public SoundWrapper getSound()
{
return sounds[recipeType.ordinal()];
}
@ -935,10 +933,11 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I
@SideOnly(Side.CLIENT)
public void initSounds()
{
sounds = new IResettableSound[RecipeType.values().length];
sounds = new SoundWrapper[RecipeType.values().length];
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,13 +2,12 @@ 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;
@ -21,7 +20,7 @@ public abstract class TileEntityNoisyElectricBlock extends TileEntityElectricBlo
/** The bundled URL of this machine's sound effect */
@SideOnly(Side.CLIENT)
public IResettableSound sound;
public SoundWrapper sound;
/**
* The base of all blocks that deal with electricity and make noise.
@ -38,7 +37,7 @@ public abstract class TileEntityNoisyElectricBlock extends TileEntityElectricBlo
@Override
@SideOnly(Side.CLIENT)
public IResettableSound getSound()
public SoundWrapper getSound()
{
return sound;
}
@ -113,7 +112,7 @@ public abstract class TileEntityNoisyElectricBlock extends TileEntityElectricBlo
@SideOnly(Side.CLIENT)
public void initSounds()
{
sound = new TileSound(this, this);
sound = new SoundWrapper(this, this);
}
@Override
@ -130,10 +129,10 @@ public abstract class TileEntityNoisyElectricBlock extends TileEntityElectricBlo
@SideOnly(Side.CLIENT)
public void updateSound()
{
if(shouldPlaySound() && SoundHandler.canRestartSound(getSound()) && client.enableMachineSounds)
if(shouldPlaySound() && getSound().canRestart() && client.enableMachineSounds)
{
getSound().reset();
SoundHandler.playSound(getSound());
getSound().play();
}
}
}

View file

@ -6,17 +6,16 @@ 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.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 +23,7 @@ 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;

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;
@ -53,7 +51,7 @@ public class TileEntityReactorController extends TileEntityReactorBlock implemen
public ResourceLocation soundURL = new ResourceLocation("mekanism", "tile.machine.fusionreactor");
@SideOnly(Side.CLIENT)
public IResettableSound sound;
public SoundWrapper sound;
public double clientTemp = 0;
public boolean clientBurning = false;
@ -128,10 +126,10 @@ public class TileEntityReactorController extends TileEntityReactorBlock implemen
@SideOnly(Side.CLIENT)
public void updateSound()
{
if(shouldPlaySound() && SoundHandler.canRestartSound(getSound()) && client.enableMachineSounds)
if(shouldPlaySound() && getSound().canRestart() && client.enableMachineSounds)
{
getSound().reset();
SoundHandler.playSound(getSound());
getSound().play();
}
}
@ -335,7 +333,7 @@ public class TileEntityReactorController extends TileEntityReactorBlock implemen
@Override
@SideOnly(Side.CLIENT)
public IResettableSound getSound()
public SoundWrapper getSound()
{
return sound;
}
@ -410,6 +408,6 @@ public class TileEntityReactorController extends TileEntityReactorBlock implemen
@SideOnly(Side.CLIENT)
public void initSounds()
{
sound = new TileSound(this, this);
sound = new SoundWrapper(this, this);
}
}