aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin/util')
-rw-r--r--src/main/kotlin/util/HoveredItemStack.kt42
-rw-r--r--src/main/kotlin/util/SkyblockId.kt5
-rw-r--r--src/main/kotlin/util/compatloader/CompatLoader.kt3
3 files changed, 26 insertions, 24 deletions
diff --git a/src/main/kotlin/util/HoveredItemStack.kt b/src/main/kotlin/util/HoveredItemStack.kt
index 47a59d0..a2e4ad2 100644
--- a/src/main/kotlin/util/HoveredItemStack.kt
+++ b/src/main/kotlin/util/HoveredItemStack.kt
@@ -1,31 +1,27 @@
-
-
package moe.nea.firmament.util
-import me.shedaniel.math.impl.PointHelper
-import me.shedaniel.rei.api.client.REIRuntime
-import me.shedaniel.rei.api.client.gui.widgets.Slot
-import me.shedaniel.rei.api.client.registry.screen.ScreenRegistry
-import net.minecraft.client.gui.Element
-import net.minecraft.client.gui.ParentElement
+import com.google.auto.service.AutoService
import net.minecraft.client.gui.screen.ingame.HandledScreen
import net.minecraft.item.ItemStack
import moe.nea.firmament.mixins.accessor.AccessorHandledScreen
+import moe.nea.firmament.util.compatloader.CompatLoader
+
+interface HoveredItemStackProvider {
+ fun provideHoveredItemStack(screen: HandledScreen<*>): ItemStack?
+
+ companion object : CompatLoader<HoveredItemStackProvider>(HoveredItemStackProvider::class)
+}
+@AutoService(HoveredItemStackProvider::class)
+class VanillaScreenProvider : HoveredItemStackProvider {
+ override fun provideHoveredItemStack(screen: HandledScreen<*>): ItemStack? {
+ screen as AccessorHandledScreen
+ val vanillaSlot = screen.focusedSlot_Firmament?.stack
+ return vanillaSlot
+ }
+}
val HandledScreen<*>.focusedItemStack: ItemStack?
- get() {
- this as AccessorHandledScreen
- val vanillaSlot = this.focusedSlot_Firmament?.stack
- if (vanillaSlot != null) return vanillaSlot
- val focusedSlot = ScreenRegistry.getInstance().getFocusedStack(this, PointHelper.ofMouse())
- if (focusedSlot != null) return focusedSlot.cheatsAs().value
- var baseElement: Element? = REIRuntime.getInstance().overlay.orElse(null)
- val mx = PointHelper.getMouseFloatingX()
- val my = PointHelper.getMouseFloatingY()
- while (true) {
- if (baseElement is Slot) return baseElement.currentEntry.cheatsAs().value
- if (baseElement !is ParentElement) return null
- baseElement = baseElement.hoveredElement(mx, my).orElse(null)
- }
- }
+ get() =
+ HoveredItemStackProvider.allValidInstances
+ .firstNotNullOfOrNull { it.provideHoveredItemStack(this) }
diff --git a/src/main/kotlin/util/SkyblockId.kt b/src/main/kotlin/util/SkyblockId.kt
index 31227e2..059e746 100644
--- a/src/main/kotlin/util/SkyblockId.kt
+++ b/src/main/kotlin/util/SkyblockId.kt
@@ -2,6 +2,7 @@
package moe.nea.firmament.util
+import io.github.moulberry.repo.data.NEUIngredient
import io.github.moulberry.repo.data.NEUItem
import io.github.moulberry.repo.data.Rarity
import java.util.Optional
@@ -61,7 +62,8 @@ value class SkyblockId(val neuItem: String) {
}
companion object {
- val COINS: SkyblockId = SkyblockId("SKYBLOCK_COIN")
+ val COINS: SkyblockId = SkyblockId(NEUIngredient.NEU_SENTINEL_COINS)
+ val SENTINEL_EMPTY: SkyblockId = SkyblockId(NEUIngredient.NEU_SENTINEL_EMPTY)
private val bazaarEnchantmentRegex = "ENCHANTMENT_(\\D*)_(\\d+)".toRegex()
val NULL: SkyblockId = SkyblockId("null")
val PET_NULL: SkyblockId = SkyblockId("null_pet")
@@ -70,6 +72,7 @@ value class SkyblockId(val neuItem: String) {
}
val NEUItem.skyblockId get() = SkyblockId(skyblockItemId)
+val NEUIngredient.skyblockId get() = SkyblockId(itemId)
fun NEUItem.guessRecipeId(): String? {
if (!skyblockItemId.contains(";")) return skyblockItemId
diff --git a/src/main/kotlin/util/compatloader/CompatLoader.kt b/src/main/kotlin/util/compatloader/CompatLoader.kt
index c5d45bc..6b60e87 100644
--- a/src/main/kotlin/util/compatloader/CompatLoader.kt
+++ b/src/main/kotlin/util/compatloader/CompatLoader.kt
@@ -2,10 +2,13 @@ package moe.nea.firmament.util.compatloader
import java.util.ServiceLoader
import net.fabricmc.loader.api.FabricLoader
+import kotlin.reflect.KClass
import kotlin.streams.asSequence
import moe.nea.firmament.Firmament
abstract class CompatLoader<T : Any>(val kClass: Class<T>) {
+ constructor(kClass: KClass<T>) : this(kClass.java)
+
val loader: ServiceLoader<T> = ServiceLoader.load(kClass)
val allValidInstances by lazy {
loader.reload()