From 22cb7698523cd83d827efc3e879e180ac959c305 Mon Sep 17 00:00:00 2001 From: Lorenz Date: Tue, 23 Aug 2022 14:21:51 +0200 Subject: added option to hide mob nametags close to minions --- .../skyhanni/features/minion/MinionFeatures.kt | 180 +++++++++++++++++++++ .../skyhanni/features/minion/MinionHelper.kt | 158 ------------------ 2 files changed, 180 insertions(+), 158 deletions(-) create mode 100644 src/main/java/at/hannibal2/skyhanni/features/minion/MinionFeatures.kt delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/minion/MinionHelper.kt (limited to 'src/main/java/at/hannibal2/skyhanni/features/minion') diff --git a/src/main/java/at/hannibal2/skyhanni/features/minion/MinionFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/minion/MinionFeatures.kt new file mode 100644 index 000000000..f88f23772 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/minion/MinionFeatures.kt @@ -0,0 +1,180 @@ +package at.hannibal2.skyhanni.features.minion + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.ConfigLoadEvent +import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.test.GriffinUtils.drawWaypointFilled +import at.hannibal2.skyhanni.utils.* +import at.hannibal2.skyhanni.utils.LorenzUtils.matchRegex +import at.hannibal2.skyhanni.utils.RenderUtils.drawString +import net.minecraft.client.Minecraft +import net.minecraft.entity.EntityLivingBase +import net.minecraft.entity.item.EntityArmorStand +import net.minecraftforge.client.event.RenderLivingEvent +import net.minecraftforge.client.event.RenderWorldLastEvent +import net.minecraftforge.event.world.WorldEvent +import net.minecraftforge.fml.common.eventhandler.EventPriority +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import net.minecraftforge.fml.common.gameevent.InputEvent +import net.minecraftforge.fml.common.gameevent.TickEvent +import org.lwjgl.input.Mouse +import java.awt.Color + +class MinionFeatures { + + var lastClickedEntity: LorenzVec? = null + var lastMinion: LorenzVec? = null + var lastMinionOpened = 0L + var minionInventoryOpen = false + + var lastCoinsRecived = 0L + var lastMinionPickedUp = 0L + val minions = mutableMapOf() + + @SubscribeEvent + fun onConfigLoad(event: ConfigLoadEvent) { + for (minion in SkyHanniMod.feature.hidden.minions) { + val vec = LorenzVec.decodeFromString(minion.key) + minions[vec] = minion.value + } + } + + @SubscribeEvent + fun onClick(event: InputEvent.MouseInputEvent) { + if (!LorenzUtils.inSkyblock) return + if (LorenzUtils.skyBlockIsland != "Private Island") return + + if (!Mouse.getEventButtonState()) return + if (Mouse.getEventButton() != 1) return + + val minecraft = Minecraft.getMinecraft() + val entity = minecraft.pointedEntity + if (entity != null) { + lastClickedEntity = entity.getLorenzVec() + } + } + + @SubscribeEvent + fun onRenderLastClickedMinion(event: RenderWorldLastEvent) { + if (!LorenzUtils.inSkyblock) return + if (LorenzUtils.skyBlockIsland != "Private Island") return + if (!SkyHanniMod.feature.minions.lastClickedMinionDisplay) return + + val special = SkyHanniMod.feature.minions.lastOpenedMinionColor + val color = Color(SpecialColour.specialToChromaRGB(special), true) + + val loc = lastMinion + if (loc != null) { + val time = SkyHanniMod.feature.minions.lastOpenedMinionTime * 1_000 + if (lastMinionOpened + time > System.currentTimeMillis()) { + event.drawWaypointFilled(loc.add(-0.5, 0.0, -0.5), color, true) + } + } + } + + @SubscribeEvent + fun onTick(event: TickEvent.ClientTickEvent) { + if (LorenzUtils.skyBlockIsland != "Private Island") return + + if (InventoryUtils.currentlyOpenInventory().contains("Minion")) { + if (lastClickedEntity != null) { + lastMinion = lastClickedEntity + lastClickedEntity = null + minionInventoryOpen = true + lastMinionOpened = 0 + } + } else { + if (minionInventoryOpen) { + minionInventoryOpen = false + lastMinionOpened = System.currentTimeMillis() + + val location = lastMinion + if (location != null) { + + if (System.currentTimeMillis() - lastCoinsRecived < 2_000) { + minions[location] = System.currentTimeMillis() + saveConfig() + } + + if (System.currentTimeMillis() - lastMinionPickedUp < 2_000) { + minions.remove(location) + saveConfig() + } + } + } + } + } + + private fun saveConfig() { + val minionConfig = SkyHanniMod.feature.hidden.minions + + minionConfig.clear() + for (minion in minions) { + minionConfig[minion.key.encodeToString()] = minion.value + } + + } + + @SubscribeEvent + fun onWorldChange(event: WorldEvent.Load) { + lastClickedEntity = null + lastMinion = null + lastMinionOpened = 0L + minionInventoryOpen = false + } + + @SubscribeEvent + fun onChatMessage(event: LorenzChatEvent) { + if (!LorenzUtils.inSkyblock) return + if (LorenzUtils.skyBlockIsland != "Private Island") return + + if (event.message.matchRegex("§aYou received §r§6(.*) coins§r§a!")) { + lastCoinsRecived = System.currentTimeMillis() + } + if (event.message.startsWith("§aYou picked up a minion!")) { + println("pick up minion message") + lastMinionPickedUp = System.currentTimeMillis() + } + } + + @SubscribeEvent + fun onRenderLastEmptied(event: RenderWorldLastEvent) { + if (!LorenzUtils.inSkyblock) return + if (!SkyHanniMod.feature.minions.emptiedTimeDisplay) return + if (LorenzUtils.skyBlockIsland != "Private Island") return + + val playerLocation = LocationUtils.playerLocation() + for (minion in minions) { + val location = minion.key + if (playerLocation.distance(location) < SkyHanniMod.feature.minions.emptiedTimeDistance) { + val duration = System.currentTimeMillis() - minion.value + val format = StringUtils.formatDuration(duration / 1000) + + val text = "§eHopper Emptied: $format" + event.drawString(location.add(0.0, 2.0, 0.0), text) + } + } + } + + @SubscribeEvent(priority = EventPriority.HIGH) + fun onRenderLiving(event: RenderLivingEvent.Specials.Pre) { + if (!LorenzUtils.inSkyblock) return + if (LorenzUtils.skyBlockIsland != "Private Island") return + if (!SkyHanniMod.feature.minions.hideMobsNametagNearby) return + + val entity = event.entity + if (entity !is EntityArmorStand) return +// if (entity.ticksExisted > 300 || entity !is EntityArmorStand) return + if (!entity.hasCustomName()) return + if (entity.isDead) return + + if (entity.customNameTag.contains("§c❤")) { + var loc = entity.getLorenzVec() + if (minions.any { it.key.distance(loc) < 5 }) { + event.isCanceled = true + } + } + } +} + +// \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/minion/MinionHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/minion/MinionHelper.kt deleted file mode 100644 index 039dd06df..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/minion/MinionHelper.kt +++ /dev/null @@ -1,158 +0,0 @@ -package at.hannibal2.skyhanni.features.minion - -import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.events.ConfigLoadEvent -import at.hannibal2.skyhanni.events.LorenzChatEvent -import at.hannibal2.skyhanni.test.GriffinUtils.drawWaypointFilled -import at.hannibal2.skyhanni.utils.* -import at.hannibal2.skyhanni.utils.LorenzUtils.matchRegex -import at.hannibal2.skyhanni.utils.RenderUtils.drawString -import net.minecraft.client.Minecraft -import net.minecraftforge.client.event.RenderWorldLastEvent -import net.minecraftforge.event.world.WorldEvent -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import net.minecraftforge.fml.common.gameevent.InputEvent -import net.minecraftforge.fml.common.gameevent.TickEvent -import org.lwjgl.input.Mouse -import java.awt.Color - -class MinionHelper { - - var lastClickedEntity: LorenzVec? = null - var lastMinion: LorenzVec? = null - var lastMinionOpened = 0L - var minionInventoryOpen = false - - var lastCoinsRecived = 0L - var lastMinionPickedUp = 0L - val minions = mutableMapOf() - - @SubscribeEvent - fun onConfigLoad(event: ConfigLoadEvent) { - for (minion in SkyHanniMod.feature.hidden.minions) { - val vec = LorenzVec.decodeFromString(minion.key) - minions[vec] = minion.value - } - } - - @SubscribeEvent - fun onClick(event: InputEvent.MouseInputEvent) { - if (!LorenzUtils.inSkyblock) return - if (LorenzUtils.skyBlockIsland != "Private Island") return - - val minecraft = Minecraft.getMinecraft() - val buttonState = Mouse.getEventButtonState() - val eventButton = Mouse.getEventButton() - - if (buttonState) { - if (eventButton == 1) { - val entity = minecraft.pointedEntity - if (entity != null) { - lastClickedEntity = entity.getLorenzVec() - } - } - } - } - - @SubscribeEvent - fun onRenderLastClickedMinion(event: RenderWorldLastEvent) { - if (!LorenzUtils.inSkyblock) return - if (LorenzUtils.skyBlockIsland != "Private Island") return - if (!SkyHanniMod.feature.minions.lastClickedMinionDisplay) return - - val special = SkyHanniMod.feature.minions.lastOpenedMinionColor - val color = Color(SpecialColour.specialToChromaRGB(special), true) - - val loc = lastMinion - if (loc != null) { - val time = SkyHanniMod.feature.minions.lastOpenedMinionTime * 1_000 - if (lastMinionOpened + time > System.currentTimeMillis()) { - event.drawWaypointFilled(loc.add(-0.5, 0.0, -0.5), color, true) - } - } - } - - @SubscribeEvent - fun onTick(event: TickEvent.ClientTickEvent) { - if (LorenzUtils.skyBlockIsland != "Private Island") return - - if (InventoryUtils.currentlyOpenInventory().contains("Minion")) { - if (lastClickedEntity != null) { - lastMinion = lastClickedEntity - lastClickedEntity = null - minionInventoryOpen = true - lastMinionOpened = 0 - } - } else { - if (minionInventoryOpen) { - minionInventoryOpen = false - lastMinionOpened = System.currentTimeMillis() - - val location = lastMinion - if (location != null) { - - if (System.currentTimeMillis() - lastCoinsRecived < 2_000) { - minions[location] = System.currentTimeMillis() - saveConfig() - } - - if (System.currentTimeMillis() - lastMinionPickedUp < 2_000) { - minions.remove(location) - saveConfig() - } - } - } - } - } - - private fun saveConfig() { - val minionConfig = SkyHanniMod.feature.hidden.minions - - minionConfig.clear() - for (minion in minions) { - minionConfig[minion.key.encodeToString()] = minion.value - } - - } - - @SubscribeEvent - fun onWorldChange(event: WorldEvent.Load) { - lastClickedEntity = null - lastMinion = null - lastMinionOpened = 0L - minionInventoryOpen = false - } - - @SubscribeEvent - fun onChatMessage(event: LorenzChatEvent) { - if (!LorenzUtils.inSkyblock) return - if (LorenzUtils.skyBlockIsland != "Private Island") return - - if (event.message.matchRegex("§aYou received §r§6(.*) coins§r§a!")) { - lastCoinsRecived = System.currentTimeMillis() - } - if (event.message.startsWith("§aYou picked up a minion!")) { - println("pick up minion message") - lastMinionPickedUp = System.currentTimeMillis() - } - } - - @SubscribeEvent - fun onRenderLastEmptied(event: RenderWorldLastEvent) { - if (!LorenzUtils.inSkyblock) return - if (!SkyHanniMod.feature.minions.emptiedTimeDisplay) return - if (LorenzUtils.skyBlockIsland != "Private Island") return - - val playerLocation = LocationUtils.playerLocation() - for (minion in minions) { - val location = minion.key - if (playerLocation.distance(location) < SkyHanniMod.feature.minions.emptiedTimeDistance) { - val duration = System.currentTimeMillis() - minion.value - val format = StringUtils.formatDuration(duration / 1000) - - val text = "§eHopper Emptied: $format" - event.drawString(location.add(0.0, 2.0, 0.0), text) - } - } - } -} \ No newline at end of file -- cgit