diff options
Diffstat (limited to 'src/compat/rei')
19 files changed, 511 insertions, 463 deletions
diff --git a/src/compat/rei/java/moe/nea/firmament/compat/rei/EntityWidget.kt b/src/compat/rei/java/moe/nea/firmament/compat/rei/EntityWidget.kt index 1097654..cc55fb8 100644 --- a/src/compat/rei/java/moe/nea/firmament/compat/rei/EntityWidget.kt +++ b/src/compat/rei/java/moe/nea/firmament/compat/rei/EntityWidget.kt @@ -5,9 +5,9 @@ import me.shedaniel.math.FloatingDimension import me.shedaniel.math.Point import me.shedaniel.math.Rectangle import me.shedaniel.rei.api.client.gui.widgets.WidgetWithBounds -import net.minecraft.client.gui.DrawContext -import net.minecraft.client.gui.Element -import net.minecraft.entity.LivingEntity +import net.minecraft.client.gui.GuiGraphics +import net.minecraft.client.gui.components.events.GuiEventListener +import net.minecraft.world.entity.LivingEntity import moe.nea.firmament.gui.entity.EntityRenderer import moe.nea.firmament.util.ErrorUtil @@ -17,13 +17,13 @@ class EntityWidget( val point: Point, val size: FloatingDimension = FloatingDimension(defaultSize) ) : WidgetWithBounds() { - override fun children(): List<Element> { + override fun children(): List<GuiEventListener> { return emptyList() } var hasErrored = false - override fun render(context: DrawContext, mouseX: Int, mouseY: Int, delta: Float) { + override fun render(context: GuiGraphics, mouseX: Int, mouseY: Int, delta: Float) { try { if (!hasErrored) { EntityRenderer.renderEntity( diff --git a/src/compat/rei/java/moe/nea/firmament/compat/rei/FirmamentReiCommonPlugin.kt b/src/compat/rei/java/moe/nea/firmament/compat/rei/FirmamentReiCommonPlugin.kt index 98ac276..71e867a 100644 --- a/src/compat/rei/java/moe/nea/firmament/compat/rei/FirmamentReiCommonPlugin.kt +++ b/src/compat/rei/java/moe/nea/firmament/compat/rei/FirmamentReiCommonPlugin.kt @@ -2,9 +2,11 @@ package moe.nea.firmament.compat.rei import me.shedaniel.rei.api.common.entry.type.EntryTypeRegistry import me.shedaniel.rei.api.common.plugins.REICommonPlugin +import moe.nea.firmament.repo.RepoManager class FirmamentReiCommonPlugin : REICommonPlugin { override fun registerEntryTypes(registry: EntryTypeRegistry) { + if (!RepoManager.shouldLoadREI()) return registry.register(FirmamentReiPlugin.SKYBLOCK_ITEM_TYPE_ID, SBItemEntryDefinition) } } diff --git a/src/compat/rei/java/moe/nea/firmament/compat/rei/FirmamentReiPlugin.kt b/src/compat/rei/java/moe/nea/firmament/compat/rei/FirmamentReiPlugin.kt index aade59e..ad0da89 100644 --- a/src/compat/rei/java/moe/nea/firmament/compat/rei/FirmamentReiPlugin.kt +++ b/src/compat/rei/java/moe/nea/firmament/compat/rei/FirmamentReiPlugin.kt @@ -1,5 +1,6 @@ package moe.nea.firmament.compat.rei +import io.github.moulberry.repo.data.NEUCraftingRecipe import me.shedaniel.rei.api.client.plugins.REIClientPlugin import me.shedaniel.rei.api.client.registry.category.CategoryRegistry import me.shedaniel.rei.api.client.registry.display.DisplayRegistry @@ -12,25 +13,29 @@ import me.shedaniel.rei.api.client.registry.transfer.TransferHandler import me.shedaniel.rei.api.client.registry.transfer.TransferHandlerRegistry import me.shedaniel.rei.api.common.entry.EntryStack import me.shedaniel.rei.api.common.entry.type.VanillaEntryTypes -import net.minecraft.client.gui.screen.Screen -import net.minecraft.client.gui.screen.ingame.GenericContainerScreen -import net.minecraft.client.gui.screen.ingame.HandledScreen -import net.minecraft.item.ItemStack -import net.minecraft.text.Text -import net.minecraft.util.ActionResult -import net.minecraft.util.Identifier -import moe.nea.firmament.compat.rei.recipes.SBCraftingRecipe -import moe.nea.firmament.compat.rei.recipes.SBEssenceUpgradeRecipe -import moe.nea.firmament.compat.rei.recipes.SBForgeRecipe +import net.minecraft.client.gui.screens.Screen +import net.minecraft.client.gui.screens.inventory.ContainerScreen +import net.minecraft.client.gui.screens.inventory.MenuAccess +import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen +import net.minecraft.world.item.ItemStack +import net.minecraft.network.chat.Component +import net.minecraft.world.InteractionResult +import net.minecraft.resources.ResourceLocation +import moe.nea.firmament.compat.rei.recipes.GenericREIRecipeCategory import moe.nea.firmament.compat.rei.recipes.SBKatRecipe import moe.nea.firmament.compat.rei.recipes.SBMobDropRecipe +import moe.nea.firmament.compat.rei.recipes.SBRecipe import moe.nea.firmament.compat.rei.recipes.SBReforgeRecipe import moe.nea.firmament.compat.rei.recipes.SBShopRecipe import moe.nea.firmament.events.HandledScreenPushREIEvent import moe.nea.firmament.features.inventory.CraftingOverlay import moe.nea.firmament.features.inventory.storageoverlay.StorageOverlayScreen +import moe.nea.firmament.repo.ExpensiveItemCacheApi import moe.nea.firmament.repo.RepoManager import moe.nea.firmament.repo.SBItemStack +import moe.nea.firmament.repo.recipes.SBCraftingRecipeRenderer +import moe.nea.firmament.repo.recipes.SBEssenceUpgradeRecipeRenderer +import moe.nea.firmament.repo.recipes.SBForgeRecipeRenderer import moe.nea.firmament.util.MC import moe.nea.firmament.util.SkyblockId import moe.nea.firmament.util.guessRecipeId @@ -41,30 +46,40 @@ import moe.nea.firmament.util.unformattedString class FirmamentReiPlugin : REIClientPlugin { companion object { + @ExpensiveItemCacheApi fun EntryStack<SBItemStack>.asItemEntry(): EntryStack<ItemStack> { return EntryStack.of(VanillaEntryTypes.ITEM, value.asImmutableItemStack()) } - val SKYBLOCK_ITEM_TYPE_ID = Identifier.of("firmament", "skyblockitems") + val SKYBLOCK_ITEM_TYPE_ID = ResourceLocation.fromNamespaceAndPath("firmament", "skyblockitems") } + @OptIn(ExpensiveItemCacheApi::class) override fun registerTransferHandlers(registry: TransferHandlerRegistry) { + if (!RepoManager.shouldLoadREI()) return registry.register(TransferHandler { context -> val screen = context.containerScreen val display = context.display - if (display !is SBCraftingRecipe) return@TransferHandler TransferHandler.Result.createNotApplicable() - val neuItem = RepoManager.getNEUItem(SkyblockId(display.neuRecipe.output.itemId)) - ?: error("Could not find neu item ${display.neuRecipe.output.itemId} which is used in a recipe output") - val useSuperCraft = context.isStackedCrafting || RepoManager.Config.alwaysSuperCraft - if (neuItem.isVanilla && useSuperCraft) return@TransferHandler TransferHandler.Result.createFailed(Text.translatable( - "firmament.recipe.novanilla")) + if (display !is SBRecipe) return@TransferHandler TransferHandler.Result.createNotApplicable() + val recipe = display.neuRecipe + if (recipe !is NEUCraftingRecipe) return@TransferHandler TransferHandler.Result.createNotApplicable() + val neuItem = RepoManager.getNEUItem(SkyblockId(recipe.output.itemId)) + ?: error("Could not find neu item ${recipe.output.itemId} which is used in a recipe output") + val useSuperCraft = context.isStackedCrafting || RepoManager.TConfig.alwaysSuperCraft + if (neuItem.isVanilla && useSuperCraft) return@TransferHandler TransferHandler.Result.createFailed( + Component.translatable( + "firmament.recipe.novanilla" + ) + ) var shouldReturn = true if (context.isActuallyCrafting && !useSuperCraft) { - if (screen !is GenericContainerScreen || screen.title?.unformattedString != CraftingOverlay.CRAFTING_SCREEN_NAME) { + val craftingScreen = (screen as? ContainerScreen) + ?.takeIf { it.title?.string == CraftingOverlay.CRAFTING_SCREEN_NAME } + if (craftingScreen == null) { MC.sendCommand("craft") shouldReturn = false } - CraftingOverlay.setOverlay(screen as? GenericContainerScreen, display.neuRecipe) + CraftingOverlay.setOverlay(craftingScreen, recipe) } if (context.isActuallyCrafting && useSuperCraft) { shouldReturn = false @@ -75,54 +90,61 @@ class FirmamentReiPlugin : REIClientPlugin { } + val generics = listOf<GenericREIRecipeCategory<*>>( + // Order matters: The order in here is the order in which they show up in REI + GenericREIRecipeCategory(SBCraftingRecipeRenderer), + GenericREIRecipeCategory(SBForgeRecipeRenderer), + GenericREIRecipeCategory(SBEssenceUpgradeRecipeRenderer), + ) + override fun registerCategories(registry: CategoryRegistry) { - registry.add(SBCraftingRecipe.Category) - registry.add(SBForgeRecipe.Category) + if (!RepoManager.shouldLoadREI()) return + + registry.add(generics) registry.add(SBMobDropRecipe.Category) registry.add(SBKatRecipe.Category) registry.add(SBReforgeRecipe.Category) - registry.add(SBEssenceUpgradeRecipe.Category) registry.add(SBShopRecipe.Category) } override fun registerExclusionZones(zones: ExclusionZones) { - zones.register(HandledScreen::class.java) { HandledScreenPushREIEvent.publish(HandledScreenPushREIEvent(it)).rectangles } + zones.register(AbstractContainerScreen::class.java) { HandledScreenPushREIEvent.publish(HandledScreenPushREIEvent(it)).rectangles } zones.register(StorageOverlayScreen::class.java) { it.getBounds() } } override fun registerDisplays(registry: DisplayRegistry) { - registry.registerDisplayGenerator( - SBCraftingRecipe.Category.catIdentifier, - SkyblockCraftingRecipeDynamicGenerator) + if (!RepoManager.shouldLoadREI()) return + + generics.forEach { + it.registerDynamicGenerator(registry) + } registry.registerDisplayGenerator( SBReforgeRecipe.catIdentifier, SBReforgeRecipe.DynamicGenerator ) registry.registerDisplayGenerator( - SBForgeRecipe.Category.categoryIdentifier, - SkyblockForgeRecipeDynamicGenerator) - registry.registerDisplayGenerator( SBMobDropRecipe.Category.categoryIdentifier, - SkyblockMobDropRecipeDynamicGenerator) + SkyblockMobDropRecipeDynamicGenerator + ) registry.registerDisplayGenerator( SBShopRecipe.Category.categoryIdentifier, - SkyblockShopRecipeDynamicGenerator) + SkyblockShopRecipeDynamicGenerator + ) registry.registerDisplayGenerator( SBKatRecipe.Category.categoryIdentifier, - SkyblockKatRecipeDynamicGenerator) - registry.registerDisplayGenerator( - SBEssenceUpgradeRecipe.Category.categoryIdentifier, - SkyblockEssenceRecipeDynamicGenerator + SkyblockKatRecipeDynamicGenerator ) } override fun registerCollapsibleEntries(registry: CollapsibleEntryRegistry) { - if (!RepoManager.Config.disableItemGroups) + if (!RepoManager.shouldLoadREI()) return + + if (!RepoManager.TConfig.disableItemGroups) RepoManager.neuRepo.constants.parents.parents .forEach { (parent, children) -> registry.group( SkyblockId(parent).identifier, - Text.literal(RepoManager.getNEUItem(SkyblockId(parent))?.displayName ?: parent), + Component.literal(RepoManager.getNEUItem(SkyblockId(parent))?.displayName ?: parent), (children + parent).map { SBItemEntryDefinition.getEntry(SkyblockId(it)) }) } } @@ -133,14 +155,16 @@ class FirmamentReiPlugin : REIClientPlugin { return screen == StorageOverlayScreen::class.java } - override fun <R : Screen?> shouldScreenBeOverlaid(screen: R): ActionResult { - return ActionResult.SUCCESS + override fun <R : Screen?> shouldScreenBeOverlaid(screen: R): InteractionResult { + return InteractionResult.SUCCESS } }) registry.registerFocusedStack(SkyblockItemIdFocusedStackProvider) } override fun registerEntries(registry: EntryRegistry) { + if (!RepoManager.shouldLoadREI()) return + registry.removeEntryIf { true } RepoManager.neuRepo.items?.items?.values?.forEach { neuItem -> registry.addEntry(SBItemEntryDefinition.getEntry(neuItem.skyblockId)) diff --git a/src/compat/rei/java/moe/nea/firmament/compat/rei/HoveredItemStackProvider.kt b/src/compat/rei/java/moe/nea/firmament/compat/rei/HoveredItemStackProvider.kt index b917c3e..a19355b 100644 --- a/src/compat/rei/java/moe/nea/firmament/compat/rei/HoveredItemStackProvider.kt +++ b/src/compat/rei/java/moe/nea/firmament/compat/rei/HoveredItemStackProvider.kt @@ -5,17 +5,18 @@ 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 net.minecraft.client.gui.screen.ingame.HandledScreen -import net.minecraft.item.ItemStack +import net.minecraft.client.gui.components.events.GuiEventListener +import net.minecraft.client.gui.components.events.ContainerEventHandler +import net.minecraft.client.gui.screens.Screen +import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen +import net.minecraft.world.item.ItemStack import moe.nea.firmament.util.HoveredItemStackProvider import moe.nea.firmament.util.compatloader.CompatLoader @AutoService(HoveredItemStackProvider::class) @CompatLoader.RequireMod("roughlyenoughitems") class ScreenRegistryHoveredItemStackProvider : HoveredItemStackProvider { - override fun provideHoveredItemStack(screen: HandledScreen<*>): ItemStack? { + override fun provideHoveredItemStack(screen: Screen): ItemStack? { val entryStack = ScreenRegistry.getInstance().getFocusedStack(screen, PointHelper.ofMouse()) ?: return null return entryStack.value as? ItemStack ?: entryStack.cheatsAs().value @@ -25,14 +26,14 @@ class ScreenRegistryHoveredItemStackProvider : HoveredItemStackProvider { @AutoService(HoveredItemStackProvider::class) @CompatLoader.RequireMod("roughlyenoughitems") class OverlayHoveredItemStackProvider : HoveredItemStackProvider { - override fun provideHoveredItemStack(screen: HandledScreen<*>): ItemStack? { - var baseElement: Element? = REIRuntime.getInstance().overlay.orElse(null) + override fun provideHoveredItemStack(screen: Screen): ItemStack? { + var baseElement: GuiEventListener? = 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) + if (baseElement !is ContainerEventHandler) return null + baseElement = baseElement.getChildAt(mx, my).orElse(null) } } } diff --git a/src/compat/rei/java/moe/nea/firmament/compat/rei/NEUItemEntryRenderer.kt b/src/compat/rei/java/moe/nea/firmament/compat/rei/NEUItemEntryRenderer.kt index 35a1e1b..0e24f4e 100644 --- a/src/compat/rei/java/moe/nea/firmament/compat/rei/NEUItemEntryRenderer.kt +++ b/src/compat/rei/java/moe/nea/firmament/compat/rei/NEUItemEntryRenderer.kt @@ -15,15 +15,20 @@ 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 net.fabricmc.fabric.api.client.item.v1.ItemTooltipCallback -import net.minecraft.client.MinecraftClient -import net.minecraft.client.gui.DrawContext -import net.minecraft.item.tooltip.TooltipType -import net.minecraft.text.Text -import moe.nea.firmament.compat.rei.FirmamentReiPlugin.Companion.asItemEntry +import net.minecraft.client.Minecraft +import net.minecraft.client.gui.GuiGraphics +import net.minecraft.world.item.ItemStack +import net.minecraft.world.item.Items +import net.minecraft.world.item.TooltipFlag +import net.minecraft.network.chat.Component import moe.nea.firmament.events.ItemTooltipEvent +import moe.nea.firmament.repo.ExpensiveItemCacheApi +import moe.nea.firmament.repo.ItemCache +import moe.nea.firmament.repo.RepoManager import moe.nea.firmament.repo.SBItemStack import moe.nea.firmament.util.ErrorUtil import moe.nea.firmament.util.FirmFormatters +import moe.nea.firmament.util.MC import moe.nea.firmament.util.darkGrey import moe.nea.firmament.util.mc.displayNameAccordingToNbt import moe.nea.firmament.util.mc.loreAccordingToNbt @@ -31,31 +36,53 @@ import moe.nea.firmament.util.mc.loreAccordingToNbt // TODO: make this re implement BatchedEntryRenderer, if possible (likely not, due to no-alloc rendering) // Also it is probably not even that much faster now, with render layers. object NEUItemEntryRenderer : EntryRenderer<SBItemStack> { + @OptIn(ExpensiveItemCacheApi::class) override fun render( entry: EntryStack<SBItemStack>, - context: DrawContext, + context: GuiGraphics, bounds: Rectangle, mouseX: Int, mouseY: Int, delta: Float ) { - context.matrices.push() - context.matrices.translate(bounds.centerX.toFloat(), bounds.centerY.toFloat(), 0F) - context.matrices.scale(bounds.width.toFloat() / 16F, bounds.height.toFloat() / 16F, 1f) - val item = entry.asItemEntry().value - context.drawItemWithoutEntity(item, -8, -8) - context.drawStackOverlay(minecraft.textRenderer, item, -8, -8, - if (entry.value.getStackSize() > 1000) FirmFormatters.shortFormat(entry.value.getStackSize() - .toDouble()) - else null + val neuItem = entry.value.neuItem + val itemToRender = if(!RepoManager.TConfig.perfectRenders.rendersPerfectVisuals() && !entry.value.isWarm() && neuItem != null) { + ItemCache.recacheSoon(neuItem) + ItemStack(Items.PAINTING) + } else { + entry.value.asImmutableItemStack() + } + + context.pose().pushMatrix() + context.pose().translate(bounds.centerX.toFloat(), bounds.centerY.toFloat()) + context.pose().scale(bounds.width.toFloat() / 16F, bounds.height.toFloat() / 16F) + context.renderItem(itemToRender, -8, -8) + context.renderItemDecorations( + MC.font, itemToRender, -8, -8, + if (entry.value.getStackSize() > 1000) FirmFormatters.shortFormat( + entry.value.getStackSize() + .toDouble() + ) + else null ) - context.matrices.pop() + context.pose().popMatrix() } - val minecraft = MinecraftClient.getInstance() + val minecraft = Minecraft.getInstance() var canUseVanillaTooltipEvents = true + @OptIn(ExpensiveItemCacheApi::class) override fun getTooltip(entry: EntryStack<SBItemStack>, tooltipContext: TooltipContext): Tooltip? { + if (!entry.value.isWarm() && !RepoManager.TConfig.perfectRenders.rendersPerfectText()) { + val neuItem = entry.value.neuItem + if (neuItem != null) { + val lore = mutableListOf<Component>() + lore.add(Component.literal(neuItem.displayName)) + neuItem.lore.mapTo(mutableListOf()) { Component.literal(it) } + return Tooltip.create(lore) + } + } + val stack = entry.value.asImmutableItemStack() val lore = mutableListOf(stack.displayNameAccordingToNbt) @@ -63,22 +90,24 @@ object NEUItemEntryRenderer : EntryRenderer<SBItemStack> { if (canUseVanillaTooltipEvents) { try { ItemTooltipCallback.EVENT.invoker().getTooltip( - stack, tooltipContext.vanillaContext(), TooltipType.BASIC, lore + stack, tooltipContext.vanillaContext(), TooltipFlag.Default.NORMAL, lore ) } catch (ex: Exception) { canUseVanillaTooltipEvents = false ErrorUtil.softError("Failed to use vanilla tooltips", ex) } } else { - ItemTooltipEvent.publish(ItemTooltipEvent( - stack, - tooltipContext.vanillaContext(), - TooltipType.BASIC, - lore - )) + ItemTooltipEvent.publish( + ItemTooltipEvent( + stack, + tooltipContext.vanillaContext(), + TooltipFlag.Default.NORMAL, + lore + ) + ) } if (entry.value.getStackSize() > 1000 && lore.isNotEmpty()) - lore.add(1, Text.literal("${entry.value.getStackSize()}x").darkGrey()) + lore.add(1, Component.literal("${entry.value.getStackSize()}x").darkGrey()) // TODO: tags aren't sent as early now so some tooltip components that use tags will crash the game // stack.getTooltip( // Item.TooltipContext.create( @@ -86,7 +115,7 @@ object NEUItemEntryRenderer : EntryRenderer<SBItemStack> { // ?: MC.defaultRegistries // ), // MC.player, -// TooltipType.BASIC +// TooltipFlag.Default.NORMAL // ) return Tooltip.create(lore) } diff --git a/src/compat/rei/java/moe/nea/firmament/compat/rei/NEUItemEntrySerializer.kt b/src/compat/rei/java/moe/nea/firmament/compat/rei/NEUItemEntrySerializer.kt index 724d193..9f32472 100644 --- a/src/compat/rei/java/moe/nea/firmament/compat/rei/NEUItemEntrySerializer.kt +++ b/src/compat/rei/java/moe/nea/firmament/compat/rei/NEUItemEntrySerializer.kt @@ -2,8 +2,8 @@ package moe.nea.firmament.compat.rei import com.mojang.serialization.Codec import me.shedaniel.rei.api.common.entry.EntrySerializer -import net.minecraft.network.RegistryByteBuf -import net.minecraft.network.codec.PacketCodec +import net.minecraft.network.RegistryFriendlyByteBuf +import net.minecraft.network.codec.StreamCodec import moe.nea.firmament.repo.SBItemStack object NEUItemEntrySerializer : EntrySerializer<SBItemStack> { @@ -11,7 +11,7 @@ object NEUItemEntrySerializer : EntrySerializer<SBItemStack> { return SBItemStack.CODEC } - override fun streamCodec(): PacketCodec<RegistryByteBuf, SBItemStack> { + override fun streamCodec(): StreamCodec<RegistryFriendlyByteBuf, SBItemStack> { return SBItemStack.PACKET_CODEC.cast() } } diff --git a/src/compat/rei/java/moe/nea/firmament/compat/rei/REIRecipeLayouter.kt b/src/compat/rei/java/moe/nea/firmament/compat/rei/REIRecipeLayouter.kt new file mode 100644 index 0000000..54bc7f0 --- /dev/null +++ b/src/compat/rei/java/moe/nea/firmament/compat/rei/REIRecipeLayouter.kt @@ -0,0 +1,82 @@ +package moe.nea.firmament.compat.rei + +import io.github.notenoughupdates.moulconfig.gui.GuiComponent +import me.shedaniel.math.Dimension +import me.shedaniel.math.FloatingDimension +import me.shedaniel.math.Point +import me.shedaniel.math.Rectangle +import me.shedaniel.rei.api.client.gui.widgets.Widget +import me.shedaniel.rei.api.client.gui.widgets.Widgets +import net.minecraft.network.chat.Component +import net.minecraft.world.entity.LivingEntity +import moe.nea.firmament.compat.rei.recipes.wrapWidget +import moe.nea.firmament.repo.SBItemStack +import moe.nea.firmament.repo.recipes.RecipeLayouter + +class REIRecipeLayouter : RecipeLayouter { + val container: MutableList<Widget> = mutableListOf() + fun <T: Widget> add(t: T): T = t.also(container::add) + + override fun createCyclingItemSlot( + x: Int, + y: Int, + content: List<SBItemStack>, + slotKind: RecipeLayouter.SlotKind + ): RecipeLayouter.CyclingItemSlot { + val slot = Widgets.createSlot(Point(x, y)) + if (content.isNotEmpty()) + slot.entries(content.map { SBItemEntryDefinition.getEntry(it) }) + when (slotKind) { + RecipeLayouter.SlotKind.SMALL_INPUT -> slot.markInput() + RecipeLayouter.SlotKind.SMALL_OUTPUT -> slot.markOutput() + RecipeLayouter.SlotKind.BIG_OUTPUT -> { + slot.markOutput().disableBackground() + add(Widgets.createResultSlotBackground(Point(x, y))) + } + RecipeLayouter.SlotKind.DISPLAY -> { + slot.disableBackground() + slot.disableHighlight() + } + } + add(slot) + return object : RecipeLayouter.CyclingItemSlot { + override fun current(): SBItemStack = content.firstOrNull() ?: SBItemStack.EMPTY + override fun update(newValue: SBItemStack) {} + override fun onUpdate(action: () -> Unit) {} + } + } + + override fun createTooltip(rectangle: Rectangle, label: List<Component>) { + add(Widgets.createTooltip(rectangle, *label.toTypedArray())) + } + + override fun createLabel(x: Int, y: Int, text: Component): RecipeLayouter.Updater<Component> { + val label = add(Widgets.createLabel(Point(x, y), text)) + return object : RecipeLayouter.Updater<Component> { + override fun update(newValue: Component) { + label.message = newValue + } + } + } + + override fun createArrow(x: Int, y: Int) = + add(Widgets.createArrow(Point(x, y))).bounds + + override fun createMoulConfig( + x: Int, + y: Int, + w: Int, + h: Int, + component: GuiComponent + ) { + add(wrapWidget(Rectangle(Point(x, y), Dimension(w, h)), component)) + } + + override fun createFire(point: Point, animationTicks: Int) { + add(Widgets.createBurningFire(point).animationDurationTicks(animationTicks.toDouble())) + } + + override fun createEntity(rectangle: Rectangle, entity: LivingEntity) { + add(EntityWidget(entity, rectangle.location, FloatingDimension(rectangle.size))) + } +} diff --git a/src/compat/rei/java/moe/nea/firmament/compat/rei/SBItemEntryDefinition.kt b/src/compat/rei/java/moe/nea/firmament/compat/rei/SBItemEntryDefinition.kt index 2b1700d..fde3e3d 100644 --- a/src/compat/rei/java/moe/nea/firmament/compat/rei/SBItemEntryDefinition.kt +++ b/src/compat/rei/java/moe/nea/firmament/compat/rei/SBItemEntryDefinition.kt @@ -9,12 +9,13 @@ 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.item.ItemConvertible -import net.minecraft.item.ItemStack -import net.minecraft.registry.tag.TagKey -import net.minecraft.text.Text -import net.minecraft.util.Identifier +import net.minecraft.world.level.ItemLike +import net.minecraft.world.item.ItemStack +import net.minecraft.tags.TagKey +import net.minecraft.network.chat.Component +import net.minecraft.resources.ResourceLocation import moe.nea.firmament.compat.rei.FirmamentReiPlugin.Companion.asItemEntry +import moe.nea.firmament.repo.ExpensiveItemCacheApi import moe.nea.firmament.repo.RepoManager import moe.nea.firmament.repo.SBItemStack import moe.nea.firmament.util.SkyblockId @@ -24,6 +25,7 @@ object SBItemEntryDefinition : EntryDefinition<SBItemStack> { return o1.skyblockId == o2.skyblockId && o1.getStackSize() == o2.getStackSize() } + @OptIn(ExpensiveItemCacheApi::class) override fun cheatsAs(entry: EntryStack<SBItemStack>?, value: SBItemStack): ItemStack { return value.asCopiedItemStack() } @@ -41,8 +43,14 @@ object SBItemEntryDefinition : EntryDefinition<SBItemStack> { return Stream.empty() } - override fun asFormattedText(entry: EntryStack<SBItemStack>, value: SBItemStack): Text { - return VanillaEntryTypes.ITEM.definition.asFormattedText(entry.asItemEntry(), value.asImmutableItemStack()) + @OptIn(ExpensiveItemCacheApi::class) + override fun asFormattedText(entry: EntryStack<SBItemStack>, value: SBItemStack): Component { + val neuItem = entry.value.neuItem + return if (!RepoManager.TConfig.perfectRenders.rendersPerfectText() || entry.value.isWarm() || neuItem == null) { + VanillaEntryTypes.ITEM.definition.asFormattedText(entry.asItemEntry(), value.asImmutableItemStack()) + } else { + Component.literal(neuItem.displayName) + } } override fun hash(entry: EntryStack<SBItemStack>, value: SBItemStack, context: ComparisonContext): Long { @@ -51,8 +59,10 @@ object SBItemEntryDefinition : EntryDefinition<SBItemStack> { } override fun wildcard(entry: EntryStack<SBItemStack>?, value: SBItemStack): SBItemStack { - return value.copy(stackSize = 1, petData = RepoManager.getPotentialStubPetData(value.skyblockId), - stars = 0, extraLore = listOf(), reforge = null) + return value.copy( + stackSize = 1, petData = RepoManager.getPotentialStubPetData(value.skyblockId), + stars = 0, extraLore = listOf(), reforge = null + ) } override fun normalize(entry: EntryStack<SBItemStack>?, value: SBItemStack): SBItemStack { @@ -67,7 +77,7 @@ object SBItemEntryDefinition : EntryDefinition<SBItemStack> { return value.getStackSize() == 0 } - override fun getIdentifier(entry: EntryStack<SBItemStack>?, value: SBItemStack): Identifier { + override fun getIdentifier(entry: EntryStack<SBItemStack>?, value: SBItemStack): ResourceLocation { return value.skyblockId.identifier } @@ -80,7 +90,7 @@ object SBItemEntryDefinition : EntryDefinition<SBItemStack> { fun getEntry(ingredient: NEUIngredient): EntryStack<SBItemStack> = getEntry(SkyblockId(ingredient.itemId), count = ingredient.amount.toInt()) - fun getPassthrough(item: ItemConvertible) = getEntry(SBItemStack.passthrough(ItemStack(item.asItem()))) + fun getPassthrough(item: ItemLike) = getEntry(SBItemStack.passthrough(ItemStack(item.asItem()))) fun getEntry(stack: ItemStack): EntryStack<SBItemStack> = getEntry(SBItemStack(stack)) diff --git a/src/compat/rei/java/moe/nea/firmament/compat/rei/SkyblockCraftingRecipeDynamicGenerator.kt b/src/compat/rei/java/moe/nea/firmament/compat/rei/SkyblockCraftingRecipeDynamicGenerator.kt index e80840f..900ebab 100644 --- a/src/compat/rei/java/moe/nea/firmament/compat/rei/SkyblockCraftingRecipeDynamicGenerator.kt +++ b/src/compat/rei/java/moe/nea/firmament/compat/rei/SkyblockCraftingRecipeDynamicGenerator.kt @@ -1,6 +1,5 @@ package moe.nea.firmament.compat.rei -import io.github.moulberry.repo.data.NEUCraftingRecipe import io.github.moulberry.repo.data.NEUForgeRecipe import io.github.moulberry.repo.data.NEUKatUpgradeRecipe import io.github.moulberry.repo.data.NEUMobDropRecipe @@ -11,9 +10,6 @@ import me.shedaniel.rei.api.client.registry.display.DynamicDisplayGenerator import me.shedaniel.rei.api.client.view.ViewSearchBuilder import me.shedaniel.rei.api.common.display.Display import me.shedaniel.rei.api.common.entry.EntryStack -import moe.nea.firmament.compat.rei.recipes.SBCraftingRecipe -import moe.nea.firmament.compat.rei.recipes.SBEssenceUpgradeRecipe -import moe.nea.firmament.compat.rei.recipes.SBForgeRecipe import moe.nea.firmament.compat.rei.recipes.SBKatRecipe import moe.nea.firmament.compat.rei.recipes.SBMobDropRecipe import moe.nea.firmament.compat.rei.recipes.SBShopRecipe @@ -22,33 +18,27 @@ import moe.nea.firmament.repo.RepoManager import moe.nea.firmament.repo.SBItemStack -val SkyblockCraftingRecipeDynamicGenerator = - neuDisplayGenerator<SBCraftingRecipe, NEUCraftingRecipe> { SBCraftingRecipe(it) } - -val SkyblockForgeRecipeDynamicGenerator = - neuDisplayGenerator<SBForgeRecipe, NEUForgeRecipe> { SBForgeRecipe(it) } - val SkyblockMobDropRecipeDynamicGenerator = neuDisplayGenerator<SBMobDropRecipe, NEUMobDropRecipe> { SBMobDropRecipe(it) } val SkyblockShopRecipeDynamicGenerator = neuDisplayGenerator<SBShopRecipe, NEUNpcShopRecipe> { SBShopRecipe(it) } val SkyblockKatRecipeDynamicGenerator = neuDisplayGenerator<SBKatRecipe, NEUKatUpgradeRecipe> { SBKatRecipe(it) } -val SkyblockEssenceRecipeDynamicGenerator = - neuDisplayGeneratorWithItem<SBEssenceUpgradeRecipe, EssenceRecipeProvider.EssenceUpgradeRecipe> { item, recipe -> - SBEssenceUpgradeRecipe(recipe, item) - } inline fun <D : Display, reified T : NEURecipe> neuDisplayGenerator(crossinline mapper: (T) -> D) = neuDisplayGeneratorWithItem<D, T> { _, it -> mapper(it) } inline fun <D : Display, reified T : NEURecipe> neuDisplayGeneratorWithItem(crossinline mapper: (SBItemStack, T) -> D) = + neuDisplayGeneratorWithItem(T::class.java, mapper) +inline fun <D : Display, T : NEURecipe> neuDisplayGeneratorWithItem( + filter: Class<T>, + crossinline mapper: (SBItemStack, T) -> D) = object : DynamicDisplayGenerator<D> { override fun getRecipeFor(entry: EntryStack<*>): Optional<List<D>> { if (entry.type != SBItemEntryDefinition.type) return Optional.empty() val item = entry.castValue<SBItemStack>() val recipes = RepoManager.getRecipesFor(item.skyblockId) - val craftingRecipes = recipes.filterIsInstance<T>() + val craftingRecipes = recipes.filterIsInstance<T>(filter) return Optional.of(craftingRecipes.map { mapper(item, it) }) } @@ -60,7 +50,7 @@ inline fun <D : Display, reified T : NEURecipe> neuDisplayGeneratorWithItem(cros if (entry.type != SBItemEntryDefinition.type) return Optional.empty() val item = entry.castValue<SBItemStack>() val recipes = RepoManager.getUsagesFor(item.skyblockId) - val craftingRecipes = recipes.filterIsInstance<T>() + val craftingRecipes = recipes.filterIsInstance<T>(filter) return Optional.of(craftingRecipes.map { mapper(item, it) }) } } diff --git a/src/compat/rei/java/moe/nea/firmament/compat/rei/SkyblockItemIdFocusedStackProvider.kt b/src/compat/rei/java/moe/nea/firmament/compat/rei/SkyblockItemIdFocusedStackProvider.kt index 518f7b4..1db0376 100 |
