Split REI classes
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
package moe.nea.notenoughupdates.rei
|
||||
|
||||
import io.github.moulberry.repo.data.NEUItem
|
||||
import me.shedaniel.math.Rectangle
|
||||
import me.shedaniel.rei.api.client.entry.renderer.EntryRenderer
|
||||
import me.shedaniel.rei.api.client.gui.widgets.Tooltip
|
||||
import me.shedaniel.rei.api.client.gui.widgets.TooltipContext
|
||||
import me.shedaniel.rei.api.common.entry.EntryStack
|
||||
import me.shedaniel.rei.api.common.entry.type.VanillaEntryTypes
|
||||
import moe.nea.notenoughupdates.rei.NEUReiPlugin.Companion.asItemEntry
|
||||
import net.minecraft.client.util.math.MatrixStack
|
||||
|
||||
object NEUItemEntryRenderer : EntryRenderer<NEUItem> {
|
||||
override fun render(
|
||||
entry: EntryStack<NEUItem>,
|
||||
matrices: MatrixStack,
|
||||
bounds: Rectangle,
|
||||
mouseX: Int,
|
||||
mouseY: Int,
|
||||
delta: Float
|
||||
) {
|
||||
VanillaEntryTypes.ITEM.definition.renderer
|
||||
.render(
|
||||
entry.asItemEntry(),
|
||||
matrices, bounds, mouseX, mouseY, delta
|
||||
)
|
||||
}
|
||||
|
||||
override fun getTooltip(entry: EntryStack<NEUItem>, tooltipContext: TooltipContext): Tooltip? {
|
||||
return VanillaEntryTypes.ITEM.definition.renderer
|
||||
.getTooltip(entry.asItemEntry(), tooltipContext)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package moe.nea.notenoughupdates.rei
|
||||
|
||||
import io.github.moulberry.repo.data.NEUItem
|
||||
import me.shedaniel.rei.api.common.entry.EntrySerializer
|
||||
import me.shedaniel.rei.api.common.entry.EntryStack
|
||||
import net.minecraft.nbt.NbtCompound
|
||||
import moe.nea.notenoughupdates.repo.RepoManager
|
||||
import moe.nea.notenoughupdates.util.SkyblockId
|
||||
|
||||
object NEUItemEntrySerializer : EntrySerializer<NEUItem?> {
|
||||
override fun supportSaving(): Boolean = true
|
||||
override fun supportReading(): Boolean = true
|
||||
|
||||
override fun read(tag: NbtCompound): NEUItem? {
|
||||
return RepoManager.getNEUItem(SkyblockId(tag.getString("SKYBLOCK_ID")))
|
||||
}
|
||||
|
||||
override fun save(entry: EntryStack<NEUItem?>, value: NEUItem?): NbtCompound {
|
||||
return NbtCompound().apply {
|
||||
putString("SKYBLOCK_ID", value?.skyblockItemId ?: "null")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,23 +1,16 @@
|
||||
package moe.nea.notenoughupdates.rei
|
||||
|
||||
import dev.architectury.event.CompoundEventResult
|
||||
import io.github.moulberry.repo.data.NEUItem
|
||||
import me.shedaniel.math.Point
|
||||
import me.shedaniel.rei.api.client.plugins.REIClientPlugin
|
||||
import me.shedaniel.rei.api.client.registry.entry.EntryRegistry
|
||||
import me.shedaniel.rei.api.client.registry.screen.FocusedStackProvider
|
||||
import me.shedaniel.rei.api.client.registry.screen.ScreenRegistry
|
||||
import me.shedaniel.rei.api.common.entry.EntryStack
|
||||
import me.shedaniel.rei.api.common.entry.type.EntryTypeRegistry
|
||||
import me.shedaniel.rei.api.common.entry.type.VanillaEntryTypes
|
||||
import net.minecraft.client.gui.screen.Screen
|
||||
import net.minecraft.client.gui.screen.ingame.HandledScreen
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.util.Identifier
|
||||
import moe.nea.notenoughupdates.mixins.accessor.AccessorHandledScreen
|
||||
import moe.nea.notenoughupdates.repo.ItemCache.asItemStack
|
||||
import moe.nea.notenoughupdates.repo.RepoManager
|
||||
import moe.nea.notenoughupdates.util.skyBlockId
|
||||
|
||||
|
||||
class NEUReiPlugin : REIClientPlugin {
|
||||
@@ -35,19 +28,7 @@ class NEUReiPlugin : REIClientPlugin {
|
||||
}
|
||||
|
||||
override fun registerScreens(registry: ScreenRegistry) {
|
||||
registry.registerFocusedStack(object : FocusedStackProvider {
|
||||
override fun provide(screen: Screen?, mouse: Point?): CompoundEventResult<EntryStack<*>> {
|
||||
if (screen !is HandledScreen<*>) return CompoundEventResult.pass()
|
||||
screen as AccessorHandledScreen
|
||||
val focusedSlot = screen.focusedSlot_NEU ?: return CompoundEventResult.pass()
|
||||
val item = focusedSlot.stack ?: return CompoundEventResult.pass()
|
||||
val skyblockId = item.skyBlockId ?: return CompoundEventResult.pass()
|
||||
val neuItem = RepoManager.getNEUItem(skyblockId) ?: return CompoundEventResult.interrupt(false, null)
|
||||
return CompoundEventResult.interruptTrue(EntryStack.of(SBItemEntryDefinition, neuItem))
|
||||
}
|
||||
|
||||
override fun getPriority(): Double = 1_000_000.0
|
||||
})
|
||||
registry.registerFocusedStack(SkyblockItemIdFocusedStackProvider)
|
||||
}
|
||||
|
||||
override fun registerEntries(registry: EntryRegistry) {
|
||||
|
||||
@@ -2,27 +2,20 @@ package moe.nea.notenoughupdates.rei
|
||||
|
||||
import io.github.moulberry.repo.data.NEUItem
|
||||
import java.util.stream.Stream
|
||||
import me.shedaniel.math.Rectangle
|
||||
import me.shedaniel.rei.api.client.entry.renderer.EntryRenderer
|
||||
import me.shedaniel.rei.api.client.gui.widgets.Tooltip
|
||||
import me.shedaniel.rei.api.client.gui.widgets.TooltipContext
|
||||
import me.shedaniel.rei.api.common.entry.EntrySerializer
|
||||
import me.shedaniel.rei.api.common.entry.EntryStack
|
||||
import me.shedaniel.rei.api.common.entry.comparison.ComparisonContext
|
||||
import me.shedaniel.rei.api.common.entry.type.EntryDefinition
|
||||
import me.shedaniel.rei.api.common.entry.type.EntryType
|
||||
import me.shedaniel.rei.api.common.entry.type.VanillaEntryTypes
|
||||
import net.minecraft.client.util.math.MatrixStack
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.nbt.NbtCompound
|
||||
import net.minecraft.registry.tag.TagKey
|
||||
import net.minecraft.text.Text
|
||||
import net.minecraft.util.Identifier
|
||||
import moe.nea.notenoughupdates.rei.NEUReiPlugin.Companion.asItemEntry
|
||||
import moe.nea.notenoughupdates.repo.ItemCache.asItemStack
|
||||
import moe.nea.notenoughupdates.repo.ItemCache.getIdentifier
|
||||
import moe.nea.notenoughupdates.repo.RepoManager
|
||||
import moe.nea.notenoughupdates.util.SkyblockId
|
||||
|
||||
object SBItemEntryDefinition : EntryDefinition<NEUItem> {
|
||||
override fun equals(o1: NEUItem?, o2: NEUItem?, context: ComparisonContext?): Boolean {
|
||||
@@ -34,47 +27,12 @@ object SBItemEntryDefinition : EntryDefinition<NEUItem> {
|
||||
}
|
||||
|
||||
override fun getValueType(): Class<NEUItem> = NEUItem::class.java
|
||||
override fun getType(): EntryType<NEUItem> =
|
||||
EntryType.deferred(NEUReiPlugin.SKYBLOCK_ITEM_TYPE_ID)
|
||||
override fun getType(): EntryType<NEUItem> = EntryType.deferred(NEUReiPlugin.SKYBLOCK_ITEM_TYPE_ID)
|
||||
|
||||
override fun getRenderer(): EntryRenderer<NEUItem> = object : EntryRenderer<NEUItem> {
|
||||
override fun render(
|
||||
entry: EntryStack<NEUItem>,
|
||||
matrices: MatrixStack,
|
||||
bounds: Rectangle,
|
||||
mouseX: Int,
|
||||
mouseY: Int,
|
||||
delta: Float
|
||||
) {
|
||||
VanillaEntryTypes.ITEM.definition.renderer
|
||||
.render(
|
||||
entry.asItemEntry(),
|
||||
matrices, bounds, mouseX, mouseY, delta
|
||||
)
|
||||
}
|
||||
|
||||
override fun getTooltip(entry: EntryStack<NEUItem>, tooltipContext: TooltipContext): Tooltip? {
|
||||
return VanillaEntryTypes.ITEM.definition.renderer
|
||||
.getTooltip(entry.asItemEntry(), tooltipContext)
|
||||
}
|
||||
|
||||
}
|
||||
override fun getRenderer(): EntryRenderer<NEUItem> = NEUItemEntryRenderer
|
||||
|
||||
override fun getSerializer(): EntrySerializer<NEUItem?> {
|
||||
return object : EntrySerializer<NEUItem?> {
|
||||
override fun supportSaving(): Boolean = true
|
||||
override fun supportReading(): Boolean = true
|
||||
|
||||
override fun read(tag: NbtCompound): NEUItem? {
|
||||
return RepoManager.getNEUItem(SkyblockId(tag.getString("SKYBLOCK_ID")))
|
||||
}
|
||||
|
||||
override fun save(entry: EntryStack<NEUItem?>, value: NEUItem?): NbtCompound {
|
||||
return NbtCompound().apply {
|
||||
putString("SKYBLOCK_ID", value?.skyblockItemId ?: "null")
|
||||
}
|
||||
}
|
||||
}
|
||||
return NEUItemEntrySerializer
|
||||
}
|
||||
|
||||
override fun getTagsFor(entry: EntryStack<NEUItem>?, value: NEUItem?): Stream<out TagKey<*>>? {
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package moe.nea.notenoughupdates.rei
|
||||
|
||||
import dev.architectury.event.CompoundEventResult
|
||||
import me.shedaniel.math.Point
|
||||
import me.shedaniel.rei.api.client.registry.screen.FocusedStackProvider
|
||||
import me.shedaniel.rei.api.common.entry.EntryStack
|
||||
import moe.nea.notenoughupdates.mixins.accessor.AccessorHandledScreen
|
||||
import moe.nea.notenoughupdates.repo.RepoManager
|
||||
import moe.nea.notenoughupdates.util.skyBlockId
|
||||
import net.minecraft.client.gui.screen.Screen
|
||||
import net.minecraft.client.gui.screen.ingame.HandledScreen
|
||||
|
||||
object SkyblockItemIdFocusedStackProvider : FocusedStackProvider {
|
||||
override fun provide(screen: Screen?, mouse: Point?): CompoundEventResult<EntryStack<*>> {
|
||||
if (screen !is HandledScreen<*>) return CompoundEventResult.pass()
|
||||
screen as AccessorHandledScreen
|
||||
val focusedSlot = screen.focusedSlot_NEU ?: return CompoundEventResult.pass()
|
||||
val item = focusedSlot.stack ?: return CompoundEventResult.pass()
|
||||
val skyblockId = item.skyBlockId ?: return CompoundEventResult.pass()
|
||||
val neuItem = RepoManager.getNEUItem(skyblockId) ?: return CompoundEventResult.interrupt(false, null)
|
||||
return CompoundEventResult.interruptTrue(EntryStack.of(SBItemEntryDefinition, neuItem))
|
||||
}
|
||||
|
||||
override fun getPriority(): Double = 1_000_000.0
|
||||
}
|
||||
Reference in New Issue
Block a user