From 0e60e84eb3872ce6d14713dcc068dd2db4d147ac Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Tue, 9 Jan 2024 12:22:53 +0700 Subject: [PATCH] Mod name and JEI on fluid gauge panel --- .../client/screen/widget/FluidGaugePanel.kt | 44 ++++++++++++++++++- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/widget/FluidGaugePanel.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/widget/FluidGaugePanel.kt index 670246d22..854e521f7 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/widget/FluidGaugePanel.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/widget/FluidGaugePanel.kt @@ -1,29 +1,40 @@ package ru.dbotthepony.mc.otm.client.screen.widget +import com.mojang.blaze3d.platform.InputConstants import com.mojang.blaze3d.systems.RenderSystem import com.mojang.blaze3d.vertex.DefaultVertexFormat import com.mojang.blaze3d.vertex.VertexFormat +import mezz.jei.api.forge.ForgeTypes +import mezz.jei.api.recipe.RecipeIngredientRole +import net.minecraft.ChatFormatting import net.minecraft.client.gui.screens.Screen import net.minecraft.client.renderer.GameRenderer import net.minecraft.network.chat.Component import net.minecraft.resources.ResourceLocation import net.minecraft.world.inventory.InventoryMenu import net.minecraftforge.client.extensions.common.IClientFluidTypeExtensions +import net.minecraftforge.fml.ModList import org.lwjgl.opengl.GL11 import ru.dbotthepony.mc.otm.OverdriveThatMatters +import ru.dbotthepony.mc.otm.client.CursorType import ru.dbotthepony.mc.otm.client.render.MGUIGraphics import ru.dbotthepony.mc.otm.client.ShiftPressedCond import ru.dbotthepony.mc.otm.client.minecraft import ru.dbotthepony.mc.otm.client.render.sprites.MatterySprite import ru.dbotthepony.mc.otm.client.render.tesselator import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel +import ru.dbotthepony.mc.otm.client.screen.panels.button.AbstractButtonPanel +import ru.dbotthepony.mc.otm.compat.jei.JEIPlugin +import ru.dbotthepony.mc.otm.compat.jei.isJeiLoaded import ru.dbotthepony.mc.otm.core.TextComponent import ru.dbotthepony.mc.otm.core.TranslatableComponent import ru.dbotthepony.mc.otm.core.isNotEmpty import ru.dbotthepony.mc.otm.core.math.RGBAColor import ru.dbotthepony.mc.otm.core.math.linearInterpolation +import ru.dbotthepony.mc.otm.core.registryName import ru.dbotthepony.mc.otm.core.util.formatFluidLevel import ru.dbotthepony.mc.otm.menu.widget.FluidGaugeWidget +import kotlin.jvm.optionals.getOrNull open class FluidGaugePanel( screen: S, @@ -31,16 +42,22 @@ open class FluidGaugePanel( val widget: FluidGaugeWidget, x: Float = 0f, y: Float = 0f -) : EditablePanel(screen, parent, x, y, width = GAUGE.width, height = GAUGE.height) { +) : AbstractButtonPanel(screen, parent, x, y, width = GAUGE.width, height = GAUGE.height) { init { scissor = true } protected open fun makeTooltip(): MutableList { - return mutableListOf( + val tooltip = mutableListOf( if (widget.fluid.isEmpty) TranslatableComponent("otm.gui.empty") else TextComponent(String.format("%s: %.2f%%", widget.fluid.displayName.string, widget.percentage * 100.0)), formatFluidLevel(if (widget.fluid.isEmpty) 0 else widget.fluid.amount, widget.maxCapacity, formatAsReadable = ShiftPressedCond) ) + + if (widget.fluid.isNotEmpty) { + tooltip.add(TextComponent(ModList.get().getModContainerById(widget.fluid.fluid.registryName!!.namespace).get().modInfo.displayName).withStyle(ChatFormatting.BLUE).withStyle(ChatFormatting.ITALIC)) + } + + return tooltip } override fun innerRenderTooltips(graphics: MGUIGraphics, mouseX: Float, mouseY: Float, partialTick: Float): Boolean { @@ -52,6 +69,29 @@ open class FluidGaugePanel( return false } + private fun openFluidRecipes(button: Int) { + val ingredient = JEIPlugin.RUNTIME.ingredientManager.createTypedIngredient(ForgeTypes.FLUID_STACK, widget.fluid).getOrNull() ?: return + + if (button == InputConstants.MOUSE_BUTTON_RIGHT) { + JEIPlugin.RUNTIME.recipesGui.show(JEIPlugin.RUNTIME.jeiHelpers.focusFactory.createFocus(RecipeIngredientRole.INPUT, ingredient)) + } else { + JEIPlugin.RUNTIME.recipesGui.show(JEIPlugin.RUNTIME.jeiHelpers.focusFactory.createFocus(RecipeIngredientRole.OUTPUT, ingredient)) + } + } + + override val cursorType: CursorType + get() = if (isJeiLoaded && widget.fluid.isNotEmpty) CursorType.HAND else CursorType.ARROW + + override fun test(value: Int): Boolean { + return (value == InputConstants.MOUSE_BUTTON_RIGHT || value == InputConstants.MOUSE_BUTTON_LEFT) && isJeiLoaded && widget.fluid.isNotEmpty + } + + override fun onClick(mouseButton: Int) { + if (isJeiLoaded && widget.fluid.isNotEmpty) { + openFluidRecipes(mouseButton) + } + } + override fun innerRender(graphics: MGUIGraphics, mouseX: Float, mouseY: Float, partialTick: Float) { if (widget.percentage > 0.01f && widget.fluid.isNotEmpty) { val data = IClientFluidTypeExtensions.of(widget.fluid.fluid)