diff --git a/gradle.properties b/gradle.properties index 722c636..48039a3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,7 +5,7 @@ org.gradle.configuration-cache=false # Mod mod_id=video_player -mod_version=0.4.21 +mod_version=0.4.22 maven_group=com.ejclaw.videoplayer archives_base_name=video_player diff --git a/src/main/java/com/ejclaw/videoplayer/VideoPlayerClient.java b/src/main/java/com/ejclaw/videoplayer/VideoPlayerClient.java index 6911ae7..97d4b7a 100644 --- a/src/main/java/com/ejclaw/videoplayer/VideoPlayerClient.java +++ b/src/main/java/com/ejclaw/videoplayer/VideoPlayerClient.java @@ -20,6 +20,7 @@ import net.fabricmc.fabric.api.event.player.AttackBlockCallback; import net.minecraft.client.Minecraft; import net.minecraft.client.player.LocalPlayer; import net.minecraft.core.BlockPos; +import net.minecraft.sounds.SoundSource; import net.minecraft.world.InteractionResult; import net.minecraft.world.phys.Vec3; @@ -89,17 +90,26 @@ public class VideoPlayerClient implements ClientModInitializer { * Distance is measured from the player's eye to the panel center, not the anchor * block corner — for a 4×4 panel the corner is ~2 blocks off from where the screen visually * sits, which made the audio feel like it was off to the side. + * + *
Gain is also gated by the Minecraft sound options so the in-game sliders work as + * expected: vanilla {@code SoundEngine.calculateVolume} multiplies by master × category, so + * we do the same with {@link SoundSource#PLAYERS} as the category. Result: dragging the + * "Players" slider in Options → Music & Sounds attenuates video audio just like other + * player sounds, and "Master" still gates everything. */ private static void updateDistanceGains(Minecraft client) { LocalPlayer p = client.player; if (p == null || client.level == null) return; Vec3 eye = p.getEyePosition(); + float masterVol = client.options.getSoundSourceVolume(SoundSource.MASTER); + float playersVol = client.options.getSoundSourceVolume(SoundSource.PLAYERS); + float categoryScale = masterVol * playersVol; for (BlockPos pos : VideoPlayback.activePositions()) { if (!(client.level.getBlockEntity(pos) instanceof VideoAnchorBlockEntity be)) continue; Vec3 center = be.panelCenter(); double d = center.distanceTo(eye); float attenuation = (float) Math.max(0.0, Math.min(1.0, 1.0 - d / 16.0)); - float gain = be.isMuted() ? 0F : be.getVolume() * attenuation; + float gain = be.isMuted() ? 0F : be.getVolume() * attenuation * categoryScale; VideoPlayback.setGain(pos, gain); } }