diff options
author | nea <nea@nea.moe> | 2023-05-04 15:24:22 +0200 |
---|---|---|
committer | nea <nea@nea.moe> | 2023-05-04 15:24:22 +0200 |
commit | 857427b0766fe68590589c22e86dbcf1196b4ed5 (patch) | |
tree | f2709a31611bad37be170123ed35b830b0e1f9be /src | |
parent | 720cfdd1ed9fc203dd65bbcdc368e124dd35d3cf (diff) | |
download | Firmament-857427b0766fe68590589c22e86dbcf1196b4ed5.tar.gz Firmament-857427b0766fe68590589c22e86dbcf1196b4ed5.tar.bz2 Firmament-857427b0766fe68590589c22e86dbcf1196b4ed5.zip |
Split REI classes
Diffstat (limited to 'src')
5 files changed, 86 insertions, 65 deletions
diff --git a/src/main/kotlin/moe/nea/notenoughupdates/rei/NEUItemEntryRenderer.kt b/src/main/kotlin/moe/nea/notenoughupdates/rei/NEUItemEntryRenderer.kt new file mode 100644 index 0000000..e794039 --- /dev/null +++ b/src/main/kotlin/moe/nea/notenoughupdates/rei/NEUItemEntryRenderer.kt @@ -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) + } + +} diff --git a/src/main/kotlin/moe/nea/notenoughupdates/rei/NEUItemEntrySerializer.kt b/src/main/kotlin/moe/nea/notenoughupdates/rei/NEUItemEntrySerializer.kt new file mode 100644 index 0000000..97082e2 --- /dev/null +++ b/src/main/kotlin/moe/nea/notenoughupdates/rei/NEUItemEntrySerializer.kt @@ -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") + } + } +} diff --git a/src/main/kotlin/moe/nea/notenoughupdates/rei/NEUReiPlugin.kt b/src/main/kotlin/moe/nea/notenoughupdates/rei/NEUReiPlugin.kt index f4a01fd..e89b007 100644 --- a/src/main/kotlin/moe/nea/notenoughupdates/rei/NEUReiPlugin.kt +++ b/src/main/kotlin/moe/nea/notenoughupdates/rei/NEUReiPlugin.kt @@ -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) { diff --git a/src/main/kotlin/moe/nea/notenoughupdates/rei/SBItemEntryDefinition.kt b/src/main/kotlin/moe/nea/notenoughupdates/rei/SBItemEntryDefinition.kt index 8ea691b..a9d4a7c 100644 --- a/src/main/kotlin/moe/nea/notenoughupdates/rei/SBItemEntryDefinition.kt +++ b/src/main/kotlin/moe/nea/notenoughupdates/rei/SBItemEntryDefinition.kt @@ -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 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 getType(): EntryType<NEUItem> = EntryType.deferred(NEUReiPlugin.SKYBLOCK_ITEM_TYPE_ID) - } + 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<*>>? { diff --git a/src/main/kotlin/moe/nea/notenoughupdates/rei/SkyblockItemIdFocusedStackProvider.kt b/src/main/kotlin/moe/nea/notenoughupdates/rei/SkyblockItemIdFocusedStackProvider.kt new file mode 100644 index 0000000..8592126 --- /dev/null +++ b/src/main/kotlin/moe/nea/notenoughupdates/rei/SkyblockItemIdFocusedStackProvider.kt @@ -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 +} |