diff --git a/src/main/java/gg/skytils/skytilsmod/mixins/transformers/accessors/AccessorPlayerControllerMP.java b/src/main/java/gg/skytils/skytilsmod/mixins/transformers/accessors/AccessorPlayerControllerMP.java deleted file mode 100644 index bdf349239..000000000 --- a/src/main/java/gg/skytils/skytilsmod/mixins/transformers/accessors/AccessorPlayerControllerMP.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Skytils - Hypixel Skyblock Quality of Life Mod - * Copyright (C) 2020-2024 Skytils - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published - * by the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package gg.skytils.skytilsmod.mixins.transformers.accessors; - -import net.minecraft.client.multiplayer.PlayerControllerMP; -import net.minecraft.client.network.NetHandlerPlayClient; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -@Mixin(PlayerControllerMP.class) -public interface AccessorPlayerControllerMP { - @Accessor - NetHandlerPlayClient getNetClientHandler(); -} diff --git a/src/main/kotlin/gg/skytils/skytilsmod/listeners/ServerPayloadInterceptor.kt b/src/main/kotlin/gg/skytils/skytilsmod/listeners/ServerPayloadInterceptor.kt index 21933fc02..5b3281660 100644 --- a/src/main/kotlin/gg/skytils/skytilsmod/listeners/ServerPayloadInterceptor.kt +++ b/src/main/kotlin/gg/skytils/skytilsmod/listeners/ServerPayloadInterceptor.kt @@ -18,21 +18,20 @@ package gg.skytils.skytilsmod.listeners +import gg.skytils.skytilsmod.Skytils import gg.skytils.skytilsmod.Skytils.Companion.IO import gg.skytils.skytilsmod.Skytils.Companion.mc +import gg.skytils.skytilsmod.core.MC import gg.skytils.skytilsmod.events.impl.HypixelPacketEvent import gg.skytils.skytilsmod.events.impl.PacketEvent import gg.skytils.skytilsmod.mixins.transformers.accessors.AccessorHypixelModAPI -import gg.skytils.skytilsmod.mixins.transformers.accessors.AccessorPlayerControllerMP import gg.skytils.skytilsmod.utils.Utils import gg.skytils.skytilsmod.utils.ifNull import io.netty.buffer.Unpooled -import kotlinx.coroutines.delay +import kotlinx.coroutines.* import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.first -import kotlinx.coroutines.launch -import kotlinx.coroutines.withTimeout import net.hypixel.modapi.HypixelModAPI import net.hypixel.modapi.error.ErrorReason import net.hypixel.modapi.packet.ClientboundHypixelPacket @@ -40,7 +39,6 @@ import net.hypixel.modapi.packet.impl.clientbound.ClientboundHelloPacket import net.hypixel.modapi.packet.impl.clientbound.event.ClientboundLocationPacket import net.hypixel.modapi.packet.impl.serverbound.ServerboundVersionedPacket import net.hypixel.modapi.serializer.PacketSerializer -import net.minecraft.client.network.NetHandlerPlayClient import net.minecraft.network.PacketBuffer import net.minecraft.network.play.client.C17PacketCustomPayload import net.minecraft.network.play.server.S3FPacketCustomPayload @@ -107,13 +105,15 @@ object ServerPayloadInterceptor { } != null } } - IO.launch { + Skytils.launch { while (getNetClientHandler() == null) { println("Waiting for client handler to be set.") delay(50L) } - modAPI.subscribeToEventPacket(ClientboundLocationPacket::class.java) - modAPI.invokeSendRegisterPacket(true) + withContext(Dispatchers.MC) { + modAPI.subscribeToEventPacket(ClientboundLocationPacket::class.java) + modAPI.invokeSendRegisterPacket(true) + } } } } @@ -131,5 +131,5 @@ object ServerPayloadInterceptor { return@withTimeout receivedPackets.filter { it.identifier == this@getResponse.identifier }.first() as T } - private fun getNetClientHandler() = (mc.playerController as AccessorPlayerControllerMP?)?.netClientHandler ?: Utils.lastNHPC + private fun getNetClientHandler() = mc.netHandler ?: Utils.lastNHPC } \ No newline at end of file