actually block the sound too

This commit is contained in:
Chayapak 2023-06-03 16:43:20 +07:00
parent d7a69dc0e5
commit 3530238408

View file

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