diff options
Diffstat (limited to 'src/main/kotlin/util/HoveredItemStack.kt')
-rw-r--r-- | src/main/kotlin/util/HoveredItemStack.kt | 42 |
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) } |