Skip to content

Commit

Permalink
Fix client packets not being received by the server (#1905)
Browse files Browse the repository at this point in the history
  • Loading branch information
altrisi authored Apr 28, 2024
1 parent 3df0111 commit 5943a2a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/carpet.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@
"PistonStructureResolver_customStickyMixin",

"CustomPacketPayload_networkStuffMixin",
"ServerCommonPacketListenerimpl_connectionMixin"
"ServerGamePacketListenerimpl_connectionMixin"

],
"client": [
Expand Down

0 comments on commit 5943a2a

Please sign in to comment.