Fix client packets not being received by the server (#1905)
This commit is contained in:
1 parent
3df01112b3
commit
5943a2a24b
2 files changed
+11
-8
No files matched your search
+10
-7
@@ -5,26 +5,29 @@ import carpet.network.ServerNetworkHandler;
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -180,7 +180,7 @@
|
||||
"PistonStructureResolver_customStickyMixin",
|
||||
|
||||
"CustomPacketPayload_networkStuffMixin",
|
||||
"ServerCommonPacketListenerimpl_connectionMixin"
|
||||
"ServerGamePacketListenerimpl_connectionMixin"
|
||||
|
||||
],
|
||||
"client": [
|
||||
|
||||
Reference in new issue
Block a user