diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientConnectionMixin.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientConnectionMixin.java index 7895307..854af0e 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientConnectionMixin.java +++ b/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientConnectionMixin.java @@ -49,6 +49,8 @@ public class ClientConnectionMixin { listener.packetReceived(packet); } + final MinecraftClient client = MinecraftClient.getInstance(); + // please don't skid this.,. // mabe mabe mabe if (packet instanceof ParticleS2CPacket t_packet) { @@ -58,40 +60,34 @@ public class ClientConnectionMixin { ci.cancel(); } } else if (packet instanceof PlaySoundS2CPacket t_packet) { + final SoundEvent soundEvent = t_packet.getSound().value(); + + final Identifier sound = soundEvent.getId(); + + final Matcher matcher = CUSTOM_PITCH_PATTERN.matcher(sound.getPath()); + + if (!matcher.find()) return; + try { - final SoundEvent soundEvent = t_packet.getSound().value(); + final String stringPitch = matcher.group(1); - final Identifier sound = soundEvent.getId(); + final float pitch = Float.parseFloat(stringPitch); - final Matcher matcher = CUSTOM_PITCH_PATTERN.matcher(sound.getPath()); + final ClientWorld world = client.world; - if (!matcher.find()) return; + if (world == null) return; - try { - final String stringPitch = matcher.group(1); + // huge mess + final SoundEvent newSound = SoundEvent.of(new Identifier(sound.getNamespace(), sound.getPath().substring(0, sound.getPath().length() - (".pitch." + stringPitch).length()))); - final float pitch = Float.parseFloat(stringPitch); + client.executeSync(() -> world.playSound(client.player, t_packet.getX(), t_packet.getY(), t_packet.getZ(), newSound, t_packet.getCategory(), t_packet.getVolume(), pitch, t_packet.getSeed())); - final MinecraftClient client = MinecraftClient.getInstance(); - - final ClientWorld world = client.world; - - if (world == null) return; - - // huge mess - final SoundEvent newSound = SoundEvent.of(new Identifier(sound.getNamespace(), sound.getPath().substring(0, sound.getPath().length() - (".pitch." + stringPitch).length()))); - - world.playSound(client.player, t_packet.getX(), t_packet.getY(), t_packet.getZ(), newSound, t_packet.getCategory(), t_packet.getVolume(), pitch, t_packet.getSeed()); - - ci.cancel(); - } catch (NumberFormatException e) { - e.printStackTrace(); - } - - if (t_packet.getVolume() == 1 && sound.getPath().equals("entity.enderman.scream")) ci.cancel(); - } catch (Exception e) { + ci.cancel(); + } catch (NumberFormatException e) { e.printStackTrace(); } + + if (t_packet.getVolume() == 1 && sound.getPath().equals("entity.enderman.scream")) ci.cancel(); } }