From 54e1b917cd4aeb7c47cc8b85bdf250e7f7bf51ff Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Fri, 4 Aug 2023 16:17:54 +0100 Subject: [PATCH] Compile and mixin fixes. Enough to get to the main menu --- .../client/ClientPlayNetworkHandlerMixin.java | 9 ++--- .../content/registry/ContentRegistryTest.java | 1 - .../client/ClientPlayNetworkHandlerMixin.java | 2 +- .../networking/v1/ClientPlayNetworking.java | 4 +-- .../client/ClientLoginNetworkAddon.java | 7 ++-- .../client/ClientNetworkingImpl.java | 11 +++--- .../client/ClientPlayNetworkAddon.java | 14 ++++---- .../ClientCommonNetworkHandlerMixin.java | 19 +++++++++++ .../client/ClientPlayNetworkHandlerMixin.java | 28 +++++++-------- ...abric-networking-api-v1.client.mixins.json | 1 + .../networking/v1/ServerPlayNetworking.java | 6 ++-- ...PacketByteBufLoginQueryRequestPayload.java | 12 +++++++ .../PacketByteBufLoginQueryResponse.java | 11 ++++++ .../impl/networking/PacketByteBufPayload.java | 12 +++++++ .../server/ServerLoginNetworkAddon.java | 16 +++++---- .../server/ServerNetworkingImpl.java | 11 +++--- .../server/ServerPlayNetworkAddon.java | 16 ++++----- .../networking/ClientConnectionMixin.java | 11 +++--- .../ServerLoginNetworkHandlerMixin.java | 18 +++++----- .../ServerPlayNetworkHandlerMixin.java | 32 ++++++++--------- .../CustomPayloadC2SPacketAccessor.java | 33 ------------------ .../LoginQueryResponseC2SPacketAccessor.java | 34 ------------------- ...> ServerCommonNetworkHandlerAccessor.java} | 6 ++-- .../fabric-networking-api-v1.mixins.json | 4 +-- .../play/NetworkingPlayPacketTest.java | 12 +++---- ...TypeAwareBuyForOneEmeraldFactoryMixin.java | 5 +-- .../ingredient/CustomIngredientSync.java | 2 +- .../SupportedIngredientsPacketEncoder.java | 2 +- .../recipe/ingredient/PacketEncoderMixin.java | 2 +- .../rendering/EntityRenderersMixin.java | 5 ++- .../fabric/mixin/screen/MouseMixin.java | 4 +-- .../client/PositionedScreen.java | 2 +- src/main/resources/fabric.mod.json | 4 +-- 33 files changed, 167 insertions(+), 189 deletions(-) create mode 100644 fabric-networking-api-v1/src/client/java/net/fabricmc/fabric/mixin/networking/client/ClientCommonNetworkHandlerMixin.java create mode 100644 fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/impl/networking/PacketByteBufLoginQueryRequestPayload.java create mode 100644 fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/impl/networking/PacketByteBufLoginQueryResponse.java create mode 100644 fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/impl/networking/PacketByteBufPayload.java delete mode 100644 fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/mixin/networking/accessor/CustomPayloadC2SPacketAccessor.java delete mode 100644 fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/mixin/networking/accessor/LoginQueryResponseC2SPacketAccessor.java rename fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/mixin/networking/accessor/{ServerPlayNetworkHandlerAccessor.java => ServerCommonNetworkHandlerAccessor.java} (84%) diff --git a/fabric-command-api-v2/src/client/java/net/fabricmc/fabric/mixin/command/client/ClientPlayNetworkHandlerMixin.java b/fabric-command-api-v2/src/client/java/net/fabricmc/fabric/mixin/command/client/ClientPlayNetworkHandlerMixin.java index c7177974c3..02471be870 100644 --- a/fabric-command-api-v2/src/client/java/net/fabricmc/fabric/mixin/command/client/ClientPlayNetworkHandlerMixin.java +++ b/fabric-command-api-v2/src/client/java/net/fabricmc/fabric/mixin/command/client/ClientPlayNetworkHandlerMixin.java @@ -26,14 +26,13 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import net.minecraft.client.network.ClientCommandSource; -import net.minecraft.client.network.ClientDynamicRegistryType; import net.minecraft.client.network.ClientPlayNetworkHandler; import net.minecraft.command.CommandRegistryAccess; import net.minecraft.command.CommandSource; import net.minecraft.network.packet.s2c.play.CommandTreeS2CPacket; import net.minecraft.network.packet.s2c.play.GameJoinS2CPacket; +import net.minecraft.registry.DynamicRegistryManager; import net.minecraft.resource.featuretoggle.FeatureSet; -import net.minecraft.registry.CombinedDynamicRegistries; import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; @@ -48,17 +47,19 @@ abstract class ClientPlayNetworkHandlerMixin { @Final private ClientCommandSource commandSource; + @Final @Shadow private FeatureSet enabledFeatures; + @Final @Shadow - private CombinedDynamicRegistries combinedDynamicRegistries; + private DynamicRegistryManager.Immutable combinedDynamicRegistries; @Inject(method = "onGameJoin", at = @At("RETURN")) private void onGameJoin(GameJoinS2CPacket packet, CallbackInfo info) { final CommandDispatcher dispatcher = new CommandDispatcher<>(); ClientCommandInternals.setActiveDispatcher(dispatcher); - ClientCommandRegistrationCallback.EVENT.invoker().register(dispatcher, CommandRegistryAccess.of(this.combinedDynamicRegistries.getCombinedRegistryManager(), this.enabledFeatures)); + ClientCommandRegistrationCallback.EVENT.invoker().register(dispatcher, CommandRegistryAccess.of(this.combinedDynamicRegistries, this.enabledFeatures)); ClientCommandInternals.finalizeInit(); } diff --git a/fabric-content-registries-v0/src/testmod/java/net/fabricmc/fabric/test/content/registry/ContentRegistryTest.java b/fabric-content-registries-v0/src/testmod/java/net/fabricmc/fabric/test/content/registry/ContentRegistryTest.java index 4401ad68d9..02ae19cecb 100644 --- a/fabric-content-registries-v0/src/testmod/java/net/fabricmc/fabric/test/content/registry/ContentRegistryTest.java +++ b/fabric-content-registries-v0/src/testmod/java/net/fabricmc/fabric/test/content/registry/ContentRegistryTest.java @@ -87,7 +87,6 @@ public void onInitialize() { // - instant health potions can be brewed from awkward potions with any item in the 'minecraft:small_flowers' tag // - dirty potions can be brewed by adding any item in the 'minecraft:dirt' tag to any standard potion - Registry.register(Registries.GAME_EVENT, TEST_EVENT_ID, TEST_EVENT); CompostingChanceRegistry.INSTANCE.add(Items.OBSIDIAN, 0.5F); FlammableBlockRegistry.getDefaultInstance().add(Blocks.DIAMOND_BLOCK, 4, 4); FlammableBlockRegistry.getDefaultInstance().add(BlockTags.SAND, 4, 4); diff --git a/fabric-lifecycle-events-v1/src/client/java/net/fabricmc/fabric/mixin/event/lifecycle/client/ClientPlayNetworkHandlerMixin.java b/fabric-lifecycle-events-v1/src/client/java/net/fabricmc/fabric/mixin/event/lifecycle/client/ClientPlayNetworkHandlerMixin.java index a30cc78809..d6ac064379 100644 --- a/fabric-lifecycle-events-v1/src/client/java/net/fabricmc/fabric/mixin/event/lifecycle/client/ClientPlayNetworkHandlerMixin.java +++ b/fabric-lifecycle-events-v1/src/client/java/net/fabricmc/fabric/mixin/event/lifecycle/client/ClientPlayNetworkHandlerMixin.java @@ -101,7 +101,7 @@ private void onClearWorld(CallbackInfo ci) { method = "onSynchronizeTags", at = @At( value = "INVOKE", - target = "java/util/Map.forEach(Ljava/util/function/BiConsumer;)V", + target = "Lnet/minecraft/client/network/ClientCommonNetworkHandler;onSynchronizeTags(Lnet/minecraft/network/packet/s2c/common/SynchronizeTagsS2CPacket;)V", shift = At.Shift.AFTER, by = 1 ) ) diff --git a/fabric-networking-api-v1/src/client/java/net/fabricmc/fabric/api/client/networking/v1/ClientPlayNetworking.java b/fabric-networking-api-v1/src/client/java/net/fabricmc/fabric/api/client/networking/v1/ClientPlayNetworking.java index c95700577a..f9c620af92 100644 --- a/fabric-networking-api-v1/src/client/java/net/fabricmc/fabric/api/client/networking/v1/ClientPlayNetworking.java +++ b/fabric-networking-api-v1/src/client/java/net/fabricmc/fabric/api/client/networking/v1/ClientPlayNetworking.java @@ -25,7 +25,7 @@ import net.minecraft.client.network.ClientPlayNetworkHandler; import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.network.PacketByteBuf; -import net.minecraft.network.listener.ServerPlayPacketListener; +import net.minecraft.network.listener.ServerCommonPacketListener; import net.minecraft.network.packet.Packet; import net.minecraft.util.Identifier; import net.minecraft.util.thread.ThreadExecutor; @@ -331,7 +331,7 @@ public static boolean canSend(PacketType type) { * @param buf the packet byte buf which represents the payload of the packet * @return a new packet */ - public static Packet createC2SPacket(Identifier channelName, PacketByteBuf buf) { + public static Packet createC2SPacket(Identifier channelName, PacketByteBuf buf) { Objects.requireNonNull(channelName, "Channel name cannot be null"); Objects.requireNonNull(buf, "Buf cannot be null"); diff --git a/fabric-networking-api-v1/src/client/java/net/fabricmc/fabric/impl/networking/client/ClientLoginNetworkAddon.java b/fabric-networking-api-v1/src/client/java/net/fabricmc/fabric/impl/networking/client/ClientLoginNetworkAddon.java index bcf64337ca..bb16ac2ce1 100644 --- a/fabric-networking-api-v1/src/client/java/net/fabricmc/fabric/impl/networking/client/ClientLoginNetworkAddon.java +++ b/fabric-networking-api-v1/src/client/java/net/fabricmc/fabric/impl/networking/client/ClientLoginNetworkAddon.java @@ -38,6 +38,8 @@ import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; import net.fabricmc.fabric.impl.networking.AbstractNetworkAddon; import net.fabricmc.fabric.impl.networking.GenericFutureListenerHolder; +import net.fabricmc.fabric.impl.networking.PacketByteBufLoginQueryRequestPayload; +import net.fabricmc.fabric.impl.networking.PacketByteBufLoginQueryResponse; import net.fabricmc.fabric.mixin.networking.client.accessor.ClientLoginNetworkHandlerAccessor; public final class ClientLoginNetworkAddon extends AbstractNetworkAddon { @@ -55,7 +57,8 @@ public ClientLoginNetworkAddon(ClientLoginNetworkHandler handler, MinecraftClien } public boolean handlePacket(LoginQueryRequestS2CPacket packet) { - return handlePacket(packet.getQueryId(), packet.getChannel(), packet.getPayload()); + PacketByteBufLoginQueryRequestPayload payload = (PacketByteBufLoginQueryRequestPayload) packet.payload(); + return handlePacket(packet.queryId(), packet.payload().id(), payload.data()); } private boolean handlePacket(int queryId, Identifier channelName, PacketByteBuf originalBuf) { @@ -83,7 +86,7 @@ private boolean handlePacket(int queryId, Identifier channelName, PacketByteBuf try { CompletableFuture<@Nullable PacketByteBuf> future = handler.receive(this.client, this.handler, buf, futureListeners::add); future.thenAccept(result -> { - LoginQueryResponseC2SPacket packet = new LoginQueryResponseC2SPacket(queryId, result); + LoginQueryResponseC2SPacket packet = new LoginQueryResponseC2SPacket(queryId, new PacketByteBufLoginQueryResponse(result)); GenericFutureListener> listener = null; for (GenericFutureListener> each : futureListeners) { diff --git a/fabric-networking-api-v1/src/client/java/net/fabricmc/fabric/impl/networking/client/ClientNetworkingImpl.java b/fabric-networking-api-v1/src/client/java/net/fabricmc/fabric/impl/networking/client/ClientNetworkingImpl.java index 50e6f83930..d6c91e9d55 100644 --- a/fabric-networking-api-v1/src/client/java/net/fabricmc/fabric/impl/networking/client/ClientNetworkingImpl.java +++ b/fabric-networking-api-v1/src/client/java/net/fabricmc/fabric/impl/networking/client/ClientNetworkingImpl.java @@ -28,10 +28,10 @@ import net.minecraft.client.network.ClientLoginNetworkHandler; import net.minecraft.client.network.ClientPlayNetworkHandler; import net.minecraft.network.ClientConnection; -import net.minecraft.network.packet.Packet; import net.minecraft.network.PacketByteBuf; -import net.minecraft.network.listener.ServerPlayPacketListener; -import net.minecraft.network.packet.c2s.play.CustomPayloadC2SPacket; +import net.minecraft.network.listener.ServerCommonPacketListener; +import net.minecraft.network.packet.Packet; +import net.minecraft.network.packet.c2s.common.CustomPayloadC2SPacket; import net.minecraft.util.Identifier; import net.fabricmc.fabric.api.client.networking.v1.ClientLoginNetworking; @@ -42,6 +42,7 @@ import net.fabricmc.fabric.impl.networking.GlobalReceiverRegistry; import net.fabricmc.fabric.impl.networking.NetworkHandlerExtensions; import net.fabricmc.fabric.impl.networking.NetworkingImpl; +import net.fabricmc.fabric.impl.networking.PacketByteBufPayload; import net.fabricmc.fabric.mixin.networking.client.accessor.ClientLoginNetworkHandlerAccessor; import net.fabricmc.fabric.mixin.networking.client.accessor.ConnectScreenAccessor; import net.fabricmc.fabric.mixin.networking.client.accessor.MinecraftClientAccessor; @@ -59,8 +60,8 @@ public static ClientLoginNetworkAddon getAddon(ClientLoginNetworkHandler handler return (ClientLoginNetworkAddon) ((NetworkHandlerExtensions) handler).getAddon(); } - public static Packet createPlayC2SPacket(Identifier channelName, PacketByteBuf buf) { - return new CustomPayloadC2SPacket(channelName, buf); + public static Packet createPlayC2SPacket(Identifier channelName, PacketByteBuf buf) { + return new CustomPayloadC2SPacket(new PacketByteBufPayload(channelName, buf)); } /** diff --git a/fabric-networking-api-v1/src/client/java/net/fabricmc/fabric/impl/networking/client/ClientPlayNetworkAddon.java b/fabric-networking-api-v1/src/client/java/net/fabricmc/fabric/impl/networking/client/ClientPlayNetworkAddon.java index 26e3d0211a..d12a54ffb7 100644 --- a/fabric-networking-api-v1/src/client/java/net/fabricmc/fabric/impl/networking/client/ClientPlayNetworkAddon.java +++ b/fabric-networking-api-v1/src/client/java/net/fabricmc/fabric/impl/networking/client/ClientPlayNetworkAddon.java @@ -25,9 +25,8 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.ClientPlayNetworkHandler; -import net.minecraft.network.packet.Packet; import net.minecraft.network.PacketByteBuf; -import net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket; +import net.minecraft.network.packet.Packet; import net.minecraft.util.Identifier; import net.fabricmc.fabric.api.client.networking.v1.C2SPlayChannelEvents; @@ -36,6 +35,7 @@ import net.fabricmc.fabric.impl.networking.AbstractChanneledNetworkAddon; import net.fabricmc.fabric.impl.networking.ChannelInfoHolder; import net.fabricmc.fabric.impl.networking.NetworkingImpl; +import net.fabricmc.fabric.impl.networking.PacketByteBufPayload; public final class ClientPlayNetworkAddon extends AbstractChanneledNetworkAddon { private final ClientPlayNetworkHandler handler; @@ -80,16 +80,14 @@ public void onServerReady() { /** * Handles an incoming packet. * - * @param packet the packet to handle + * @param payload the payload to handle * @return true if the packet has been handled */ - public boolean handle(CustomPayloadS2CPacket packet) { - PacketByteBuf buf = packet.getData(); - + public boolean handle(PacketByteBufPayload payload) { try { - return this.handle(packet.getChannel(), buf); + return this.handle(payload.id(), payload.data()); } finally { - buf.release(); + payload.data().release(); } } diff --git a/fabric-networking-api-v1/src/client/java/net/fabricmc/fabric/mixin/networking/client/ClientCommonNetworkHandlerMixin.java b/fabric-networking-api-v1/src/client/java/net/fabricmc/fabric/mixin/networking/client/ClientCommonNetworkHandlerMixin.java new file mode 100644 index 0000000000..88d25e3c1a --- /dev/null +++ b/fabric-networking-api-v1/src/client/java/net/fabricmc/fabric/mixin/networking/client/ClientCommonNetworkHandlerMixin.java @@ -0,0 +1,19 @@ +package net.fabricmc.fabric.mixin.networking.client; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import net.minecraft.client.network.ClientCommonNetworkHandler; +import net.minecraft.text.Text; + +import net.fabricmc.fabric.impl.networking.NetworkHandlerExtensions; + +@Mixin(ClientCommonNetworkHandler.class) +public abstract class ClientCommonNetworkHandlerMixin implements NetworkHandlerExtensions { + @Inject(method = "onDisconnected", at = @At("HEAD")) + private void handleDisconnection(Text reason, CallbackInfo ci) { + this.getAddon().handleDisconnect(); + } +} diff --git a/fabric-networking-api-v1/src/client/java/net/fabricmc/fabric/mixin/networking/client/ClientPlayNetworkHandlerMixin.java b/fabric-networking-api-v1/src/client/java/net/fabricmc/fabric/mixin/networking/client/ClientPlayNetworkHandlerMixin.java index 418b25acea..0c0dcb4a14 100644 --- a/fabric-networking-api-v1/src/client/java/net/fabricmc/fabric/mixin/networking/client/ClientPlayNetworkHandlerMixin.java +++ b/fabric-networking-api-v1/src/client/java/net/fabricmc/fabric/mixin/networking/client/ClientPlayNetworkHandlerMixin.java @@ -16,34 +16,35 @@ package net.fabricmc.fabric.mixin.networking.client; -import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import net.minecraft.client.MinecraftClient; +import net.minecraft.client.network.ClientCommonNetworkHandler; +import net.minecraft.client.network.ClientConnectionState; import net.minecraft.client.network.ClientPlayNetworkHandler; -import net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket; +import net.minecraft.network.ClientConnection; +import net.minecraft.network.packet.CustomPayload; import net.minecraft.network.packet.s2c.play.GameJoinS2CPacket; -import net.minecraft.text.Text; import net.fabricmc.fabric.impl.networking.NetworkHandlerExtensions; +import net.fabricmc.fabric.impl.networking.PacketByteBufPayload; import net.fabricmc.fabric.impl.networking.client.ClientNetworkingImpl; import net.fabricmc.fabric.impl.networking.client.ClientPlayNetworkAddon; // We want to apply a bit earlier than other mods which may not use us in order to prevent refCount issues @Mixin(value = ClientPlayNetworkHandler.class, priority = 999) -abstract class ClientPlayNetworkHandlerMixin implements NetworkHandlerExtensions { - @Final - @Shadow - private MinecraftClient client; - +abstract class ClientPlayNetworkHandlerMixin extends ClientCommonNetworkHandler implements NetworkHandlerExtensions { @Unique private ClientPlayNetworkAddon addon; + protected ClientPlayNetworkHandlerMixin(MinecraftClient client, ClientConnection connection, ClientConnectionState connectionState) { + super(client, connection, connectionState); + } + @Inject(method = "", at = @At("RETURN")) private void initAddon(CallbackInfo ci) { this.addon = new ClientPlayNetworkAddon((ClientPlayNetworkHandler) (Object) this, this.client); @@ -58,17 +59,12 @@ private void handleServerPlayReady(GameJoinS2CPacket packet, CallbackInfo ci) { } @Inject(method = "onCustomPayload", at = @At("HEAD"), cancellable = true) - private void handleCustomPayload(CustomPayloadS2CPacket packet, CallbackInfo ci) { - if (this.addon.handle(packet)) { + private void handleCustomPayload(CustomPayload payload, CallbackInfo ci) { + if (payload instanceof PacketByteBufPayload byteBufPayload && this.addon.handle(byteBufPayload)) { ci.cancel(); } } - @Inject(method = "onDisconnected", at = @At("HEAD")) - private void handleDisconnection(Text reason, CallbackInfo ci) { - this.addon.handleDisconnect(); - } - @Override public ClientPlayNetworkAddon getAddon() { return this.addon; diff --git a/fabric-networking-api-v1/src/client/resources/fabric-networking-api-v1.client.mixins.json b/fabric-networking-api-v1/src/client/resources/fabric-networking-api-v1.client.mixins.json index 2d4b321abc..a5737d5ac4 100644 --- a/fabric-networking-api-v1/src/client/resources/fabric-networking-api-v1.client.mixins.json +++ b/fabric-networking-api-v1/src/client/resources/fabric-networking-api-v1.client.mixins.json @@ -6,6 +6,7 @@ "accessor.ClientLoginNetworkHandlerAccessor", "accessor.ConnectScreenAccessor", "accessor.MinecraftClientAccessor", + "ClientCommonNetworkHandlerMixin", "ClientLoginNetworkHandlerMixin", "ClientPlayNetworkHandlerMixin" ], diff --git a/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/api/networking/v1/ServerPlayNetworking.java b/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/api/networking/v1/ServerPlayNetworking.java index 9d3c082986..2d6a625f67 100644 --- a/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/api/networking/v1/ServerPlayNetworking.java +++ b/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/api/networking/v1/ServerPlayNetworking.java @@ -21,9 +21,9 @@ import org.jetbrains.annotations.Nullable; -import net.minecraft.network.packet.Packet; import net.minecraft.network.PacketByteBuf; -import net.minecraft.network.listener.ClientPlayPacketListener; +import net.minecraft.network.listener.ClientCommonPacketListener; +import net.minecraft.network.packet.Packet; import net.minecraft.server.MinecraftServer; import net.minecraft.server.network.ServerPlayNetworkHandler; import net.minecraft.server.network.ServerPlayerEntity; @@ -381,7 +381,7 @@ public static boolean canSend(ServerPlayNetworkHandler handler, PacketType ty * @param buf the packet byte buf which represents the payload of the packet * @return a new packet */ - public static Packet createS2CPacket(Identifier channelName, PacketByteBuf buf) { + public static Packet createS2CPacket(Identifier channelName, PacketByteBuf buf) { Objects.requireNonNull(channelName, "Channel cannot be null"); Objects.requireNonNull(buf, "Buf cannot be null"); diff --git a/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/impl/networking/PacketByteBufLoginQueryRequestPayload.java b/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/impl/networking/PacketByteBufLoginQueryRequestPayload.java new file mode 100644 index 0000000000..c87e559d35 --- /dev/null +++ b/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/impl/networking/PacketByteBufLoginQueryRequestPayload.java @@ -0,0 +1,12 @@ +package net.fabricmc.fabric.impl.networking; + +import net.minecraft.network.PacketByteBuf; +import net.minecraft.network.packet.s2c.login.LoginQueryRequestPayload; +import net.minecraft.util.Identifier; + +public record PacketByteBufLoginQueryRequestPayload(Identifier id, PacketByteBuf data) implements LoginQueryRequestPayload { + @Override + public void write(PacketByteBuf buf) { + buf.writeBytes(this.data()); + } +} diff --git a/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/impl/networking/PacketByteBufLoginQueryResponse.java b/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/impl/networking/PacketByteBufLoginQueryResponse.java new file mode 100644 index 0000000000..2741677324 --- /dev/null +++ b/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/impl/networking/PacketByteBufLoginQueryResponse.java @@ -0,0 +1,11 @@ +package net.fabricmc.fabric.impl.networking; + +import net.minecraft.network.PacketByteBuf; +import net.minecraft.network.packet.c2s.login.LoginQueryResponse; + +public record PacketByteBufLoginQueryResponse(PacketByteBuf data) implements LoginQueryResponse { + @Override + public void write(PacketByteBuf buf) { + buf.writeBytes(this.data()); + } +} diff --git a/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/impl/networking/PacketByteBufPayload.java b/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/impl/networking/PacketByteBufPayload.java new file mode 100644 index 0000000000..abdd4e8787 --- /dev/null +++ b/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/impl/networking/PacketByteBufPayload.java @@ -0,0 +1,12 @@ +package net.fabricmc.fabric.impl.networking; + +import net.minecraft.network.PacketByteBuf; +import net.minecraft.network.packet.CustomPayload; +import net.minecraft.util.Identifier; + +public record PacketByteBufPayload(Identifier id, PacketByteBuf data) implements CustomPayload { + @Override + public void write(PacketByteBuf buf) { + buf.writeBytes(this.data()); + } +} diff --git a/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/impl/networking/server/ServerLoginNetworkAddon.java b/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/impl/networking/server/ServerLoginNetworkAddon.java index e601c1e697..cba632dcf0 100644 --- a/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/impl/networking/server/ServerLoginNetworkAddon.java +++ b/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/impl/networking/server/ServerLoginNetworkAddon.java @@ -30,9 +30,9 @@ import org.jetbrains.annotations.Nullable; import net.minecraft.network.ClientConnection; -import net.minecraft.network.packet.Packet; import net.minecraft.network.PacketByteBuf; import net.minecraft.network.PacketCallbacks; +import net.minecraft.network.packet.Packet; import net.minecraft.network.packet.c2s.login.LoginQueryResponseC2SPacket; import net.minecraft.network.packet.s2c.login.LoginCompressionS2CPacket; import net.minecraft.network.packet.s2c.login.LoginQueryRequestS2CPacket; @@ -46,7 +46,8 @@ import net.fabricmc.fabric.api.networking.v1.ServerLoginNetworking; import net.fabricmc.fabric.impl.networking.AbstractNetworkAddon; import net.fabricmc.fabric.impl.networking.GenericFutureListenerHolder; -import net.fabricmc.fabric.mixin.networking.accessor.LoginQueryResponseC2SPacketAccessor; +import net.fabricmc.fabric.impl.networking.PacketByteBufLoginQueryRequestPayload; +import net.fabricmc.fabric.impl.networking.PacketByteBufLoginQueryResponse; import net.fabricmc.fabric.mixin.networking.accessor.ServerLoginNetworkHandlerAccessor; public final class ServerLoginNetworkAddon extends AbstractNetworkAddon implements PacketSender { @@ -128,8 +129,9 @@ private void sendCompressionPacket() { * @return true if the packet was handled */ public boolean handle(LoginQueryResponseC2SPacket packet) { - LoginQueryResponseC2SPacketAccessor access = (LoginQueryResponseC2SPacketAccessor) packet; - return handle(access.getQueryId(), access.getResponse()); + // TODO 1.20.2 likely an unsafe cast. + PacketByteBufLoginQueryResponse response = (PacketByteBufLoginQueryResponse) packet.response(); + return handle(packet.queryId(), response.data()); } private boolean handle(int queryId, @Nullable PacketByteBuf originalBuf) { @@ -164,7 +166,7 @@ private boolean handle(int queryId, @Nullable PacketByteBuf originalBuf) { public Packet createPacket(Identifier channelName, PacketByteBuf buf) { int queryId = this.queryIdFactory.nextId(); - LoginQueryRequestS2CPacket ret = new LoginQueryRequestS2CPacket(queryId, channelName, buf); + LoginQueryRequestS2CPacket ret = new LoginQueryRequestS2CPacket(queryId, new PacketByteBufLoginQueryRequestPayload(channelName, buf)); return ret; } @@ -188,7 +190,7 @@ public void sendPacket(Packet packet, PacketCallbacks callback) { } public void registerOutgoingPacket(LoginQueryRequestS2CPacket packet) { - this.channels.put(packet.getQueryId(), packet.getChannel()); + this.channels.put(packet.queryId(), packet.payload().id()); } @Override @@ -205,7 +207,7 @@ protected void invokeDisconnectEvent() { this.receiver.endSession(this); } - public void handlePlayTransition() { + public void handleConfigurationTransition() { this.receiver.endSession(this); } diff --git a/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/impl/networking/server/ServerNetworkingImpl.java b/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/impl/networking/server/ServerNetworkingImpl.java index 6414ac59a9..24fb1530c1 100644 --- a/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/impl/networking/server/ServerNetworkingImpl.java +++ b/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/impl/networking/server/ServerNetworkingImpl.java @@ -16,10 +16,10 @@ package net.fabricmc.fabric.impl.networking.server; -import net.minecraft.network.packet.Packet; import net.minecraft.network.PacketByteBuf; -import net.minecraft.network.listener.ClientPlayPacketListener; -import net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket; +import net.minecraft.network.listener.ClientCommonPacketListener; +import net.minecraft.network.packet.Packet; +import net.minecraft.network.packet.s2c.common.CustomPayloadS2CPacket; import net.minecraft.server.network.ServerLoginNetworkHandler; import net.minecraft.server.network.ServerPlayNetworkHandler; import net.minecraft.util.Identifier; @@ -28,6 +28,7 @@ import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; import net.fabricmc.fabric.impl.networking.GlobalReceiverRegistry; import net.fabricmc.fabric.impl.networking.NetworkHandlerExtensions; +import net.fabricmc.fabric.impl.networking.PacketByteBufPayload; public final class ServerNetworkingImpl { public static final GlobalReceiverRegistry LOGIN = new GlobalReceiverRegistry<>(); @@ -41,7 +42,7 @@ public static ServerLoginNetworkAddon getAddon(ServerLoginNetworkHandler handler return (ServerLoginNetworkAddon) ((NetworkHandlerExtensions) handler).getAddon(); } - public static Packet createPlayC2SPacket(Identifier channel, PacketByteBuf buf) { - return new CustomPayloadS2CPacket(channel, buf); + public static Packet createPlayC2SPacket(Identifier channel, PacketByteBuf buf) { + return new CustomPayloadS2CPacket(new PacketByteBufPayload(channel, buf)); } } diff --git a/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/impl/networking/server/ServerPlayNetworkAddon.java b/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/impl/networking/server/ServerPlayNetworkAddon.java index 395fa1b328..58d68a1b58 100644 --- a/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/impl/networking/server/ServerPlayNetworkAddon.java +++ b/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/impl/networking/server/ServerPlayNetworkAddon.java @@ -20,9 +20,8 @@ import java.util.List; import java.util.Map; -import net.minecraft.network.packet.Packet; import net.minecraft.network.PacketByteBuf; -import net.minecraft.network.packet.c2s.play.CustomPayloadC2SPacket; +import net.minecraft.network.packet.Packet; import net.minecraft.server.MinecraftServer; import net.minecraft.server.network.ServerPlayNetworkHandler; import net.minecraft.util.Identifier; @@ -33,8 +32,8 @@ import net.fabricmc.fabric.impl.networking.AbstractChanneledNetworkAddon; import net.fabricmc.fabric.impl.networking.ChannelInfoHolder; import net.fabricmc.fabric.impl.networking.NetworkingImpl; -import net.fabricmc.fabric.mixin.networking.accessor.CustomPayloadC2SPacketAccessor; -import net.fabricmc.fabric.mixin.networking.accessor.ServerPlayNetworkHandlerAccessor; +import net.fabricmc.fabric.impl.networking.PacketByteBufPayload; +import net.fabricmc.fabric.mixin.networking.accessor.ServerCommonNetworkHandlerAccessor; public final class ServerPlayNetworkAddon extends AbstractChanneledNetworkAddon { private final ServerPlayNetworkHandler handler; @@ -42,7 +41,7 @@ public final class ServerPlayNetworkAddon extends AbstractChanneledNetworkAddon< private boolean sentInitialRegisterPacket; public ServerPlayNetworkAddon(ServerPlayNetworkHandler handler, MinecraftServer server) { - super(ServerNetworkingImpl.PLAY, ((ServerPlayNetworkHandlerAccessor) handler).getConnection(), "ServerPlayNetworkAddon for " + handler.player.getEntityName()); + super(ServerNetworkingImpl.PLAY, ((ServerCommonNetworkHandlerAccessor) handler).getConnection(), "ServerPlayNetworkAddon for " + handler.player.getEntityName()); this.handler = handler; this.server = server; @@ -72,12 +71,11 @@ public void onClientReady() { /** * Handles an incoming packet. * - * @param packet the packet to handle + * @param payload the payload to handle * @return true if the packet has been handled */ - public boolean handle(CustomPayloadC2SPacket packet) { - CustomPayloadC2SPacketAccessor access = (CustomPayloadC2SPacketAccessor) packet; - return this.handle(access.getChannel(), access.getData()); + public boolean handle(PacketByteBufPayload payload) { + return this.handle(payload.id(), payload.data()); } @Override diff --git a/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/mixin/networking/ClientConnectionMixin.java b/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/mixin/networking/ClientConnectionMixin.java index 99b61ad630..9926db37c6 100644 --- a/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/mixin/networking/ClientConnectionMixin.java +++ b/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/mixin/networking/ClientConnectionMixin.java @@ -35,10 +35,9 @@ import net.minecraft.network.ClientConnection; import net.minecraft.network.NetworkSide; -import net.minecraft.network.NetworkState; -import net.minecraft.network.packet.Packet; import net.minecraft.network.PacketCallbacks; import net.minecraft.network.listener.PacketListener; +import net.minecraft.network.packet.Packet; import net.minecraft.text.Text; import net.minecraft.util.Identifier; @@ -81,7 +80,7 @@ private void resendOnExceptionCaught(ClientConnection self, Packet packet, Pa } @Inject(method = "sendImmediately", at = @At(value = "FIELD", target = "Lnet/minecraft/network/ClientConnection;packetsSentCounter:I")) - private void checkPacket(Packet packet, PacketCallbacks callback, CallbackInfo ci) { + private void checkPacket(Packet packet, PacketCallbacks callback, boolean flush, CallbackInfo ci) { if (this.packetListener instanceof PacketCallbackListener) { ((PacketCallbackListener) this.packetListener).sent(packet); } @@ -94,9 +93,9 @@ private void handleDisconnect(ChannelHandlerContext channelHandlerContext, Callb } } - @Inject(method = "sendInternal", at = @At(value = "INVOKE_ASSIGN", target = "Lio/netty/channel/Channel;writeAndFlush(Ljava/lang/Object;)Lio/netty/channel/ChannelFuture;", remap = false), locals = LocalCapture.CAPTURE_FAILHARD) - private void sendInternal(Packet packet, @Nullable PacketCallbacks listener, NetworkState packetState, NetworkState currentState, CallbackInfo ci, ChannelFuture channelFuture) { - if (listener instanceof GenericFutureListenerHolder holder) { + @Inject(method = "sendInternal", at = @At(value = "INVOKE", target = "Lio/netty/channel/ChannelFuture;addListener(Lio/netty/util/concurrent/GenericFutureListener;)Lio/netty/channel/ChannelFuture;", remap = false), locals = LocalCapture.CAPTURE_FAILHARD) + private void sendInternal(Packet packet, @Nullable PacketCallbacks callbacks, boolean flush, CallbackInfo ci, ChannelFuture channelFuture) { + if (callbacks instanceof GenericFutureListenerHolder holder) { channelFuture.addListener(holder.getDelegate()); channelFuture.addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE); ci.cancel(); diff --git a/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/mixin/networking/ServerLoginNetworkHandlerMixin.java b/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/mixin/networking/ServerLoginNetworkHandlerMixin.java index 2d141bcca3..c81f3f5f64 100644 --- a/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/mixin/networking/ServerLoginNetworkHandlerMixin.java +++ b/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/mixin/networking/ServerLoginNetworkHandlerMixin.java @@ -16,6 +16,7 @@ package net.fabricmc.fabric.mixin.networking; +import com.mojang.authlib.GameProfile; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -31,7 +32,6 @@ import net.minecraft.network.packet.s2c.login.LoginQueryRequestS2CPacket; import net.minecraft.server.MinecraftServer; import net.minecraft.server.network.ServerLoginNetworkHandler; -import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.Text; import net.fabricmc.fabric.impl.networking.DisconnectPacketSource; @@ -46,7 +46,7 @@ abstract class ServerLoginNetworkHandlerMixin implements NetworkHandlerExtension private MinecraftServer server; @Shadow - public abstract void acceptPlayer(); + protected abstract void tickVerify(GameProfile profile); @Unique private ServerLoginNetworkAddon addon; @@ -56,11 +56,11 @@ private void initAddon(CallbackInfo ci) { this.addon = new ServerLoginNetworkAddon((ServerLoginNetworkHandler) (Object) this); } - @Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerLoginNetworkHandler;acceptPlayer()V")) - private void handlePlayerJoin(ServerLoginNetworkHandler handler) { + @Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerLoginNetworkHandler;tickVerify(Lcom/mojang/authlib/GameProfile;)V")) + private void handlePlayerJoin(ServerLoginNetworkHandler instance, GameProfile profile) { // Do not accept the player, thereby moving into play stage until all login futures being waited on are completed if (this.addon.queryTick()) { - this.acceptPlayer(); + this.tickVerify(profile); } } @@ -72,7 +72,7 @@ private void handleCustomPayloadReceivedAsync(LoginQueryResponseC2SPacket packet } } - @Redirect(method = "acceptPlayer", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;getNetworkCompressionThreshold()I", ordinal = 0)) + @Redirect(method = "tickVerify", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;getNetworkCompressionThreshold()I", ordinal = 0)) private int removeLateCompressionPacketSending(MinecraftServer server) { return -1; } @@ -82,9 +82,9 @@ private void handleDisconnection(Text reason, CallbackInfo ci) { this.addon.handleDisconnect(); } - @Inject(method = "addToServer", at = @At("HEAD")) - private void handlePlayTransitionNormal(ServerPlayerEntity player, CallbackInfo ci) { - this.addon.handlePlayTransition(); + @Inject(method = "sendSuccessPacket", at = @At("HEAD")) + private void handlePlayTransitionNormal(GameProfile profile, CallbackInfo ci) { + this.addon.handleConfigurationTransition(); } @Override diff --git a/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/mixin/networking/ServerPlayNetworkHandlerMixin.java b/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/mixin/networking/ServerPlayNetworkHandlerMixin.java index 675ede32b7..db2b298d97 100644 --- a/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/mixin/networking/ServerPlayNetworkHandlerMixin.java +++ b/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/mixin/networking/ServerPlayNetworkHandlerMixin.java @@ -16,9 +16,7 @@ package net.fabricmc.fabric.mixin.networking; -import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -26,9 +24,9 @@ import net.minecraft.network.ClientConnection; import net.minecraft.network.packet.Packet; -import net.minecraft.network.packet.c2s.play.CustomPayloadC2SPacket; -import net.minecraft.network.packet.s2c.play.DisconnectS2CPacket; +import net.minecraft.network.packet.s2c.common.DisconnectS2CPacket; import net.minecraft.server.MinecraftServer; +import net.minecraft.server.network.ServerCommonNetworkHandler; import net.minecraft.server.network.ServerPlayNetworkHandler; import net.minecraft.text.Text; @@ -38,17 +36,14 @@ // We want to apply a bit earlier than other mods which may not use us in order to prevent refCount issues @Mixin(value = ServerPlayNetworkHandler.class, priority = 999) -abstract class ServerPlayNetworkHandlerMixin implements NetworkHandlerExtensions, DisconnectPacketSource { - @Shadow - @Final - private MinecraftServer server; - @Shadow - @Final - public ClientConnection connection; - +abstract class ServerPlayNetworkHandlerMixin extends ServerCommonNetworkHandler implements NetworkHandlerExtensions, DisconnectPacketSource { @Unique private ServerPlayNetworkAddon addon; + private ServerPlayNetworkHandlerMixin(MinecraftServer server, ClientConnection connection, int keepAliveId) { + super(server, connection, keepAliveId); + } + @Inject(method = "", at = @At("RETURN")) private void initAddon(CallbackInfo ci) { this.addon = new ServerPlayNetworkAddon((ServerPlayNetworkHandler) (Object) this, this.server); @@ -56,12 +51,13 @@ private void initAddon(CallbackInfo ci) { this.addon.lateInit(); } - @Inject(method = "onCustomPayload", at = @At("HEAD"), cancellable = true) - private void handleCustomPayloadReceivedAsync(CustomPayloadC2SPacket packet, CallbackInfo ci) { - if (this.addon.handle(packet)) { - ci.cancel(); - } - } + // TODO call from ServerCommonNetworkHandler but with the addon here? +// @Inject(method = "onCustomPayload", at = @At("HEAD"), cancellable = true) +// private void handleCustomPayloadReceivedAsync(CustomPayloadC2SPacket packet, CallbackInfo ci) { +// if (this.addon.handle(packet)) { +// ci.cancel(); +// } +// } @Inject(method = "onDisconnected", at = @At("HEAD")) private void handleDisconnection(Text reason, CallbackInfo ci) { diff --git a/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/mixin/networking/accessor/CustomPayloadC2SPacketAccessor.java b/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/mixin/networking/accessor/CustomPayloadC2SPacketAccessor.java deleted file mode 100644 index 219d77d5e2..0000000000 --- a/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/mixin/networking/accessor/CustomPayloadC2SPacketAccessor.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2016, 2017, 2018, 2019 FabricMC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.fabricmc.fabric.mixin.networking.accessor; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -import net.minecraft.network.PacketByteBuf; -import net.minecraft.network.packet.c2s.play.CustomPayloadC2SPacket; -import net.minecraft.util.Identifier; - -@Mixin(CustomPayloadC2SPacket.class) -public interface CustomPayloadC2SPacketAccessor { - @Accessor - Identifier getChannel(); - - @Accessor - PacketByteBuf getData(); -} diff --git a/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/mixin/networking/accessor/LoginQueryResponseC2SPacketAccessor.java b/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/mixin/networking/accessor/LoginQueryResponseC2SPacketAccessor.java deleted file mode 100644 index d518193d75..0000000000 --- a/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/mixin/networking/accessor/LoginQueryResponseC2SPacketAccessor.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2016, 2017, 2018, 2019 FabricMC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.fabricmc.fabric.mixin.networking.accessor; - -import org.jetbrains.annotations.Nullable; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -import net.minecraft.network.PacketByteBuf; -import net.minecraft.network.packet.c2s.login.LoginQueryResponseC2SPacket; - -@Mixin(LoginQueryResponseC2SPacket.class) -public interface LoginQueryResponseC2SPacketAccessor { - @Accessor - int getQueryId(); - - @Nullable - @Accessor - PacketByteBuf getResponse(); -} diff --git a/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/mixin/networking/accessor/ServerPlayNetworkHandlerAccessor.java b/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/mixin/networking/accessor/ServerCommonNetworkHandlerAccessor.java similarity index 84% rename from fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/mixin/networking/accessor/ServerPlayNetworkHandlerAccessor.java rename to fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/mixin/networking/accessor/ServerCommonNetworkHandlerAccessor.java index 9ff3de7a8e..75083378d9 100644 --- a/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/mixin/networking/accessor/ServerPlayNetworkHandlerAccessor.java +++ b/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/mixin/networking/accessor/ServerCommonNetworkHandlerAccessor.java @@ -20,10 +20,10 @@ import org.spongepowered.asm.mixin.gen.Accessor; import net.minecraft.network.ClientConnection; -import net.minecraft.server.network.ServerPlayNetworkHandler; +import net.minecraft.server.network.ServerCommonNetworkHandler; -@Mixin(ServerPlayNetworkHandler.class) -public interface ServerPlayNetworkHandlerAccessor { +@Mixin(ServerCommonNetworkHandler.class) +public interface ServerCommonNetworkHandlerAccessor { @Accessor ClientConnection getConnection(); } diff --git a/fabric-networking-api-v1/src/main/resources/fabric-networking-api-v1.mixins.json b/fabric-networking-api-v1/src/main/resources/fabric-networking-api-v1.mixins.json index 8f71d23272..8445706fa4 100644 --- a/fabric-networking-api-v1/src/main/resources/fabric-networking-api-v1.mixins.json +++ b/fabric-networking-api-v1/src/main/resources/fabric-networking-api-v1.mixins.json @@ -8,10 +8,8 @@ "PlayerManagerMixin", "ServerLoginNetworkHandlerMixin", "ServerPlayNetworkHandlerMixin", - "accessor.CustomPayloadC2SPacketAccessor", "accessor.EntityTrackerAccessor", - "accessor.LoginQueryResponseC2SPacketAccessor", - "accessor.ServerPlayNetworkHandlerAccessor", + "accessor.ServerCommonNetworkHandlerAccessor", "accessor.ServerLoginNetworkHandlerAccessor", "accessor.ThreadedAnvilChunkStorageAccessor" ], diff --git a/fabric-networking-api-v1/src/testmod/java/net/fabricmc/fabric/test/networking/play/NetworkingPlayPacketTest.java b/fabric-networking-api-v1/src/testmod/java/net/fabricmc/fabric/test/networking/play/NetworkingPlayPacketTest.java index 52da7a1db6..9d986498f9 100644 --- a/fabric-networking-api-v1/src/testmod/java/net/fabricmc/fabric/test/networking/play/NetworkingPlayPacketTest.java +++ b/fabric-networking-api-v1/src/testmod/java/net/fabricmc/fabric/test/networking/play/NetworkingPlayPacketTest.java @@ -20,14 +20,11 @@ import static net.minecraft.server.command.CommandManager.argument; import static net.minecraft.server.command.CommandManager.literal; -import java.util.List; - import com.mojang.brigadier.Command; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.arguments.StringArgumentType; import net.minecraft.network.PacketByteBuf; -import net.minecraft.network.packet.s2c.play.BundleS2CPacket; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.Text; @@ -64,10 +61,11 @@ public static void registerCommand(CommandDispatcher dispat PacketByteBuf buf2 = PacketByteBufs.create(); buf2.writeText(Text.literal("bundled #2")); - BundleS2CPacket packet = new BundleS2CPacket(List.of( - ServerPlayNetworking.createS2CPacket(TEST_CHANNEL, buf1), - ServerPlayNetworking.createS2CPacket(TEST_CHANNEL, buf2))); - ctx.getSource().getPlayer().networkHandler.sendPacket(packet); + // TODO 1.20.2 +// BundleS2CPacket packet = new BundleS2CPacket(List.of( +// ServerPlayNetworking.createS2CPacket(TEST_CHANNEL, buf1), +// ServerPlayNetworking.createS2CPacket(TEST_CHANNEL, buf2))); +// ctx.getSource().getPlayer().networkHandler.sendPacket(packet); return Command.SINGLE_SUCCESS; }))); } diff --git a/fabric-object-builder-api-v1/src/main/java/net/fabricmc/fabric/mixin/object/builder/TradeOffersTypeAwareBuyForOneEmeraldFactoryMixin.java b/fabric-object-builder-api-v1/src/main/java/net/fabricmc/fabric/mixin/object/builder/TradeOffersTypeAwareBuyForOneEmeraldFactoryMixin.java index 3baca35b2f..7fb62d719b 100644 --- a/fabric-object-builder-api-v1/src/main/java/net/fabricmc/fabric/mixin/object/builder/TradeOffersTypeAwareBuyForOneEmeraldFactoryMixin.java +++ b/fabric-object-builder-api-v1/src/main/java/net/fabricmc/fabric/mixin/object/builder/TradeOffersTypeAwareBuyForOneEmeraldFactoryMixin.java @@ -27,10 +27,11 @@ import net.minecraft.entity.Entity; import net.minecraft.item.ItemStack; -import net.minecraft.util.math.random.Random; import net.minecraft.registry.DefaultedRegistry; +import net.minecraft.util.math.random.Random; import net.minecraft.village.TradeOffer; import net.minecraft.village.TradeOffers; +import net.minecraft.village.VillagerDataContainer; import net.minecraft.village.VillagerType; @Mixin(TradeOffers.TypeAwareBuyForOneEmeraldFactory.class) @@ -50,7 +51,7 @@ private Stream disableVanillaCheck(DefaultedRegistry instan * To prevent "item" -> "air" trades, if the result of a type aware trade is air, make sure no offer is created. */ @Inject(method = "create", at = @At(value = "NEW", target = "net/minecraft/village/TradeOffer"), locals = LocalCapture.CAPTURE_FAILEXCEPTION, cancellable = true) - private void failOnNullItem(Entity entity, Random random, CallbackInfoReturnable cir, ItemStack buyingItem) { + private void failOnNullItem(Entity entity, Random random, CallbackInfoReturnable cir, VillagerDataContainer villagerDataContainer, ItemStack buyingItem) { if (buyingItem.isEmpty()) { // Will return true for an "empty" item stack that had null passed in the ctor cir.setReturnValue(null); // Return null to prevent creation of empty trades } diff --git a/fabric-recipe-api-v1/src/main/java/net/fabricmc/fabric/impl/recipe/ingredient/CustomIngredientSync.java b/fabric-recipe-api-v1/src/main/java/net/fabricmc/fabric/impl/recipe/ingredient/CustomIngredientSync.java index 9a51ddc8a8..8daf639167 100644 --- a/fabric-recipe-api-v1/src/main/java/net/fabricmc/fabric/impl/recipe/ingredient/CustomIngredientSync.java +++ b/fabric-recipe-api-v1/src/main/java/net/fabricmc/fabric/impl/recipe/ingredient/CustomIngredientSync.java @@ -23,7 +23,7 @@ import org.jetbrains.annotations.Nullable; import net.minecraft.network.PacketByteBuf; -import net.minecraft.network.PacketEncoder; +import net.minecraft.network.handler.PacketEncoder; import net.minecraft.util.Identifier; import net.fabricmc.api.ModInitializer; diff --git a/fabric-recipe-api-v1/src/main/java/net/fabricmc/fabric/impl/recipe/ingredient/SupportedIngredientsPacketEncoder.java b/fabric-recipe-api-v1/src/main/java/net/fabricmc/fabric/impl/recipe/ingredient/SupportedIngredientsPacketEncoder.java index c5de3e8607..ac75f6dbea 100644 --- a/fabric-recipe-api-v1/src/main/java/net/fabricmc/fabric/impl/recipe/ingredient/SupportedIngredientsPacketEncoder.java +++ b/fabric-recipe-api-v1/src/main/java/net/fabricmc/fabric/impl/recipe/ingredient/SupportedIngredientsPacketEncoder.java @@ -18,7 +18,7 @@ import java.util.Set; -import net.minecraft.network.PacketEncoder; +import net.minecraft.network.handler.PacketEncoder; import net.minecraft.util.Identifier; /** diff --git a/fabric-recipe-api-v1/src/main/java/net/fabricmc/fabric/mixin/recipe/ingredient/PacketEncoderMixin.java b/fabric-recipe-api-v1/src/main/java/net/fabricmc/fabric/mixin/recipe/ingredient/PacketEncoderMixin.java index 50d2776072..633cf5af1e 100644 --- a/fabric-recipe-api-v1/src/main/java/net/fabricmc/fabric/mixin/recipe/ingredient/PacketEncoderMixin.java +++ b/fabric-recipe-api-v1/src/main/java/net/fabricmc/fabric/mixin/recipe/ingredient/PacketEncoderMixin.java @@ -27,7 +27,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import net.minecraft.network.packet.Packet; -import net.minecraft.network.PacketEncoder; +import net.minecraft.network.handler.PacketEncoder; import net.minecraft.util.Identifier; import net.fabricmc.fabric.impl.recipe.ingredient.CustomIngredientSync; diff --git a/fabric-rendering-v1/src/client/java/net/fabricmc/fabric/mixin/client/rendering/EntityRenderersMixin.java b/fabric-rendering-v1/src/client/java/net/fabricmc/fabric/mixin/client/rendering/EntityRenderersMixin.java index 0967783f30..8e1a1b454f 100644 --- a/fabric-rendering-v1/src/client/java/net/fabricmc/fabric/mixin/client/rendering/EntityRenderersMixin.java +++ b/fabric-rendering-v1/src/client/java/net/fabricmc/fabric/mixin/client/rendering/EntityRenderersMixin.java @@ -27,10 +27,9 @@ import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import net.minecraft.client.render.entity.EntityRenderer; import net.minecraft.client.render.entity.EntityRendererFactory; import net.minecraft.client.render.entity.EntityRenderers; -import net.minecraft.client.network.AbstractClientPlayerEntity; -import net.minecraft.client.render.entity.EntityRenderer; import net.minecraft.client.render.entity.LivingEntityRenderer; import net.minecraft.entity.EntityType; import net.minecraft.entity.LivingEntity; @@ -69,7 +68,7 @@ private static EntityRenderer createEntityRenderer(EntityRendererFactory e // private static synthetic method_32175(Lcom/google/common/collect/ImmutableMap$Builder;Lnet/minecraft/class_5617$class_5618;Ljava/lang/String;Lnet/minecraft/class_5617;)V @SuppressWarnings({"unchecked", "rawtypes"}) @Redirect(method = "method_32175", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/entity/EntityRendererFactory;create(Lnet/minecraft/client/render/entity/EntityRendererFactory$Context;)Lnet/minecraft/client/render/entity/EntityRenderer;")) - private static EntityRenderer createPlayerEntityRenderer(EntityRendererFactory playerEntityRendererFactory, EntityRendererFactory.Context context, ImmutableMap.Builder builder, EntityRendererFactory.Context context2, String str, EntityRendererFactory playerEntityRendererFactory2) { + private static EntityRenderer createPlayerEntityRenderer(EntityRendererFactory playerEntityRendererFactory, EntityRendererFactory.Context context) { EntityRenderer entityRenderer = playerEntityRendererFactory.create(context); LivingEntityRendererAccessor accessor = (LivingEntityRendererAccessor) entityRenderer; diff --git a/fabric-screen-api-v1/src/client/java/net/fabricmc/fabric/mixin/screen/MouseMixin.java b/fabric-screen-api-v1/src/client/java/net/fabricmc/fabric/mixin/screen/MouseMixin.java index 79017698fa..2ee567fea9 100644 --- a/fabric-screen-api-v1/src/client/java/net/fabricmc/fabric/mixin/screen/MouseMixin.java +++ b/fabric-screen-api-v1/src/client/java/net/fabricmc/fabric/mixin/screen/MouseMixin.java @@ -116,7 +116,7 @@ private static void afterMouseReleasedEvent(boolean[] resultHack, Screen screen, thisRef.currentScreen = null; } - @Inject(method = "onMouseScroll", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/Screen;mouseScrolled(DDD)Z"), locals = LocalCapture.CAPTURE_FAILEXCEPTION, cancellable = true) + @Inject(method = "onMouseScroll", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/Screen;mouseScrolled(DDDD)Z"), locals = LocalCapture.CAPTURE_FAILEXCEPTION, cancellable = true) private void beforeMouseScrollEvent(long window, double horizontal, double vertical, CallbackInfo ci, double verticalAmount, double mouseX, double mouseY) { // Store the screen in a variable in case someone tries to change the screen during this before event. // If someone changes the screen, the after event will likely have class cast exceptions or throw a NPE. @@ -139,7 +139,7 @@ private void beforeMouseScrollEvent(long window, double horizontal, double verti ScreenMouseEvents.beforeMouseScroll(this.currentScreen).invoker().beforeMouseScroll(this.currentScreen, mouseX, mouseY, this.horizontalScrollAmount, verticalAmount); } - @Inject(method = "onMouseScroll", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/Screen;mouseScrolled(DDD)Z", shift = At.Shift.AFTER), locals = LocalCapture.CAPTURE_FAILEXCEPTION) + @Inject(method = "onMouseScroll", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/Screen;mouseScrolled(DDDD)Z", shift = At.Shift.AFTER), locals = LocalCapture.CAPTURE_FAILEXCEPTION) private void afterMouseScrollEvent(long window, double horizontal, double vertical, CallbackInfo ci, double verticalAmount, double mouseX, double mouseY) { if (this.currentScreen == null) { return; diff --git a/fabric-screen-handler-api-v1/src/testmodClient/java/net/fabricmc/fabric/test/screenhandler/client/PositionedScreen.java b/fabric-screen-handler-api-v1/src/testmodClient/java/net/fabricmc/fabric/test/screenhandler/client/PositionedScreen.java index e3309ec595..13a655de80 100644 --- a/fabric-screen-handler-api-v1/src/testmodClient/java/net/fabricmc/fabric/test/screenhandler/client/PositionedScreen.java +++ b/fabric-screen-handler-api-v1/src/testmodClient/java/net/fabricmc/fabric/test/screenhandler/client/PositionedScreen.java @@ -48,7 +48,7 @@ private static Optional getPositionText(ScreenHandler handler) { @Override public void render(DrawContext drawContext, int mouseX, int mouseY, float delta) { - renderBackground(drawContext); + renderBackground(drawContext, mouseX, mouseY, delta); super.render(drawContext, mouseX, mouseY, delta); drawMouseoverTooltip(drawContext, mouseX, mouseY); } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 77274002d1..08aeb5ae21 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -19,9 +19,9 @@ "FabricMC" ], "depends": { - "fabricloader": ">=0.14.21", + "fabricloader": ">=0.14.22", "java": ">=17", - "minecraft": ">=1.20 <1.20.2-" + "minecraft": ">=1.20.2- <1.20.3-" }, "description": "Core API module providing key hooks and intercompatibility features." }