diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientConnectionMixin.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientConnectionMixin.java index c4d3f20..1a3d2bb 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientConnectionMixin.java +++ b/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientConnectionMixin.java @@ -8,12 +8,18 @@ import net.minecraft.network.listener.PacketListener; import net.minecraft.network.packet.Packet; import net.minecraft.network.packet.c2s.play.RequestCommandCompletionsC2SPacket; import net.minecraft.network.packet.s2c.play.ParticleS2CPacket; +import net.minecraft.network.packet.s2c.play.PlaySoundS2CPacket; +import net.minecraft.registry.RegistryKey; +import net.minecraft.sound.SoundEvent; import net.minecraft.text.Text; +import net.minecraft.util.Identifier; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import java.util.Optional; + @Mixin(net.minecraft.network.ClientConnection.class) public class ClientConnectionMixin { @Inject(at = @At("HEAD"), method = "disconnect", cancellable = true) @@ -33,6 +39,10 @@ public class ClientConnectionMixin { @Inject(method = "handlePacket", at = @At("HEAD"), cancellable = true) private static void handlePacket (Packet packet, PacketListener _listener, CallbackInfo ci) { + for (Listener listener : ListenerManager.listeners) { + listener.packetReceived(packet); + } + // please don't skid this.,. // mabe mabe mabe if (packet instanceof ParticleS2CPacket t_packet) { @@ -41,10 +51,18 @@ public class ClientConnectionMixin { if (t_packet.getCount() > max) { ci.cancel(); } - } + } else if (packet instanceof PlaySoundS2CPacket t_packet) { + if (t_packet.getVolume() != 1) return; - for (Listener listener : ListenerManager.listeners) { - listener.packetReceived(packet); + final Optional> event = t_packet.getSound().getKey(); + + if (event.isEmpty()) return; + + final Identifier sound = event.get().getValue(); + + if (!sound.getPath().equals("entity.enderman.scream")) return; + + ci.cancel(); } }