aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/features/mining/PickaxeAbility.kt
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin/features/mining/PickaxeAbility.kt')
-rw-r--r--src/main/kotlin/features/mining/PickaxeAbility.kt99
1 files changed, 65 insertions, 34 deletions
diff --git a/src/main/kotlin/features/mining/PickaxeAbility.kt b/src/main/kotlin/features/mining/PickaxeAbility.kt
index d39694a..23b55e5 100644
--- a/src/main/kotlin/features/mining/PickaxeAbility.kt
+++ b/src/main/kotlin/features/mining/PickaxeAbility.kt
@@ -1,17 +1,17 @@
package moe.nea.firmament.features.mining
+import io.github.notenoughupdates.moulconfig.ChromaColour
import java.util.regex.Pattern
import kotlin.jvm.optionals.getOrNull
import kotlin.time.Duration
import kotlin.time.Duration.Companion.seconds
-import net.minecraft.client.MinecraftClient
-import net.minecraft.client.toast.SystemToast
-import net.minecraft.item.ItemStack
-import net.minecraft.text.Text
-import net.minecraft.util.DyeColor
-import net.minecraft.util.Hand
-import net.minecraft.util.Identifier
-import net.minecraft.util.StringIdentifiable
+import net.minecraft.client.Minecraft
+import net.minecraft.client.gui.components.toasts.SystemToast
+import net.minecraft.world.item.ItemStack
+import net.minecraft.world.item.DyeColor
+import net.minecraft.world.InteractionHand
+import net.minecraft.resources.ResourceLocation
+import net.minecraft.util.StringRepresentable
import moe.nea.firmament.annotations.Subscribe
import moe.nea.firmament.events.HudRenderEvent
import moe.nea.firmament.events.ProcessChatEvent
@@ -19,8 +19,6 @@ import moe.nea.firmament.events.ProfileSwitchEvent
import moe.nea.firmament.events.SlotClickEvent
import moe.nea.firmament.events.UseItemEvent
import moe.nea.firmament.events.WorldReadyEvent
-import moe.nea.firmament.features.FirmamentFeature
-import moe.nea.firmament.gui.config.ManagedConfig
import moe.nea.firmament.util.DurabilityBarEvent
import moe.nea.firmament.util.MC
import moe.nea.firmament.util.SBData
@@ -28,6 +26,8 @@ import moe.nea.firmament.util.SHORT_NUMBER_FORMAT
import moe.nea.firmament.util.SkyBlockIsland
import moe.nea.firmament.util.TIME_PATTERN
import moe.nea.firmament.util.TimeMark
+import moe.nea.firmament.util.data.Config
+import moe.nea.firmament.util.data.ManagedConfig
import moe.nea.firmament.util.extraAttributes
import moe.nea.firmament.util.mc.displayNameAccordingToNbt
import moe.nea.firmament.util.mc.loreAccordingToNbt
@@ -37,20 +37,39 @@ import moe.nea.firmament.util.red
import moe.nea.firmament.util.render.RenderCircleProgress
import moe.nea.firmament.util.render.lerp
import moe.nea.firmament.util.skyblock.AbilityUtils
+import moe.nea.firmament.util.skyblock.DungeonUtil
import moe.nea.firmament.util.skyblock.ItemType
import moe.nea.firmament.util.toShedaniel
import moe.nea.firmament.util.tr
import moe.nea.firmament.util.unformattedString
import moe.nea.firmament.util.useMatch
-object PickaxeAbility : FirmamentFeature {
- override val identifier: String
+object PickaxeAbility {
+ val identifier: String
get() = "pickaxe-info"
+ enum class ShowOnTools(val label: String, val items: Set<ItemType>) : StringRepresentable {
+ ALL("all", ItemType.DRILL, ItemType.PICKAXE, ItemType.SHOVEL, ItemType.AXE),
+ PICKAXES_AND_DRILLS("pick-and-drill", ItemType.PICKAXE, ItemType.DRILL),
+ DRILLS("drills", ItemType.DRILL),
+ ;
+ override fun getSerializedName(): String? {
+ return label
+ }
+
+ constructor(label: String, vararg items: ItemType) : this(label, items.toSet())
+
+ fun matches(type: ItemType) = items.contains(type)
+ }
+
+ @Config
object TConfig : ManagedConfig(identifier, Category.MINING) {
val cooldownEnabled by toggle("ability-cooldown") { false }
+ val disableInDungeons by toggle("disable-in-dungeons") { true }
+ val showOnTools by choice("show-on-tools") { ShowOnTools.PICKAXES_AND_DRILLS }
val cooldownScale by integer("ability-scale", 16, 64) { 16 }
+ val cooldownColour by colour("ability-colour") { ChromaColour.fromStaticRGB(187, 54, 44, 128) }
val cooldownReadyToast by toggle("ability-cooldown-toast") { false }
val drillFuelBar by toggle("fuel-bar") { true }
val blockOnPrivateIsland by choice(
@@ -60,12 +79,12 @@ object PickaxeAbility : FirmamentFeature {
}
}
- enum class BlockPickaxeAbility : StringIdentifiable {
+ enum class BlockPickaxeAbility : StringRepresentable {
NEVER,
ALWAYS,
ONLY_DESTRUCTIVE;
- override fun asString(): String {
+ override fun getSerializedName(): String {
return name
}
}
@@ -84,9 +103,6 @@ object PickaxeAbility : FirmamentFeature {
val destructiveAbilities = setOf("Pickobulus")
val pickaxeTypes = setOf(ItemType.PICKAXE, ItemType.DRILL, ItemType.GAUNTLET)
- override val config: ManagedConfig
- get() = TConfig
-
fun getCooldownPercentage(name: String, cooldown: Duration): Double {
val sinceLastUsage = lastUsage[name]?.passedTime() ?: Duration.INFINITE
val sinceLobbyJoin = lobbyJoinTime.passedTime()
@@ -113,9 +129,12 @@ object PickaxeAbility : FirmamentFeature {
BlockPickaxeAbility.ONLY_DESTRUCTIVE -> ability.any { it.name in destructiveAbilities }
}
if (shouldBlock) {
- MC.sendChat(tr("firmament.pickaxe.blocked",
- "Firmament blocked a pickaxe ability from being used on a private island.")
- .red() // TODO: .clickCommand("firm confignavigate ${TConfig.identifier} block-on-dynamic")
+ MC.sendChat(
+ tr(
+ "firmament.pickaxe.blocked",
+ "Firmament blocked a pickaxe ability from being used on a private island."
+ )
+ .red() // TODO: .clickCommand("firm confignavigate ${TConfig.identifier} block-on-dynamic")
)
event.cancel()
}
@@ -146,7 +165,8 @@ object PickaxeAbility : FirmamentFeature {
} ?: return
val extra = it.item.extraAttributes
val fuel = extra.getInt("drill_fuel").getOrNull() ?: return
- val percentage = fuel / maxFuel.toFloat()
+ var percentage = fuel / maxFuel.toFloat()
+ if (percentage > 1f) percentage = 1f
it.barOverride = DurabilityBarEvent.DurabilityBar(
lerp(
DyeColor.RED.toShedaniel(),
@@ -175,9 +195,14 @@ object PickaxeAbility : FirmamentFeature {
val ability = group("name")
lastUsage[ability] = TimeMark.farPast()
if (!TConfig.cooldownReadyToast) return
- val mc: MinecraftClient = MinecraftClient.getInstance()
- mc.toastManager.add(
- SystemToast.create(mc, SystemToast.Type.NARRATOR_TOGGLE, tr("firmament.pickaxe.ability-ready","Pickaxe Cooldown"), tr("firmament.pickaxe.ability-ready.desc", "Pickaxe ability is ready!"))
+ val mc: Minecraft = Minecraft.getInstance()
+ mc.toastManager.addToast(
+ SystemToast.multiline(
+ mc,
+ SystemToast.SystemToastId.NARRATOR_TOGGLE,
+ tr("firmament.pickaxe.ability-ready", "Pickaxe Cooldown"),
+ tr("firmament.pickaxe.ability-ready.desc", "Pickaxe ability is ready!")
+ )
)
}
}
@@ -221,21 +246,27 @@ object PickaxeAbility : FirmamentFeature {
@Subscribe
fun renderHud(event: HudRenderEvent) {
if (!TConfig.cooldownEnabled) return
+ if (TConfig.disableInDungeons && DungeonUtil.isInDungeonIsland) return
if (!event.isRenderingCursor) return
- var ability = getCooldownFromLore(MC.player?.getStackInHand(Hand.MAIN_HAND) ?: return) ?: return
- defaultAbilityDurations[ability.name] = ability.cooldown
+ val stack = MC.player?.getItemInHand(InteractionHand.MAIN_HAND) ?: return
+ if (!TConfig.showOnTools.matches(ItemType.fromItemStack(stack) ?: ItemType.NIL))
+ return
+ var ability = getCooldownFromLore(stack)?.also { ability ->
+ defaultAbilityDurations[ability.name] = ability.cooldown
+ }
val ao = abilityOverride
- if (ao != ability.name && ao != null) {
- ability = PickaxeAbilityData(ao, defaultAbilityDurations[ao] ?: 120.seconds)
+ if (ability == null || (ao != ability.name && ao != null)) {
+ ability = PickaxeAbilityData(ao ?: return, defaultAbilityDurations[ao] ?: 120.seconds)
}
- event.context.matrices.push()
- event.context.matrices.translate(MC.window.scaledWidth / 2F, MC.window.scaledHeight / 2F, 0F)
- event.context.matrices.scale(TConfig.cooldownScale.toFloat(), TConfig.cooldownScale.toFloat(), 1F)
+ event.context.pose().pushMatrix()
+ event.context.pose().translate(MC.window.guiScaledWidth / 2F, MC.window.guiScaledHeight / 2F)
+ event.context.pose().scale(TConfig.cooldownScale.toFloat(), TConfig.cooldownScale.toFloat())
RenderCircleProgress.renderCircle(
- event.context, Identifier.of("firmament", "textures/gui/circle.png"),
+ event.context, ResourceLocation.fromNamespaceAndPath("firmament", "textures/gui/circle.png"),
getCooldownPercentage(ability.name, ability.cooldown).toFloat(),
- 0f, 1f, 0f, 1f
+ 0f, 1f, 0f, 1f,
+ color = TConfig.cooldownColour.getEffectiveColourRGB()
)
- event.context.matrices.pop()
+ event.context.pose().popMatrix()
}
}