Skip to content

Commit

Permalink
fix: do not fire receive packet event if singleplayer and is server
Browse files Browse the repository at this point in the history
  • Loading branch information
My-Name-Is-Jeff committed Jan 19, 2024
1 parent bad4f2d commit d595899
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,23 @@
import gg.skytils.skytilsmod.mixins.hooks.network.NetworkManagerHookKt;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import net.minecraft.network.EnumPacketDirection;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(value = NetworkManager.class, priority = 1001)
public abstract class MixinNetworkManager extends SimpleChannelInboundHandler<Packet<?>> {
@Shadow @Final private EnumPacketDirection direction;

@Inject(method = "channelRead0", at = @At("HEAD"), cancellable = true)
private void onReceivePacket(ChannelHandlerContext context, Packet<?> packet, CallbackInfo ci) {
NetworkManagerHookKt.onReceivePacket(context, packet, ci);
if (this.direction == EnumPacketDirection.CLIENTBOUND)
NetworkManagerHookKt.onReceivePacket(context, packet, ci);
}
}

0 comments on commit d595899

Please sign in to comment.