Skip to content

Commit 5943a2a

Browse files
authored
Fix client packets not being received by the server (#1905)
1 parent 3df0111 commit 5943a2a

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

src/main/java/carpet/mixins/ServerCommonPacketListenerimpl_connectionMixin.java src/main/java/carpet/mixins/ServerGamePacketListenerimpl_connectionMixin.java

+10-7
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,29 @@
55
import net.minecraft.network.protocol.PacketUtils;
66
import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket;
77
import net.minecraft.network.protocol.game.ServerGamePacketListener;
8-
import net.minecraft.server.network.ServerCommonPacketListenerImpl;
8+
import net.minecraft.server.level.ServerPlayer;
99
import net.minecraft.server.network.ServerGamePacketListenerImpl;
1010
import org.spongepowered.asm.mixin.Mixin;
11+
import org.spongepowered.asm.mixin.Shadow;
1112
import org.spongepowered.asm.mixin.injection.At;
1213
import org.spongepowered.asm.mixin.injection.Inject;
1314
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
1415

15-
@Mixin(ServerCommonPacketListenerImpl.class)
16-
public class ServerCommonPacketListenerimpl_connectionMixin
16+
@Mixin(ServerGamePacketListenerImpl.class)
17+
public class ServerGamePacketListenerimpl_connectionMixin
1718
{
19+
@Shadow
20+
public ServerPlayer player;
21+
1822
@Inject(method = "handleCustomPayload", at = @At("HEAD"), cancellable = true)
1923
private void onCustomCarpetPayload(ServerboundCustomPayloadPacket serverboundCustomPayloadPacket, CallbackInfo ci)
2024
{
21-
Object thiss = this;
22-
if (thiss instanceof ServerGamePacketListenerImpl impl && serverboundCustomPayloadPacket.payload() instanceof CarpetClient.CarpetPayload cpp) {
25+
if (serverboundCustomPayloadPacket.payload() instanceof CarpetClient.CarpetPayload cpp) {
2326
// We should force onto the main thread here
2427
// ServerNetworkHandler.handleData can possibly mutate data that isn't
2528
// thread safe, and also allows for client commands to be executed
26-
PacketUtils.ensureRunningOnSameThread(serverboundCustomPayloadPacket, (ServerGamePacketListener) this, impl.player.serverLevel());
27-
ServerNetworkHandler.onClientData(impl.player, cpp.data());
29+
PacketUtils.ensureRunningOnSameThread(serverboundCustomPayloadPacket, (ServerGamePacketListener) this, player.serverLevel());
30+
ServerNetworkHandler.onClientData(player, cpp.data());
2831
ci.cancel();
2932
}
3033
}

src/main/resources/carpet.mixins.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@
180180
"PistonStructureResolver_customStickyMixin",
181181

182182
"CustomPacketPayload_networkStuffMixin",
183-
"ServerCommonPacketListenerimpl_connectionMixin"
183+
"ServerGamePacketListenerimpl_connectionMixin"
184184

185185
],
186186
"client": [

0 commit comments

Comments
 (0)