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.PacketUtils;
|
||||||
import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket;
|
import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket;
|
||||||
import net.minecraft.network.protocol.game.ServerGamePacketListener;
|
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 net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
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.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
@Mixin(ServerCommonPacketListenerImpl.class)
|
@Mixin(ServerGamePacketListenerImpl.class)
|
||||||
public class ServerCommonPacketListenerimpl_connectionMixin
|
public class ServerGamePacketListenerimpl_connectionMixin
|
||||||
{
|
{
|
||||||
|
@Shadow
|
||||||
|
public ServerPlayer player;
|
||||||
|
|
||||||
@Inject(method = "handleCustomPayload", at = @At("HEAD"), cancellable = true)
|
@Inject(method = "handleCustomPayload", at = @At("HEAD"), cancellable = true)
|
||||||
private void onCustomCarpetPayload(ServerboundCustomPayloadPacket serverboundCustomPayloadPacket, CallbackInfo ci)
|
private void onCustomCarpetPayload(ServerboundCustomPayloadPacket serverboundCustomPayloadPacket, CallbackInfo ci)
|
||||||
{
|
{
|
||||||
Object thiss = this;
|
if (serverboundCustomPayloadPacket.payload() instanceof CarpetClient.CarpetPayload cpp) {
|
||||||
if (thiss instanceof ServerGamePacketListenerImpl impl && serverboundCustomPayloadPacket.payload() instanceof CarpetClient.CarpetPayload cpp) {
|
|
||||||
// We should force onto the main thread here
|
// We should force onto the main thread here
|
||||||
// ServerNetworkHandler.handleData can possibly mutate data that isn't
|
// ServerNetworkHandler.handleData can possibly mutate data that isn't
|
||||||
// thread safe, and also allows for client commands to be executed
|
// thread safe, and also allows for client commands to be executed
|
||||||
PacketUtils.ensureRunningOnSameThread(serverboundCustomPayloadPacket, (ServerGamePacketListener) this, impl.player.serverLevel());
|
PacketUtils.ensureRunningOnSameThread(serverboundCustomPayloadPacket, (ServerGamePacketListener) this, player.serverLevel());
|
||||||
ServerNetworkHandler.onClientData(impl.player, cpp.data());
|
ServerNetworkHandler.onClientData(player, cpp.data());
|
||||||
ci.cancel();
|
ci.cancel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -180,7 +180,7 @@
|
|||||||
"PistonStructureResolver_customStickyMixin",
|
"PistonStructureResolver_customStickyMixin",
|
||||||
|
|
||||||
"CustomPacketPayload_networkStuffMixin",
|
"CustomPacketPayload_networkStuffMixin",
|
||||||
"ServerCommonPacketListenerimpl_connectionMixin"
|
"ServerGamePacketListenerimpl_connectionMixin"
|
||||||
|
|
||||||
],
|
],
|
||||||
"client": [
|
"client": [
|
||||||
|
|||||||
Reference in new issue
Block a user