aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/util/HoveredItemStack.kt
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-10-28 12:07:55 +0100
committerLinnea Gräf <nea@nea.moe>2024-10-28 12:07:55 +0100
commitc38dcee2c5f483ef5990ae9204355e1bc3c2bf74 (patch)
tree3b70359076001e14514c496e3c44980fdbd92d01 /src/main/kotlin/util/HoveredItemStack.kt
parent8ab44088546bf3360564e1a09f0831fea7659d2e (diff)
downloadfirmament-c38dcee2c5f483ef5990ae9204355e1bc3c2bf74.tar.gz
firmament-c38dcee2c5f483ef5990ae9204355e1bc3c2bf74.tar.bz2
firmament-c38dcee2c5f483ef5990ae9204355e1bc3c2bf74.zip
Make REI optional
Diffstat (limited to 'src/main/kotlin/util/HoveredItemStack.kt')
-rw-r--r--src/main/kotlin/util/HoveredItemStack.kt42
1 files changed, 19 insertions, 23 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) }