Skip to content

Commit

Permalink
chore: update to mod-api 0.3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
My-Name-Is-Jeff committed Apr 29, 2024
1 parent 5d3740c commit ffcc869
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ dependencies {
shadowMe(project(":hypixel-api:types"))
shadowMe(project(":ws-shared"))

shadowMe("net.hypixel:mod-api:0.3.1")
shadowMe("net.hypixel:mod-api:0.3.2")


shadowMe(annotationProcessor("io.github.llamalad7:mixinextras-common:0.3.5")!!)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import net.hypixel.modapi.HypixelModAPI
import net.hypixel.modapi.packet.ClientboundHypixelPacket
import net.hypixel.modapi.packet.impl.serverbound.ServerboundVersionedPacket
import net.minecraft.client.entity.EntityPlayerSP
import net.minecraft.client.gui.GuiScreen
import net.minecraft.command.WrongUsageException
Expand Down Expand Up @@ -378,7 +379,7 @@ object SkytilsCommand : BaseCommand("skytils", listOf("st")) {
UChat.chat("$failPrefix §cPacket not found!")
} else {
registry as AccessorHypixelPacketRegistry
val packetClass = registry.classToIdentifier.entries.find { it.value == id && !ClientboundHypixelPacket::class.java.isAssignableFrom(it.key) }
val packetClass = registry.classToIdentifier.entries.find { it.value == id && ServerboundVersionedPacket::class.java.isAssignableFrom(it.key) }
?: return UChat.chat("$failPrefix §cPacket not found!")
val packet = packetClass.key.newInstance()
UChat.chat("$successPrefix §aPacket created: $packet")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import net.hypixel.modapi.HypixelModAPI
import net.hypixel.modapi.error.ErrorReason
import net.hypixel.modapi.packet.ClientboundHypixelPacket
import net.hypixel.modapi.packet.HypixelPacket
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
Expand Down Expand Up @@ -75,14 +76,14 @@ object ServerPayloadInterceptor {
}
}

fun HypixelPacket.toCustomPayload(): C17PacketCustomPayload {
fun ServerboundVersionedPacket.toCustomPayload(): C17PacketCustomPayload {
val buffer = PacketBuffer(Unpooled.buffer())
val serializer = PacketSerializer(buffer)
this.write(serializer)
return C17PacketCustomPayload(this.identifier, buffer)
}

suspend fun <T : ClientboundHypixelPacket> HypixelPacket.getResponse(handler: NetHandlerPlayClient): T = withTimeout(1.minutes) {
suspend fun <T : ClientboundHypixelPacket> ServerboundVersionedPacket.getResponse(handler: NetHandlerPlayClient): T = withTimeout(1.minutes) {
val packet: C17PacketCustomPayload = this@getResponse.toCustomPayload()
handler.addToSendQueue(packet)
return@withTimeout receivedPackets.filter { it.identifier == this@getResponse.identifier }.first() as T
Expand Down

0 comments on commit ffcc869

Please sign in to comment.