From c6b688f864c28fcd7c1cbcb248086e5caee7f230 Mon Sep 17 00:00:00 2001 From: Lorenz Date: Mon, 12 Sep 2022 00:01:31 +0200 Subject: edited features order and made better wording --- .../java/at/hannibal2/skyhanni/SkyHanniMod.java | 13 +- .../at/hannibal2/skyhanni/config/Features.java | 14 +- .../skyhanni/config/features/Abilities.java | 73 ---- .../skyhanni/config/features/Inventory.java | 3 +- .../skyhanni/config/features/ItemAbilities.java | 37 ++ .../hannibal2/skyhanni/config/features/Misc.java | 10 - .../hannibal2/skyhanni/config/features/Slayer.java | 18 + .../skyhanni/config/features/Summonings.java | 43 +++ .../hannibal2/skyhanni/data/VanillaItemManager.kt | 53 +++ .../skyhanni/features/FireVeilWandParticles.kt | 64 ---- .../skyhanni/features/SummoningMobManager.kt | 209 ---------- .../skyhanni/features/SummoningSoulsName.kt | 132 ------- .../features/inventory/HideNotClickableItems.kt | 419 +++++++++++++++++++++ .../inventory/ItemDisplayOverlayFeatures.kt | 120 ++++++ .../skyhanni/features/inventory/ItemStars.kt | 150 ++++++++ .../features/inventory/RngMeterInventory.kt | 91 +++++ .../itemabilities/FireVeilWandParticles.kt | 64 ++++ .../abilitycooldown/ItemAbilityCooldown.kt | 214 +++++++++++ .../abilitycooldown/WitherImpactDetection.kt | 74 ++++ .../features/items/HideNotClickableItems.kt | 418 -------------------- .../features/items/ItemDisplayOverlayFeatures.kt | 120 ------ .../hannibal2/skyhanni/features/items/ItemStars.kt | 150 -------- .../skyhanni/features/items/RngMeterInventory.kt | 91 ----- .../skyhanni/features/items/VanillaItemManager.kt | 53 --- .../items/abilitycooldown/ItemAbilityCooldown.kt | 214 ----------- .../items/abilitycooldown/WitherImpactDetection.kt | 74 ---- .../features/slayer/EndermanSlayerBeacon.kt | 2 +- .../features/slayer/HighlightSlayerMiniboss.kt | 2 +- .../features/summonings/SummoningMobManager.kt | 209 ++++++++++ .../features/summonings/SummoningSoulsName.kt | 132 +++++++ 30 files changed, 1647 insertions(+), 1619 deletions(-) delete mode 100644 src/main/java/at/hannibal2/skyhanni/config/features/Abilities.java create mode 100644 src/main/java/at/hannibal2/skyhanni/config/features/ItemAbilities.java create mode 100644 src/main/java/at/hannibal2/skyhanni/config/features/Slayer.java create mode 100644 src/main/java/at/hannibal2/skyhanni/config/features/Summonings.java create mode 100644 src/main/java/at/hannibal2/skyhanni/data/VanillaItemManager.kt delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/FireVeilWandParticles.kt delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/SummoningMobManager.kt delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/SummoningSoulsName.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/inventory/HideNotClickableItems.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/inventory/ItemDisplayOverlayFeatures.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/inventory/ItemStars.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/inventory/RngMeterInventory.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/itemabilities/FireVeilWandParticles.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/itemabilities/abilitycooldown/ItemAbilityCooldown.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/itemabilities/abilitycooldown/WitherImpactDetection.kt delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/items/HideNotClickableItems.kt delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/items/ItemDisplayOverlayFeatures.kt delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/items/ItemStars.kt delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/items/RngMeterInventory.kt delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/items/VanillaItemManager.kt delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/items/abilitycooldown/ItemAbilityCooldown.kt delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/items/abilitycooldown/WitherImpactDetection.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/summonings/SummoningMobManager.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/summonings/SummoningSoulsName.kt (limited to 'src/main') diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java index f44020e4b..b545c7c22 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java @@ -18,15 +18,18 @@ import at.hannibal2.skyhanni.features.end.VoidlingExtremistColor; import at.hannibal2.skyhanni.features.fishing.SeaCreatureManager; import at.hannibal2.skyhanni.features.fishing.SeaCreatureMessageShortener; import at.hannibal2.skyhanni.features.fishing.TrophyFishMessages; -import at.hannibal2.skyhanni.features.items.HideNotClickableItems; -import at.hannibal2.skyhanni.features.items.ItemDisplayOverlayFeatures; -import at.hannibal2.skyhanni.features.items.ItemStars; -import at.hannibal2.skyhanni.features.items.RngMeterInventory; -import at.hannibal2.skyhanni.features.items.abilitycooldown.ItemAbilityCooldown; +import at.hannibal2.skyhanni.features.inventory.HideNotClickableItems; +import at.hannibal2.skyhanni.features.inventory.ItemDisplayOverlayFeatures; +import at.hannibal2.skyhanni.features.inventory.ItemStars; +import at.hannibal2.skyhanni.features.inventory.RngMeterInventory; +import at.hannibal2.skyhanni.features.itemabilities.FireVeilWandParticles; +import at.hannibal2.skyhanni.features.itemabilities.abilitycooldown.ItemAbilityCooldown; import at.hannibal2.skyhanni.features.minion.MinionFeatures; import at.hannibal2.skyhanni.features.nether.ashfang.*; import at.hannibal2.skyhanni.features.slayer.EndermanSlayerBeacon; import at.hannibal2.skyhanni.features.slayer.HighlightSlayerMiniboss; +import at.hannibal2.skyhanni.features.summonings.SummoningMobManager; +import at.hannibal2.skyhanni.features.summonings.SummoningSoulsName; import at.hannibal2.skyhanni.test.LorenzTest; import at.hannibal2.skyhanni.utils.MinecraftConsoleFilter; import net.minecraft.client.Minecraft; diff --git a/src/main/java/at/hannibal2/skyhanni/config/Features.java b/src/main/java/at/hannibal2/skyhanni/config/Features.java index 8688ab603..3495e4d96 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/Features.java +++ b/src/main/java/at/hannibal2/skyhanni/config/Features.java @@ -77,7 +77,7 @@ public class Features extends Config { } if (runnableId.equals("summoningMobDisplay")) { - editOverlay(activeConfigCategory, 200, 16, abilities.summoningMobDisplayPos); + editOverlay(activeConfigCategory, 200, 16, summonings.summoningMobDisplayPos); return; } @@ -110,8 +110,12 @@ public class Features extends Config { public Inventory inventory = new Inventory(); @Expose - @Category(name = "Abilities", desc = "Stuff about abilities") - public Abilities abilities = new Abilities(); + @Category(name = "Item Abilities", desc = "Stuff about item abilities") + public ItemAbilities itemAbilities = new ItemAbilities(); + + @Expose + @Category(name = "Summonings", desc = "Ashfang fight in Crimson Isle") + public Summonings summonings = new Summonings(); @Expose @Category(name = "Ashfang", desc = "Ashfang fight in Crimson Isle") @@ -133,6 +137,10 @@ public class Features extends Config { @Category(name = "Damage Indicator", desc = "Better damage overview in combat with bosses of all sorts.") public DamageIndicator damageIndicator = new DamageIndicator(); + @Expose + @Category(name = "Slayer", desc = "Slayer Features.") + public Slayer slayer = new Slayer(); + @Expose @Category(name = "Misc", desc = "Settings without a category.") public Misc misc = new Misc(); diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Abilities.java b/src/main/java/at/hannibal2/skyhanni/config/features/Abilities.java deleted file mode 100644 index feaf50a60..000000000 --- a/src/main/java/at/hannibal2/skyhanni/config/features/Abilities.java +++ /dev/null @@ -1,73 +0,0 @@ -package at.hannibal2.skyhanni.config.features; - -import at.hannibal2.skyhanni.config.core.config.Position; -import at.hannibal2.skyhanni.config.core.config.annotations.*; -import com.google.gson.annotations.Expose; - -public class Abilities { - - @Expose - @ConfigOption(name = "Ability Cooldown", desc = "Show the cooldown of item abilities.") - @ConfigEditorBoolean - public boolean itemAbilityCooldown = false; - - @Expose - @ConfigOption(name = "Ability Cooldown Background", desc = "Show the cooldown color of item abilities in the background.") - @ConfigEditorBoolean - public boolean itemAbilityCooldownBackground = false; - - @Expose - @ConfigOption(name = "Summoning Soul Display", desc = "Show the name of dropped summoning souls laying on the ground. " + - "§cNot working in Dungeon if Skytils' 'Hide Non-Starred Mobs Nametags' feature is enabled!") - @ConfigEditorBoolean - public boolean summoningSoulDisplay = false; - - @Expose - @ConfigOption(name = "Summoning Mob", desc = "") - @ConfigEditorAccordion(id = 0) - public boolean summoningMob = false; - - @Expose - @ConfigOption(name = "Summoning Mob Display", desc = "Show the health of your spawned summoning mobs") - @ConfigEditorBoolean - @ConfigAccordionId(id = 0) - public boolean summoningMobDisplay = false; - - @Expose - @ConfigOption(name = "Summoning Mob Display Position", desc = "") - @ConfigEditorButton(runnableId = "summoningMobDisplay", buttonText = "Edit") - @ConfigAccordionId(id = 0) - public Position summoningMobDisplayPos = new Position(10, 10, false, true); - - @Expose - @ConfigOption(name = "Summoning Mob Nametag", desc = "Hide the nametag of your spawned summoning mobs") - @ConfigEditorBoolean - @ConfigAccordionId(id = 0) - public boolean summoningMobHideNametag = false; - - @Expose - @ConfigOption(name = "Summoning Mob Color", desc = "Marks own summoning mobs green") - @ConfigEditorBoolean - @ConfigAccordionId(id = 0) - public boolean summoningMobColored = false; - - @Expose - @ConfigOption(name = "Fire Veil", desc = "") - @ConfigEditorAccordion(id = 1) - public boolean fireVeilWand = false; - - @Expose - @ConfigOption(name = "Fire Veil Design", desc = "Changes the flame particles of the Fire Veil Wand ability") - @ConfigEditorDropdown(values = {"Particles", "Line", "Off"}) - @ConfigAccordionId(id = 1) - public int fireVeilWandDisplay = 0; - - @Expose - @ConfigOption( - name = "Line Color", - desc = "Changes the color of the Fire Veil Wand line" - ) - @ConfigEditorColour - @ConfigAccordionId(id = 1) - public String fireVeilWandDisplayColor = "0:245:255:85:85"; -} diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Inventory.java b/src/main/java/at/hannibal2/skyhanni/config/features/Inventory.java index 0aa24cb28..ad0a32b74 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/Inventory.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/Inventory.java @@ -4,6 +4,7 @@ import at.hannibal2.skyhanni.config.core.config.annotations.*; import com.google.gson.annotations.Expose; import java.util.ArrayList; +import java.util.Collections; import java.util.List; public class Inventory { @@ -47,7 +48,7 @@ public class Inventory { "\u00a7bCrimson Armor", } ) - public List itemNumberAsStackSize = new ArrayList<>(3); + public List itemNumberAsStackSize = new ArrayList<>(Collections.singletonList(3)); @Expose @ConfigOption(name = "Sack Name", desc = "Show an abbreviation of the Sack name.") diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/ItemAbilities.java b/src/main/java/at/hannibal2/skyhanni/config/features/ItemAbilities.java new file mode 100644 index 000000000..38cb20940 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/features/ItemAbilities.java @@ -0,0 +1,37 @@ +package at.hannibal2.skyhanni.config.features; + +import at.hannibal2.skyhanni.config.core.config.annotations.*; +import com.google.gson.annotations.Expose; + +public class ItemAbilities { + + @Expose + @ConfigOption(name = "Ability Cooldown", desc = "Show the cooldown of item abilities.") + @ConfigEditorBoolean + public boolean itemAbilityCooldown = false; + + @Expose + @ConfigOption(name = "Ability Cooldown Background", desc = "Show the cooldown color of item abilities in the background.") + @ConfigEditorBoolean + public boolean itemAbilityCooldownBackground = false; + + @Expose + @ConfigOption(name = "Fire Veil", desc = "") + @ConfigEditorAccordion(id = 1) + public boolean fireVeilWand = false; + + @Expose + @ConfigOption(name = "Fire Veil Design", desc = "Changes the flame particles of the Fire Veil Wand ability") + @ConfigEditorDropdown(values = {"Particles", "Line", "Off"}) + @ConfigAccordionId(id = 1) + public int fireVeilWandDisplay = 0; + + @Expose + @ConfigOption( + name = "Line Color", + desc = "Changes the color of the Fire Veil Wand line" + ) + @ConfigEditorColour + @ConfigAccordionId(id = 1) + public String fireVeilWandDisplayColor = "0:245:255:85:85"; +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Misc.java b/src/main/java/at/hannibal2/skyhanni/config/features/Misc.java index cb9071510..6fa5b8b2d 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/Misc.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/Misc.java @@ -52,14 +52,4 @@ public class Misc { @ConfigOption(name = "Corrupted Mob Highlight", desc = "Highlight corrupted mobs in purple color") @ConfigEditorBoolean public boolean corruptedMobHighlight = false; - - @Expose - @ConfigOption(name = "Slayer Miniboss Highlight", desc = "Highlight slayer miniboss in blue color") - @ConfigEditorBoolean - public boolean slayerMinibossHighlight = false; - - @Expose - @ConfigOption(name = "Slayer Enderman Beacon", desc = "Highlight the enderman slayer Yang Glyph (Beacon) in red color (supports beacon in hand and beacon flying)") - @ConfigEditorBoolean - public boolean slayerEndermanBeacon = false; } \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Slayer.java b/src/main/java/at/hannibal2/skyhanni/config/features/Slayer.java new file mode 100644 index 000000000..cac13b109 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/features/Slayer.java @@ -0,0 +1,18 @@ +package at.hannibal2.skyhanni.config.features; + +import at.hannibal2.skyhanni.config.core.config.annotations.ConfigEditorBoolean; +import at.hannibal2.skyhanni.config.core.config.annotations.ConfigOption; +import com.google.gson.annotations.Expose; + +public class Slayer { + + @Expose + @ConfigOption(name = "Slayer Miniboss Highlight", desc = "Highlight slayer miniboss in blue color") + @ConfigEditorBoolean + public boolean slayerMinibossHighlight = false; + + @Expose + @ConfigOption(name = "Slayer Enderman Beacon", desc = "Highlight the enderman slayer Yang Glyph (Beacon) in red color (supports beacon in hand and beacon flying)") + @ConfigEditorBoolean + public boolean slayerEndermanBeacon = false; +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Summonings.java b/src/main/java/at/hannibal2/skyhanni/config/features/Summonings.java new file mode 100644 index 000000000..88253fb0a --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/features/Summonings.java @@ -0,0 +1,43 @@ +package at.hannibal2.skyhanni.config.features; + +import at.hannibal2.skyhanni.config.core.config.Position; +import at.hannibal2.skyhanni.config.core.config.annotations.*; +import com.google.gson.annotations.Expose; + +public class Summonings { + + @Expose + @ConfigOption(name = "Summoning Soul Display", desc = "Show the name of dropped summoning souls laying on the ground. " + + "§cNot working in Dungeon if Skytils' 'Hide Non-Starred Mobs Nametags' feature is enabled!") + @ConfigEditorBoolean + public boolean summoningSoulDisplay = false; + + @Expose + @ConfigOption(name = "Summoning Mob", desc = "") + @ConfigEditorAccordion(id = 0) + public boolean summoningMob = false; + + @Expose + @ConfigOption(name = "Summoning Mob Display", desc = "Show the health of your spawned summoning mobs") + @ConfigEditorBoolean + @ConfigAccordionId(id = 0) + public boolean summoningMobDisplay = false; + + @Expose + @ConfigOption(name = "Summoning Mob Display Position", desc = "") + @ConfigEditorButton(runnableId = "summoningMobDisplay", buttonText = "Edit") + @ConfigAccordionId(id = 0) + public Position summoningMobDisplayPos = new Position(10, 10, false, true); + + @Expose + @ConfigOption(name = "Summoning Mob Nametag", desc = "Hide the nametag of your spawned summoning mobs") + @ConfigEditorBoolean + @ConfigAccordionId(id = 0) + public boolean summoningMobHideNametag = false; + + @Expose + @ConfigOption(name = "Summoning Mob Color", desc = "Marks own summoning mobs green") + @ConfigEditorBoolean + @ConfigAccordionId(id = 0) + public boolean summoningMobColored = false; +} diff --git a/src/main/java/at/hannibal2/skyhanni/data/VanillaItemManager.kt b/src/main/java/at/hannibal2/skyhanni/data/VanillaItemManager.kt new file mode 100644 index 000000000..a61548309 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/data/VanillaItemManager.kt @@ -0,0 +1,53 @@ +package at.hannibal2.skyhanni.data + +import com.google.gson.GsonBuilder +import com.google.gson.JsonObject +import java.io.BufferedReader +import java.io.File +import java.io.FileInputStream +import java.io.InputStreamReader +import java.nio.charset.StandardCharsets + +class VanillaItemManager { + private val gson = GsonBuilder().setPrettyPrinting().create() + + companion object { + private val vanillaItems: MutableList = ArrayList() + + fun isVanillaItem(internalName: String): Boolean { + return vanillaItems.contains(internalName) + } + } + + init { + load() + } + + private fun load() { + vanillaItems.clear() + val itemDirectory = File("config/notenoughupdates/repo/items") + if (!itemDirectory.isDirectory) return + val files = itemDirectory.listFiles() ?: return + for (file in files) { + val jsonObject = getJsonFromFile(file) + if (jsonObject != null) { + if (jsonObject.has("vanilla") && jsonObject["vanilla"].asBoolean) { + val name = file.name + val internalName = name.split(".")[0] + vanillaItems.add(internalName) + } + } + } + + } + + private fun getJsonFromFile(file: File): JsonObject? { + try { + BufferedReader(InputStreamReader(FileInputStream(file), + StandardCharsets.UTF_8 + )).use { reader -> return gson.fromJson(reader, JsonObject::class.java) } + } catch (e: Exception) { + return null + } + } +} \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/FireVeilWandParticles.kt b/src/main/java/at/hannibal2/skyhanni/features/FireVeilWandParticles.kt deleted file mode 100644 index d7af6d6c3..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/FireVeilWandParticles.kt +++ /dev/null @@ -1,64 +0,0 @@ -package at.hannibal2.skyhanni.features - -import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.events.ItemClickInHandEvent -import at.hannibal2.skyhanni.events.PacketEvent -import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName -import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.RenderUtils -import at.hannibal2.skyhanni.utils.SpecialColour -import net.minecraft.client.Minecraft -import net.minecraft.network.play.server.S2APacketParticles -import net.minecraft.util.EnumParticleTypes -import net.minecraftforge.client.event.RenderWorldLastEvent -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import java.awt.Color - -class FireVeilWandParticles { - - var lastClick = 0L - - @SubscribeEvent - fun onChatPacket(event: PacketEvent.ReceiveEvent) { - if (!LorenzUtils.inSkyblock) return - if (SkyHanniMod.feature.abilities.fireVeilWandDisplay == 0) return - if (System.currentTimeMillis() > lastClick + 5_500) return - - val packet = event.packet - if (packet !is S2APacketParticles) return - - - if (packet.particleType == EnumParticleTypes.FLAME && packet.particleCount == 1 && packet.particleSpeed == 0f && - packet.xOffset == 0f && - packet.yOffset == 0f && - packet.zOffset == 0f - ) { - event.isCanceled = true - } - } - - @SubscribeEvent - fun onItemClick(event: ItemClickInHandEvent) { - if (!LorenzUtils.inSkyblock) return - if (event.clickType != ItemClickInHandEvent.ClickType.RIGHT_CLICK) return - - val itemInHand = event.itemInHand ?: return - - val internalName = itemInHand.getInternalName() - if (internalName == "FIRE_VEIL_WAND") { - lastClick = System.currentTimeMillis() - } - } - - @SubscribeEvent - fun onRenderWorld(event: RenderWorldLastEvent) { - if (!LorenzUtils.inSkyblock) return - if (SkyHanniMod.feature.abilities.fireVeilWandDisplay != 1) return - if (System.currentTimeMillis() > lastClick + 5_500) return - - val color = - Color(SpecialColour.specialToChromaRGB(SkyHanniMod.feature.abilities.fireVeilWandDisplayColor), true) - - RenderUtils.drawCircle(Minecraft.getMinecraft().thePlayer, event.partialTicks, 3.5, color) - } -} \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/SummoningMobManager.kt b/src/main/java/at/hannibal2/skyhanni/features/SummoningMobManager.kt deleted file mode 100644 index 0d272771d..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/SummoningMobManager.kt +++ /dev/null @@ -1,209 +0,0 @@ -package at.hannibal2.skyhanni.features - -import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.events.LorenzChatEvent -import at.hannibal2.skyhanni.events.RenderMobColoredEvent -import at.hannibal2.skyhanni.events.ResetEntityHurtEvent -import at.hannibal2.skyhanni.events.withAlpha -import at.hannibal2.skyhanni.utils.* -import at.hannibal2.skyhanni.utils.LorenzUtils.baseMaxHealth -import at.hannibal2.skyhanni.utils.RenderUtils.renderStrings -import net.minecraft.client.Minecraft -import net.minecraft.entity.EntityLiving -import net.minecraft.entity.EntityLivingBase -import net.minecraft.entity.item.EntityArmorStand -import net.minecraftforge.client.event.RenderGameOverlayEvent -import net.minecraftforge.client.event.RenderLivingEvent -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.TickEvent -import java.util.regex.Pattern - -class SummoningMobManager { - - - private val summoningMobs = mutableMapOf() - private val summoningMobNametags = mutableListOf() - private var summoningsSpawned = 0 - private var searchArmorStands = false - private var searchMobs = false - - //§aYou have spawned your Tank Zombie §r§asoul! §r§d(249 Mana) - private val spawnPatter = Pattern.compile("§aYou have spawned your (.+) §r§asoul! §r§d\\((\\d+) Mana\\)") - private val despawnPatter = Pattern.compile("§cYou have despawned your (monster|monsters)!") - - //§a§ohannibal2's Tank Zombie§r §a160k§c❤ - private val healthPattern = Pattern.compile("§a§o(.+)'s (.+)§r §[ae]([\\dkm]+)§c❤") - - //§cThe Seraph recalled your 3 summoned allies! - private val seraphRecallPattern = Pattern.compile("§cThe Seraph recalled your (\\d) summoned allies!") - - @SubscribeEvent - fun onChatMessage(event: LorenzChatEvent) { - if (!LorenzUtils.isOnHypixel) return - - val message = event.message - val matcher = spawnPatter.matcher(message) - if (matcher.matches()) { - if (SkyHanniMod.feature.abilities.summoningMobDisplay) { - event.blockedReason = "summoning_soul" - } - summoningsSpawned++ - searchArmorStands = true - searchMobs = true - } - - if (despawnPatter.matcher(message).matches() || message.startsWith("§c ☠ §r§7You ")) { - despawned() - if (SkyHanniMod.feature.abilities.summoningMobDisplay && !message.contains("☠")) { - event.blockedReason = "summoning_soul" - } - } - if (message == "§cThe Seraph recalled your summoned ally!" || seraphRecallPattern.matcher(message).matches()) { - despawned() - if (SkyHanniMod.feature.abilities.summoningMobDisplay) { - event.blockedReason = "summoning_soul" - } - } - } - - var tick = 0 - - @SubscribeEvent - fun onTick(event: TickEvent.ClientTickEvent) { - if (!isEnabled()) return - - if (SkyHanniMod.feature.abilities.summoningMobDisplay) { - if (tick++ % 20 == 0) { - updateData() - } - } - - if (searchArmorStands) { - Minecraft.getMinecraft().theWorld.loadedEntityList.filter { it is EntityArmorStand && it !in summoningMobNametags } - .forEach { - val name = it.displayName.unformattedText - val matcher = healthPattern.matcher(name) - if (matcher.matches()) { - val playerName = Minecraft.getMinecraft().thePlayer.name - if (name.contains(playerName)) { - summoningMobNametags.add(it as EntityArmorStand) - if (summoningMobNametags.size == summoningsSpawned) { - searchArmorStands = false - } - } - } - } - } - - if (searchMobs) { - val playerLocation = LocationUtils.playerLocation() - Minecraft.getMinecraft().theWorld.loadedEntityList.filter { - it is EntityLiving && it !in summoningMobs.keys && it.getLorenzVec() - .distance(playerLocation) < 10 && it.ticksExisted < 2 - }.forEach { - summoningMobs[it as EntityLiving] = SummoningMob(System.currentTimeMillis(), name = "Mob") - updateData() - if (summoningMobs.size == summoningsSpawned) { - searchMobs = false - } - } - } - } - - private fun updateData() { - if (summoningMobs.isEmpty()) return - - for (entry in HashMap(summoningMobs)) { - val entityLiving = entry.key - val summoningMob = entry.value - - val currentHealth = entityLiving.health.toInt() - val name = summoningMob.name - if (currentHealth == 0) { - summoningMobs.remove(entityLiving) - LorenzUtils.chat("§e[SkyHanni] Your Summoning Mob just §cdied!") - continue - } - - val maxHealth = entityLiving.baseMaxHealth - val color = NumberUtil.percentageColor(currentHealth.toLong(), maxHealth.toLong()).getChatColor() - - val currentFormat = NumberUtil.format(currentHealth) - val maxFormat = NumberUtil.format(maxHealth) - summoningMob.lastDisplayName = "§a$name $color$currentFormat/$maxFormat" - } - } - - @SubscribeEvent - fun renderOverlay(event: RenderGameOverlayEvent.Post) { - if (!SkyHanniMod.feature.abilities.summoningMobDisplay) return - if (summoningMobs.isEmpty()) return - - val list = mutableListOf() - list.add("Summoning mobs: " + summoningMobs.size) - var id = 1 - for (mob in summoningMobs) { - val name = mob.value.lastDisplayName - list.add("#$id $name") - id++ - } - - SkyHanniMod.feature.abilities.summoningMobDisplayPos.renderStrings(list) - } - - @SubscribeEvent - fun onWorldChange(event: WorldEvent.Load) { - despawned() - } - - @SubscribeEvent(priority = EventPriority.HIGH) - fun onRenderLiving(event: RenderLivingEvent.Specials.Pre) { - if (!LorenzUtils.inSkyblock) return - if (!SkyHanniMod.feature.abilities.summoningMobHideNametag) return - - val entity = event.entity - if (entity !is EntityArmorStand) return - if (!entity.hasCustomName()) return - if (entity.isDead) return - - event.isCanceled = entity in summoningMobNametags - } - - @SubscribeEvent - fun onRenderMobColored(event: RenderMobColoredEvent) { - if (SkyHanniMod.feature.abilities.summoningMobColored) { - val entity = event.entity - if (entity is EntityLiving && entity in summoningMobs.keys) { - event.color = LorenzColor.GREEN.toColor().withAlpha(127) - } - } - } - - @SubscribeEvent - fun onResetEntityHurtTime(event: ResetEntityHurtEvent) { - val entity = event.entity - if (SkyHanniMod.feature.abilities.summoningMobColored && entity in summoningMobs.keys) { - event.shouldReset = true - } - } - - private fun despawned() { - summoningMobs.clear() - summoningMobNametags.clear() - summoningsSpawned = 0 - searchArmorStands = false - searchMobs = false - } - - private fun isEnabled(): Boolean { - return LorenzUtils.inSkyblock && (SkyHanniMod.feature.abilities.summoningMobDisplay || SkyHanniMod.feature.abilities.summoningMobHideNametag) - } - - class SummoningMob( - val spawnTime: Long, - var name: String = "", - var lastDisplayName: String = "", - ) -} \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/SummoningSoulsName.kt b/src/main/java/at/hannibal2/skyhanni/features/SummoningSoulsName.kt deleted file mode 100644 index 59784f027..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/SummoningSoulsName.kt +++ /dev/null @@ -1,132 +0,0 @@ -package at.hannibal2.skyhanni.features - -import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.test.GriffinJavaUtils -import at.hannibal2.skyhanni.utils.EntityUtils.getNameTagWith -import at.hannibal2.skyhanni.utils.ItemUtils.getSkullTexture -import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.LorenzVec -import at.hannibal2.skyhanni.utils.RenderUtils.drawString -import at.hannibal2.skyhanni.utils.getLorenzVec -import net.minecraft.client.Minecraft -import net.minecraft.entity.EntityLiving -import net.minecraft.entity.item.EntityArmorStand -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.TickEvent - -class SummoningSoulsName { - - var tick = 0 - private val texture = - "ewogICJ0aW1lc3RhbXAiIDogMTYwMTQ3OTI2NjczMywKICAicHJvZmlsZUlkIiA6ICJmMzA1ZjA5NDI0NTg0ZjU" + - "4YmEyYjY0ZjAyZDcyNDYyYyIsCiAgInByb2ZpbGVOYW1lIiA6ICJqcm9ja2EzMyIsCiAgInNpZ25hdH" + - "VyZVJlcXVpcmVkIiA6IHRydWUsCiAgInRleHR1cmVzIiA6IHsKICAgICJTS0lOIiA6IHsKICAgICAgI" + - "nVybCIgOiAiaHR0cDovL3RleHR1cmVzLm1pbmVjcmFmdC5uZXQvdGV4dHVyZS81YWY0MDM1ZWMwZGMx" + - "NjkxNzc4ZDVlOTU4NDAxNzAyMjdlYjllM2UyOTQzYmVhODUzOTI5Y2U5MjNjNTk4OWFkIgogICAgfQogIH0KfQ" - - private val souls = mutableMapOf() - private val mobsLastLocation = mutableMapOf() - private val mobsName = mutableMapOf() - - @SubscribeEvent - fun onTick(event: TickEvent.ClientTickEvent) { - if (!isEnabled()) return - - tick++ - //TODO use packets instead of this - if (tick % 1 == 0) { - check() - } - } - - private fun check() { - val minecraft = Minecraft.getMinecraft() - val world = minecraft.theWorld - for (entity in world.loadedEntityList) { - if (souls.contains(entity)) continue - - if (entity is EntityArmorStand) { - if (isSoul(entity)) { - val soulLocation = entity.getLorenzVec() - - val map = mutableMapOf() - for ((mob, loc) in mobsLastLocation) { - val distance = loc.distance(soulLocation) - map[mob] = distance - } - - val nearestMob = GriffinJavaUtils.sortByValueAsc(map).firstNotNullOfOrNull { it.key } - if (nearestMob != null) { -// val mobDistance = nearestMob.getLorenzVec().add(0.0, -1.4375, 0.0) -// val distance = mobDistance.distance(soulLocation) -// val diff = mobDistance.add(soulLocation.multiply(-1)) - -// println(" ") -// println("mobDistance: $mobDistance") -// println("soulLocation: $soulLocation") -// println("diff: $diff") -// LorenzUtils.chat("distance: $distance") - val name = mobsName[nearestMob]!! -// LorenzUtils.chat("maybe its $name") - souls[entity] = name - } - - } - } - } - - for (entity in world.loadedEntityList) { - if (entity is EntityLiving) { - val consumer = entity.getNameTagWith(2, "§c❤") - if (consumer != null) { - if (!consumer.name.contains("§e0")) { - mobsLastLocation[entity] = entity.getLorenzVec() - mobsName[entity] = consumer.name - } - } - } - } - - souls.keys.removeIf { it !in world.loadedEntityList } - //TODO fix overhead! -// mobs.keys.removeIf { it !in world.loadedEntityList } - } - - @SubscribeEvent - fun onWorldRender(event: RenderWorldLastEvent) { - if (!isEnabled()) return - - for ((entity, name) in souls) { - val vec = entity.getLorenzVec() - event.drawString(vec.add(0.0, 2.5, 0.0), name) - } - } - - @SubscribeEvent - fun onWorldChange(event: WorldEvent.Load) { - souls.clear() - mobsLastLocation.clear() - mobsName.clear() - } - - private fun isSoul(entity: EntityArmorStand): Boolean { - for (stack in entity.inventory) { - if (stack != null) { - val skullTexture = stack.getSkullTexture() - if (skullTexture != null) { - if (skullTexture == texture) { - return true - } - } - } - } - - return false - } - - private fun isEnabled(): Boolean { - return LorenzUtils.inSkyblock && SkyHanniMod.feature.abilities.summoningSoulDisplay - } -} \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/HideNotClickableItems.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/HideNotClickableItems.kt new file mode 100644 index 000000000..c9a27eac6 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/HideNotClickableItems.kt @@ -0,0 +1,419 @@ +package at.hannibal2.skyhanni.features.inventory + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.data.ItemRenderBackground.Companion.background +import at.hannibal2.skyhanni.data.VanillaItemManager +import at.hannibal2.skyhanni.events.GuiContainerEvent +import at.hannibal2.skyhanni.events.RepositoryReloadEvent +import at.hannibal2.skyhanni.features.bazaar.BazaarApi +import at.hannibal2.skyhanni.utils.* +import at.hannibal2.skyhanni.utils.ItemUtils.cleanName +import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName +import at.hannibal2.skyhanni.utils.ItemUtils.getLore +import at.hannibal2.skyhanni.utils.StringUtils.removeColor +import com.google.gson.JsonObject +import net.minecraft.client.Minecraft +import net.minecraft.client.gui.inventory.GuiChest +import net.minecraft.inventory.ContainerChest +import net.minecraft.item.ItemStack +import net.minecraftforge.event.entity.player.ItemTooltipEvent +import net.minecraftforge.fml.common.eventhandler.EventPriority +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class HideNotClickableItems { + + private var hideReason = "" + + private var lastClickTime = 0L + private var bypassUntil = 0L + + private val hideNpcSellFilter = MultiFilter() + private val hideInStorageFilter = MultiFilter() + private val tradeNpcFilter = MultiFilter() + private val itemsToSalvage = mutableListOf() + private val hidePlayerTradeFilter = MultiFilter() + private val notAuctionableFilter = MultiFilter() + + @SubscribeEvent + fun onRepoReload(event: RepositoryReloadEvent) { + try { + val hideNotClickableItems = event.getConstant("HideNotClickableItems")!! + hideNpcSellFilter.load(hideNotClickableItems["hide_npc_sell"].asJsonObject) + hideInStorageFilter.load(hideNotClickableItems["hide_in_storage"].asJsonObject) + tradeNpcFilter.load(event.getConstant("TradeNpcs")!!) + updateSalvageList(hideNotClickableItems) + hidePlayerTradeFilter.load(hideNotClickableItems["hide_player_trade"].asJsonObject) + notAuctionableFilter.load(hideNotClickableItems["not_auctionable"].asJsonObject) + + } catch (e: Exception) { + e.printStackTrace() + LorenzUtils.error("error in RepositoryReloadEvent") + } + } + + private fun updateSalvageList(hideNotClickableItems: JsonObject) { + itemsToSalvage.clear() + val salvage = hideNotClickableItems["salvage"].asJsonObject + itemsToSalvage.addAll(salvage.asJsonObject["items"].asJsonArray.map { it.asString }) + for (armor in salvage.asJsonObject["armor"].asJsonArray.map { it.asString }) { + itemsToSalvage.add("$armor Helmet") + itemsToSalvage.add("$armor Chestplate") + itemsToSalvage.add("$armor Leggings") + itemsToSalvage.add("$armor Boots") + } + } + + @SubscribeEvent + fun onBackgroundDrawn(event: GuiContainerEvent.BackgroundDrawnEvent) { + if (!LorenzUtils.inSkyblock) return + if (isDisabled()) return + if (event.gui !is GuiChest) return + val guiChest = event.gui + val chest = guiChest.inventorySlots as ContainerChest + val chestName = chest.lowerChestInventory.displayName.unformattedText.trim() + + for (slot in chest.inventorySlots) { + if (slot == null) continue + + if (slot.slotNumber == slot.slotIndex) continue + if (slot.stack == null) continue + + if (hide(chestName, slot.stack)) { +// val color = LorenzColor.DARK_GRAY.addOpacity(160) +// val color = LorenzColor.DARK_GRAY.addOpacity(LorenzTest.a.toInt()) + val opacity = SkyHanniMod.feature.inventory.hideNotClickableOpacity + val color = LorenzColor.DARK_GRAY.addOpacity(opacity) + slot.stack.background = color.rgb + } + } + } + + @SubscribeEvent(priority = EventPriority.LOWEST) + fun onTooltip(event: ItemTooltipEvent) { + if (isDisabled()) return + if (event.toolTip == null) return + val guiChest = Minecraft.getMinecraft().currentScreen + if (guiChest !is GuiChest) return + val chest = guiChest.inventorySlots as ContainerChest + val chestName = chest.lowerChestInventory.displayName.unformattedText.trim() + + val stack = event.itemStack + if (InventoryUtils.getItemsInOpenChest().map { it.stack }.contains(stack)) return + if (!ItemUtils.getItemsInInventory().contains(stack)) return + + if (hide(chestName, stack)) { + val first = event.toolTip[0] + event.toolTip.clear() + event.toolTip.add("§7" + first.removeColor()) + event.toolTip.add("") + if (hideReason == "") { + event.toolTip.add("§4No hide reason!") + LorenzUtils.warning("No hide reason for not clickable item!") + } else { + event.toolTip.add("§c$hideReason") + } + } + } + + @SubscribeEvent + fun onSlotClick(event: GuiContainerEvent.SlotClickEvent) { + if (isDisabled()) return + if (event.gui !is GuiChest) return + val guiChest = event.gui + val chest = guiChest.inventorySlots as ContainerChest + val chestName = chest.lowerChestInventory.displayName.unformattedText.trim() + + val slot = event.slot ?: return + + if (slot.slotNumber == slot.slotIndex) return + if (slot.stack == null) return + + val stack = slot.stack + + if (hide(chestName, stack)) { + event.isCanceled = true + + if (System.currentTimeMillis() > lastClickTime + 5_000) { + lastClickTime = System.currentTimeMillis() + } + return + } + } + + private fun isDisabled(): Boolean { + if (bypassUntil > System.currentTimeMillis()) return true + + return !SkyHanniMod.feature.inventory.hideNotClickableItems + } + + private fun hide(chestName: String, stack: ItemStack): Boolean { + hideReason = "" + return when { + hideNpcSell(chestName, stack) -> true + hideInStorage(chestName, stack) -> true + hideSalvage(chestName, stack) -> true + hidePlayerTrade(chestName, stack) -> true + hideBazaarOrAH(chestName, stack) -> true + hideAccessoryBag(chestName, stack) -> true + hideSackOfSacks(chestName, stack) -> true + hideFishingBag(chestName, stack) -> true + hidePotionBag(chestName, stack) -> true + hidePrivateIslandChest(chestName, stack) -> true + hideAttributeFusion(chestName, stack) -> true + hideYourEquipment(chestName, stack) -> true + else -> false + } + } + + private fun hideYourEquipment(chestName: String, stack: ItemStack): Boolean { + if (!chestName.startsWith("Your Equipment")) return false + + val list = listOf( + "HELMET", + "CHESTPLATE", + "LEGGINGS", + "BOOTS", + + "NECKLACE", + "CLOAK", + "BELT", + "GLOVES", + "BRACELET" + ) + for (type in list) { + if (stack.getLore().any { it.contains("§l") && it.contains(type) }) {//todo use item api + return false + } + } + + if (isSkyBlockMenuItem(stack)) { + hideReason = "The SkyBlock Menu cannot be put into the potion bag!" + return true + } + + hideReason = "This item cannot be put into your equipment!" + return true + } + + private fun hideAttributeFusion(chestName: String, stack: ItemStack): Boolean { + if (!chestName.startsWith("Attribute Fusion")) return false + + if (ItemUtils.hasAttributes(stack)) return false + + hideReason = "This item has no attributes!" + return true + } + + private fun hidePrivateIslandChest(chestName: String, stack: ItemStack): Boolean { + if (chestName != "Chest" && chestName != "Large Chest") return false + //TODO make check if player is on private island + + if (!ItemUtils.isSoulBound(stack)) return false + + hideReason = "This item cannot be stored into a chest!" + return true + } + + private fun hidePotionBag(chestName: String, stack: ItemStack): Boolean { + if (!chestName.startsWith("Potion Bag")) return false + + if (isSkyBlockMenuItem(stack)) { + hideReason = "The SkyBlock Menu cannot be put into the potion bag!" + return true + } + + if (stack.cleanName().endsWith(" Potion")) return false + + hideReason = "This item is not a potion!" + return true + } + + private fun hideFishingBag(chestName: String, stack: ItemStack): Boolean { + if (!chestName.startsWith("Fishing Bag")) return false + + if (isSkyBlockMenuItem(stack)) { + hideReason = "The SkyBlock Menu cannot be put into the fishing bag!" + return true + } + + if (stack.getLore().any { it.removeColor() == "Fishing Bait" }) { + return false + } + hideReason = "This item is not a fishing bait!" + return true + } + + private fun hideSackOfSacks(chestName: String, stack: ItemStack): Boolean { + if (!chestName.startsWith("Sack of Sacks")) return false + + val name = stack.cleanName() + if (ItemUtils.isSack(name)) return false + if (isSkyBlockMenuItem(stack)) return false + + hideReason = "This item is not a sack!" + return true + } + + private fun hideAccessoryBag(chestName: String, stack: ItemStack): Boolean { + if (!chestName.startsWith("Accessory Bag")) return false + + if (stack.getLore().any { it.contains("ACCESSORY") }) return false + if (isSkyBlockMenuItem(stack)) return false + + hideReason = "This item is not an accessory!" + return true + } + + private fun hidePlayerTrade(chestName: String, stack: ItemStack): Boolean { + if (!chestName.startsWith("You ")) return false + + if (ItemUtils.isCoopSoulBound(stack)) { + hideReason = "Soulbound items cannot be traded!" + return true + } + + if (isSkyBlockMenuItem(stack)) { + hideReason = "The SkyBlock Menu cannot be traded!" + return true + } + + val name = stack.cleanName() + + if (ItemUtils.isSack(name)) { + hideReason = "Sacks cannot be traded!" + return true + } + + val result = hidePlayerTradeFilter.match(name) + LorenzDebug.log("hidePlayerTradeList filter result for '$name': $result") + + if (result) hideReason = "This item cannot be traded!" + return result + } + + private fun hideNpcSell(chestName: String, stack: ItemStack): Boolean { + if (!tradeNpcFilter.match(chestName)) return false + + var name = stack.cleanName() + val size = stack.stackSize + val amountText = " x$size" + if (name.endsWith(amountText)) { + name = name.substring(0, name.length - amountText.length) + } + + if (isSkyBlockMenuItem(stack)) { + hideReason = "The SkyBlock Menu cannot be sold at the NPC!" + return true + } + + if (!ItemUtils.isRecombobulated(stack)) { + if (hideNpcSellFilter.match(name)) return false + + val id = stack.getInternalName() + if (VanillaItemManager.isVanillaItem(id) && !stack.isItemEnchanted) { + return false + } + } + + hideReason = "This item should not be sold at the NPC!" + return true + } + + private fun hideInStorage(chestName: String, stack: ItemStack): Boolean { + if (!chestName.contains("Ender Chest") && !chestName.contains("Backpack") && chestName != "Storage") return false + + if (isSkyBlockMenuItem(stack)) { + hideReason = "The SkyBlock Menu cannot be put into the storage!" + return true + } + + val name = stack.cleanName() + + if (ItemUtils.isSack(name)) { + hideReason = "Sacks cannot be put into the storage!" + return true + } + + val result = hideInStorageFilter.match(name) + + if (result) hideReason = "Bags cannot be put into the storage!" + return result + } + + private fun hideSalvage(chestName: String, stack: ItemStack): Boolean { + if (chestName != "Salvage Item") return false + + if (ItemUtils.isRecombobulated(stack)) { + hideReason = "This item should not be salvaged! (Recombobulated)" + return true + } + for (line in stack.getLore()) { + if (line.contains("LEGENDARY DUNGEON")) { + hideReason = "This item should not be salvaged! (Legendary)" + return true + } + } + + if (isSkyBlockMenuItem(stack)) { + hideReason = "The SkyBlock Menu cannot be salvaged!" + return true + } + + val name = stack.cleanName() + for (item in itemsToSalvage) { + if (name.endsWith(item)) { + return false + } + } + + hideReason = "This item cannot be salvaged!" + return true + } + + private fun hideBazaarOrAH(chestName: String, stack: ItemStack): Boolean { + val bazaarInventory = BazaarApi.isBazaarInventory(chestName) + + val auctionHouseInventory = + chestName == "Co-op Auction House" || chestName == "Auction House" || chestName == "Create BIN Auction" || chestName == "Create Auction" + if (!bazaarInventory && !auctionHouseInventory) return false + + + + if (isSkyBlockMenuItem(stack)) { + if (bazaarInventory) hideReason = "The SkyBlock Menu is not a Bazaar Product!" + if (auctionHouseInventory) hideReason = "The SkyBlock Menu cannot be auctioned!" + return true + } + + if (bazaarInventory != BazaarApi.isBazaarItem(stack)) { + if (bazaarInventory) hideReason = "This item is not a Bazaar Product!" + if (auctionHouseInventory) hideReason = "Bazaar Products cannot be auctioned!" + + return true + } + + if (isNotAuctionable(stack)) return true + + return false + } + + private fun isNotAuctionable(stack: ItemStack): Boolean { + if (ItemUtils.isCoopSoulBound(stack)) { + hideReason = "Soulbound items cannot be auctioned!" + return true + } + + val name = stack.cleanName() + + if (ItemUtils.isSack(name)) { + hideReason = "Sacks cannot be auctioned!" + return true + } + + val result = notAuctionableFilter.match(name) + if (result) hideReason = "This item cannot be auctioned!" + return result + } + + private fun isSkyBlockMenuItem(stack: ItemStack): Boolean = stack.getInternalName() == "SKYBLOCK_MENU" +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/ItemDisplayOverlayFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/ItemDisplayOverlayFeatures.kt new file mode 100644 index 000000000..650d68a17 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/ItemDisplayOverlayFeatures.kt @@ -0,0 +1,120 @@ +package at.hannibal2.skyhanni.features.inventory + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.GuiRenderItemEvent +import at.hannibal2.skyhanni.utils.ItemUtils +import at.hannibal2.skyhanni.utils.ItemUtils.cleanName +import at.hannibal2.skyhanni.utils.ItemUtils.getLore +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.LorenzUtils.between +import at.hannibal2.skyhanni.utils.LorenzUtils.matchRegex +import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimal +import net.minecraft.client.renderer.GlStateManager +import net.minecraft.item.ItemStack +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class ItemDisplayOverlayFeatures { + + @SubscribeEvent + fun onRenderItemOverlayPost(event: GuiRenderItemEvent.RenderOverlayEvent.Post) { + val stack = event.stack ?: return + + if (!LorenzUtils.inSkyblock || stack.stackSize != 1) return + + val stackTip = getStackTip(stack) + + if (stackTip.isNotEmpty()) { + GlStateManager.disableLighting() + GlStateManager.disableDepth() + GlStateManager.disableBlend() + event.fontRenderer.drawStringWithShadow( + stackTip, + (event.x + 17 - event.fontRenderer.getStringWidth(stackTip)).toFloat(), + (event.y + 9).toFloat(), + 16777215 + ) + GlStateManager.enableLighting() + GlStateManager.enableDepth() + } + } + + private fun getStackTip(item: ItemStack): String { + val name = item.cleanName() + + if (SkyHanniMod.feature.inventory.itemNumberAsStackSize.contains(0)) { + when (name) { + "First Master Star" -> return "1" + "Second Master Star" -> return "2" + "Third Master Star" -> return "3" + "Fourth Master Star" -> return "4" + "Fifth Master Star" -> return "5" + } + } + + if (SkyHanniMod.feature.inventory.itemNumberAsStackSize.contains(1)) { + if (name.matchRegex("(.*)Master Skull - Tier .")) { + return name.substring(name.length - 1) + } + } + + if (SkyHanniMod.feature.inventory.itemNumberAsStackSize.contains(2)) { + if (name.contains("Golden ") || name.contains("Diamond ")) { + when { + name.contains("Bonzo") -> return "1" + name.contains("Scarf") -> return "2" + name.contains("Professor") -> return "3" + name.contains("Thorn") -> return "4" + name.contains("Livid") -> return "5" + name.contains("Sadan") -> return "6" + name.contains("Necron") -> return "7" + } + } + } + + if (SkyHanniMod.feature.inventory.itemNumberAsStackSize.contains(3)) { + if (name.startsWith("New Year Cake (")) { + return "§b" + name.between("(Year ", ")") + } + } + + if (SkyHanniMod.feature.inventory.itemNumberAsStackSize.contains(4)) { + if (ItemUtils.isPet(name)) { + val level = name.between("Lvl ", "] ").toInt() + if (level != ItemUtils.maxPetLevel(name)) { + return "$level" + } + } + } + + if (SkyHanniMod.feature.inventory.itemNumberAsStackSize.contains(5)) { + if (name.contains(" Minion ")) { + if (item.getLore().any { it.contains("Place this minion") }) { + val array = name.split(" ") + val last = array[array.size - 1] + return last.romanToDecimal().toString() + } + } + } + + if (SkyHanniMod.feature.inventory.displaySackName) { + if (ItemUtils.isSack(name)) { + //TODO fix this and replace other +// val sackName = grabSackName(name) + val split = name.split(" ") + val sackName = split[split.size - 2] + return (if (name.contains("Enchanted")) "§5" else "") + sackName.substring(0, 2) + } + } + + return "" + } + +// private fun grabSackName(name: String): String { +// val split = name.split(" ") +// val text = split[0] +// for (line in arrayOf("Large", "Medium", "Small", "Enchanted")) { +// if (text == line) return grabSackName(name.substring(text.length + 1)) +// } +// return text +// } +} \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/ItemStars.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/ItemStars.kt new file mode 100644 index 000000000..0e503c052 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/ItemStars.kt @@ -0,0 +1,150 @@ +package at.hannibal2.skyhanni.features.inventory + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.GuiRenderItemEvent +import at.hannibal2.skyhanni.events.RepositoryReloadEvent +import at.hannibal2.skyhanni.utils.ItemUtils.name +import at.hannibal2.skyhanni.utils.LorenzUtils +import net.minecraft.client.renderer.GlStateManager +import net.minecraftforge.event.entity.player.ItemTooltipEvent +import net.minecraftforge.fml.common.eventhandler.EventPriority +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import java.util.regex.Pattern + +class ItemStars { + + private val armorNames = mutableListOf() + private val tiers = mutableMapOf() + private val STAR_FIND_PATCHER = Pattern.compile("(.*)§.✪(.*)") + private val armorParts = listOf("Helmet", "Chestplate", "Leggings", "Boots") + + @SubscribeEvent(priority = EventPriority.LOW) + fun onTooltip(event: ItemTooltipEvent) { + if (!LorenzUtils.inSkyblock) return + + val stack = event.itemStack ?: return + if (stack.stackSize != 1) return + if (!SkyHanniMod.feature.inventory.itemStars) return + + val itemName = stack.name ?: return + val stars = getStars(itemName) + + if (stars > 0) { + var name = itemName + while (STAR_FIND_PATCHER.matcher(name).matches()) { + name = name.replaceFirst("§.✪".toRegex(), "") + } + name = name.trim() + event.toolTip[0] = "$name §c$stars✪" + } + } + + @SubscribeEvent + fun onRepoReload(event: RepositoryReloadEvent) { + try { + val items = event.getConstant("Items")!! + if (items.has("crimson_armors")) { + armorNames.clear() + armorNames.addAll(items.getAsJsonArray("crimson_armors").map { it.asString }) + } + + tiers.clear() + if (items.has("crimson_tiers")) { + items.getAsJsonObject("crimson_tiers").entrySet().forEach { + tiers[it.key] = it.value.asInt + } + } + + } catch (e: Exception) { + e.printStackTrace() + LorenzUtils.error("error in RepositoryReloadEvent") + } + } + + @SubscribeEvent + fun onRenderItemOverlayPost(event: GuiRenderItemEvent.RenderOverlayEvent.Post) { + if (!LorenzUtils.inSkyblock) return + if (!SkyHanniMod.feature.inventory.itemNumberAsStackSize.contains(6)) return + + val stack = event.stack ?: return + if (stack.stackSize != 1) return + val number = getCrimsonStars(stack.name ?: return) + val stackTip = if (number == -1) "" else number.toString() + + if (stackTip.isNotEmpty()) { + GlStateManager.disableLighting() + GlStateManager.disableDepth() + GlStateManager.disableBlend() + event.fontRenderer.drawStringWithShadow( + stackTip, + (event.x + 17 - event.fontRenderer.getStringWidth(stackTip)).toFloat(),//TODO search for this line and replace all other methods into an api + (event.y + 9).toFloat(), + 16777215 + ) + GlStateManager.enableLighting() + GlStateManager.enableDepth() + } + } + + private fun getStars(name: String): Int { + val stars = getCrimsonStars(name) + if (stars != -1) { + return stars + } + + return getOtherStars(name) + } + + private fun getCrimsonStars(name: String): Int { + if (!armorNames.any { name.contains(it) } || !armorParts.any { name.contains(it) }) { + return -1 + } + var name1 = name + var gold = 0 + var pink = 0 + var aqua = 0 + while (name1.contains("§6✪")) { + name1 = name1.replaceFirst("§6✪", "") + gold++ + } + while (name1.contains("§d✪")) { + name1 = name1.replaceFirst("§d✪", "") + pink++ + } + while (name1.contains("§b✪")) { + name1 = name1.replaceFirst("§b✪", "") + aqua++ + } + return (tiers.entries.find { name1.contains(it.key) }?.value ?: 0) + if (aqua > 0) { + 10 + aqua + } else if (pink > 0) { + 5 + pink + } else { + gold + } + } + + private fun getOtherStars(originalName: String): Int { + var name = originalName + + var gold = 0 + var red = 0 + while (name.contains("§6✪")) { + name = name.replaceFirst("§6✪", "") + gold++ + } + while (name.contains("§c✪")) { + name = name.replaceFirst("§c✪", "") + red++ + } + while (name.contains("§d✪")) { + name = name.replaceFirst("§d✪", "") + red++ + } + + if (red > 0) return 5 + red + if (gold > 0) return gold + + return -1 + } +} \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/RngMeterInventory.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/RngMeterInventory.kt new file mode 100644 index 000000000..51d81c5af --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/RngMeterInventory.kt @@ -0,0 +1,91 @@ +package at.hannibal2.skyhanni.features.inventory + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.GuiContainerEvent +import at.hannibal2.skyhanni.events.GuiRenderItemEvent +import at.hannibal2.skyhanni.utils.InventoryUtils +import at.hannibal2.skyhanni.utils.ItemUtils.getLore +import at.hannibal2.skyhanni.utils.ItemUtils.name +import at.hannibal2.skyhanni.utils.LorenzColor +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.LorenzUtils.between +import at.hannibal2.skyhanni.utils.RenderUtils.highlight +import at.hannibal2.skyhanni.utils.StringUtils.removeColor +import net.minecraft.client.Minecraft +import net.minecraft.client.gui.inventory.GuiChest +import net.minecraft.client.renderer.GlStateManager +import net.minecraft.inventory.ContainerChest +import net.minecraftforge.fml.common.eventhandler.EventPriority +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class RngMeterInventory { + + @SubscribeEvent + fun onRenderItemOverlayPost(event: GuiRenderItemEvent.RenderOverlayEvent.Post) { + if (!LorenzUtils.inSkyblock) return + + val screen = Minecraft.getMinecraft().currentScreen + if (screen !is GuiChest) return + val chest = screen.inventorySlots as ContainerChest + val chestName = chest.lowerChestInventory.displayName.unformattedText.trim() + + var stackTip = "" + + val stack = event.stack ?: return + if (SkyHanniMod.feature.inventory.rngMeterFloorName) { + if (chestName == "Catacombs RNG Meter") { + val name = stack.name ?: return + if (name.removeColor() == "RNG Meter") { + stackTip = stack.getLore()[0].between("(", ")") + } + } + } + + + if (stackTip.isNotEmpty()) { + GlStateManager.disableLighting() + GlStateManager.disableDepth() + GlStateManager.disableBlend() + event.fontRenderer.drawStringWithShadow( + stackTip, + (event.x + 17 - event.fontRenderer.getStringWidth(stackTip)).toFloat(), + (event.y + 9).toFloat(), + 16777215 + ) + GlStateManager.enableLighting() + GlStateManager.enableDepth() + } + } + + @SubscribeEvent(priority = EventPriority.LOW) + fun onBackgroundDrawn(event: GuiContainerEvent.BackgroundDrawnEvent) { + if (!LorenzUtils.inSkyblock) return + + if (event.gui !is GuiChest) return + val guiChest = event.gui + val chest = guiChest.inventorySlots as ContainerChest + val chestName = chest.lowerChestInventory.displayName.unformattedText.trim() + + if (SkyHanniMod.feature.inventory.rngMeterNoDrop) { + if (chestName == "Catacombs RNG Meter") { + for (slot in InventoryUtils.getItemsInOpenChest()) { + val stack = slot.stack + if (stack.getLore().any { it.contains("You don't have an RNG drop") }) { + slot highlight LorenzColor.RED + } + } + } + } + + if (SkyHanniMod.feature.inventory.rngMeterSelectedDrop) { + if (chestName.endsWith(" RNG Meter")) { + for (slot in InventoryUtils.getItemsInOpenChest()) { + val stack = slot.stack + if (stack.getLore().any { it.contains("§aSELECTED") }) { + slot highlight LorenzColor.YELLOW + } + } + } + } + } +} \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/itemabilities/FireVeilWandParticles.kt b/src/main/java/at/hannibal2/skyhanni/features/itemabilities/FireVeilWandParticles.kt new file mode 100644 index 000000000..c2b9ced29 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/itemabilities/FireVeilWandParticles.kt @@ -0,0 +1,64 @@ +package at.hannibal2.skyhanni.features.itemabilities + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.ItemClickInHandEvent +import at.hannibal2.skyhanni.events.PacketEvent +import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.RenderUtils +import at.hannibal2.skyhanni.utils.SpecialColour +import net.minecraft.client.Minecraft +import net.minecraft.network.play.server.S2APacketParticles +import net.minecraft.util.EnumParticleTypes +import net.minecraftforge.client.event.RenderWorldLastEvent +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import java.awt.Color + +class FireVeilWandParticles { + + var lastClick = 0L + + @SubscribeEvent + fun onChatPacket(event: PacketEvent.ReceiveEvent) { + if (!LorenzUtils.inSkyblock) return + if (SkyHanniMod.feature.itemAbilities.fireVeilWandDisplay == 0) return + if (System.currentTimeMillis() > lastClick + 5_500) return + + val packet = event.packet + if (packet !is S2APacketParticles) return + + + if (packet.particleType == EnumParticleTypes.FLAME && packet.particleCount == 1 && packet.particleSpeed == 0f && + packet.xOffset == 0f && + packet.yOffset == 0f && + packet.zOffset == 0f + ) { + event.isCanceled = true + } + } + + @SubscribeEvent + fun onItemClick(event: ItemClickInHandEvent) { + if (!LorenzUtils.inSkyblock) return + if (event.clickType != ItemClickInHandEvent.ClickType.RIGHT_CLICK) return + + val itemInHand = event.itemInHand ?: return + + val internalName = itemInHand.getInternalName() + if (internalName == "FIRE_VEIL_WAND") { + lastClick = System.currentTimeMillis() + } + } + + @SubscribeEvent + fun onRenderWorld(event: RenderWorldLastEvent) { + if (!LorenzUtils.inSkyblock) return + if (SkyHanniMod.feature.itemAbilities.fireVeilWandDisplay != 1) return + if (System.currentTimeMillis() > lastClick + 5_500) return + + val color = + Color(SpecialColour.specialToChromaRGB(SkyHanniMod.feature.itemAbilities.fireVeilWandDisplayColor), true) + + RenderUtils.drawCircle(Minecraft.getMinecraft().thePlayer, event.partialTicks, 3.5, color) + } +} \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/itemabilities/abilitycooldown/ItemAbilityCooldown.kt b/src/main/java/at/hannibal2/skyhanni/features/itemabilities/abilitycooldown/ItemAbilityCooldown.kt new file mode 100644 index 000000000..01bef358f --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/itemabilities/abilitycooldown/ItemAbilityCooldown.kt @@ -0,0 +1,214 @@ +package at.hannibal2.skyhanni.features.itemabilities.abilitycooldown + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.data.ItemRenderBackground.Companion.background +import at.hannibal2.skyhanni.events.GuiRenderItemEvent +import at.hannibal2.skyhanni.events.LorenzActionBarEvent +import at.hannibal2.skyhanni.utils.ItemUtils +import at.hannibal2.skyhanni.utils.ItemUtils.cleanName +import at.hannibal2.skyhanni.utils.LorenzColor +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.LorenzUtils.between +import net.minecraft.client.Minecraft +import net.minecraft.client.renderer.GlStateManager +import net.minecraft.item.ItemStack +import net.minecraftforge.common.MinecraftForge +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import net.minecraftforge.fml.common.gameevent.TickEvent + +class ItemAbilityCooldown { + + var lastAbility = "" + var tick = 0 + val items = mutableMapOf() + val witherImpactDetection = WitherImpactDetection(this) + + init { + MinecraftForge.EVENT_BUS.register(witherImpactDetection) + } + + fun clickWitherImpact() { + Ability.WITHER_IMPACT.click() + } + + @SubscribeEvent + fun onActionBar(event: LorenzActionBarEvent) { + if (!isEnabled()) return + + val message: String = event.message + if (message.contains(" (§6")) { + if (message.contains("§b) ")) { + val name: String = message.between(" (§6", "§b) ") + if (name == lastAbility) return + lastAbility = name + for (ability in Ability.values()) { + if (ability.abilityName == name) { + click(ability) + return + } + } + return + } + } + lastAbility = "" + } + + private fun isEnabled(): Boolean { + return LorenzUtils.inSkyblock && SkyHanniMod.feature.itemAbilities.itemAbilityCooldown + } + + private fun click(ability: Ability) { +// if (ability.isActive()) return + if (!ability.actionBarDetection) return + ability.click() + } + + @SubscribeEvent + fun onTick(event: TickEvent.ClientTickEvent) { + if (!isEnabled()) return + + tick++ + if (tick % 2 == 0) { + checkHotbar() + } + } + + private fun checkHotbar() { + items.clear() + for ((stack, slot) in ItemUtils.getItemsInInventoryWithSlots(true)) { +// val inHotbar = slot in 36..43 + + val itemName: String = stack.cleanName() + val ability = hasAbility(itemName) + if (ability != null) { + + if (ability.isOnCooldown()) { + val duration: Long = ability.lastClick + ability.getCooldown() - System.currentTimeMillis() + val color = if (duration < 600) LorenzColor.RED else LorenzColor.YELLOW + items[stack] = ItemText(color, ability.getDurationText(), true) + } else { + items[stack] = ItemText(LorenzColor.GREEN, "R", false) + } + } + } + + } + + @SubscribeEvent + fun onRenderItemOverlayPost(event: GuiRenderItemEvent.RenderOverlayEvent.Post) { + if (!isEnabled()) return + + val item = event.stack ?: return + if (item.stackSize != 1) return + + var stackTip = "" + + val guiOpen = Minecraft.getMinecraft().currentScreen != null + val itemText = items.filter { it.key == item } + .firstNotNullOfOrNull { it.value } ?: return + if (guiOpen && !itemText.onCooldown) return + + val color = itemText.color + stackTip = color.getChatColor() + itemText.text + + if (SkyHanniMod.feature.itemAbilities.itemAbilityCooldownBackground) { + var opacity = 130 + if (color == LorenzColor.GREEN) { + opacity = 80 + } + item.background = color.addOpacity(opacity).rgb + } + + if (stackTip.isNotEmpty()) { + GlStateManager.disableLighting() + GlStateManager.disableDepth() + GlStateManager.disableBlend() + event.fontRenderer.drawStringWithShadow( + stackTip, + (event.x + 17 - event.fontRenderer.getStringWidth(stackTip)).toFloat(), + (event.y + 9).toFloat(), + 16777215 + ) + GlStateManager.enableLighting() + GlStateManager.enableDepth() + } + } + + private fun hasAbility(itemName: String): Ability? { + for (ability in Ability.values()) { + for (name in ability.itemNames) { + if (itemName.contains(name)) { + return ability + } + } + } + return null + } + + enum class Ability( + val abilityName: String, + val cooldownInSeconds: Long, + vararg val itemNames: String, + var lastClick: Long = 0L, + val actionBarDetection: Boolean = true, + ) { + //TODO add into repo + ATOMSPLIT("Soulcry", 4, "Atomsplit Katana", "Vorpal Katana", "Voidedge Katana"), + WITHER_IMPACT("Wither Impact", 5, "Hyperion", "Scylla", "Valkyrie", "Astrea", actionBarDetection = false), + + HEAL_1("Small Heal", 7, "Wand of Healing"), + HEAL_2("Medium Heal", 7, "Wand of Mending"), + HEAL_3("Big Heal", 7, "Wand of Restoration"), + HEAL_4("Huge Heal", 7, "Wand of Atonement"), + + ICE_SPRAY("Ice Spray", 5, "Ice Spray Wand"), + GYRO("Gravity Storm", 30, "Gyrokinetic Wand"), + GIANTS_SWORD("Giant's Slam", 30, "Giant's Sword"), + + STAR_FALL("Starfall", 2, "Starlight Wand"), + VODOO_DOLL("Acupuncture", 5, "Voodoo Doll"), + INK_WAND("Ink Bomb", 30, "Ink Wand"), + GOLEM_SWORD("Iron Punch", 3, "Golem Sword"), + EMBER_ROD("Fire Blast", 30, "Ember Rod"), + ENDER_BOW("Ender Warp", 30, "Ender Bow"), + + LIVID_DAGGER("Throw", 5, "Livid Dagger"), + WEIRD_TUBA("Howl", 20, "Weird Tuba"), + + ENDSTONE_SWORD("Extreme Focus", 5, "End Stone Sword"), + PIGMAN_SWORD("Burning Souls", 5, "Pigman Sword"), + + SOULWARD("Soulward", 20, "Soul Esoward"), + ECHO("Echo", 3, "Ancestral Spade"), + + FIRE_VEIL("Fire Veil", 5, "Fire Veil Wand"), + //TODO add new crimson isle weapons + + ; + + fun click() { + lastClick = System.currentTimeMillis() + } + + fun isOnCooldown(): Boolean = lastClick + getCooldown() > System.currentTimeMillis() + + fun getCooldown(): Long = cooldownInSeconds * 1000 + + fun getDurationText(): String { + var duration: Long = lastClick + getCooldown() - System.currentTimeMillis() + return if (duration < 1600) { + duration /= 100 + var d = duration.toDouble() + d /= 10.0 + LorenzUtils.formatDouble(d) + } else { + duration /= 1000 + duration++ + LorenzUtils.formatInteger(duration.toInt()) + } + } + + } + + class ItemText(val color: LorenzColor, val text: String, val onCooldown: Boolean) +} \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/itemabilities/abilitycooldown/WitherImpactDetection.kt b/src/main/java/at/hannibal2/skyhanni/features/itemabilities/abilitycooldown/WitherImpactDetection.kt new file mode 100644 index 000000000..5ad5a4bb0 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/itemabilities/abilitycooldown/WitherImpactDetection.kt @@ -0,0 +1,74 @@ +package at.hannibal2.skyhanni.features.itemabilities.abilitycooldown + +import at.hannibal2.skyhanni.events.PacketEvent +import at.hannibal2.skyhanni.utils.LorenzUtils +import net.minecraft.client.Minecraft +import net.minecraft.init.Items +import net.minecraft.item.ItemStack +import net.minecraft.nbt.NBTTagCompound +import net.minecraft.nbt.NBTTagList +import net.minecraft.network.play.client.C08PacketPlayerBlockPlacement +import net.minecraft.network.play.server.S1CPacketEntityMetadata +import net.minecraft.network.play.server.S2APacketParticles +import net.minecraft.util.EnumParticleTypes +import net.minecraftforge.common.util.Constants +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import net.minecraftforge.fml.common.gameevent.TickEvent + +/** + * Taken from Skytils under AGPL 3.0 + * Modified + * https://github.com/Skytils/SkytilsMod/blob/1.x/LICENSE.md + * @author Skytils + */ +class WitherImpactDetection(private val itemAbilityCooldown: ItemAbilityCooldown) { + + val S2APacketParticles.type: EnumParticleTypes + get() = this.particleType + var lastShieldUse = -1L + var lastShieldClick = 0L + + @SubscribeEvent + fun onReceivePacket(event: PacketEvent.ReceiveEvent) { + val mc = Minecraft.getMinecraft() + if (!LorenzUtils.inSkyblock || mc.theWorld == null) return + + event.packet.apply { + + if (this is S1CPacketEntityMetadata && lastShieldClick != -1L && entityId == mc.thePlayer?.entityId && System.currentTimeMillis() - lastShieldClick <= 500 && func_149376_c()?.any { it.dataValueId == 17 } == true) { + lastShieldUse = System.currentTimeMillis() + lastShieldClick = -1 + itemAbilityCooldown.clickWitherImpact() + } + } + } + + @SubscribeEvent + fun onSendPacket(event: PacketEvent.SendEvent) { + val mc = Minecraft.getMinecraft() + if (!LorenzUtils.inSkyblock || lastShieldUse != -1L || mc.thePlayer?.heldItem == null) return + if (event.packet is C08PacketPlayerBlockPlacement && mc.thePlayer.heldItem.item == Items.iron_sword && getExtraAttributes( + mc.thePlayer.heldItem + )?.getTagList("ability_scroll", Constants.NBT.TAG_STRING)?.asStringSet() + ?.contains("WITHER_SHIELD_SCROLL") == true + ) { + lastShieldClick = System.currentTimeMillis() + } + } + + @SubscribeEvent + fun onTick(event: TickEvent.ClientTickEvent) { + if (lastShieldUse != -1L) { + val diff = ((lastShieldUse + 5000 - System.currentTimeMillis()) / 1000f) + if (diff < 0) lastShieldUse = -1 + } + } + + private fun getExtraAttributes(item: ItemStack?): NBTTagCompound? { + return if (item == null || !item.hasTagCompound()) { + null + } else item.getSubCompound("ExtraAttributes", false) + } + + private fun NBTTagList.asStringSet() = (0..tagCount()).mapTo(hashSetOf()) { getStringTagAt(it) } +} \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/items/HideNotClickableItems.kt b/src/main/java/at/hannibal2/skyhanni/features/items/HideNotClickableItems.kt deleted file mode 100644 index 2829742dc..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/items/HideNotClickableItems.kt +++ /dev/null @@ -1,418 +0,0 @@ -package at.hannibal2.skyhanni.features.items - -import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.data.ItemRenderBackground.Companion.background -import at.hannibal2.skyhanni.events.GuiContainerEvent -import at.hannibal2.skyhanni.events.RepositoryReloadEvent -import at.hannibal2.skyhanni.features.bazaar.BazaarApi -import at.hannibal2.skyhanni.utils.* -import at.hannibal2.skyhanni.utils.ItemUtils.cleanName -import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName -import at.hannibal2.skyhanni.utils.ItemUtils.getLore -import at.hannibal2.skyhanni.utils.StringUtils.removeColor -import com.google.gson.JsonObject -import net.minecraft.client.Minecraft -import net.minecraft.client.gui.inventory.GuiChest -import net.minecraft.inventory.ContainerChest -import net.minecraft.item.ItemStack -import net.minecraftforge.event.entity.player.ItemTooltipEvent -import net.minecraftforge.fml.common.eventhandler.EventPriority -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent - -class HideNotClickableItems { - - private var hideReason = "" - - private var lastClickTime = 0L - private var bypassUntil = 0L - - private val hideNpcSellFilter = MultiFilter() - private val hideInStorageFilter = MultiFilter() - private val tradeNpcFilter = MultiFilter() - private val itemsToSalvage = mutableListOf() - private val hidePlayerTradeFilter = MultiFilter() - private val notAuctionableFilter = MultiFilter() - - @SubscribeEvent - fun onRepoReload(event: RepositoryReloadEvent) { - try { - val hideNotClickableItems = event.getConstant("HideNotClickableItems")!! - hideNpcSellFilter.load(hideNotClickableItems["hide_npc_sell"].asJsonObject) - hideInStorageFilter.load(hideNotClickableItems["hide_in_storage"].asJsonObject) - tradeNpcFilter.load(event.getConstant("TradeNpcs")!!) - updateSalvageList(hideNotClickableItems) - hidePlayerTradeFilter.load(hideNotClickableItems["hide_player_trade"].asJsonObject) - notAuctionableFilter.load(hideNotClickableItems["not_auctionable"].asJsonObject) - - } catch (e: Exception) { - e.printStackTrace() - LorenzUtils.error("error in RepositoryReloadEvent") - } - } - - private fun updateSalvageList(hideNotClickableItems: JsonObject) { - itemsToSalvage.clear() - val salvage = hideNotClickableItems["salvage"].asJsonObject - itemsToSalvage.addAll(salvage.asJsonObject["items"].asJsonArray.map { it.asString }) - for (armor in salvage.asJsonObject["armor"].asJsonArray.map { it.asString }) { - itemsToSalvage.add("$armor Helmet") - itemsToSalvage.add("$armor Chestplate") - itemsToSalvage.add("$armor Leggings") - itemsToSalvage.add("$armor Boots") - } - } - - @SubscribeEvent - fun onBackgroundDrawn(event: GuiContainerEvent.BackgroundDrawnEvent) { - if (!LorenzUtils.inSkyblock) return - if (isDisabled()) return - if (event.gui !is GuiChest) return - val guiChest = event.gui - val chest = guiChest.inventorySlots as ContainerChest - val chestName = chest.lowerChestInventory.displayName.unformattedText.trim() - - for (slot in chest.inventorySlots) { - if (slot == null) continue - - if (slot.slotNumber == slot.slotIndex) continue - if (slot.stack == null) continue - - if (hide(chestName, slot.stack)) { -// val color = LorenzColor.DARK_GRAY.addOpacity(160) -// val color = LorenzColor.DARK_GRAY.addOpacity(LorenzTest.a.toInt()) - val opacity = SkyHanniMod.feature.inventory.hideNotClickableOpacity - val color = LorenzColor.DARK_GRAY.addOpacity(opacity) - slot.stack.background = color.rgb - } - } - } - - @SubscribeEvent(priority = EventPriority.LOWEST) - fun onTooltip(event: ItemTooltipEvent) { - if (isDisabled()) return - if (event.toolTip == null) return - val guiChest = Minecraft.getMinecraft().currentScreen - if (guiChest !is GuiChest) return - val chest = guiChest.inventorySlots as ContainerChest - val chestName = chest.lowerChestInventory.displayName.unformattedText.trim() - - val stack = event.itemStack - if (InventoryUtils.getItemsInOpenChest().map { it.stack }.contains(stack)) return - if (!ItemUtils.getItemsInInventory().contains(stack)) return - - if (hide(chestName, stack)) { - val first = event.toolTip[0] - event.toolTip.clear() - event.toolTip.add("§7" + first.removeColor()) - event.toolTip.add("") - if (hideReason == "") { - event.toolTip.add("§4No hide reason!") - LorenzUtils.warning("No hide reason for not clickable item!") - } else { - event.toolTip.add("§c$hideReason") - } - } - } - - @SubscribeEvent - fun onSlotClick(event: GuiContainerEvent.SlotClickEvent) { - if (isDisabled()) return - if (event.gui !is GuiChest) return - val guiChest = event.gui - val chest = guiChest.inventorySlots as ContainerChest - val chestName = chest.lowerChestInventory.displayName.unformattedText.trim() - - val slot = event.slot ?: return - - if (slot.slotNumber == slot.slotIndex) return - if (slot.stack == null) return - - val stack = slot.stack - - if (hide(chestName, stack)) { - event.isCanceled = true - - if (System.currentTimeMillis() > lastClickTime + 5_000) { - lastClickTime = System.currentTimeMillis() - } - return - } - } - - private fun isDisabled(): Boolean { - if (bypassUntil > System.currentTimeMillis()) return true - - return !SkyHanniMod.feature.inventory.hideNotClickableItems - } - - private fun hide(chestName: String, stack: ItemStack): Boolean { - hideReason = "" - return when { - hideNpcSell(chestName, stack) -> true - hideInStorage(chestName, stack) -> true - hideSalvage(chestName, stack) -> true - hidePlayerTrade(chestName, stack) -> true - hideBazaarOrAH(chestName, stack) -> true - hideAccessoryBag(chestName, stack) -> true - hideSackOfSacks(chestName, stack) -> true - hideFishingBag(chestName, stack) -> true - hidePotionBag(chestName, stack) -> true - hidePrivateIslandChest(chestName, stack) -> true - hideAttributeFusion(chestName, stack) -> true - hideYourEquipment(chestName, stack) -> true - else -> false - } - } - - private fun hideYourEquipment(chestName: String, stack: ItemStack): Boolean { - if (!chestName.startsWith("Your Equipment")) return false - - val list = listOf( - "HELMET", - "CHESTPLATE", - "LEGGINGS", - "BOOTS", - - "NECKLACE", - "CLOAK", - "BELT", - "GLOVES", - "BRACELET" - ) - for (type in list) { - if (stack.getLore().any { it.contains("§l") && it.contains(type) }) {//todo use item api - return false - } - } - - if (isSkyBlockMenuItem(stack)) { - hideReason = "The SkyBlock Menu cannot be put into the potion bag!" - return true - } - - hideReason = "This item cannot be put into your equipment!" - return true - } - - private fun hideAttributeFusion(chestName: String, stack: ItemStack): Boolean { - if (!chestName.startsWith("Attribute Fusion")) return false - - if (ItemUtils.hasAttributes(stack)) return false - - hideReason = "This item has no attributes!" - return true - } - - private fun hidePrivateIslandChest(chestName: String, stack: ItemStack): Boolean { - if (chestName != "Chest" && chestName != "Large Chest") return false - //TODO make check if player is on private island - - if (!ItemUtils.isSoulBound(stack)) return false - - hideReason = "This item cannot be stored into a chest!" - return true - } - - private fun hidePotionBag(chestName: String, stack: ItemStack): Boolean { - if (!chestName.startsWith("Potion Bag")) return false - - if (isSkyBlockMenuItem(stack)) { - hideReason = "The SkyBlock Menu cannot be put into the potion bag!" - return true - } - - if (stack.cleanName().endsWith(" Potion")) return false - - hideReason = "This item is not a potion!" - return true - } - - private fun hideFishingBag(chestName: String, stack: ItemStack): Boolean { - if (!chestName.startsWith("Fishing Bag")) return false - - if (isSkyBlockMenuItem(stack)) { - hideReason = "The SkyBlock Menu cannot be put into the fishing bag!" - return true - } - - if (stack.getLore().any { it.removeColor() == "Fishing Bait" }) { - return false - } - hideReason = "This item is not a fishing bait!" - return true - } - - private fun hideSackOfSacks(chestName: String, stack: ItemStack): Boolean { - if (!chestName.startsWith("Sack of Sacks")) return false - - val name = stack.cleanName() - if (ItemUtils.isSack(name)) return false - if (isSkyBlockMenuItem(stack)) return false - - hideReason = "This item is not a sack!" - return true - } - - private fun hideAccessoryBag(chestName: String, stack: ItemStack): Boolean { - if (!chestName.startsWith("Accessory Bag")) return false - - if (stack.getLore().any { it.contains("ACCESSORY") }) return false - if (isSkyBlockMenuItem(stack)) return false - - hideReason = "This item is not an accessory!" - return true - } - - private fun hidePlayerTrade(chestName: String, stack: ItemStack): Boolean { - if (!chestName.startsWith("You ")) return false - - if (ItemUtils.isCoopSoulBound(stack)) { - hideReason = "Soulbound items cannot be traded!" - return true - } - - if (isSkyBlockMenuItem(stack)) { - hideReason = "The SkyBlock Menu cannot be traded!" - return true - } - - val name = stack.cleanName() - - if (ItemUtils.isSack(name)) { - hideReason = "Sacks cannot be traded!" - return true - } - - val result = hidePlayerTradeFilter.match(name) - LorenzDebug.log("hidePlayerTradeList filter result for '$name': $result") - - if (result) hideReason = "This item cannot be traded!" - return result - } - - private fun hideNpcSell(chestName: String, stack: ItemStack): Boolean { - if (!tradeNpcFilter.match(chestName)) return false - - var name = stack.cleanName() - val size = stack.stackSize - val amountText = " x$size" - if (name.endsWith(amountText)) { - name = name.substring(0, name.length - amountText.length) - } - - if (isSkyBlockMenuItem(stack)) { - hideReason = "The SkyBlock Menu cannot be sold at the NPC!" - return true - } - - if (!ItemUtils.isRecombobulated(stack)) { - if (hideNpcSellFilter.match(name)) return false - - val id = stack.getInternalName() - if (VanillaItemManager.isVanillaItem(id) && !stack.isItemEnchanted) { - return false - } - } - - hideReason = "This item should not be sold at the NPC!" - return true - } - - private fun hideInStorage(chestName: String, stack: ItemStack): Boolean { - if (!chestName.contains("Ender Chest") && !chestName.contains("Backpack") && chestName != "Storage") return false - - if (isSkyBlockMenuItem(stack)) { - hideReason = "The SkyBlock Menu cannot be put into the storage!" - return true - } - - val name = stack.cleanName() - - if (ItemUtils.isSack(name)) { - hideReason = "Sacks cannot be put into the storage!" - return true - } - - val result = hideInStorageFilter.match(name) - - if (result) hideReason = "Bags cannot be put into the storage!" - return result - } - - private fun hideSalvage(chestName: String, stack: ItemStack): Boolean { - if (chestName != "Salvage Item") return false - - if (ItemUtils.isRecombobulated(stack)) { - hideReason = "This item should not be salvaged! (Recombobulated)" - return true - } - for (line in stack.getLore()) { - if (line.contains("LEGENDARY DUNGEON")) { - hideReason = "This item should not be salvaged! (Legendary)" - return true - } - } - - if (isSkyBlockMenuItem(stack)) { - hideReason = "The SkyBlock Menu cannot be salvaged!" - return true - } - - val name = stack.cleanName() - for (item in itemsToSalvage) { - if (name.endsWith(item)) { - return false - } - } - - hideReason = "This item cannot be salvaged!" - return true - } - - private fun hideBazaarOrAH(chestName: String, stack: ItemStack): Boolean { - val bazaarInventory = BazaarApi.isBazaarInventory(chestName) - - val auctionHouseInventory = - chestName == "Co-op Auction House" || chestName == "Auction House" || chestName == "Create BIN Auction" || chestName == "Create Auction" - if (!bazaarInventory && !auctionHouseInventory) return false - - - - if (isSkyBlockMenuItem(stack)) { - if (bazaarInventory) hideReason = "The SkyBlock Menu is not a Bazaar Product!" - if (auctionHouseInventory) hideReason = "The SkyBlock Menu cannot be auctioned!" - return true - } - - if (bazaarInventory != BazaarApi.isBazaarItem(stack)) { - if (bazaarInventory) hideReason = "This item is not a Bazaar Product!" - if (auctionHouseInventory) hideReason = "Bazaar Products cannot be auctioned!" - - return true - } - - if (isNotAuctionable(stack)) return true - - return false - } - - private fun isNotAuctionable(stack: ItemStack): Boolean { - if (ItemUtils.isCoopSoulBound(stack)) { - hideReason = "Soulbound items cannot be auctioned!" - return true - } - - val name = stack.cleanName() - - if (ItemUtils.isSack(name)) { - hideReason = "Sacks cannot be auctioned!" - return true - } - - val result = notAuctionableFilter.match(name) - if (result) hideReason = "This item cannot be auctioned!" - return result - } - - private fun isSkyBlockMenuItem(stack: ItemStack): Boolean = stack.getInternalName() == "SKYBLOCK_MENU" -} diff --git a/src/main/java/at/hannibal2/skyhanni/features/items/ItemDisplayOverlayFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/items/ItemDisplayOverlayFeatures.kt deleted file mode 100644 index bc4caf181..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/items/ItemDisplayOverlayFeatures.kt +++ /dev/null @@ -1,120 +0,0 @@ -package at.hannibal2.skyhanni.features.items - -import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.events.GuiRenderItemEvent -import at.hannibal2.skyhanni.utils.ItemUtils -import at.hannibal2.skyhanni.utils.ItemUtils.cleanName -import at.hannibal2.skyhanni.utils.ItemUtils.getLore -import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.LorenzUtils.between -import at.hannibal2.skyhanni.utils.LorenzUtils.matchRegex -import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimal -import net.minecraft.client.renderer.GlStateManager -import net.minecraft.item.ItemStack -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent - -class ItemDisplayOverlayFeatures { - - @SubscribeEvent - fun onRenderItemOverlayPost(event: GuiRenderItemEvent.RenderOverlayEvent.Post) { - val stack = event.stack ?: return - - if (!LorenzUtils.inSkyblock || stack.stackSize != 1) return - - val stackTip = getStackTip(stack) - - if (stackTip.isNotEmpty()) { - GlStateManager.disableLighting() - GlStateManager.disableDepth() - GlStateManager.disableBlend() - event.fontRenderer.drawStringWithShadow( - stackTip, - (event.x + 17 - event.fontRenderer.getStringWidth(stackTip)).toFloat(), - (event.y + 9).toFloat(), - 16777215 - ) - GlStateManager.enableLighting() - GlStateManager.enableDepth() - } - } - - private fun getStackTip(item: ItemStack): String { - val name = item.cleanName() - - if (SkyHanniMod.feature.inventory.itemNumberAsStackSize.contains(0)) { - when (name) { - "First Master Star" -> return "1" - "Second Master Star" -> return "2" - "Third Master Star" -> return "3" - "Fourth Master Star" -> return "4" - "Fifth Master Star" -> return "5" - } - } - - if (SkyHanniMod.feature.inventory.itemNumberAsStackSize.contains(1)) { - if (name.matchRegex("(.*)Master Skull - Tier .")) { - return name.substring(name.length - 1) - } - } - - if (SkyHanniMod.feature.inventory.itemNumberAsStackSize.contains(2)) { - if (name.contains("Golden ") || name.contains("Diamond ")) { - when { - name.contains("Bonzo") -> return "1" - name.contains("Scarf") -> return "2" - name.contains("Professor") -> return "3" - name.contains("Thorn") -> return "4" - name.contains("Livid") -> return "5" - name.contains("Sadan") -> return "6" - name.contains("Necron") -> return "7" - } - } - } - - if (SkyHanniMod.feature.inventory.itemNumberAsStackSize.contains(3)) { - if (name.startsWith("New Year Cake (")) { - return "§b" + name.between("(Year ", ")") - } - } - - if (SkyHanniMod.feature.inventory.itemNumberAsStackSize.contains(4)) { - if (ItemUtils.isPet(name)) { - val level = name.between("Lvl ", "] ").toInt() - if (level != ItemUtils.maxPetLevel(name)) { - return "$level" - } - } - } - - if (SkyHanniMod.feature.inventory.itemNumberAsStackSize.contains(5)) { - if (name.contains(" Minion ")) { - if (item.getLore().any { it.contains("Place this minion") }) { - val array = name.split(" ") - val last = array[array.size - 1] - return last.romanToDecimal().toString() - } - } - } - - if (SkyHanniMod.feature.inventory.displaySackName) { - if (ItemUtils.isSack(name)) { - //TODO fix this and replace other -// val sackName = grabSackName(name) - val split = name.split(" ") - val sackName = split[split.size - 2] - return (if (name.contains("Enchanted")) "§5" else "") + sackName.substring(0, 2) - } - } - - return "" - } - -// private fun grabSackName(name: String): String { -// val split = name.split(" ") -// val text = split[0] -// for (line in arrayOf("Large", "Medium", "Small", "Enchanted")) { -// if (text == line) return grabSackName(name.substring(text.length + 1)) -// } -// return text -// } -} \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/items/ItemStars.kt b/src/main/java/at/hannibal2/skyhanni/features/items/ItemStars.kt deleted file mode 100644 index 0301ddb53..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/items/ItemStars.kt +++ /dev/null @@ -1,150 +0,0 @@ -package at.hannibal2.skyhanni.features.items - -import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.events.GuiRenderItemEvent -import at.hannibal2.skyhanni.events.RepositoryReloadEvent -import at.hannibal2.skyhanni.utils.ItemUtils.name -import at.hannibal2.skyhanni.utils.LorenzUtils -import net.minecraft.client.renderer.GlStateManager -import net.minecraftforge.event.entity.player.ItemTooltipEvent -import net.minecraftforge.fml.common.eventhandler.EventPriority -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import java.util.regex.Pattern - -class ItemStars { - - private val armorNames = mutableListOf() - private val tiers = mutableMapOf() - private val STAR_FIND_PATCHER = Pattern.compile("(.*)§.✪(.*)") - private val armorParts = listOf("Helmet", "Chestplate", "Leggings", "Boots") - - @SubscribeEvent(priority = EventPriority.LOW) - fun onTooltip(event: ItemTooltipEvent) { - if (!LorenzUtils.inSkyblock) return - - val stack = event.itemStack ?: return - if (stack.stackSize != 1) return - if (!SkyHanniMod.feature.inventory.itemStars) return - - val itemName = stack.name ?: return - val stars = getStars(itemName) - - if (stars > 0) { - var name = itemName - while (STAR_FIND_PATCHER.matcher(name).matches()) { - name = name.replaceFirst("§.✪".toRegex(), "") - } - name = name.trim() - event.toolTip[0] = "$name §c$stars✪" - } - } - - @SubscribeEvent - fun onRepoReload(event: RepositoryReloadEvent) { - try { - val items = event.getConstant("Items")!! - if (items.has("crimson_armors")) { - armorNames.clear() - armorNames.addAll(items.getAsJsonArray("crimson_armors").map { it.asString }) - } - - tiers.clear() - if (items.has("crimson_tiers")) { - items.getAsJsonObject("crimson_tiers").entrySet().forEach { - tiers[it.key] = it.value.asInt - } - } - - } catch (e: Exception) { - e.printStackTrace() - LorenzUtils.error("error in RepositoryReloadEvent") - } - } - - @SubscribeEvent - fun onRenderItemOverlayPost(event: GuiRenderItemEvent.RenderOverlayEvent.Post) { - if (!LorenzUtils.inSkyblock) return - if (!SkyHanniMod.feature.inventory.itemNumberAsStackSize.contains(6)) return - - val stack = event.stack ?: return - if (stack.stackSize != 1) return - val number = getCrimsonStars(stack.name ?: return) - val stackTip = if (number == -1) "" else number.toString() - - if (stackTip.isNotEmpty()) { - GlStateManager.disableLighting() - GlStateManager.disableDepth() - GlStateManager.disableBlend() - event.fontRenderer.drawStringWithShadow( - stackTip, - (event.x + 17 - event.fontRenderer.getStringWidth(stackTip)).toFloat(),//TODO search for this line and replace all other methods into an api - (event.y + 9).toFloat(), - 16777215 - ) - GlStateManager.enableLighting() - GlStateManager.enableDepth() - } - } - - private fun getStars(name: String): Int { - val stars = getCrimsonStars(name) - if (stars != -1) { - return stars - } - - return getOtherStars(name) - } - - private fun getCrimsonStars(name: String): Int { - if (!armorNames.any { name.contains(it) } || !armorParts.any { name.contains(it) }) { - return -1 - } - var name1 = name - var gold = 0 - var pink = 0 - var aqua = 0 - while (name1.contains("§6✪")) { - name1 = name1.replaceFirst("§6✪", "") - gold++ - } - while (name1.contains("§d✪")) { - name1 = name1.replaceFirst("§d✪", "") - pink++ - } - while (name1.contains("§b✪")) { - name1 = name1.replaceFirst("§b✪", "") - aqua++ - } - return (tiers.entries.find { name1.contains(it.key) }?.value ?: 0) + if (aqua > 0) { - 10 + aqua - } else if (pink > 0) { - 5 + pink - } else { - gold - } - } - - private fun getOtherStars(originalName: String): Int { - var name = originalName - - var gold = 0 - var red = 0 - while (name.contains("§6✪")) { - name = name.replaceFirst("§6✪", "") - gold++ - } - while (name.contains("§c✪")) { - name = name.replaceFirst("§c✪", "") - red++ - } - while (name.contains("§d✪")) { - name = name.replaceFirst("§d✪", "") - red++ - } - - if (red > 0) return 5 + red - if (gold > 0) return gold - - return -1 - } -} \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/items/RngMeterInventory.kt b/src/main/java/at/hannibal2/skyhanni/features/items/RngMeterInventory.kt deleted file mode 100644 index 19c4ea249..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/items/RngMeterInventory.kt +++ /dev/null @@ -1,91 +0,0 @@ -package at.hannibal2.skyhanni.features.items - -import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.events.GuiContainerEvent -import at.hannibal2.skyhanni.events.GuiRenderItemEvent -import at.hannibal2.skyhanni.utils.InventoryUtils -import at.hannibal2.skyhanni.utils.ItemUtils.getLore -import at.hannibal2.skyhanni.utils.ItemUtils.name -import at.hannibal2.skyhanni.utils.LorenzColor -import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.LorenzUtils.between -import at.hannibal2.skyhanni.utils.RenderUtils.highlight -import at.hannibal2.skyhanni.utils.StringUtils.removeColor -import net.minecraft.client.Minecraft -import net.minecraft.client.gui.inventory.GuiChest -import net.minecraft.client.renderer.GlStateManager -import net.minecraft.inventory.ContainerChest -import net.minecraftforge.fml.common.eventhandler.EventPriority -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent - -class RngMeterInventory { - - @SubscribeEvent - fun onRenderItemOverlayPost(event: GuiRenderItemEvent.RenderOverlayEvent.Post) { - if (!LorenzUtils.inSkyblock) return - - val screen = Minecraft.getMinecraft().currentScreen - if (screen !is GuiChest) return - val chest = screen.inventorySlots as ContainerChest - val chestName = chest.lowerChestInventory.displayName.unformattedText.trim() - - var stackTip = "" - - val stack = event.stack ?: return - if (SkyHanniMod.feature.inventory.rngMeterFloorName) { - if (chestName == "Catacombs RNG Meter") { - val name = stack.name ?: return - if (name.removeColor() == "RNG Meter") { - stackTip = stack.getLore()[0].between("(", ")") - } - } - } - - - if (stackTip.isNotEmpty()) { - GlStateManager.disableLighting() - GlStateManager.disableDepth() - GlStateManager.disableBlend() - event.fontRenderer.drawStringWithShadow( - stackTip, - (event.x + 17 - event.fontRenderer.getStringWidth(stackTip)).toFloat(), - (event.y + 9).toFloat(), - 16777215 - ) - GlStateManager.enableLighting() - GlStateManager.enableDepth() - } - } - - @SubscribeEvent(priority = EventPriority.LOW) - fun onBackgroundDrawn(event: GuiContainerEvent.BackgroundDrawnEvent) { - if (!LorenzUtils.inSkyblock) return - - if (event.gui !is GuiChest) return - val guiChest = event.gui - val chest = guiChest.inventorySlots as ContainerChest - val chestName = chest.lowerChestInventory.displayName.unformattedText.trim() - - if (SkyHanniMod.feature.inventory.rngMeterNoDrop) { - if (chestName == "Catacombs RNG Meter") { - for (slot in InventoryUtils.getItemsInOpenChest()) { - val stack = slot.stack - if (stack.getLore().any { it.contains("You don't have an RNG drop") }) { - slot highlight LorenzColor.RED - } - } - } - } - - if (SkyHanniMod.feature.inventory.rngMeterSelectedDrop) { - if (chestName.endsWith(" RNG Meter")) { - for (slot in InventoryUtils.getItemsInOpenChest()) { - val stack = slot.stack - if (stack.getLore().any { it.contains("§aSELECTED") }) { - slot highlight LorenzColor.YELLOW - } - } - } - } - } -} \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/items/VanillaItemManager.kt b/src/main/java/at/hannibal2/skyhanni/features/items/VanillaItemManager.kt deleted file mode 100644 index f138d9c23..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/items/VanillaItemManager.kt +++ /dev/null @@ -1,53 +0,0 @@ -package at.hannibal2.skyhanni.features.items - -import com.google.gson.GsonBuilder -import com.google.gson.JsonObject -import java.io.BufferedReader -import java.io.File -import java.io.FileInputStream -import java.io.InputStreamReader -import java.nio.charset.StandardCharsets - -class VanillaItemManager { - private val gson = GsonBuilder().setPrettyPrinting().create() - - companion object { - private val vanillaItems: MutableList = ArrayList() - - fun isVanillaItem(internalName: String): Boolean { - return vanillaItems.contains(internalName) - } - } - - init { - load() - } - - private fun load() { - vanillaItems.clear() - val itemDirectory = File("config/notenoughupdates/repo/items") - if (!itemDirectory.isDirectory) return - val files = itemDirectory.listFiles() ?: return - for (file in files) { - val jsonObject = getJsonFromFile(file) - if (jsonObject != null) { - if (jsonObject.has("vanilla") && jsonObject["vanilla"].asBoolean) { - val name = file.name - val internalName = name.split(".")[0] - vanillaItems.add(internalName) - } - } - } - - } - - private fun getJsonFromFile(file: File): JsonObject? { - try { - BufferedReader(InputStreamReader(FileInputStream(file), - StandardCharsets.UTF_8 - )).use { reader -> return gson.fromJson(reader, JsonObject::class.java) } - } catch (e: Exception) { - return null - } - } -} \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/items/abilitycooldown/ItemAbilityCooldown.kt b/src/main/java/at/hannibal2/skyhanni/features/items/abilitycooldown/ItemAbilityCooldown.kt deleted file mode 100644 index b2974837b..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/items/abilitycooldown/ItemAbilityCooldown.kt +++ /dev/null @@ -1,214 +0,0 @@ -package at.hannibal2.skyhanni.features.items.abilitycooldown - -import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.data.ItemRenderBackground.Companion.background -import at.hannibal2.skyhanni.events.GuiRenderItemEvent -import at.hannibal2.skyhanni.events.LorenzActionBarEvent -import at.hannibal2.skyhanni.utils.ItemUtils -import at.hannibal2.skyhanni.utils.ItemUtils.cleanName -import at.hannibal2.skyhanni.utils.LorenzColor -import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.LorenzUtils.between -import net.minecraft.client.Minecraft -import net.minecraft.client.renderer.GlStateManager -import net.minecraft.item.ItemStack -import net.minecraftforge.common.MinecraftForge -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import net.minecraftforge.fml.common.gameevent.TickEvent - -class ItemAbilityCooldown { - - var lastAbility = "" - var tick = 0 - val items = mutableMapOf() - val witherImpactDetection = WitherImpactDetection(this) - - init { - MinecraftForge.EVENT_BUS.register(witherImpactDetection) - } - - fun clickWitherImpact() { - Ability.WITHER_IMPACT.click() - } - - @SubscribeEvent - fun onActionBar(event: LorenzActionBarEvent) { - if (!isEnabled()) return - - val message: String = event.message - if (message.contains(" (§6")) { - if (message.contains("§b) ")) { - val name: String = message.between(" (§6", "§b) ") - if (name == lastAbility) return - lastAbility = name - for (ability in Ability.values()) { - if (ability.abilityName == name) { - click(ability) - return - } - } - return - } - } - lastAbility = "" - } - - private fun isEnabled(): Boolean { - return LorenzUtils.inSkyblock && SkyHanniMod.feature.abilities.itemAbilityCooldown - } - - private fun click(ability: Ability) { -// if (ability.isActive()) return - if (!ability.actionBarDetection) return - ability.click() - } - - @SubscribeEvent - fun onTick(event: TickEvent.ClientTickEvent) { - if (!isEnabled()) return - - tick++ - if (tick % 2 == 0) { - checkHotbar() - } - } - - private fun checkHotbar() { - items.clear() - for ((stack, slot) in ItemUtils.getItemsInInventoryWithSlots(true)) { -// val inHotbar = slot in 36..43 - - val itemName: String = stack.cleanName() - val ability = hasAbility(itemName) - if (ability != null) { - - if (ability.isOnCooldown()) { - val duration: Long = ability.lastClick + ability.getCooldown() - System.currentTimeMillis() - val color = if (duration < 600) LorenzColor.RED else LorenzColor.YELLOW - items[stack] = ItemText(color, ability.getDurationText(), true) - } else { - items[stack] = ItemText(LorenzColor.GREEN, "R", false) - } - } - } - - } - - @SubscribeEvent - fun onRenderItemOverlayPost(event: GuiRenderItemEvent.RenderOverlayEvent.Post) { - if (!isEnabled()) return - - val item = event.stack ?: return - if (item.stackSize != 1) return - - var stackTip = "" - - val guiOpen = Minecraft.getMinecraft().currentScreen != null - val itemText = items.filter { it.key == item } - .firstNotNullOfOrNull { it.value } ?: return - if (guiOpen && !itemText.onCooldown) return - - val color = itemText.color - stackTip = color.getChatColor() + itemText.text - - if (SkyHanniMod.feature.abilities.itemAbilityCooldownBackground) { - var opacity = 130 - if (color == LorenzColor.GREEN) { - opacity = 80 - } - item.background = color.addOpacity(opacity).rgb - } - - if (stackTip.isNotEmpty()) { - GlStateManager.disableLighting() - GlStateManager.disableDepth() - GlStateManager.disableBlend() - event.fontRenderer.drawStringWithShadow( - stackTip, - (event.x + 17 - event.fontRenderer.getStringWidth(stackTip)).toFloat(), - (event.y + 9).toFloat(), - 16777215 - ) - GlStateManager.enableLighting() - GlStateManager.enableDepth() - } - } - - private fun hasAbility(itemName: String): Ability? { - for (ability in Ability.values()) { - for (name in ability.itemNames) { - if (itemName.contains(name)) { - return ability - } - } - } - return null - } - - enum class Ability( - val abilityName: String, - val cooldownInSeconds: Long, - vararg val itemNames: String, - var lastClick: Long = 0L, - val actionBarDetection: Boolean = true, - ) { - //TODO add into repo - ATOMSPLIT("Soulcry", 4, "Atomsplit Katana", "Vorpal Katana", "Voidedge Katana"), - WITHER_IMPACT("Wither Impact", 5, "Hyperion", "Scylla", "Valkyrie", "Astrea", actionBarDetection = false), - - HEAL_1("Small Heal", 7, "Wand of Healing"), - HEAL_2("Medium Heal", 7, "Wand of Mending"), - HEAL_3("Big Heal", 7, "Wand of Restoration"), - HEAL_4("Huge Heal", 7, "Wand of Atonement"), - - ICE_SPRAY("Ice Spray", 5, "Ice Spray Wand"), - GYRO("Gravity Storm", 30, "Gyrokinetic Wand"), - GIANTS_SWORD("Giant's Slam", 30, "Giant's Sword"), - - STAR_FALL("Starfall", 2, "Starlight Wand"), - VODOO_DOLL("Acupuncture", 5, "Voodoo Doll"), - INK_WAND("Ink Bomb", 30, "Ink Wand"), - GOLEM_SWORD("Iron Punch", 3, "Golem Sword"), - EMBER_ROD("Fire Blast", 30, "Ember Rod"), - ENDER_BOW("Ender Warp", 30, "Ender Bow"), - - LIVID_DAGGER("Throw", 5, "Livid Dagger"), - WEIRD_TUBA("Howl", 20, "Weird Tuba"), - - ENDSTONE_SWORD("Extreme Focus", 5, "End Stone Sword"), - PIGMAN_SWORD("Burning Souls", 5, "Pigman Sword"), - - SOULWARD("Soulward", 20, "Soul Esoward"), - ECHO("Echo", 3, "Ancestral Spade"), - - FIRE_VEIL("Fire Veil", 5, "Fire Veil Wand"), - //TODO add new crimson isle weapons - - ; - - fun click() { - lastClick = System.currentTimeMillis() - } - - fun isOnCooldown(): Boolean = lastClick + getCooldown() > System.currentTimeMillis() - - fun getCooldown(): Long = cooldownInSeconds * 1000 - - fun getDurationText(): String { - var duration: Long = lastClick + getCooldown() - System.currentTimeMillis() - return if (duration < 1600) { - duration /= 100 - var d = duration.toDouble() - d /= 10.0 - LorenzUtils.formatDouble(d) - } else { - duration /= 1000 - duration++ - LorenzUtils.formatInteger(duration.toInt()) - } - } - - } - - class ItemText(val color: LorenzColor, val text: String, val onCooldown: Boolean) -} \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/items/abilitycooldown/WitherImpactDetection.kt b/src/main/java/at/hannibal2/skyhanni/features/items/abilitycooldown/WitherImpactDetection.kt deleted file mode 100644 index da0d5068c..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/items/abilitycooldown/WitherImpactDetection.kt +++ /dev/null @@ -1,74 +0,0 @@ -package at.hannibal2.skyhanni.features.items.abilitycooldown - -import at.hannibal2.skyhanni.events.PacketEvent -import at.hannibal2.skyhanni.utils.LorenzUtils -import net.minecraft.client.Minecraft -import net.minecraft.init.Items -import net.minecraft.item.ItemStack -import net.minecraft.nbt.NBTTagCompound -import net.minecraft.nbt.NBTTagList -import net.minecraft.network.play.client.C08PacketPlayerBlockPlacement -import net.minecraft.network.play.server.S1CPacketEntityMetadata -import net.minecraft.network.play.server.S2APacketParticles -import net.minecraft.util.EnumParticleTypes -import net.minecraftforge.common.util.Constants -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import net.minecraftforge.fml.common.gameevent.TickEvent - -/** - * Taken from Skytils under AGPL 3.0 - * Modified - * https://github.com/Skytils/SkytilsMod/blob/1.x/LICENSE.md - * @author Skytils - */ -class WitherImpactDetection(private val itemAbilityCooldown: ItemAbilityCooldown) { - - val S2APacketParticles.type: EnumParticleTypes - get() = this.particleType - var lastShieldUse = -1L - var lastShieldClick = 0L - - @SubscribeEvent - fun onReceivePacket(event: PacketEvent.ReceiveEvent) { - val mc = Minecraft.getMinecraft() - if (!LorenzUtils.inSkyblock || mc.theWorld == null) return - - event.packet.apply { - - if (this is S1CPacketEntityMetadata && lastShieldClick != -1L && entityId == mc.thePlayer?.entityId && System.currentTimeMillis() - lastShieldClick <= 500 && func_149376_c()?.any { it.dataValueId == 17 } == true) { - lastShieldUse = System.currentTimeMillis() - lastShieldClick = -1 - itemAbilityCooldown.clickWitherImpact() - } - } - } - - @SubscribeEvent - fun onSendPacket(event: PacketEvent.SendEvent) { - val mc = Minecraft.getMinecraft() - if (!LorenzUtils.inSkyblock || lastShieldUse != -1L || mc.thePlayer?.heldItem == null) return - if (event.packet is C08PacketPlayerBlockPlacement && mc.thePlayer.heldItem.item == Items.iron_sword && getExtraAttributes( - mc.thePlayer.heldItem - )?.getTagList("ability_scroll", Constants.NBT.TAG_STRING)?.asStringSet() - ?.contains("WITHER_SHIELD_SCROLL") == true - ) { - lastShieldClick = System.currentTimeMillis() - } - } - - @SubscribeEvent - fun onTick(event: TickEvent.ClientTickEvent) { - if (lastShieldUse != -1L) { - val diff = ((lastShieldUse + 5000 - System.currentTimeMillis()) / 1000f) - if (diff < 0) lastShieldUse = -1 - } - } - - private fun getExtraAttributes(item: ItemStack?): NBTTagCompound? { - return if (item == null || !item.hasTagCompound()) { - null - } else item.getSubCompound("ExtraAttributes", false) - } - - private fun NBTTagList.asStringSet() = (0..tagCount()).mapTo(hashSetOf()) { getStringTagAt(it) } -} \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/slayer/EndermanSlayerBeacon.kt b/src/main/java/at/hannibal2/skyhanni/features/slayer/EndermanSlayerBeacon.kt index 22a7826a7..847a3ab15 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/slayer/EndermanSlayerBeacon.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/slayer/EndermanSlayerBeacon.kt @@ -99,7 +99,7 @@ class EndermanSlayerBeacon { } } - private fun isEnabled(): Boolean = LorenzUtils.inSkyblock && SkyHanniMod.feature.misc.slayerEndermanBeacon && + private fun isEnabled(): Boolean = LorenzUtils.inSkyblock && SkyHanniMod.feature.slayer.slayerEndermanBeacon && LorenzUtils.skyBlockIsland == "The End" && (DamageIndicatorManager.isBossSpawned(BossType.SLAYER_ENDERMAN_2) || DamageIndicatorManager.isBossSpawned(BossType.SLAYER_ENDERMAN_3) || diff --git a/src/main/java/at/hannibal2/skyhanni/features/slayer/HighlightSlayerMiniboss.kt b/src/main/java/at/hannibal2/skyhanni/features/slayer/HighlightSlayerMiniboss.kt index 5555af33c..55a66ee14 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/slayer/HighlightSlayerMiniboss.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/slayer/HighlightSlayerMiniboss.kt @@ -87,6 +87,6 @@ class HighlightSlayerMiniboss { } private fun isEnabled(): Boolean { - return LorenzUtils.inSkyblock && SkyHanniMod.feature.misc.slayerMinibossHighlight && !LorenzUtils.inDungeons && !LorenzUtils.inKuudraFight + return LorenzUtils.inSkyblock && SkyHanniMod.feature.slayer.slayerMinibossHighlight && !LorenzUtils.inDungeons && !LorenzUtils.inKuudraFight } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/summonings/SummoningMobManager.kt b/src/main/java/at/hannibal2/skyhanni/features/summonings/SummoningMobManager.kt new file mode 100644 index 000000000..4334cd0d1 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/summonings/SummoningMobManager.kt @@ -0,0 +1,209 @@ +package at.hannibal2.skyhanni.features.summonings + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.events.RenderMobColoredEvent +import at.hannibal2.skyhanni.events.ResetEntityHurtEvent +import at.hannibal2.skyhanni.events.withAlpha +import at.hannibal2.skyhanni.utils.* +import at.hannibal2.skyhanni.utils.LorenzUtils.baseMaxHealth +import at.hannibal2.skyhanni.utils.RenderUtils.renderStrings +import net.minecraft.client.Minecraft +import net.minecraft.entity.EntityLiving +import net.minecraft.entity.EntityLivingBase +import net.minecraft.entity.item.EntityArmorStand +import net.minecraftforge.client.event.RenderGameOverlayEvent +import net.minecraftforge.client.event.RenderLivingEvent +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.TickEvent +import java.util.regex.Pattern + +class SummoningMobManager { + + + private val summoningMobs = mutableMapOf() + private val summoningMobNametags = mutableListOf() + private var summoningsSpawned = 0 + private var searchArmorStands = false + private var searchMobs = false + + //§aYou have spawned your Tank Zombie §r§asoul! §r§d(249 Mana) + private val spawnPatter = Pattern.compile("§aYou have spawned your (.+) §r§asoul! §r§d\\((\\d+) Mana\\)") + private val despawnPatter = Pattern.compile("§cYou have despawned your (monster|monsters)!") + + //§a§ohannibal2's Tank Zombie§r §a160k§c❤ + private val healthPattern = Pattern.compile("§a§o(.+)'s (.+)§r §[ae]([\\dkm]+)§c❤") + + //§cThe Seraph recalled your 3 summoned allies! + private val seraphRecallPattern = Pattern.compile("§cThe Seraph recalled your (\\d) summoned allies!") + + @SubscribeEvent + fun onChatMessage(event: LorenzChatEvent) { + if (!LorenzUtils.isOnHypixel) return + + val message = event.message + val matcher = spawnPatter.matcher(message) + if (matcher.matches()) { + if (SkyHanniMod.feature.summonings.summoningMobDisplay) { + event.blockedReason = "summoning_soul" + } + summoningsSpawned++ + searchArmorStands = true + searchMobs = true + } + + if (despawnPatter.matcher(message).matches() || message.startsWith("§c ☠ §r§7You ")) { + despawned() + if (SkyHanniMod.feature.summonings.summoningMobDisplay && !message.contains("☠")) { + event.blockedReason = "summoning_soul" + } + } + if (message == "§cThe Seraph recalled your summoned ally!" || seraphRecallPattern.matcher(message).matches()) { + despawned() + if (SkyHanniMod.feature.summonings.summoningMobDisplay) { + event.blockedReason = "summoning_soul" + } + } + } + + var tick = 0 + + @SubscribeEvent + fun onTick(event: TickEvent.ClientTickEvent) { + if (!isEnabled()) return + + if (SkyHanniMod.feature.summonings.summoningMobDisplay) { + if (tick++ % 20 == 0) { + updateData() + } + } + + if (searchArmorStands) { + Minecraft.getMinecraft().theWorld.loadedEntityList.filter { it is EntityArmorStand && it !in summoningMobNametags } + .forEach { + val name = it.displayName.unformattedText + val matcher = healthPattern.matcher(name) + if (matcher.matches()) { + val playerName = Minecraft.getMinecraft().thePlayer.name + if (name.contains(playerName)) { + summoningMobNametags.add(it as EntityArmorStand) + if (summoningMobNametags.size == summoningsSpawned) { + searchArmorStands = false + } + } + } + } + } + + if (searchMobs) { + val playerLocation = LocationUtils.playerLocation() + Minecraft.getMinecraft().theWorld.loadedEntityList.filter { + it is EntityLiving && it !in summoningMobs.keys && it.getLorenzVec() + .distance(playerLocation) < 10 && it.ticksExisted < 2 + }.forEach { + summoningMobs[it as EntityLiving] = SummoningMob(System.currentTimeMillis(), name = "Mob") + updateData() + if (summoningMobs.size == summoningsSpawned) { + searchMobs = false + } + } + } + } + + private fun updateData() { + if (summoningMobs.isEmpty()) return + + for (entry in HashMap(summoningMobs)) { + val entityLiving = entry.key + val summoningMob = entry.value + + val currentHealth = entityLiving.health.toInt() + val name = summoningMob.name + if (currentHealth == 0) { + summoningMobs.remove(entityLiving) + LorenzUtils.chat("§e[SkyHanni] Your Summoning Mob just §cdied!") + continue + } + + val maxHealth = entityLiving.baseMaxHealth + val color = NumberUtil.percentageColor(currentHealth.toLong(), maxHealth.toLong()).getChatColor() + + val currentFormat = NumberUtil.format(currentHealth) + val maxFormat = NumberUtil.format(maxHealth) + summoningMob.lastDisplayName = "§a$name $color$currentFormat/$maxFormat" + } + } + + @SubscribeEvent + fun renderOverlay(event: RenderGameOverlayEvent.Post) { + if (!SkyHanniMod.feature.summonings.summoningMobDisplay) return + if (summoningMobs.isEmpty()) return + + val list = mutableListOf() + list.add("Summoning mobs: " + summoningMobs.size) + var id = 1 + for (mob in summoningMobs) { + val name = mob.value.lastDisplayName + list.add("#$id $name") + id++ + } + + SkyHanniMod.feature.summonings.summoningMobDisplayPos.renderStrings(list) + } + + @SubscribeEvent + fun onWorldChange(event: WorldEvent.Load) { + despawned() + } + + @SubscribeEvent(priority = EventPriority.HIGH) + fun onRenderLiving(event: RenderLivingEvent.Specials.Pre) { + if (!LorenzUtils.inSkyblock) return + if (!SkyHanniMod.feature.summonings.summoningMobHideNametag) return + + val entity = event.entity + if (entity !is EntityArmorStand) return + if (!entity.hasCustomName()) return + if (entity.isDead) return + + event.isCanceled = entity in summoningMobNametags + } + + @SubscribeEvent + fun onRenderMobColored(event: RenderMobColoredEvent) { + if (SkyHanniMod.feature.summonings.summoningMobColored) { + val entity = event.entity + if (entity is EntityLiving && entity in summoningMobs.keys) { + event.color = LorenzColor.GREEN.toColor().withAlpha(127) + } + } + } + + @SubscribeEvent + fun onResetEntityHurtTime(event: ResetEntityHurtEvent) { + val entity = event.entity + if (SkyHanniMod.feature.summonings.summoningMobColored && entity in summoningMobs.keys) { + event.shouldReset = true + } + } + + private fun despawned() { + summoningMobs.clear() + summoningMobNametags.clear() + summoningsSpawned = 0 + searchArmorStands = false + searchMobs = false + } + + private fun isEnabled(): Boolean { + return LorenzUtils.inSkyblock && (SkyHanniMod.feature.summonings.summoningMobDisplay || SkyHanniMod.feature.summonings.summoningMobHideNametag) + } + + class SummoningMob( + val spawnTime: Long, + var name: String = "", + var lastDisplayName: String = "", + ) +} \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/summonings/SummoningSoulsName.kt b/src/main/java/at/hannibal2/skyhanni/features/summonings/SummoningSoulsName.kt new file mode 100644 index 000000000..c0ea8540b --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/summonings/SummoningSoulsName.kt @@ -0,0 +1,132 @@ +package at.hannibal2.skyhanni.features.summonings + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.test.GriffinJavaUtils +import at.hannibal2.skyhanni.utils.EntityUtils.getNameTagWith +import at.hannibal2.skyhanni.utils.ItemUtils.getSkullTexture +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.LorenzVec +import at.hannibal2.skyhanni.utils.RenderUtils.drawString +import at.hannibal2.skyhanni.utils.getLorenzVec +import net.minecraft.client.Minecraft +import net.minecraft.entity.EntityLiving +import net.minecraft.entity.item.EntityArmorStand +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.TickEvent + +class SummoningSoulsName { + + var tick = 0 + private val texture = + "ewogICJ0aW1lc3RhbXAiIDogMTYwMTQ3OTI2NjczMywKICAicHJvZmlsZUlkIiA6ICJmMzA1ZjA5NDI0NTg0ZjU" + + "4YmEyYjY0ZjAyZDcyNDYyYyIsCiAgInByb2ZpbGVOYW1lIiA6ICJqcm9ja2EzMyIsCiAgInNpZ25hdH" + + "VyZVJlcXVpcmVkIiA6IHRydWUsCiAgInRleHR1cmVzIiA6IHsKICAgICJTS0lOIiA6IHsKICAgICAgI" + + "nVybCIgOiAiaHR0cDovL3RleHR1cmVzLm1pbmVjcmFmdC5uZXQvdGV4dHVyZS81YWY0MDM1ZWMwZGMx" + + "NjkxNzc4ZDVlOTU4NDAxNzAyMjdlYjllM2UyOTQzYmVhODUzOTI5Y2U5MjNjNTk4OWFkIgogICAgfQogIH0KfQ" + + private val souls = mutableMapOf() + private val mobsLastLocation = mutableMapOf() + private val mobsName = mutableMapOf() + + @SubscribeEvent + fun onTick(event: TickEvent.ClientTickEvent) { + if (!isEnabled()) return + + tick++ + //TODO use packets instead of this + if (tick % 1 == 0) { + check() + } + } + + private fun check() { + val minecraft = Minecraft.getMinecraft() + val world = minecraft.theWorld + for (entity in world.loadedEntityList) { + if (souls.contains(entity)) continue + + if (entity is EntityArmorStand) { + if (isSoul(entity)) { + val soulLocation = entity.getLorenzVec() + + val map = mutableMapOf() + for ((mob, loc) in mobsLastLocation) { + val distance = loc.distance(soulLocation) + map[mob] = distance + } + + val nearestMob = GriffinJavaUtils.sortByValueAsc(map).firstNotNullOfOrNull { it.key } + if (nearestMob != null) { +// val mobDistance = nearestMob.getLorenzVec().add(0.0, -1.4375, 0.0) +// val distance = mobDistance.distance(soulLocation) +// val diff = mobDistance.add(soulLocation.multiply(-1)) + +// println(" ") +// println("mobDistance: $mobDistance") +// println("soulLocation: $soulLocation") +// println("diff: $diff") +// LorenzUtils.chat("distance: $distance") + val name = mobsName[nearestMob]!! +// LorenzUtils.chat("maybe its $name") + souls[entity] = name + } + + } + } + } + + for (entity in world.loadedEntityList) { + if (entity is EntityLiving) { + val consumer = entity.getNameTagWith(2, "§c❤") + if (consumer != null) { + if (!consumer.name.contains("§e0")) { + mobsLastLocation[entity] = entity.getLorenzVec() + mobsName[entity] = consumer.name + } + } + } + } + + souls.keys.removeIf { it !in world.loadedEntityList } + //TODO fix overhead! +// mobs.keys.removeIf { it !in world.loadedEntityList } + } + + @SubscribeEvent + fun onWorldRender(event: RenderWorldLastEvent) { + if (!isEnabled()) return + + for ((entity, name) in souls) { + val vec = entity.getLorenzVec() + event.drawString(vec.add(0.0, 2.5, 0.0), name) + } + } + + @SubscribeEvent + fun onWorldChange(event: WorldEvent.Load) { + souls.clear() + mobsLastLocation.clear() + mobsName.clear() + } + + private fun isSoul(entity: EntityArmorStand): Boolean { + for (stack in entity.inventory) { + if (stack != null) { + val skullTexture = stack.getSkullTexture() + if (skullTexture != null) { + if (skullTexture == texture) { + return true + } + } + } + } + + return false + } + + private fun isEnabled(): Boolean { + return LorenzUtils.inSkyblock && SkyHanniMod.feature.summonings.summoningSoulDisplay + } +} \ No newline at end of file -- cgit