Skip to content

Commit 0ced439

Browse files
committed
bug fix
1 parent 71334c0 commit 0ced439

10 files changed

Lines changed: 190 additions & 33 deletions

File tree

src/main/java/cn/ussshenzhou/channel/audio/client/receive/PlayerAudio.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
import cn.ussshenzhou.channel.audio.client.rt.RayTraceManager;
44
import cn.ussshenzhou.channel.config.ChannelClientConfig;
5+
import cn.ussshenzhou.channel.config.ChannelPlayerConfig;
6+
import cn.ussshenzhou.channel.gui.OutputConfigPanel;
57
import cn.ussshenzhou.channel.util.AudioHelper;
68
import com.mojang.logging.LogUtils;
79
import io.netty.util.internal.shaded.org.jctools.queues.MpscArrayQueue;
10+
import net.minecraft.client.Minecraft;
11+
import net.minecraft.world.entity.player.Player;
812

913
import javax.annotation.Nullable;
1014
import java.nio.ByteBuffer;
@@ -88,6 +92,10 @@ public void checkTooMuchDelay() {
8892
}
8993

9094
public void play() {
95+
var vol = ChannelPlayerConfig.getOrDefault(playerId);
96+
alSourcef(alSource, AL_GAIN, AudioHelper.db2factor(vol));
97+
OutputConfigPanel.PlayerVolumePanel.update(playerId, vol);
98+
9199
int processed = alGetSourcei(alSource, AL_BUFFERS_PROCESSED);
92100
while (processed-- > 0) {
93101
int buf = alSourceUnqueueBuffers(alSource);

src/main/java/cn/ussshenzhou/channel/audio/client/receive/TalkManager.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import cn.ussshenzhou.channel.audio.client.rt.RayTraceManager;
44
import cn.ussshenzhou.channel.config.ChannelClientConfig;
55
import cn.ussshenzhou.channel.config.ChannelPlayerConfig;
6+
import cn.ussshenzhou.channel.gui.OutputConfigPanel;
67
import cn.ussshenzhou.channel.util.AudioHelper;
78
import net.minecraft.client.Minecraft;
89
import net.minecraft.world.entity.Entity;
@@ -38,9 +39,6 @@ protected boolean play(Level level, UUID playerId, PlayerAudio audio) {
3839

3940
private void simplePlay(PlayerAudio audio, Vec3 pos, Entity player) {
4041
alSource3f(audio.alSource, AL_POSITION, (float) pos.x, (float) pos.y, (float) pos.z);
41-
if (player instanceof Player p) {
42-
alSourcef(audio.alSource, AL_GAIN, AudioHelper.db2factor(ChannelPlayerConfig.getOrDefault(p)));
43-
}
4442
audio.play();
4543
}
4644
}

src/main/java/cn/ussshenzhou/channel/config/ChannelClientConfig.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public class ChannelClientConfig implements TConfig {
3434
public String nvidiaDllPath = "";
3535
public Unit unit = Unit.DB;
3636
public boolean rayTraceAudio = true;
37+
public float outputAdjust = 0;
3738

3839
public static ChannelClientConfig get() {
3940
return ConfigHelper.getConfigRead(ChannelClientConfig.class);

src/main/java/cn/ussshenzhou/channel/config/ChannelPlayerConfig.java

Lines changed: 77 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,16 @@
33
import cn.ussshenzhou.channel.gui.OutputConfigPanel;
44
import cn.ussshenzhou.t88.config.ConfigHelper;
55
import cn.ussshenzhou.t88.config.TConfig;
6+
import com.google.gson.TypeAdapter;
7+
import com.google.gson.annotations.JsonAdapter;
8+
import com.google.gson.stream.JsonReader;
9+
import com.google.gson.stream.JsonToken;
10+
import com.google.gson.stream.JsonWriter;
611
import net.minecraft.world.entity.player.Player;
712

13+
import java.io.IOException;
814
import java.util.HashMap;
15+
import java.util.UUID;
916
import java.util.function.Consumer;
1017

1118
/**
@@ -14,23 +21,87 @@
1421
@SuppressWarnings("FieldMayBeFinal")
1522
public class ChannelPlayerConfig implements TConfig {
1623

17-
private HashMap<String, Float> playerVolumeAdjust = new HashMap<>();
24+
private HashMap<PlayerId, Float> playerVolumeAdjust = new HashMap<>();
1825

19-
public static float getOrDefault(Player player) {
20-
float r = get().playerVolumeAdjust.computeIfAbsent(player.getGameProfile().name(), name -> 0f);
21-
OutputConfigPanel.PlayerVolumePanel.add(player.getUUID(), r);
22-
return r;
26+
public static float getOrDefault(UUID uuid) {
27+
var cfg = get();
28+
var p = new PlayerId(uuid, "UNKNOWN");
29+
if (cfg.playerVolumeAdjust.containsKey(p)) {
30+
return cfg.playerVolumeAdjust.get(p);
31+
}
32+
return ChannelClientConfig.get().outputAdjust;
2333
}
2434

2535
public static void set(Player player, float db) {
26-
write(thiz -> thiz.playerVolumeAdjust.put(player.getGameProfile().name(), db));
36+
write(thiz -> thiz.playerVolumeAdjust.put(PlayerId.from(player), db));
2737
}
2838

2939
private static ChannelPlayerConfig get() {
3040
return ConfigHelper.getConfigRead(ChannelPlayerConfig.class);
3141
}
3242

43+
public static void clear() {
44+
write(thiz -> thiz.playerVolumeAdjust.clear());
45+
}
46+
3347
private static void write(Consumer<ChannelPlayerConfig> writer) {
3448
ConfigHelper.getConfigWrite(ChannelPlayerConfig.class, writer);
3549
}
50+
51+
@JsonAdapter(PlayerIdAdapter.class)
52+
public static class PlayerId {
53+
private UUID uuid;
54+
private String name;
55+
56+
public PlayerId(UUID uuid, String name) {
57+
this.uuid = uuid;
58+
this.name = name;
59+
}
60+
61+
public static PlayerId from(Player player) {
62+
return new PlayerId(player.getUUID(), player.getGameProfile().name());
63+
}
64+
65+
@Override
66+
public boolean equals(Object obj) {
67+
if (obj == this) {
68+
return true;
69+
}
70+
return obj instanceof PlayerId p && p.uuid.equals(uuid);
71+
}
72+
73+
@Override
74+
public int hashCode() {
75+
return uuid.hashCode();
76+
}
77+
}
78+
79+
public static class PlayerIdAdapter extends TypeAdapter<PlayerId> {
80+
@Override
81+
public void write(JsonWriter out, PlayerId value) throws IOException {
82+
if (value == null) {
83+
out.nullValue();
84+
return;
85+
}
86+
out.value(value.name + "|" + value.uuid.toString());
87+
}
88+
89+
@Override
90+
public PlayerId read(JsonReader in) throws IOException {
91+
if (in.peek() == JsonToken.NULL) {
92+
in.nextNull();
93+
return null;
94+
}
95+
String str = in.nextString();
96+
97+
int separatorIndex = str.lastIndexOf('|');
98+
if (separatorIndex != -1) {
99+
String name = str.substring(0, separatorIndex);
100+
UUID uuid = UUID.fromString(str.substring(separatorIndex + 1));
101+
return new PlayerId(uuid, name);
102+
} else {
103+
return new PlayerId(UUID.fromString(str), "UNKNOWN");
104+
}
105+
}
106+
}
36107
}

src/main/java/cn/ussshenzhou/channel/gui/OutputConfigPanel.java

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,22 @@
11
package cn.ussshenzhou.channel.gui;
22

3-
import cn.ussshenzhou.channel.Channel;
4-
import cn.ussshenzhou.channel.audio.NC;
5-
import cn.ussshenzhou.channel.audio.Trigger;
6-
import cn.ussshenzhou.channel.audio.Vad;
73
import cn.ussshenzhou.channel.audio.client.receive.AudioManagerManager;
8-
import cn.ussshenzhou.channel.audio.client.send.LevelGatherer;
9-
import cn.ussshenzhou.channel.audio.client.send.MicManager;
10-
import cn.ussshenzhou.channel.audio.client.send.WebRTCHelper;
11-
import cn.ussshenzhou.channel.audio.nativ.NvidiaHelper;
124
import cn.ussshenzhou.channel.config.ChannelClientConfig;
135
import cn.ussshenzhou.channel.config.ChannelPlayerConfig;
14-
import cn.ussshenzhou.channel.util.AudioHelper;
15-
import cn.ussshenzhou.channel.util.ModConstant;
166
import cn.ussshenzhou.t88.gui.advanced.TOptionsPanel;
17-
import cn.ussshenzhou.t88.gui.notification.TSimpleNotification;
18-
import cn.ussshenzhou.t88.gui.util.ImageFit;
197
import cn.ussshenzhou.t88.gui.widegt.*;
208
import net.minecraft.client.Minecraft;
219
import net.minecraft.client.gui.GuiGraphics;
2210
import net.minecraft.client.gui.components.PlayerFaceRenderer;
2311
import net.minecraft.client.gui.components.Tooltip;
2412
import net.minecraft.network.chat.Component;
25-
import net.minecraft.resources.Identifier;
26-
import net.minecraft.util.Mth;
2713
import net.neoforged.api.distmarker.Dist;
2814
import net.neoforged.bus.api.SubscribeEvent;
2915
import net.neoforged.fml.common.EventBusSubscriber;
3016
import net.neoforged.neoforge.client.event.ClientPlayerNetworkEvent;
3117
import org.joml.Vector2i;
3218

33-
import javax.sound.sampled.*;
3419
import java.util.*;
35-
import java.util.stream.Stream;
3620

3721
/**
3822
* @author USS_Shenzhou
@@ -51,7 +35,21 @@ public OutputConfigPanel() {
5135
entry -> entry.getContent() == cfg.rayTraceAudio
5236
).getB().setTooltip(Tooltip.create(Component.translatable("channel.config.post.rt.tooltip")));
5337

38+
addOptionSplitter(Component.translatable("channel.config.post.control"));
39+
addOptionSliderDoubleInit(Component.translatable("channel.config.post.control_adjust"),
40+
-30, 30,
41+
(_, v) -> Component.literal(cfg.unit.get(v)),
42+
Component.translatable("channel.config.post.control_adjust.tooltip"),
43+
(slider, _) -> {
44+
ChannelClientConfig.write(c -> c.outputAdjust = (float) slider.getAbsValue());
45+
},
46+
cfg.outputAdjust, false
47+
);
5448
addOptionSplitter(Component.translatable("channel.config.post.player_control"));
49+
addOption(Component.empty(), new TButton(Component.translatable("channel.config.post.player_control_clear"), _ -> {
50+
ChannelPlayerConfig.clear();
51+
PlayerVolumePanel.PLAYER_VOLUME.replaceAll((_, _) -> 0f);
52+
})).getB().setTooltip(Tooltip.create(Component.translatable("channel.config.post.player_control_clear.tooltip")));
5553
this.container.add(new PlayerVolumePanel());
5654
}
5755

@@ -64,10 +62,10 @@ public static class PlayerVolumePanel extends TPanel {
6462

6563
public PlayerVolumePanel() {
6664
// FIXME remove
67-
add(Minecraft.getInstance().player.getUUID(), 0);
65+
update(Minecraft.getInstance().player.getUUID(), 0);
6866
}
6967

70-
public static void add(UUID id, float db) {
68+
public static void update(UUID id, float db) {
7169
PLAYER_VOLUME.put(id, db);
7270
dirty = true;
7371
}
@@ -78,7 +76,7 @@ public static void onLogout(ClientPlayerNetworkEvent.LoggingOut event) {
7876
dirty = true;
7977
}
8078

81-
private void update() {
79+
private void refresh() {
8280
if (!dirty) {
8381
return;
8482
}
@@ -88,9 +86,14 @@ private void update() {
8886
layout();
8987
}
9088

89+
@Override
90+
public Vector2i getPreferredSize() {
91+
return new Vector2i(0, 20 * PLAYER_VOLUME.size());
92+
}
93+
9194
@Override
9295
public void tickT() {
93-
update();
96+
refresh();
9497
super.tickT();
9598
}
9699

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package cn.ussshenzhou.channel.mixin;
2+
3+
import net.minecraft.core.Direction;
4+
import net.minecraft.world.phys.shapes.BitSetDiscreteVoxelShape;
5+
import net.minecraft.world.phys.shapes.DiscreteVoxelShape;
6+
import org.spongepowered.asm.mixin.Mixin;
7+
import org.spongepowered.asm.mixin.Unique;
8+
import org.spongepowered.asm.mixin.injection.At;
9+
import org.spongepowered.asm.mixin.injection.Redirect;
10+
11+
import java.util.BitSet;
12+
13+
/**
14+
* @author USS_Shenzhou
15+
*/
16+
@Mixin(value = BitSetDiscreteVoxelShape.class, priority = 9999)
17+
public abstract class BitSetDiscreteVoxelShapeMixin extends DiscreteVoxelShape {
18+
@Unique
19+
private static final ThreadLocal<BitSetDiscreteVoxelShape> LOCAL_THIS = ThreadLocal.withInitial(() -> new BitSetDiscreteVoxelShape(0, 0, 0));
20+
21+
protected BitSetDiscreteVoxelShapeMixin(int xSize, int ySize, int zSize) {
22+
super(xSize, ySize, zSize);
23+
}
24+
25+
@Redirect(method = "forAllBoxes", at = @At(value = "NEW", target = "net/minecraft/world/phys/shapes/BitSetDiscreteVoxelShape"), require = 0)
26+
private static BitSetDiscreteVoxelShape channelUseThreadLocalInstead(DiscreteVoxelShape voxelShape) {
27+
var instance = LOCAL_THIS.get();
28+
29+
if (voxelShape.xSize >= 0 && voxelShape.ySize >= 0 && voxelShape.zSize >= 0) {
30+
instance.xSize = voxelShape.xSize;
31+
instance.ySize = voxelShape.ySize;
32+
instance.zSize = voxelShape.zSize;
33+
} else {
34+
throw new IllegalArgumentException("Need all positive sizes: x: " + voxelShape.xSize + ", y: " + voxelShape.ySize + ", z: " + voxelShape.zSize);
35+
}
36+
if (voxelShape instanceof BitSetDiscreteVoxelShape) {
37+
instance.storage = (BitSet) ((BitSetDiscreteVoxelShape) voxelShape).storage.clone();
38+
} else {
39+
instance.storage = new BitSet(instance.xSize * instance.ySize * instance.zSize);
40+
41+
for (int x = 0; x < instance.xSize; ++x) {
42+
for (int y = 0; y < instance.ySize; ++y) {
43+
for (int z = 0; z < instance.zSize; ++z) {
44+
if (voxelShape.isFull(x, y, z)) {
45+
instance.storage.set(instance.getIndex(x, y, z));
46+
}
47+
}
48+
}
49+
}
50+
}
51+
52+
instance.xMin = voxelShape.firstFull(Direction.Axis.X);
53+
instance.yMin = voxelShape.firstFull(Direction.Axis.Y);
54+
instance.zMin = voxelShape.firstFull(Direction.Axis.Z);
55+
instance.xMax = voxelShape.lastFull(Direction.Axis.X);
56+
instance.yMax = voxelShape.lastFull(Direction.Axis.Y);
57+
instance.zMax = voxelShape.lastFull(Direction.Axis.Z);
58+
59+
return instance;
60+
}
61+
62+
}

src/main/resources/META-INF/accesstransformer.cfg

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@ public net.minecraft.client.sounds.SoundEngine library # library
33
public com.mojang.blaze3d.audio.Library currentDevice # currentDevice
44
public com.mojang.blaze3d.audio.Library context # context
55
public net.minecraft.client.sounds.SoundEngine loaded # loaded
6-
public net.minecraft.client.sounds.SoundEngine executor
6+
public net.minecraft.client.sounds.SoundEngine executor
7+
public-f net.minecraft.world.phys.shapes.DiscreteVoxelShape *
8+
public-f net.minecraft.world.phys.shapes.BitSetDiscreteVoxelShape *
9+
public net.minecraft.world.phys.shapes.BitSetDiscreteVoxelShape getIndex(III)I

src/main/resources/assets/channel/lang/en_us.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,13 @@
8383
"channel.config.post": " Post-processing",
8484
"channel.config.post.rt": "Path Tracing",
8585
"channel.config.post.rt.tooltip": "§6Experimental Feature§r\nUse path tracing for a more realistic audio experience.\nWill consume additional CPU resources.",
86-
"channel.config.post.player_control": " Adjust Loudness Individually",
87-
"channel.config.post.player_control.tooltip": "Adjust the sound loudness of this person individually.\nA larger value makes the sound you hear louder.\n§6Not controlled by the limiter.",
86+
"channel.config.post.player_control": " Adjust Individual Loudness",
87+
"channel.config.post.player_control.tooltip": "Adjust the sound loudness of this person individually.\nWill override the overall loudness.\nA larger value makes the sound you hear louder.\n§6Not controlled by the limiter.",
88+
"channel.config.post.control": " Adjust Overall Loudness",
89+
"channel.config.post.control_adjust": "Adjust Overall Loudness",
90+
"channel.config.post.control_adjust.tooltip": "Adjust the sound loudness of all outputs.\nA larger value makes the sound you hear louder.\n§6Not controlled by the limiter.",
91+
"channel.config.post.player_control_clear": "§6Reset All",
92+
"channel.config.post.player_control_clear.tooltip": "Reset all individual loudness adjustments below.",
8893

8994
"channel.config.tab.general": "General",
9095
"Channel.config.unit": "Display Unit",

src/main/resources/assets/channel/lang/zh_cn.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,12 @@
8484
"channel.config.post.rt": "路径追踪",
8585
"channel.config.post.rt.tooltip": "§6实验性功能§r\n使用路径追踪来获得更真实的音频体验。\n会额外占用CPU资源。",
8686
"channel.config.post.player_control": " 单独调整响度",
87-
"channel.config.post.player_control.tooltip": "单独调整此人的声音响度。\n更大的值使你听到的的声音更响。\n§6不受限幅器控制。",
87+
"channel.config.post.player_control.tooltip": "单独调整此人的声音响度。\n将会覆盖总体响度。\n更大的值使你听到的的声音更响。\n§6不受限幅器控制。",
88+
"channel.config.post.control": " 整体调整响度",
89+
"channel.config.post.control_adjust": "整体调整响度",
90+
"channel.config.post.control_adjust.tooltip": "调整所有输出的声音响度。\n更大的值使你听到的的声音更响。\n§6不受限幅器控制。",
91+
"channel.config.post.player_control_clear": "§6重置全部",
92+
"channel.config.post.player_control_clear.tooltip": "重置以下全部单独调整响度。",
8893

8994
"channel.config.tab.general": "通用",
9095
"Channel.config.unit": "显示单位",

src/main/resources/channel.mixins.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"package": "cn.ussshenzhou.channel.mixin",
55
"compatibilityLevel": "JAVA_21",
66
"mixins": [
7+
"BitSetDiscreteVoxelShapeMixin",
78
"NativeLoaderMixin"
89
],
910
"client": [

0 commit comments

Comments
 (0)