Skip to content

Commit

Permalink
update to 0.4.0
Browse files Browse the repository at this point in the history
ImToggle committed May 29, 2024
1 parent d8f232e commit b9bccd8
Showing 4 changed files with 22 additions and 42 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -95,7 +95,7 @@ repositories {

// Configures the libraries/dependencies for your mod.
dependencies {
shade("net.hypixel:mod-api:0.1.7")
shade("net.hypixel:mod-api:0.4.0")
// Adds the OneConfig library, so we can develop with it.
modCompileOnly("cc.polyfrost:oneconfig-$platform:0.2.2-alpha+")

22 changes: 14 additions & 8 deletions src/main/kotlin/me/imtoggle/apiexample/ApiExampleMod.kt
Original file line number Diff line number Diff line change
@@ -8,16 +8,16 @@ import cc.polyfrost.oneconfig.utils.dsl.mc
import io.netty.buffer.Unpooled
import net.hypixel.modapi.HypixelModAPI
import net.hypixel.modapi.handler.ClientboundPacketHandler
import net.hypixel.modapi.packet.HypixelPacketType
import net.hypixel.modapi.packet.HypixelPacket
import net.hypixel.modapi.packet.impl.clientbound.*
import net.hypixel.modapi.packet.impl.clientbound.event.ClientboundLocationPacket
import net.hypixel.modapi.serializer.PacketSerializer
import net.minecraft.network.PacketBuffer
import net.minecraft.network.play.client.C17PacketCustomPayload
import net.minecraft.network.play.server.S3FPacketCustomPayload
import net.minecraftforge.fml.common.Mod
import net.minecraftforge.fml.common.event.FMLInitializationEvent


@Mod(modid = ApiExampleMod.MODID, name = ApiExampleMod.NAME, version = ApiExampleMod.VERSION, modLanguageAdapter = "cc.polyfrost.oneconfig.utils.KotlinLanguageAdapter")
object ApiExampleMod {
const val MODID = "@ID@"
@@ -26,12 +26,14 @@ object ApiExampleMod {

@Mod.EventHandler
fun onInit(event: FMLInitializationEvent) {
HypixelModAPI.getInstance().subscribeToEventPacket(ClientboundLocationPacket::class.java)
HypixelModAPI.getInstance().setPacketSender(this::sendPacket)
HypixelModAPI.getInstance().registerHandler(object : ClientboundPacketHandler {
override fun onPingPacket(packet: ClientboundPingPacket) {
UChat.chat(packet.toString())
}

override fun onLocationPacket(packet: ClientboundLocationPacket) {
override fun onLocationEvent(packet: ClientboundLocationPacket) {
UChat.chat(packet.toString())
}

@@ -47,16 +49,20 @@ object ApiExampleMod {
fun onReceive(e: ReceivePacketEvent) {
if (e.packet is S3FPacketCustomPayload) {
val packet = e.packet as S3FPacketCustomPayload
if (!packet.channelName.startsWith("hypixel")) return
if (!HypixelModAPI.getInstance().registry.isRegistered(packet.channelName)) return

HypixelModAPI.getInstance().handle(packet.channelName, PacketSerializer(packet.bufferData))
}
}

fun sendPacket(type: HypixelPacketType) {
val packet = PacketRegistry.createPacket(type)
private fun sendPacket(packet: HypixelPacket): Boolean {
val netHandler = mc.netHandler ?: return false

val buf = PacketBuffer(Unpooled.buffer())
packet?.write(PacketSerializer(buf))
mc.thePlayer.sendQueue.addToSendQueue(C17PacketCustomPayload(packet?.type?.identifier, buf))
val serializer = PacketSerializer(buf)
packet.write(serializer)
netHandler.addToSendQueue(C17PacketCustomPayload(packet.identifier, buf))
return true
}

}
11 changes: 7 additions & 4 deletions src/main/kotlin/me/imtoggle/apiexample/ModConfig.kt
Original file line number Diff line number Diff line change
@@ -3,23 +3,26 @@ package me.imtoggle.apiexample
import cc.polyfrost.oneconfig.config.Config
import cc.polyfrost.oneconfig.config.annotations.Button
import cc.polyfrost.oneconfig.config.data.*
import net.hypixel.modapi.packet.HypixelPacketType
import net.hypixel.modapi.HypixelModAPI
import net.hypixel.modapi.packet.impl.serverbound.ServerboundPartyInfoPacket
import net.hypixel.modapi.packet.impl.serverbound.ServerboundPingPacket
import net.hypixel.modapi.packet.impl.serverbound.ServerboundRegisterPacket

object ModConfig : Config(Mod(ApiExampleMod.NAME, ModType.UTIL_QOL), "${ApiExampleMod.MODID}.json") {

@Button(name = "Ping", text = "")
var ping = Runnable {
ApiExampleMod.sendPacket(HypixelPacketType.PING)
HypixelModAPI.getInstance().sendPacket(ServerboundPingPacket())
}

@Button(name = "Location", text = "")
var location = Runnable {
ApiExampleMod.sendPacket(HypixelPacketType.LOCATION)
HypixelModAPI.getInstance().sendPacket(ServerboundRegisterPacket(HypixelModAPI.getInstance().registry.getEventVersions(setOf("hyevent:location"))))
}

@Button(name = "Party Info", text = "")
var partyInfo = Runnable {
ApiExampleMod.sendPacket(HypixelPacketType.PARTY_INFO)
HypixelModAPI.getInstance().sendPacket(ServerboundPartyInfoPacket())
}

init {
29 changes: 0 additions & 29 deletions src/main/kotlin/me/imtoggle/apiexample/PacketRegistry.kt

This file was deleted.

0 comments on commit b9bccd8

Please sign in to comment.