Skip to content

Commit

Permalink
Feature: Crown of Avarice Counter (#2229)
Browse files Browse the repository at this point in the history
  • Loading branch information
Thunderblade73 authored Jul 17, 2024
1 parent fb73845 commit 81358be
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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.")
Expand Down
Original file line number Diff line number Diff line change
@@ -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()),
),
)
}
}
2 changes: 2 additions & 0 deletions src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 81358be

Please sign in to comment.