Skip to content

Commit

Permalink
chore: preprocess Skytils.kt to 1.16 forge
Browse files Browse the repository at this point in the history
  • Loading branch information
Sychic committed May 3, 2024
1 parent e03bf73 commit d0a79d6
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 35 deletions.
2 changes: 1 addition & 1 deletion mod/root.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ preprocess {

fabric12004.link(fabric11602)
fabric11602.link(forge11602)
forge11602.link(forge10809)
forge11602.link(forge10809, file("versions/1.16.2-1.8.9.txt"))
}
106 changes: 72 additions & 34 deletions mod/src/main/kotlin/gg/skytils/skytilsmod/Skytils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@

package gg.skytils.skytilsmod

import codes.som.anthony.koffee.modifiers.open
import gg.essential.api.EssentialAPI
import gg.essential.universal.UChat
import gg.essential.universal.UDesktop
import gg.essential.universal.UKeyboard
import gg.skytils.skytilsmod.commands.impl.*
import gg.skytils.skytilsmod.commands.stats.impl.CataCommand
Expand Down Expand Up @@ -88,25 +90,15 @@ import net.minecraft.client.gui.GuiButton
import net.minecraft.client.gui.GuiGameOver
import net.minecraft.client.gui.GuiIngameMenu
import net.minecraft.client.gui.GuiScreen
import net.minecraft.client.gui.inventory.GuiChest
import net.minecraft.client.settings.KeyBinding
import net.minecraft.inventory.ContainerChest
import net.minecraft.launchwrapper.Launch
import net.minecraft.network.play.client.C01PacketChatMessage
import net.minecraft.network.play.server.*
import net.minecraftforge.client.ClientCommandHandler
import net.minecraftforge.client.event.GuiOpenEvent
import net.minecraftforge.client.event.GuiScreenEvent
import net.minecraftforge.client.event.RenderGameOverlayEvent
import net.minecraftforge.common.MinecraftForge
import net.minecraftforge.fml.common.Loader
import net.minecraftforge.fml.common.event.FMLInitializationEvent
import net.minecraftforge.fml.common.event.FMLLoadCompleteEvent
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent
import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import net.minecraftforge.fml.common.gameevent.TickEvent
import net.minecraftforge.fml.common.network.FMLNetworkEvent
import sun.misc.Unsafe
import java.io.File
import java.net.DatagramPacket
Expand All @@ -123,6 +115,19 @@ import kotlin.math.abs

//#if FORGE
import net.minecraftforge.fml.common.Mod
//#if MC<11400
import net.minecraftforge.client.ClientCommandHandler
import net.minecraftforge.fml.common.event.FMLInitializationEvent
import net.minecraftforge.fml.common.event.FMLLoadCompleteEvent
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent
import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import net.minecraftforge.fml.common.gameevent.TickEvent
import net.minecraftforge.fml.common.network.FMLNetworkEvent
//#else
//$$ import net.minecraft.util.text.StringTextComponent
//#endif
//#endif

//#if FORGE
Expand Down Expand Up @@ -196,9 +201,8 @@ class Skytils {

override val coroutineContext: CoroutineContext = dispatcher + SupervisorJob() + CoroutineName("Skytils")

val deobfEnvironment by lazy {
Launch.blackboard.getOrDefault("fml.deobfuscatedEnvironment", false) as Boolean
}
val deobfEnvironment: Boolean
get() = isDeobfuscatedEnvironment

val unsafe by lazy {
Unsafe::class.java.getDeclaredField("theUnsafe").apply {
Expand Down Expand Up @@ -393,9 +397,9 @@ class Skytils {

@Mod.EventHandler
fun postInit(event: FMLPostInitializationEvent) {
usingLabymod = Loader.isModLoaded("labymod")
usingNEU = Loader.isModLoaded("notenoughupdates")
usingSBA = Loader.isModLoaded("skyblockaddons")
usingLabymod = isModLoaded("labymod")
usingNEU = isModLoaded("notenoughupdates")
usingSBA = isModLoaded("skyblockaddons")

MayorInfo.fetchMayorData()

Expand Down Expand Up @@ -495,26 +499,39 @@ class Skytils {

if (mc.thePlayer != null && sendMessageQueue.isNotEmpty() && System.currentTimeMillis() - lastChatMessage > 250) {
val msg = sendMessageQueue.pollFirst()
if (!msg.isNullOrBlank()) mc.thePlayer.sendChatMessage(msg)
if (!msg.isNullOrBlank()) mc.thePlayer?.sendChatMessage(msg)
}
if (Utils.inSkyblock && DevTools.getToggle("copydetails") && UKeyboard.isCtrlKeyDown()) {
if (UKeyboard.isKeyDown(UKeyboard.KEY_TAB)) {
UChat.chat("Copied tab data to clipboard")
GuiScreen.setClipboardString(TabListUtils.tabEntries.map { it.second }.toString())
UDesktop.setClipboardString(TabListUtils.tabEntries.map { it.second }.toString())
}
if (UKeyboard.isKeyDown(UKeyboard.KEY_CAPITAL)) {
UChat.chat("Copied scoreboard data to clipboard")
GuiScreen.setClipboardString(ScoreboardUtil.sidebarLines.toString())
UDesktop.setClipboardString(ScoreboardUtil.sidebarLines.toString())
}
val container = mc.thePlayer?.openContainer
if (UKeyboard.isKeyDown(UKeyboard.KEY_LMETA) && container is ContainerChest) {
UChat.chat("Copied container data to clipboard")
GuiScreen.setClipboardString(
"Name: '${container.lowerChestInventory.name}', Items: ${
container.inventorySlots.filter { it.inventory == container.lowerChestInventory }
.map { it.stack?.serializeNBT() }
}"
)
val openScreen = mc.currentScreen
if (UKeyboard.isKeyDown(UKeyboard.KEY_LMETA) && openScreen is GuiChest) {
//#if MC<11400
val container = openScreen.inventorySlots
//#else
//$$ val container = openScreen.getContainer()
//#endif
(container as? ContainerChest)?.let { chest ->
UChat.chat("Copied container data to clipboard")
//#if MC<11400
val name = chest.lowerChestInventory.name
//#else
//$$ val name = openScreen.title.string
//#endif
UDesktop.setClipboardString(
"Name: '${name}', Items: ${
chest.inventorySlots.filter { it.inventory == chest.lowerChestInventory }
.map { it.stack?.serializeNBT() }
}"
)

}
}
}
}
Expand All @@ -536,7 +553,12 @@ class Skytils {
@SubscribeEvent
fun onConnect(event: FMLNetworkEvent.ClientConnectedToServerEvent) {
Utils.isOnHypixel = mc.runCatching {
!event.isLocal && (thePlayer?.clientBrand?.lowercase()?.contains("hypixel")
//#if MC<11400
val brand = thePlayer?.clientBrand
//#else
//$$ val brand = player?.serverBrand
//#endif
!event.isLocal && (brand?.lowercase()?.contains("hypixel")
?: currentServerData?.serverIP?.lowercase()?.contains("hypixel") ?: false)
}.onFailure { it.printStackTrace() }.getOrDefault(false)

Expand All @@ -557,14 +579,18 @@ class Skytils {
printDevMessage("sb ${Utils.inSkyblock}", "utils")
}
if (event.packet is S1CPacketEntityMetadata && mc.thePlayer != null) {
val nameObj = event.packet.func_149376_c()?.find { it.dataValueId == 2 } ?: return
val entity = mc.theWorld.getEntityByID(event.packet.entityId)
//#if MC<11400
val nameObj = event.packet.func_149376_c()?.find { it.dataValueId == 2 }?.`object` ?: return
//#else
//$$ val nameObj = event.packet.dataManagerEntries?.find { it.key.id == 2 }.value ?: return
//#endif
val entity = mc.theWorld?.getEntityByID(event.packet.entityId)

if (entity is ExtensionEntityLivingBase) {
entity.skytilsHook.onNewDisplayName(nameObj.`object` as String)
entity.skytilsHook.onNewDisplayName(nameObj as String)
}
}
if (!Utils.isOnHypixel && event.packet is S3FPacketCustomPayload && event.packet.channelName == "MC|Brand") {
if (!Utils.isOnHypixel && event.packet is S3FPacketCustomPayload && event.packet.channelName.toString() == "MC|Brand") {
if (event.packet.bufferData.readStringFromBuffer(Short.MAX_VALUE.toInt()).lowercase().contains("hypixel"))
Utils.isOnHypixel = true
}
Expand Down Expand Up @@ -612,7 +638,11 @@ class Skytils {
val x2 = x + 100
var y = event.gui.height - 22
var y2 = y + 20
//#if MC<11400
val sorted = event.buttonList.sortedWith { a, b -> b.yPosition + b.height - a.yPosition + a.height }
//#else
//$$ val sorted = event.widgetList.sortedWith { a, b -> b.y + b.heightRealms - a.y + a.heightRealms }
//#endif
for (button in sorted) {
val otherX = button.xPosition
val otherX2 = button.xPosition + button.width
Expand All @@ -623,16 +653,24 @@ class Skytils {
y2 = y + 20
}
}
//#if MC<11400
event.buttonList.add(GuiButton(6969420, x, 0.coerceAtLeast(y), 100, 20, "Skytils"))
//#else
//$$ event.widgetList.add(Button(x, 0.coerceAtLeast(y), 100, 20, StringTextComponent("Skytils")) {
//$$ displayScreen = OptionsGui()
//$$ })
//#endif
}
}

//#if MC<11400
@SubscribeEvent
fun onGuiAction(event: GuiScreenEvent.ActionPerformedEvent.Post) {
if (config.configButtonOnPause && event.gui is GuiIngameMenu && event.button.id == 6969420) {
displayScreen = OptionsGui()
}
}
//#endif

@SubscribeEvent
fun onGuiChange(event: GuiOpenEvent) {
Expand Down
41 changes: 41 additions & 0 deletions mod/src/main/kotlin/gg/skytils/skytilsmod/utils/mcUtils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/

package gg.skytils.skytilsmod.utils

import net.minecraft.launchwrapper.Launch
import net.minecraftforge.fml.common.Loader

val isDeobfuscatedEnvironment by lazy {
//#if FORGE
//#if MC<11400
Launch.blackboard.getOrDefault("fml.deobfuscatedEnvironment", false) as Boolean
//#else
//$$ (System.getenv("target") ?: "").lowercase() == "fmluserdevclient"
//#endif
//#endif
}

fun isModLoaded(id: String) =
//#if FORGE
//#if MC<11400
Loader.isModLoaded(id)
//#else
//$$ FMLLoader.getLoadingModList().getModFileById(id)
//#endif
//#endif
19 changes: 19 additions & 0 deletions mod/versions/1.16.2-1.8.9.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
net.minecraft.client.gui.widget.button.Button net.minecraft.client.gui.GuiButton
net.minecraft.client.gui.screen.Screen net.minecraft.client.gui.GuiScreen
net.minecraft.entity.player.PlayerEntity container net.minecraft.entity.player.EntityPlayer inventoryContainer
net.minecraft.inventory.container.ChestContainer net.minecraft.inventory.ContainerChest
net.minecraft.client.gui.screen.inventory.ChestScreen net.minecraft.client.gui.inventory.GuiChest
net.minecraft.network.play.server.SJoinGamePacket net.minecraft.network.play.server.S01PacketJoinGame
net.minecraft.network.play.server.SDisplayObjectivePacket net.minecraft.network.play.server.S3DPacketDisplayScoreboard
net.minecraft.network.play.server.SDisplayObjectivePacket getName() net.minecraft.network.play.server.S3DPacketDisplayScoreboard func_149370_d()
net.minecraft.network.play.server.SEntityMetadataPacket net.minecraft.network.play.server.S1CPacketEntityMetadata
net.minecraft.network.play.server.SEntityMetadataPacket getDataManagerEntries() net.minecraft.network.play.server.S1CPacketEntityMetadata func_149376_c()
net.minecraft.network.play.server.SCustomPayloadPlayPacket net.minecraft.network.play.server.S3FPacketCustomPayload
net.minecraft.network.play.server.SPlayerListItemPacket net.minecraft.network.play.server.S38PacketPlayerListItem
net.minecraft.util.text.ITextComponent getString() net.minecraft.util.IChatComponent getFormattedText()
net.minecraft.network.play.client.CChatMessagePacket net.minecraft.network.play.client.C01PacketChatMessage
net.minecraft.client.gui.screen.IngameMenuScreen net.minecraft.client.gui.GuiIngameMenu
net.minecraft.client.gui.widget.Widget heightRealms net.minecraft.client.gui.GuiButton height
net.minecraft.client.gui.widget.Widget x net.minecraft.client.gui.GuiButton xPosition
net.minecraft.client.gui.widget.Widget y net.minecraft.client.gui.GuiButton yPosition
net.minecraft.client.gui.screen.DeathScreen net.minecraft.client.gui.GuiGameOver

0 comments on commit d0a79d6

Please sign in to comment.