blob: 320d627359f28b02b253c4f1e5cbfd7f23cf9340 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
package com.arslaancodes.arslaansmagichax.mixin;
import io.netty.channel.ChannelHandlerContext;
import com.arslaancodes.arslaansmagichax.events.PacketEvent;
import com.arslaancodes.arslaansmagichax.events.ReceivePacketEventBus;
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.Iterator;
import net.minecraft.network.Connection;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientGamePacketListener;
import net.minecraft.network.protocol.game.ClientboundBundlePacket;
@Mixin(Connection.class)
public class ClientConnectionMixin {
@Inject(method = "channelRead0(Lio/netty/channel/ChannelHandlerContext;Lnet/minecraft/network/protocol/Packet;)V",
at = @At(value = "INVOKE", target = "Lnet/minecraft/network/Connection;genericsFtw(Lnet/minecraft/network/protocol/Packet;Lnet/minecraft/network/PacketListener;)V", shift = At.Shift.BEFORE), cancellable = true)
private void onHandlePacket(ChannelHandlerContext channelHandlerContext, Packet<?> packet, CallbackInfo ci) {
if (packet instanceof ClientboundBundlePacket bundle) {
for (Iterator<Packet<? super ClientGamePacketListener>> it = bundle.subPackets().iterator(); it.hasNext(); ) {
Packet<? super ClientGamePacketListener> innerPacket = it.next();
PacketEvent.Receive ev = new PacketEvent.Receive(innerPacket);
ReceivePacketEventBus.post(ev);
if (ev.isCancelled()) it.remove();
}
} else {
PacketEvent.Receive ev = new PacketEvent.Receive(packet);
ReceivePacketEventBus.post(ev);
if (ev.isCancelled()) ci.cancel();
}
}
}
|