diff --git a/src/main/java/carpet/mixins/ServerCommonPacketListenerimpl_connectionMixin.java b/src/main/java/carpet/mixins/ServerGamePacketListenerimpl_connectionMixin.java similarity index 68% rename from src/main/java/carpet/mixins/ServerCommonPacketListenerimpl_connectionMixin.java rename to src/main/java/carpet/mixins/ServerGamePacketListenerimpl_connectionMixin.java index 7bdf69c1c..1811168e2 100644 --- a/src/main/java/carpet/mixins/ServerCommonPacketListenerimpl_connectionMixin.java +++ b/src/main/java/carpet/mixins/ServerGamePacketListenerimpl_connectionMixin.java @@ -5,26 +5,29 @@ import net.minecraft.network.protocol.PacketUtils; import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket; import net.minecraft.network.protocol.game.ServerGamePacketListener; -import net.minecraft.server.network.ServerCommonPacketListenerImpl; +import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.network.ServerGamePacketListenerImpl; 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(ServerCommonPacketListenerImpl.class) -public class ServerCommonPacketListenerimpl_connectionMixin +@Mixin(ServerGamePacketListenerImpl.class) +public class ServerGamePacketListenerimpl_connectionMixin { + @Shadow + public ServerPlayer player; + @Inject(method = "handleCustomPayload", at = @At("HEAD"), cancellable = true) private void onCustomCarpetPayload(ServerboundCustomPayloadPacket serverboundCustomPayloadPacket, CallbackInfo ci) { - Object thiss = this; - if (thiss instanceof ServerGamePacketListenerImpl impl && serverboundCustomPayloadPacket.payload() instanceof CarpetClient.CarpetPayload cpp) { + if (serverboundCustomPayloadPacket.payload() instanceof CarpetClient.CarpetPayload cpp) { // We should force onto the main thread here // ServerNetworkHandler.handleData can possibly mutate data that isn't // thread safe, and also allows for client commands to be executed - PacketUtils.ensureRunningOnSameThread(serverboundCustomPayloadPacket, (ServerGamePacketListener) this, impl.player.serverLevel()); - ServerNetworkHandler.onClientData(impl.player, cpp.data()); + PacketUtils.ensureRunningOnSameThread(serverboundCustomPayloadPacket, (ServerGamePacketListener) this, player.serverLevel()); + ServerNetworkHandler.onClientData(player, cpp.data()); ci.cancel(); } } diff --git a/src/main/resources/carpet.mixins.json b/src/main/resources/carpet.mixins.json index 1e5b1b3f9..768da6027 100644 --- a/src/main/resources/carpet.mixins.json +++ b/src/main/resources/carpet.mixins.json @@ -180,7 +180,7 @@ "PistonStructureResolver_customStickyMixin", "CustomPacketPayload_networkStuffMixin", - "ServerCommonPacketListenerimpl_connectionMixin" + "ServerGamePacketListenerimpl_connectionMixin" ], "client": [