diff --git a/gradle.properties b/gradle.properties index d4f1622..1ebe9be 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,10 +3,10 @@ org.gradle.daemon=false # Fabric Properties # check these on https://fabricmc.net/develop - minecraft_version=1.19.3 - yarn_mappings=1.19.3+build.2 - loader_version=0.14.11 - fabric_version=0.68.1+1.19.3 + minecraft_version=1.20-pre6 + yarn_mappings=1.20-pre6+build.2 + loader_version=0.14.21 + fabric_version=0.82.1+1.20 # Mod Properties group=com.sollace @@ -20,4 +20,4 @@ org.gradle.daemon=false modrinth_project_id=coknAH3s # Dependencies - modmenu_version=5.0.0-alpha.3 + modmenu_version=7.0.0-beta.2 diff --git a/src/main/java/com/sollace/fabwork/api/packets/C2SPacketType.java b/src/main/java/com/sollace/fabwork/api/packets/C2SPacketType.java index e6eb824..3860564 100644 --- a/src/main/java/com/sollace/fabwork/api/packets/C2SPacketType.java +++ b/src/main/java/com/sollace/fabwork/api/packets/C2SPacketType.java @@ -5,6 +5,7 @@ import java.util.function.Function; import com.google.common.base.Preconditions; +import com.sollace.fabwork.impl.ClientConnectionAccessor; import com.sollace.fabwork.impl.packets.ClientSimpleNetworkingImpl; import com.sollace.fabwork.impl.packets.ServerSimpleNetworkingImpl; @@ -50,13 +51,13 @@ public void sendToServer(T packet) { */ public Future awaitResponseFrom(ServerPlayerEntity client) { Objects.requireNonNull(client, "Client player cannot be null"); - return ServerSimpleNetworkingImpl.waitForReponse(this, client.networkHandler.getConnection()); + return ServerSimpleNetworkingImpl.waitForReponse(this, ClientConnectionAccessor.get(client.networkHandler)); } /** * Repackages a Fabwork packet into a normal Minecraft protocol packet suitable for sending to the connected server. */ - public net.minecraft.network.Packet toPacket(T packet) { + public net.minecraft.network.packet.Packet toPacket(T packet) { Objects.requireNonNull(packet, "Packet cannot be null"); return ClientSimpleNetworkingImpl.createC2SPacket(id(), packet.toBuffer()); } diff --git a/src/main/java/com/sollace/fabwork/api/packets/S2CPacketType.java b/src/main/java/com/sollace/fabwork/api/packets/S2CPacketType.java index 29991ab..8439c55 100644 --- a/src/main/java/com/sollace/fabwork/api/packets/S2CPacketType.java +++ b/src/main/java/com/sollace/fabwork/api/packets/S2CPacketType.java @@ -46,7 +46,7 @@ public void sendToSurroundingPlayers(T packet, Entity entity) { /** * Repackages a fabwork packet into a normal Minecraft protocol packet suitable for sending to a connected client. */ - public net.minecraft.network.Packet toPacket(T packet) { + public net.minecraft.network.packet.Packet toPacket(T packet) { Objects.requireNonNull(packet, "Packet cannot be null"); return ServerPlayNetworking.createS2CPacket(id(), packet.toBuffer()); } diff --git a/src/main/java/com/sollace/fabwork/impl/ClientConnectionAccessor.java b/src/main/java/com/sollace/fabwork/impl/ClientConnectionAccessor.java new file mode 100644 index 0000000..c394632 --- /dev/null +++ b/src/main/java/com/sollace/fabwork/impl/ClientConnectionAccessor.java @@ -0,0 +1,12 @@ +package com.sollace.fabwork.impl; + +import net.minecraft.network.ClientConnection; +import net.minecraft.server.network.ServerPlayNetworkHandler; + +public interface ClientConnectionAccessor { + ClientConnection getConnection(); + + static ClientConnection get(ServerPlayNetworkHandler handler) { + return ((ClientConnectionAccessor)handler).getConnection(); + } +} diff --git a/src/main/java/com/sollace/fabwork/impl/FabworkServer.java b/src/main/java/com/sollace/fabwork/impl/FabworkServer.java index 2df596b..4c53a49 100644 --- a/src/main/java/com/sollace/fabwork/impl/FabworkServer.java +++ b/src/main/java/com/sollace/fabwork/impl/FabworkServer.java @@ -37,14 +37,15 @@ public void onInitialize() { ServerPlayNetworking.registerGlobalReceiver(CONSENT_ID, (server, player, handler, buffer, response) -> { LoaderUtil.invokeUntrusted(() -> { SynchronisationState state = new SynchronisationState(ModEntryImpl.read(buffer), emptyState.installedOnServer().stream()); - LOGGER.info("Got mod list from {}[{}]: {}", player.getName().getString(), handler.getConnection().getAddress(), ModEntriesUtil.stringify(state.installedOnClient())); - clientLoginStates.put(handler.getConnection(), state); + ClientConnection connection = ClientConnectionAccessor.get(handler); + LOGGER.info("Got mod list from {}[{}]: {}", player.getName().getString(), connection.getAddress(), ModEntriesUtil.stringify(state.installedOnClient())); + clientLoginStates.put(connection, state); }, "Received synchronize response from client"); }); ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> { LoaderUtil.invokeUntrusted(() -> { - LOGGER.info("Sending mod list to {}[{}]", handler.getPlayer().getName().getString(), handler.getConnection().getAddress()); + LOGGER.info("Sending mod list to {}[{}]", handler.getPlayer().getName().getString(), handler.getConnectionAddress()); sender.sendPacket(CONSENT_ID, ModEntryImpl.write( emptyState.installedOnServer().stream(), PacketByteBufs.create()) @@ -54,23 +55,24 @@ public void onInitialize() { ServerConnectionEvents.CONNECT.register((handler, sender, server) -> { LoaderUtil.invokeUntrusted(() -> { - PlayPingSynchroniser.waitForClientResponse(handler.getConnection(), responseType -> { + PlayPingSynchroniser.waitForClientResponse(ClientConnectionAccessor.get(handler), responseType -> { + ClientConnection connection = ClientConnectionAccessor.get(handler); if (responseType == ResponseType.COMPLETED) { - if (clientLoginStates.containsKey(handler.getConnection())) { - clientLoginStates.remove(handler.getConnection()).verify(handler.getConnection(), LOGGER, true); + if (clientLoginStates.containsKey(connection)) { + clientLoginStates.remove(connection).verify(connection, LOGGER, true); } else { - LOGGER.warn("{}[{}] did not send a mod list. They may not have fabwork installed", handler.getPlayer().getName().getString(), handler.getConnection().getAddress()); + LOGGER.warn("{}[{}] did not send a mod list. They may not have fabwork installed", handler.getPlayer().getName().getString(), handler.getConnectionAddress()); if (config.allowUnmoddedClients) { - LOGGER.warn("Connection to {}[{}] has been force permitted by server configuration. They are allowed to join checking installed mods! Their game may be broken upon joining!", handler.getPlayer().getName().getString(), handler.getConnection().getAddress()); + LOGGER.warn("Connection to {}[{}] has been force permitted by server configuration. They are allowed to join checking installed mods! Their game may be broken upon joining!", handler.getPlayer().getName().getString(), handler.getConnectionAddress()); } else { - emptyState.verify(handler.getConnection(), LOGGER, false); + emptyState.verify(connection, LOGGER, false); } } } else { LOGGER.warn("Failed to receive response from client. {}[{}] ConnectionState: {}", handler.getPlayer().getName().getString(), - handler.getConnection().getAddress(), - handler.getConnection().isOpen() ? " OPEN" : " CLOSED" + handler.getConnectionAddress(), + handler.isConnectionOpen() ? " OPEN" : " CLOSED" ); } }); diff --git a/src/main/java/com/sollace/fabwork/impl/mixin/ServerPlayNetworkHandlerMixin.java b/src/main/java/com/sollace/fabwork/impl/mixin/ServerPlayNetworkHandlerMixin.java index f988883..3a3151b 100644 --- a/src/main/java/com/sollace/fabwork/impl/mixin/ServerPlayNetworkHandlerMixin.java +++ b/src/main/java/com/sollace/fabwork/impl/mixin/ServerPlayNetworkHandlerMixin.java @@ -1,22 +1,29 @@ package com.sollace.fabwork.impl.mixin; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import com.sollace.fabwork.impl.ClientConnectionAccessor; import com.sollace.fabwork.impl.PlayPingSynchroniser; +import net.minecraft.network.ClientConnection; import net.minecraft.network.NetworkThreadUtils; import net.minecraft.network.listener.ServerPlayPacketListener; import net.minecraft.network.packet.c2s.play.PlayPongC2SPacket; import net.minecraft.server.network.ServerPlayNetworkHandler; @Mixin(ServerPlayNetworkHandler.class) -abstract class ServerPlayNetworkHandlerMixin implements ServerPlayPacketListener { +abstract class ServerPlayNetworkHandlerMixin implements ServerPlayPacketListener, ClientConnectionAccessor { @Inject(method = "onPong(Lnet/minecraft/network/packet/c2s/play/PlayPongC2SPacket;)V", at = @At("HEAD")) private void onOnPong(PlayPongC2SPacket packet, CallbackInfo info) { - NetworkThreadUtils.forceMainThread(packet, this, ((ServerPlayNetworkHandler)(Object)this).player.getWorld()); + NetworkThreadUtils.forceMainThread(packet, this, ((ServerPlayNetworkHandler)(Object)this).player.getServerWorld()); PlayPingSynchroniser.onClientResponse(packet, ((ServerPlayNetworkHandler)(Object)this).player.getWorld().getServer()); } + + @Override + @Accessor("connection") + public abstract ClientConnection getConnection(); } diff --git a/src/main/java/com/sollace/fabwork/impl/packets/ClientSimpleNetworkingImpl.java b/src/main/java/com/sollace/fabwork/impl/packets/ClientSimpleNetworkingImpl.java index 13ae3a4..10bd506 100644 --- a/src/main/java/com/sollace/fabwork/impl/packets/ClientSimpleNetworkingImpl.java +++ b/src/main/java/com/sollace/fabwork/impl/packets/ClientSimpleNetworkingImpl.java @@ -28,7 +28,7 @@ public static void send(Identifier id, PacketByteBuf buffer) { ClientPlayNetworking.send(id, buffer); } - public static net.minecraft.network.Packet createC2SPacket(Identifier id, PacketByteBuf buffer) { + public static net.minecraft.network.packet.Packet createC2SPacket(Identifier id, PacketByteBuf buffer) { return ClientPlayNetworking.createC2SPacket(id, buffer); } } diff --git a/src/main/java/com/sollace/fabwork/impl/packets/ServerSimpleNetworkingImpl.java b/src/main/java/com/sollace/fabwork/impl/packets/ServerSimpleNetworkingImpl.java index 24556fc..d35c5fc 100644 --- a/src/main/java/com/sollace/fabwork/impl/packets/ServerSimpleNetworkingImpl.java +++ b/src/main/java/com/sollace/fabwork/impl/packets/ServerSimpleNetworkingImpl.java @@ -6,6 +6,7 @@ import java.util.function.Function; import com.sollace.fabwork.api.packets.*; +import com.sollace.fabwork.impl.ClientConnectionAccessor; import com.sollace.fabwork.impl.PlayPingSynchroniser; import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; @@ -39,7 +40,7 @@ public static > Future waitForReponse(C2 final CompletableFuture future = new CompletableFuture<>(); packetType.receiver().addTemporaryListener((sender, packet) -> { - if (sender.networkHandler.getConnection() == connection) { + if (ClientConnectionAccessor.get(sender.networkHandler) == connection) { receivedPacket[0] = packet; return true; }