Skip to content

Commit 7a088fd

Browse files
authored
Create ClientConnectionMixin.java
1 parent 1f97725 commit 7a088fd

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package net.Poluteclient.phosphor.mixin;
2+
3+
import net.Poluteclient.phosphor.common.Phosphor;
4+
import net.Poluteclient.phosphor.api.event.events.PacketEvent;
5+
import net.minecraft.network.ClientConnection;
6+
import net.minecraft.network.listener.PacketListener;
7+
import net.minecraft.network.packet.Packet;
8+
import org.spongepowered.asm.mixin.Mixin;
9+
import org.spongepowered.asm.mixin.injection.At;
10+
import org.spongepowered.asm.mixin.injection.Inject;
11+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
12+
13+
@Mixin(ClientConnection.class)
14+
public class ClientConnectionMixin {
15+
@Inject(method = "handlePacket",
16+
at = @At("HEAD"),
17+
cancellable = true)
18+
private static <T extends PacketListener> void handlePacket(Packet<T> packet, PacketListener listener, CallbackInfo ci) {
19+
if (Phosphor.EVENTBUS.post(PacketEvent.Receive.get(packet)).isCancelled()) ci.cancel();
20+
}
21+
22+
@Inject(method = "send(Lnet/minecraft/network/packet/Packet;)V",
23+
at = @At("HEAD"),
24+
cancellable = true)
25+
private void onPacketSend(Packet<?> packet, CallbackInfo ci) {
26+
if (Phosphor.EVENTBUS.post(PacketEvent.Send.get(packet)).isCancelled()) ci.cancel();
27+
}
28+
}

0 commit comments

Comments
 (0)