Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/main/java/com/mrcrayfish/guns/GunConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -294,13 +294,20 @@ public static class Deafen
public EffectCriteria criteria = new EffectCriteria(15, 280, 100, 360, 0.75, false);

@Config.Name("Sound Percentage")
@Config.Comment("Volume of most game sounds when deafened will play at this percent, before eventually fading back to %100.")
@Config.Comment("Volume of game sounds when deafened will play at this percent, before eventually fading back to %100.")
@Config.LangKey(PREFIX + ".sound.percentage")
@Config.RangeDouble(min = 0, max = 1)
@Config.RequiresWorldRestart
public double soundPercentage = 0.05;
public static float soundPercentageSynced = 0;

@Config.Name("Effect All Sounds")
@Config.Comment("If true, all sounds will be reduced when deafened -- even the ringing sound and the sound of the initial deafening explosion.")
@Config.LangKey(PREFIX + ".sound.effect_all")
@Config.RequiresWorldRestart
public boolean effectAllSounds = false;
public static boolean effectAllSoundsSynced = true;

@Config.Name("Sound Fade Threshold")
@Config.Comment("After the duration drops to this many ticks, the ringing volume will gradually fade to 0 and other sound volumes will fade back to %100.")
@Config.LangKey(PREFIX + ".sound.fade")
Expand Down Expand Up @@ -378,6 +385,7 @@ public static class SyncedData
private ImmutableMap<String, ServerGun> serverGunMap;
private int blindnessAlphaOverlay, alphaFadeThreshold, soundFadeThreshold;
private float soundPercentage, ringVolume;
private boolean effectAllSounds;

public void toBytes(ByteBuf buffer)
{
Expand All @@ -393,6 +401,7 @@ public void toBytes(ByteBuf buffer)
buffer.writeFloat((float) GunConfig.SERVER.stunGrenades.deafen.soundPercentage);
buffer.writeInt(GunConfig.SERVER.stunGrenades.deafen.soundFadeThreshold);
buffer.writeFloat((float) GunConfig.SERVER.stunGrenades.deafen.ringVolume);
buffer.writeBoolean(GunConfig.SERVER.stunGrenades.deafen.effectAllSounds);
}

public void fromBytes(ByteBuf buffer)
Expand All @@ -413,6 +422,7 @@ public void fromBytes(ByteBuf buffer)
soundPercentage = buffer.readFloat();
soundFadeThreshold = buffer.readInt();
ringVolume = buffer.readFloat();
effectAllSounds = buffer.readBoolean();
}

public void syncClientToServer()
Expand All @@ -423,6 +433,7 @@ public void syncClientToServer()
GunConfig.SERVER.stunGrenades.deafen.soundPercentageSynced = soundPercentage;
GunConfig.SERVER.stunGrenades.deafen.soundFadeThresholdSynced = soundFadeThreshold;
GunConfig.SERVER.stunGrenades.deafen.ringVolumeSynced = ringVolume;
GunConfig.SERVER.stunGrenades.deafen.effectAllSoundsSynced = effectAllSounds;
}
}

Expand Down
32 changes: 29 additions & 3 deletions src/main/java/com/mrcrayfish/guns/client/event/SoundEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import javax.annotation.Nullable;

import com.mrcrayfish.guns.GunConfig;
import com.mrcrayfish.guns.MrCrayfishGunMod;
import com.mrcrayfish.guns.Reference;
import com.mrcrayfish.guns.client.audio.SoundRinging;
import com.mrcrayfish.guns.init.ModPotions;
Expand Down Expand Up @@ -43,6 +42,7 @@ public class SoundEvents
private static Field soundSystem, playingSounds;
private static SoundManager soundManager;
private static SoundRinging ringing;
private static float masterVolume = -1;

public static void initReflection()
{
Expand Down Expand Up @@ -75,6 +75,31 @@ public static void deafenPlayer(ClientTickEvent event)
}
}

float percent = GunConfig.SERVER.stunGrenades.deafen.soundPercentageSynced;
if (percent == 1)
return;

if (GunConfig.SERVER.stunGrenades.deafen.effectAllSoundsSynced)
{
// Mute all game sounds -- including the ringing sound and the sound of the initial deafening explosion
if (effect != null)
{
if (masterVolume < 0)
masterVolume = Minecraft.getMinecraft().gameSettings.getSoundLevel(SoundCategory.MASTER);

Minecraft.getMinecraft().getSoundHandler().setSoundLevel(SoundCategory.MASTER, getMutedVolume(effect.getDuration(), masterVolume));
isDeafened = true;
}
else if (isDeafened)
{
// Restore sound levels to initial values
isDeafened = false;
Minecraft.getMinecraft().getSoundHandler().setSoundLevel(SoundCategory.MASTER, masterVolume);
masterVolume = -1;
}
return;
}

// Access the sound manager's sound system and list of playing sounds
SoundSystem soundSystem;
Map<String, ISound> playingSounds;
Expand Down Expand Up @@ -108,7 +133,7 @@ public static void deafenPlayer(ClientTickEvent event)
soundSystem.setVolume(id, getMutedVolume(effect.getDuration(), SOUND_VOLUMES.get(id)));
}
}
catch (ConcurrentModificationException e) {} //SoundManager#playingSounds is accessed from another thread, so it's key set iterator can throw a CME
catch (ConcurrentModificationException e) {} // SoundManager#playingSounds is accessed from another thread, so it's key set iterator can throw a CME
isDeafened = true;
}
else if (isDeafened)
Expand All @@ -128,7 +153,8 @@ public static void lowerInitialVolume(PlaySoundEvent event)
if (soundManager == null)
soundManager = event.getManager();

if (!isDeafened || Minecraft.getMinecraft().player == null || event.getSound() instanceof ITickableSound)
if (!isDeafened || GunConfig.SERVER.stunGrenades.deafen.soundPercentageSynced == 1 || GunConfig.SERVER.stunGrenades.deafen.effectAllSoundsSynced
|| Minecraft.getMinecraft().player == null || event.getSound() instanceof ITickableSound)
return;

// Exempt initial explosion from muting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.Vec3d;
import org.lwjgl.opengl.GL11;

import javax.annotation.Nullable;
Expand Down Expand Up @@ -47,15 +46,19 @@ public void doRender(EntityGrenade entity, double x, double y, double z, float e
GlStateManager.rotate(entityYaw, 0, 1, 0);

float rotation = entity.prevRotation + (entity.rotation - entity.prevRotation) * partialTicks;
GlStateManager.translate(0, 0.15, 0);
float offset = 0;
if (entity instanceof EntityGrenadeStun)
offset = entity.height / 1.5F;

GlStateManager.translate(0, 0.15 - offset * 0.5, 0);
GlStateManager.rotate(-rotation, 1, 0, 0);
GlStateManager.translate(0, -0.15, 0);

if(entity instanceof EntityGrenadeStun)
if(offset > 0)
{
GlStateManager.translate(0, 0.3, 0);
GlStateManager.rotate(-90F, 0, 0, 1);
GlStateManager.translate(0, -((EntityGrenadeStun) entity).height / 2, 0);
GlStateManager.translate(0, offset, 0);
GlStateManager.rotate(90.F, 0, 0, 1);
GlStateManager.translate(0, -offset, 0);
}

GlStateManager.translate(-0.5, 0, -0.5);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/mrcrayfish/guns/entity/EntityGrenade.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ public void onUpdate()
rotation += speed * 50;
}

world.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, posX, posY + 0.25, posZ, 0, 0, 0, 10);
float offset = this instanceof EntityGrenadeStun ? 0.25F / 3.0F : 0.25F;
world.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, posX, posY + offset, posZ, 0, 0, 0, 10);
}

@Override
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/assets/cgm/lang/en_us.lang
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ config.cgm.server.grenade.stun.blind.overlay.fade.tooltip=Transparency of the ov
config.cgm.server.grenade.stun.effect_criteria.deafen=Effect Criteria
config.cgm.server.grenade.stun.effect_criteria.deafen.tooltip=Criteria that determines the presence/absence and duration of the deafening effect.
config.cgm.server.grenade.stun.deafen.sound.percentage=Sound Percentage
config.cgm.server.grenade.stun.deafen.sound.percentage.tooltip=Volume of most game sounds when deafened will play at this percent, before eventually fading back to %100.
config.cgm.server.grenade.stun.deafen.sound.percentage.tooltip=Volume of game sounds when deafened will play at this percent, before eventually fading back to %100.
config.cgm.server.grenade.stun.deafen.sound.effect_all=Effect All Sounds
config.cgm.server.grenade.stun.deafen.sound.effect_all.tooltip=If true, all sounds will be reduced when deafened -- even the ringing sound and the sound of the initial deafening explosion.
config.cgm.server.grenade.stun.deafen.sound.fade=Sound Fade Threshold
config.cgm.server.grenade.stun.deafen.sound.fade.tooltip=After the duration drops to this many ticks, the ringing volume will gradually fade to 0 and other sound volumes will fade back to %100.
config.cgm.server.grenade.stun.deafen.sound.ring=Ring Volume
Expand Down