Make REI optional

This commit is contained in:
Linnea Gräf
2024-10-28 12:07:55 +01:00
parent 8ab4408854
commit c38dcee2c5
28 changed files with 451 additions and 374 deletions

View File

@@ -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) }

View File

@@ -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

View File

@@ -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()