From 81358be1e6fe2ba1de02afcd2d08a969679bd14a Mon Sep 17 00:00:00 2001 From: Thunderblade73 <85900443+Thunderblade73@users.noreply.github.com> Date: Wed, 17 Jul 2024 12:42:27 +0200 Subject: [PATCH] Feature: Crown of Avarice Counter (#2229) --- .../itemability/CrownOfAvariceConfig.java | 28 ++++++++++ .../itemability/ItemAbilityConfig.java | 7 +++ .../itemabilities/CrownOfAvariceCounter.kt | 51 +++++++++++++++++++ .../at/hannibal2/skyhanni/utils/ItemUtils.kt | 2 + 4 files changed, 88 insertions(+) create mode 100644 src/main/java/at/hannibal2/skyhanni/config/features/itemability/CrownOfAvariceConfig.java create mode 100644 src/main/java/at/hannibal2/skyhanni/features/itemabilities/CrownOfAvariceCounter.kt diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/itemability/CrownOfAvariceConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/itemability/CrownOfAvariceConfig.java new file mode 100644 index 000000000000..4c23afa12b7b --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/features/itemability/CrownOfAvariceConfig.java @@ -0,0 +1,28 @@ +package at.hannibal2.skyhanni.config.features.itemability; + +import at.hannibal2.skyhanni.config.FeatureToggle; +import at.hannibal2.skyhanni.config.core.config.Position; +import com.google.gson.annotations.Expose; +import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean; +import io.github.notenoughupdates.moulconfig.annotations.ConfigLink; +import io.github.notenoughupdates.moulconfig.annotations.ConfigOption; + +public class CrownOfAvariceConfig { + + @Expose + @ConfigOption(name = "Counter", + desc = "Shows the current coins of your crown of avarice (if worn).") + @ConfigEditorBoolean + @FeatureToggle + public boolean enable = false; + + @Expose + @ConfigOption(name = "Counter format", + desc = "Have the crown of avarice counter as short format instead of every digit.") + @ConfigEditorBoolean + public boolean shortFormat = true; + + @Expose + @ConfigLink(owner = CrownOfAvariceConfig.class,field = "enable") + public Position position = new Position(20,20); +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/itemability/ItemAbilityConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/itemability/ItemAbilityConfig.java index d428b591fc93..21ba39b8eccf 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/itemability/ItemAbilityConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/itemability/ItemAbilityConfig.java @@ -1,9 +1,11 @@ package at.hannibal2.skyhanni.config.features.itemability; import at.hannibal2.skyhanni.config.FeatureToggle; +import at.hannibal2.skyhanni.config.core.config.Position; import com.google.gson.annotations.Expose; import io.github.notenoughupdates.moulconfig.annotations.Accordion; import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean; +import io.github.notenoughupdates.moulconfig.annotations.ConfigLink; import io.github.notenoughupdates.moulconfig.annotations.ConfigOption; public class ItemAbilityConfig { @@ -36,6 +38,11 @@ public class ItemAbilityConfig { @Expose public ChickenHeadConfig chickenHead = new ChickenHeadConfig(); + @ConfigOption(name = "Crown of Avarice", desc = "") + @Accordion + @Expose + public CrownOfAvariceConfig crownOfAvarice = new CrownOfAvariceConfig(); + @Expose @ConfigOption(name = "Depleted Bonzo's Masks", desc = "Highlight used Bonzo's Masks and Spirit Masks with a background.") diff --git a/src/main/java/at/hannibal2/skyhanni/features/itemabilities/CrownOfAvariceCounter.kt b/src/main/java/at/hannibal2/skyhanni/features/itemabilities/CrownOfAvariceCounter.kt new file mode 100644 index 000000000000..207e1b92b6a1 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/itemabilities/CrownOfAvariceCounter.kt @@ -0,0 +1,51 @@ +package at.hannibal2.skyhanni.features.itemabilities + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.GuiRenderEvent +import at.hannibal2.skyhanni.events.LorenzTickEvent +import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule +import at.hannibal2.skyhanni.utils.InventoryUtils +import at.hannibal2.skyhanni.utils.ItemUtils.extraAttributes +import at.hannibal2.skyhanni.utils.ItemUtils.getInternalNameOrNull +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName +import at.hannibal2.skyhanni.utils.NEUItems.getItemStack +import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators +import at.hannibal2.skyhanni.utils.NumberUtil.shortFormat +import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderable +import at.hannibal2.skyhanni.utils.renderables.Renderable +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +@SkyHanniModule +object CrownOfAvariceCounter { + + private val config get() = SkyHanniMod.feature.inventory.itemAbilities.crownOfAvarice + + private val internalName = "CROWN_OF_AVARICE".asInternalName() + + private var render: Renderable? = null + + @SubscribeEvent + fun onOverlay(event: GuiRenderEvent.GuiOverlayRenderEvent) { + render?.let { config.position.renderRenderable(it, posLabel = "Crown of Avarice Counter") } + } + + @SubscribeEvent + fun onTick(event: LorenzTickEvent) { + render = check() + } + + fun check(): Renderable? { + if (!LorenzUtils.inSkyBlock) return null + if (!config.enable) return null + val item = InventoryUtils.getHelmet() + if (item?.getInternalNameOrNull() != internalName) return null + val count = item.extraAttributes.getLong("collected_coins"); + return Renderable.horizontalContainer( + listOf( + Renderable.itemStack(internalName.getItemStack()), + Renderable.string("ยง6" + if (config.shortFormat) count.shortFormat() else count.addSeparators()), + ), + ) + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt index 5bafb370a840..3f84416292bf 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt @@ -46,6 +46,8 @@ object ItemUtils { return list } + val ItemStack.extraAttributes : NBTTagCompound get() = this.tagCompound.getCompoundTag("ExtraAttributes") + // TODO change else janni is sad fun ItemStack.isCoopSoulBound(): Boolean = getLore().any {