From 29f8bad3e41c8a0215a8b4f3e971a24a2a1f9758 Mon Sep 17 00:00:00 2001 From: Lorenz Date: Sat, 9 Jul 2022 02:41:10 +0200 Subject: adding support for isOnHypixel, inSkyblock and inDungeons --- .../java/at/lorenz/mod/HideNotClickableItems.kt | 1 + .../at/lorenz/mod/ItemDisplayOverlayFeatures.kt | 5 +- src/main/java/at/lorenz/mod/LorenzMod.java | 2 + .../java/at/lorenz/mod/bazaar/BazaarDataGrabber.kt | 7 +- src/main/java/at/lorenz/mod/chat/ChatFilter.kt | 2 +- .../java/at/lorenz/mod/chat/PlayerChatFilter.kt | 1 + .../at/lorenz/mod/dungeon/DungeonChatFilter.kt | 5 +- .../mod/dungeon/DungeonHighlightClickedBlocks.kt | 9 +-- src/main/java/at/lorenz/mod/misc/ButtonOnPause.kt | 5 ++ .../java/at/lorenz/mod/misc/CurrentPetDisplay.kt | 5 ++ .../at/lorenz/mod/misc/ExpBottleOnGroundHider.kt | 2 + src/main/java/at/lorenz/mod/misc/HypixelData.kt | 76 ++++++++++++++++++++++ src/main/java/at/lorenz/mod/utils/LorenzUtils.kt | 33 ++++++++-- 13 files changed, 131 insertions(+), 22 deletions(-) create mode 100644 src/main/java/at/lorenz/mod/misc/HypixelData.kt (limited to 'src/main') diff --git a/src/main/java/at/lorenz/mod/HideNotClickableItems.kt b/src/main/java/at/lorenz/mod/HideNotClickableItems.kt index 3a882b11f..83c80b426 100644 --- a/src/main/java/at/lorenz/mod/HideNotClickableItems.kt +++ b/src/main/java/at/lorenz/mod/HideNotClickableItems.kt @@ -27,6 +27,7 @@ class HideNotClickableItems { @SubscribeEvent fun onBackgroundDrawn(event: GuiContainerEvent.BackgroundDrawnEvent) { + if (!LorenzUtils.inSkyblock) return if (isDisabled()) return if (event.gui !is GuiChest) return val guiChest = event.gui diff --git a/src/main/java/at/lorenz/mod/ItemDisplayOverlayFeatures.kt b/src/main/java/at/lorenz/mod/ItemDisplayOverlayFeatures.kt index 4c71449d9..cc41d7f6e 100644 --- a/src/main/java/at/lorenz/mod/ItemDisplayOverlayFeatures.kt +++ b/src/main/java/at/lorenz/mod/ItemDisplayOverlayFeatures.kt @@ -16,11 +16,10 @@ class ItemDisplayOverlayFeatures { @SubscribeEvent fun onRenderItemOverlayPost(event: GuiRenderItemEvent.RenderOverlayEvent.Post) { + val item = event.stack ?: return - //TODO add -// if (!Utils.inSkyblock || item.stackSize != 1 || item.tagCompound?.hasKey("SkytilsNoItemOverlay") == true) return - if (item.stackSize != 1 || item.tagCompound?.hasKey("SkytilsNoItemOverlay") == true) return + if (!LorenzUtils.inSkyblock || item.stackSize != 1 || item.tagCompound?.hasKey("SkytilsNoItemOverlay") == true) return val stackTip = getStackTip(item) diff --git a/src/main/java/at/lorenz/mod/LorenzMod.java b/src/main/java/at/lorenz/mod/LorenzMod.java index b9139ec5c..9b20e924d 100644 --- a/src/main/java/at/lorenz/mod/LorenzMod.java +++ b/src/main/java/at/lorenz/mod/LorenzMod.java @@ -11,6 +11,7 @@ import at.lorenz.mod.dungeon.DungeonHighlightClickedBlocks; import at.lorenz.mod.misc.ButtonOnPause; import at.lorenz.mod.misc.CurrentPetDisplay; import at.lorenz.mod.misc.ExpBottleOnGroundHider; +import at.lorenz.mod.misc.HypixelData; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.thatgravyboat.skyblockhud_2.commands.Commands; @@ -47,6 +48,7 @@ public class LorenzMod { new BazaarApi(); MinecraftForge.EVENT_BUS.register(this); MinecraftForge.EVENT_BUS.register(new ChatManager()); + MinecraftForge.EVENT_BUS.register(new HypixelData()); MinecraftForge.EVENT_BUS.register(new BazaarOrderHelper()); MinecraftForge.EVENT_BUS.register(new ChatFilter()); diff --git a/src/main/java/at/lorenz/mod/bazaar/BazaarDataGrabber.kt b/src/main/java/at/lorenz/mod/bazaar/BazaarDataGrabber.kt index 884d26515..9a23eb47b 100644 --- a/src/main/java/at/lorenz/mod/bazaar/BazaarDataGrabber.kt +++ b/src/main/java/at/lorenz/mod/bazaar/BazaarDataGrabber.kt @@ -38,10 +38,9 @@ internal class BazaarDataGrabber(private var bazaarMap: MutableMap return "start" } - //TODO add -// if (!LorenzUtils.inDungeon) return "" + if (!LorenzUtils.inDungeons) return "" return when { isKey(message) -> "key" diff --git a/src/main/java/at/lorenz/mod/dungeon/DungeonHighlightClickedBlocks.kt b/src/main/java/at/lorenz/mod/dungeon/DungeonHighlightClickedBlocks.kt index d6284cfca..86f205347 100644 --- a/src/main/java/at/lorenz/mod/dungeon/DungeonHighlightClickedBlocks.kt +++ b/src/main/java/at/lorenz/mod/dungeon/DungeonHighlightClickedBlocks.kt @@ -28,8 +28,7 @@ class DungeonHighlightClickedBlocks { @SubscribeEvent fun onChatMessage(event: LorenzChatEvent) { if (!LorenzMod.feature.dungeon.highlightClickedBlocks) return - //TODO add -// if (!LorenzUtils.inDungeon) return + if (!LorenzUtils.inDungeons) return if (event.message == "§cYou hear the sound of something opening...") { event.blockedReason = "dungeon_highlight_clicked_block" @@ -39,8 +38,7 @@ class DungeonHighlightClickedBlocks { @SubscribeEvent fun onSendPacket(event: PacketEvent.SendEvent) { if (!LorenzMod.feature.dungeon.highlightClickedBlocks) return - //TODO add -// if (!LorenzUtils.inDungeon) return + if (!LorenzUtils.inDungeons) return // TODO add // if (DungeonAPI.inBossRoom) return if (event.packet !is C08PacketPlayerBlockPlacement || event.packet.stack == null) return @@ -76,8 +74,7 @@ class DungeonHighlightClickedBlocks { @SubscribeEvent fun onWorldRender(event: RenderWorldLastEvent) { if (!LorenzMod.feature.dungeon.highlightClickedBlocks) return - //TODO add -// if (!LorenzUtils.inDungeon) return + if (!LorenzUtils.inDungeons) return blocks.removeAll { System.currentTimeMillis() > it.time + 3000 } blocks.forEach { diff --git a/src/main/java/at/lorenz/mod/misc/ButtonOnPause.kt b/src/main/java/at/lorenz/mod/misc/ButtonOnPause.kt index 9fe540ae9..c15ce4a44 100644 --- a/src/main/java/at/lorenz/mod/misc/ButtonOnPause.kt +++ b/src/main/java/at/lorenz/mod/misc/ButtonOnPause.kt @@ -1,6 +1,7 @@ package at.lorenz.mod.misc import at.lorenz.mod.LorenzMod +import at.lorenz.mod.utils.LorenzUtils import com.thatgravyboat.skyblockhud_2.config.SBHConfigEditor import com.thatgravyboat.skyblockhud_2.core.GuiScreenElementWrapper import net.minecraft.client.gui.GuiButton @@ -13,6 +14,8 @@ class ButtonOnPause { @SubscribeEvent fun onGuiAction(event: GuiScreenEvent.ActionPerformedEvent.Post) { + if (!LorenzUtils.isOnHypixel) return + if (LorenzMod.feature.misc.configButtonOnPause && event.gui is GuiIngameMenu && event.button.id == buttonId) { LorenzMod.screenToOpen = GuiScreenElementWrapper(SBHConfigEditor(LorenzMod.feature)) } @@ -20,6 +23,8 @@ class ButtonOnPause { @SubscribeEvent fun onGuiInitPost(event: GuiScreenEvent.InitGuiEvent.Post) { + if (!LorenzUtils.isOnHypixel) return + if (LorenzMod.feature.misc.configButtonOnPause && event.gui is GuiIngameMenu) { val x = event.gui.width - 105 val x2 = x + 100 diff --git a/src/main/java/at/lorenz/mod/misc/CurrentPetDisplay.kt b/src/main/java/at/lorenz/mod/misc/CurrentPetDisplay.kt index 9159dc3cc..dcbbc1259 100644 --- a/src/main/java/at/lorenz/mod/misc/CurrentPetDisplay.kt +++ b/src/main/java/at/lorenz/mod/misc/CurrentPetDisplay.kt @@ -3,6 +3,7 @@ package at.lorenz.mod.misc import at.lorenz.mod.LorenzMod import at.lorenz.mod.events.LorenzChatEvent import at.lorenz.mod.utils.GuiRender.renderString +import at.lorenz.mod.utils.LorenzUtils import at.lorenz.mod.utils.LorenzUtils.between import at.lorenz.mod.utils.LorenzUtils.matchRegex import net.minecraftforge.client.event.RenderGameOverlayEvent @@ -16,6 +17,8 @@ class CurrentPetDisplay { @SubscribeEvent fun onChatMessage(event: LorenzChatEvent) { + if (!LorenzUtils.inSkyblock) return + var blocked = false val message = event.message @@ -40,6 +43,8 @@ class CurrentPetDisplay { @SubscribeEvent fun renderOverlay(event: RenderGameOverlayEvent.Post) { + if (!LorenzUtils.inSkyblock) return + if (!LorenzMod.feature.misc.petDisplay) return if (currentPet == "") return diff --git a/src/main/java/at/lorenz/mod/misc/ExpBottleOnGroundHider.kt b/src/main/java/at/lorenz/mod/misc/ExpBottleOnGroundHider.kt index a82e22dc8..6b263cdd9 100644 --- a/src/main/java/at/lorenz/mod/misc/ExpBottleOnGroundHider.kt +++ b/src/main/java/at/lorenz/mod/misc/ExpBottleOnGroundHider.kt @@ -2,12 +2,14 @@ package at.lorenz.mod.misc import at.lorenz.mod.LorenzMod import at.lorenz.mod.events.CheckRenderEntityEvent +import at.lorenz.mod.utils.LorenzUtils import net.minecraft.entity.item.EntityXPOrb import net.minecraftforge.fml.common.eventhandler.SubscribeEvent class ExpBottleOnGroundHider { @SubscribeEvent fun onCheckRender(event: CheckRenderEntityEvent<*>) { + if (!LorenzUtils.inSkyblock) return if (!LorenzMod.feature.misc.hideExpBottles) return if (event.entity is EntityXPOrb) { diff --git a/src/main/java/at/lorenz/mod/misc/HypixelData.kt b/src/main/java/at/lorenz/mod/misc/HypixelData.kt new file mode 100644 index 000000000..01db59312 --- /dev/null +++ b/src/main/java/at/lorenz/mod/misc/HypixelData.kt @@ -0,0 +1,76 @@ +package at.lorenz.mod.misc + +import at.lorenz.mod.events.PacketEvent +import at.lorenz.mod.utils.LorenzUtils +import net.minecraft.client.Minecraft +import net.minecraft.network.play.server.S38PacketPlayerListItem +import net.minecraft.network.play.server.S3DPacketDisplayScoreboard +import net.minecraftforge.event.world.WorldEvent +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import net.minecraftforge.fml.common.network.FMLNetworkEvent + +class HypixelData { + + companion object { + var hypixel = false + var skyblock = false + var dungeon = false +} + + @SubscribeEvent + fun onConnect(event: FMLNetworkEvent.ClientConnectedToServerEvent) { + hypixel = Minecraft.getMinecraft().runCatching { + !event.isLocal && (thePlayer?.clientBrand?.lowercase()?.contains("hypixel") + ?: currentServerData?.serverIP?.lowercase()?.contains("hypixel") ?: false) + }.onFailure { it.printStackTrace() }.getOrDefault(false) + LorenzUtils.debug("connected to hypixel!") + if (hypixel) { + LorenzUtils.debug("connected to hypixel!") + } + } + + @SubscribeEvent + fun onScoreboardChange(event: PacketEvent.ReceiveEvent) { + if (!hypixel || skyblock || event.packet !is S3DPacketDisplayScoreboard) return + if (event.packet.func_149371_c() != 1) return + skyblock = event.packet.func_149370_d() == "SBScoreboard" + if (skyblock) { + LorenzUtils.debug("joined on skyblock!") + } + } + + val areaRegex = Regex("§r§b§l(?[\\w]+): §r§7(?[\\w ]+)§r") + + @SubscribeEvent + fun onTabUpdate(event: PacketEvent.ReceiveEvent) { + if (dungeon || !hypixel || event.packet !is S38PacketPlayerListItem || + (event.packet.action != S38PacketPlayerListItem.Action.UPDATE_DISPLAY_NAME && + event.packet.action != S38PacketPlayerListItem.Action.ADD_PLAYER) + ) return + event.packet.entries.forEach { playerData -> + val name = playerData?.displayName?.formattedText ?: playerData?.profile?.name ?: return@forEach + areaRegex.matchEntire(name)?.let { result -> + dungeon = skyblock && result.groups["area"]?.value == "Dungeon" + if (dungeon) { + LorenzUtils.debug("entered a dungeon!") + } + return@forEach + } + } + } + + @SubscribeEvent + fun onWorldChange(event: WorldEvent.Load) { + skyblock = false + dungeon = false + LorenzUtils.debug("onWorldChange") + } + + @SubscribeEvent + fun onDisconnect(event: FMLNetworkEvent.ClientDisconnectionFromServerEvent) { + hypixel = false + skyblock = false + dungeon = false + LorenzUtils.debug("ClientDisconnection") + } +} \ No newline at end of file diff --git a/src/main/java/at/lorenz/mod/utils/LorenzUtils.kt b/src/main/java/at/lorenz/mod/utils/LorenzUtils.kt index e27e0f50f..2295fa513 100644 --- a/src/main/java/at/lorenz/mod/utils/LorenzUtils.kt +++ b/src/main/java/at/lorenz/mod/utils/LorenzUtils.kt @@ -1,5 +1,6 @@ package at.lorenz.mod.utils +import at.lorenz.mod.misc.HypixelData import net.minecraft.client.Minecraft import net.minecraft.util.ChatComponentText import org.intellij.lang.annotations.Language @@ -7,26 +8,46 @@ import java.text.SimpleDateFormat object LorenzUtils { + val isOnHypixel: Boolean + get() = HypixelData.hypixel + + val inSkyblock: Boolean + get() = HypixelData.hypixel && HypixelData.skyblock + + val inDungeons: Boolean + get() = HypixelData.hypixel && HypixelData.skyblock && HypixelData.dungeon + const val DEBUG_PREFIX = "[Debug] §7" fun debug(message: String) { - internaChat(DEBUG_PREFIX + message) + internalChat(DEBUG_PREFIX + message) } fun warning(message: String) { - internaChat("§cWarning! $message") + internalChat("§cWarning! $message") } fun error(message: String) { - internaChat("§4$message") + internalChat("§4$message") } fun chat(message: String) { - internaChat(message) + internalChat(message) } - private fun internaChat(message: String) { - val thePlayer = Minecraft.getMinecraft().thePlayer + private fun internalChat(message: String) { + val minecraft = Minecraft.getMinecraft() + if (minecraft == null) { + println(message) + return + } + + val thePlayer = minecraft.thePlayer + if (thePlayer == null) { + println(message) + return + } + thePlayer.addChatMessage(ChatComponentText(message)) } -- cgit