Earmuffs work better with mechanical multiblocks now

This commit is contained in:
malte0811 2018-06-13 18:29:10 +02:00
parent 781ed3d773
commit 63603d12f1
2 changed files with 54 additions and 22 deletions

View file

@ -195,10 +195,7 @@ public class ClientProxy extends CommonProxy {
); );
} }
} }
int oldLength = Config.IEConfig.Tools.earDefenders_SoundBlacklist.length; addUnblockableSounds(TINNITUS_LOC, TURN_FAST, TURN_SLOW);
Config.IEConfig.Tools.earDefenders_SoundBlacklist =
Arrays.copyOf(Config.IEConfig.Tools.earDefenders_SoundBlacklist, oldLength + 1);
Config.IEConfig.Tools.earDefenders_SoundBlacklist[oldLength] = TINNITUS_LOC.toString();
ClientUtils.mc().getItemColors().registerItemColorHandler((stack, pass) -> { ClientUtils.mc().getItemColors().registerItemColorHandler((stack, pass) -> {
if (pass == 1) { if (pass == 1) {
@ -321,8 +318,16 @@ public class ClientProxy extends CommonProxy {
ClientCommandHandler.instance.registerCommand(new CommandIWClient()); ClientCommandHandler.instance.registerCommand(new CommandIWClient());
} }
private static final ResourceLocation TINNITUS_LOC = new ResourceLocation(IndustrialWires.MODID, "tinnitus");
private static ISound playingTinnitus = null; private static ISound playingTinnitus = null;
private void addUnblockableSounds(ResourceLocation... sounds) {
int oldLength = Config.IEConfig.Tools.earDefenders_SoundBlacklist.length;
Config.IEConfig.Tools.earDefenders_SoundBlacklist =
Arrays.copyOf(Config.IEConfig.Tools.earDefenders_SoundBlacklist, oldLength + sounds.length);
for (int i = 0;i<sounds.length;i++) {
Config.IEConfig.Tools.earDefenders_SoundBlacklist[oldLength+i] = sounds[i].toString();
}
}
@Override @Override
public void startTinnitus() { public void startTinnitus() {
final Minecraft mc = Minecraft.getMinecraft(); final Minecraft mc = Minecraft.getMinecraft();
@ -376,13 +381,14 @@ public class ClientProxy extends CommonProxy {
} }
private Map<BlockPos, List<ISound>> playingSounds = new HashMap<>(); private Map<BlockPos, List<ISound>> playingSounds = new HashMap<>();
private static ResourceLocation jacobsStart = new ResourceLocation(IndustrialWires.MODID, "jacobs_ladder_start");//~470 ms ~=9 ticks private static final ResourceLocation TINNITUS_LOC = new ResourceLocation(IndustrialWires.MODID, "tinnitus");
private static ResourceLocation jacobsMiddle = new ResourceLocation(IndustrialWires.MODID, "jacobs_ladder_middle"); private static final ResourceLocation LADDER_START = new ResourceLocation(IndustrialWires.MODID, "jacobs_ladder_start");//~470 ms ~=9 ticks
private static ResourceLocation jacobsEnd = new ResourceLocation(IndustrialWires.MODID, "jacobs_ladder_end");//~210 ms ~= 4 ticks private static final ResourceLocation LADDER_MIDDLE = new ResourceLocation(IndustrialWires.MODID, "jacobs_ladder_middle");
private static ResourceLocation marxBang = new ResourceLocation(IndustrialWires.MODID, "marx_bang"); private static final ResourceLocation LADDER_END = new ResourceLocation(IndustrialWires.MODID, "jacobs_ladder_end");//~210 ms ~= 4 ticks
private static ResourceLocation marxPop = new ResourceLocation(IndustrialWires.MODID, "marx_pop"); private static final ResourceLocation MARX_BANG = new ResourceLocation(IndustrialWires.MODID, "marx_bang");
private static ResourceLocation turnFast = new ResourceLocation(IndustrialWires.MODID, "mech_mb_fast"); private static final ResourceLocation MARX_POP = new ResourceLocation(IndustrialWires.MODID, "marx_pop");
private static ResourceLocation turnSlow = new ResourceLocation(IndustrialWires.MODID, "mech_mb_slow"); private static final ResourceLocation TURN_FAST = new ResourceLocation(IndustrialWires.MODID, "mech_mb_fast");
private static final ResourceLocation TURN_SLOW = new ResourceLocation(IndustrialWires.MODID, "mech_mb_slow");
@Override @Override
public void playJacobsLadderSound(TileEntityJacobsLadder te, int phase, Vec3d soundPos) { public void playJacobsLadderSound(TileEntityJacobsLadder te, int phase, Vec3d soundPos) {
@ -390,13 +396,13 @@ public class ClientProxy extends CommonProxy {
ResourceLocation event; ResourceLocation event;
switch (phase) { switch (phase) {
case 0: case 0:
event = jacobsStart; event = LADDER_START;
break; break;
case 1: case 1:
event = jacobsMiddle; event = LADDER_MIDDLE;
break; break;
case 2: case 2:
event = jacobsEnd; event = LADDER_END;
break; break;
default: default:
return; return;
@ -422,20 +428,20 @@ public class ClientProxy extends CommonProxy {
} }
boolean hasSlow = false, hasFast = false; boolean hasSlow = false, hasFast = false;
for (ISound s:soundsAtPos) { for (ISound s:soundsAtPos) {
if (s.getSoundLocation().equals(turnFast)) { if (s.getSoundLocation().equals(TURN_FAST)) {
hasFast = true; hasFast = true;
} else if (s.getSoundLocation().equals(turnSlow)) { } else if (s.getSoundLocation().equals(TURN_SLOW)) {
hasSlow = true; hasSlow = true;
} }
} }
if (!hasSlow && energy.getVolumeSlow() > 0) { if (!hasSlow && energy.getVolumeSlow() > 0) {
ISound snd = new IWTickableSound(turnSlow, SoundCategory.BLOCKS, energy::getVolumeSlow, energy::getPitch, ISound snd = new IWTickableSound(TURN_SLOW, SoundCategory.BLOCKS, energy::getVolumeSlow, energy::getPitch,
te.getPos().getX(), te.getPos().getY(), te.getPos().getZ()); te.getPos().getX(), te.getPos().getY(), te.getPos().getZ());
sndHandler.playSound(snd); sndHandler.playSound(snd);
addSound(te.getPos(), snd); addSound(te.getPos(), snd);
} }
if (!hasFast && energy.getVolumeFast() > 0) { if (!hasFast && energy.getVolumeFast() > 0) {
ISound snd = new IWTickableSound(turnFast, SoundCategory.BLOCKS, energy::getVolumeFast, energy::getPitch, ISound snd = new IWTickableSound(TURN_FAST, SoundCategory.BLOCKS, energy::getVolumeFast, energy::getPitch,
te.getPos().getX(), te.getPos().getY(), te.getPos().getZ()); te.getPos().getX(), te.getPos().getY(), te.getPos().getZ());
sndHandler.playSound(snd); sndHandler.playSound(snd);
addSound(te.getPos(), snd); addSound(te.getPos(), snd);
@ -444,10 +450,10 @@ public class ClientProxy extends CommonProxy {
@Override @Override
public void playMarxBang(TileEntityMarx te, Vec3d pos, float energy) { public void playMarxBang(TileEntityMarx te, Vec3d pos, float energy) {
ResourceLocation soundLoc = marxBang; ResourceLocation soundLoc = MARX_BANG;
if (energy<0) { if (energy<0) {
energy = -energy; energy = -energy;
soundLoc = marxPop; soundLoc = MARX_POP;
} }
PositionedSoundRecord sound = new PositionedSoundRecord(soundLoc, SoundCategory.BLOCKS, 5*energy, 1, PositionedSoundRecord sound = new PositionedSoundRecord(soundLoc, SoundCategory.BLOCKS, 5*energy, 1,
false, 0, ISound.AttenuationType.LINEAR, (float) pos.x, (float) pos.y, (float) pos.z); false, 0, ISound.AttenuationType.LINEAR, (float) pos.x, (float) pos.y, (float) pos.z);

View file

@ -15,8 +15,15 @@
package malte0811.industrialWires.client; package malte0811.industrialWires.client;
import blusunrize.immersiveengineering.api.Lib;
import blusunrize.immersiveengineering.common.IEContent;
import blusunrize.immersiveengineering.common.items.ItemEarmuffs;
import blusunrize.immersiveengineering.common.util.ItemNBTHelper;
import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.ITickableSound; import net.minecraft.client.audio.ITickableSound;
import net.minecraft.client.audio.PositionedSound; import net.minecraft.client.audio.PositionedSound;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundCategory; import net.minecraft.util.SoundCategory;
@ -49,9 +56,28 @@ public class IWTickableSound extends PositionedSound implements ITickableSound {
//NOP //NOP
} }
//This can be static as it's the same for all sounds
private static float mod = 1;
private static long lastCheck = Long.MIN_VALUE;
private static final int UPDATE_FREQU = 5;
@Override @Override
public float getVolume() { public float getVolume() {
return getVolume.get(); Minecraft mc = Minecraft.getMinecraft();
long time = mc.world.getTotalWorldTime();
// Earmuffs don't work well for long sounds
// so I adjust the volume manually and blacklist the sounds from the "normal" muffling
if (time>lastCheck+UPDATE_FREQU) {
mod = 1;
lastCheck = time;
ItemStack earmuffs = mc.player.getItemStackFromSlot(EntityEquipmentSlot.HEAD);
if (ItemNBTHelper.hasKey(earmuffs, Lib.NBT_Earmuffs))
earmuffs = ItemNBTHelper.getItemStack(earmuffs, Lib.NBT_Earmuffs);
if (!earmuffs.isEmpty() && IEContent.itemEarmuffs.equals(earmuffs.getItem()) &&
!ItemNBTHelper.getBoolean(earmuffs, "IE:Earmuffs:Cat_" + category.getName())) {
mod = ItemEarmuffs.getVolumeMod(earmuffs);
}
}
return mod*getVolume.get();
} }
@Override @Override