fix client communication for carpet
This commit is contained in:
1 parent
08c5c3db31
commit
7a19bbe997
8 files changed
+70
-201
No files matched your search
@@ -7,21 +7,12 @@ import net.minecraft.client.multiplayer.ClientCommonPacketListenerImpl;
|
||||
import net.minecraft.client.multiplayer.ClientPacketListener;
|
||||
import net.minecraft.client.multiplayer.CommonListenerCookie;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.protocol.common.ClientCommonPacketListener;
|
||||
import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket;
|
||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||
import net.minecraft.network.protocol.common.custom.DiscardedPayload;
|
||||
import net.minecraft.network.protocol.game.ClientboundLoginPacket;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
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;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(ClientPacketListener.class)
|
||||
public abstract class ClientPacketListener_customPacketsMixin extends ClientCommonPacketListenerImpl
|
||||
@@ -38,4 +29,16 @@ public abstract class ClientPacketListener_customPacketsMixin extends ClientComm
|
||||
CarpetClient.gameJoined( minecraft.player);
|
||||
}
|
||||
|
||||
@Inject(method = "handleUnknownCustomPayload", at = @At(
|
||||
value = "HEAD"
|
||||
), cancellable = true)
|
||||
private void onOnCustomPayload(CustomPacketPayload packet, CallbackInfo ci)
|
||||
{
|
||||
if (packet instanceof CarpetClient.CarpetPayload cpp)
|
||||
{
|
||||
ClientNetworkHandler.handleData(cpp, minecraft.player);
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,19 +17,12 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
@Mixin(ClientboundCustomPayloadPacket.class)
|
||||
public class ClientboundCustomPayloadPacket_customPacketMixin
|
||||
{
|
||||
@Inject(method = "readPayload", at = @At("HEAD"))
|
||||
private static void onOnCustomPayloadR(final ResourceLocation resourceLocation, final FriendlyByteBuf friendlyByteBuf, final CallbackInfoReturnable<CustomPacketPayload> cir)
|
||||
@Inject(method = "readUnknownPayload", at = @At("HEAD"), cancellable = true)
|
||||
private static void onOnCustomPayloadR(ResourceLocation resourceLocation, FriendlyByteBuf friendlyByteBuf, CallbackInfoReturnable<CustomPacketPayload> cir)
|
||||
{
|
||||
}
|
||||
|
||||
@Inject(method = "readUnknownPayload", at = @At(value = "HEAD"), cancellable = true)
|
||||
private static void onOnCustomPayload(ResourceLocation resourceLocation, FriendlyByteBuf friendlyByteBuf, CallbackInfoReturnable<DiscardedPayload> cir)
|
||||
{
|
||||
if (true) return;
|
||||
if (CarpetClient.CARPET_CHANNEL.equals(resourceLocation) && Minecraft.getInstance().isSameThread())
|
||||
if (resourceLocation.equals(CarpetClient.CARPET_CHANNEL))
|
||||
{
|
||||
ClientNetworkHandler.handleData(friendlyByteBuf, Minecraft.getInstance().player);
|
||||
cir.setReturnValue(new DiscardedPayload(resourceLocation));
|
||||
cir.setReturnValue(new CarpetClient.CarpetPayload(friendlyByteBuf));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.fakes.CarpetPacketPayload;
|
||||
import carpet.network.CarpetClient;
|
||||
import carpet.network.ServerNetworkHandler;
|
||||
import net.minecraft.network.protocol.PacketUtils;
|
||||
import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket;
|
||||
@@ -18,16 +18,14 @@ public class ServerCommonPacketListenerimpl_connectionMixin
|
||||
@Inject(method = "handleCustomPayload", at = @At("HEAD"), cancellable = true)
|
||||
private void onCustomCarpetPayload(ServerboundCustomPayloadPacket serverboundCustomPayloadPacket, CallbackInfo ci)
|
||||
{
|
||||
if (true) return;
|
||||
Object thiss = this;
|
||||
if (thiss instanceof ServerGamePacketListenerImpl impl && serverboundCustomPayloadPacket.payload() instanceof CarpetPacketPayload cpp) {
|
||||
if (thiss instanceof ServerGamePacketListenerImpl impl && 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.handleData(cpp.data(), impl.player);
|
||||
ServerNetworkHandler.handleData(cpp, impl.player);
|
||||
ci.cancel();
|
||||
}
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,9 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.fakes.CarpetPacketPayload;
|
||||
import carpet.network.CarpetClient;
|
||||
import carpet.network.ClientNetworkHandler;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket;
|
||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||
import net.minecraft.network.protocol.common.custom.DiscardedPayload;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
@@ -17,36 +13,12 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
@Mixin(ServerboundCustomPayloadPacket.class)
|
||||
public class ServerboundCustomPayloadPacket_mixin
|
||||
{
|
||||
@Inject(method = "readPayload", at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/network/protocol/common/ServerboundCustomPayloadPacket;readUnknownPayload(Lnet/minecraft/resources/ResourceLocation;Lnet/minecraft/network/FriendlyByteBuf;)Lnet/minecraft/network/protocol/common/custom/DiscardedPayload;"
|
||||
), cancellable = true)
|
||||
@Inject(method = "readUnknownPayload", at = @At(value = "HEAD"), cancellable = true)
|
||||
private static void onOnCustomPayload(ResourceLocation resourceLocation, FriendlyByteBuf friendlyByteBuf, CallbackInfoReturnable<CustomPacketPayload> cir)
|
||||
{
|
||||
if (true) return;
|
||||
if (CarpetClient.CARPET_CHANNEL.equals(resourceLocation))
|
||||
{
|
||||
//ClientNetworkHandler.handleData(friendlyByteBuf, Minecraft.getInstance().player);
|
||||
cir.setReturnValue(new CarpetPacketPayload()
|
||||
{
|
||||
@Override
|
||||
public FriendlyByteBuf data()
|
||||
{
|
||||
return friendlyByteBuf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final FriendlyByteBuf friendlyByteBuf)
|
||||
{
|
||||
// noop - its a client side and we handle it server side only
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation id()
|
||||
{
|
||||
return resourceLocation;
|
||||
}
|
||||
});
|
||||
cir.setReturnValue(new CarpetClient.CarpetPayload(friendlyByteBuf));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user