From 66d218a59f69c23e3c649b4e8bdad8f2cacdffc2 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Thu, 21 Mar 2019 11:51:36 -0600 Subject: [PATCH] Fix #85; make sound so that it keeps running at least 10 ticks after machine stops to better deal with per-tick flipflops. Also revert ccd7ed0; UX got too weird. --- .../java/mekanism/client/sound/SoundHandler.java | 6 ------ .../common/tile/prefab/TileEntityEffectsBlock.java | 13 ++++++++++--- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/main/java/mekanism/client/sound/SoundHandler.java b/src/main/java/mekanism/client/sound/SoundHandler.java index ac8eeee79..62f49cf56 100644 --- a/src/main/java/mekanism/client/sound/SoundHandler.java +++ b/src/main/java/mekanism/client/sound/SoundHandler.java @@ -80,12 +80,6 @@ public class SoundHandler { } public static ISound startTileSound(ResourceLocation soundLoc, float volume, BlockPos pos) { - // Check to see if the game has focus; in SP mode sounds aren't paused until AFTER the game menu is displayed, - // which means that a sound can slip into queue after user has already paused the game. - if (!Minecraft.getMinecraft().inGameHasFocus) { - return null; - } - // First, check to see if there's already a sound playing at the desired location ISound s = soundMap.get(pos.toLong()); if (s == null || !Minecraft.getMinecraft().getSoundHandler().isSoundPlaying(s)) { diff --git a/src/main/java/mekanism/common/tile/prefab/TileEntityEffectsBlock.java b/src/main/java/mekanism/common/tile/prefab/TileEntityEffectsBlock.java index 0287b5228..25db993d6 100644 --- a/src/main/java/mekanism/common/tile/prefab/TileEntityEffectsBlock.java +++ b/src/main/java/mekanism/common/tile/prefab/TileEntityEffectsBlock.java @@ -46,7 +46,10 @@ public abstract class TileEntityEffectsBlock extends TileEntityElectricBlock imp super(name, maxEnergy); // TODO: Have subclasses pass in a static SoundEvent so we avoid per-instance # of SoundEvents for same sound - soundEvent = new SoundEvent(new ResourceLocation(Mekanism.MODID, "tile." + sound)); + // TODO: Factories don't currently pass in the right value for sound ID of wrapped machine; overhaul this. + if (!sound.equals("null")) { + soundEvent = new SoundEvent(new ResourceLocation(Mekanism.MODID, "tile." + sound)); + } } @@ -67,7 +70,7 @@ public abstract class TileEntityEffectsBlock extends TileEntityElectricBlock imp @SideOnly(Side.CLIENT) private void updateSound() { // If machine sounds are disabled, noop - if (!MekanismConfig.client.enableMachineSounds) { + if (!MekanismConfig.client.enableMachineSounds || soundEvent == null) { return; } @@ -84,7 +87,11 @@ public abstract class TileEntityEffectsBlock extends TileEntityElectricBlock imp playSoundCooldown = 20; } } else { - if (activeSound != null) { + // Determine how long the machine has been stopped (ala lighting changes). Don't try and stop the sound + // unless machine has been stopped at least half-a-second, so that machines which are rapidly flipping on/off + // just sound like they are continuously on. + long downtime = world.getTotalWorldTime() - lastActive; + if (activeSound != null && downtime > 10) { SoundHandler.stopTileSound(getPos()); activeSound = null; playSoundCooldown = 0;