Mod name and JEI on fluid gauge panel

This commit is contained in:
DBotThePony 2024-01-09 12:22:53 +07:00
parent a5c1d7fbf8
commit 0e60e84eb3
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -1,29 +1,40 @@
package ru.dbotthepony.mc.otm.client.screen.widget package ru.dbotthepony.mc.otm.client.screen.widget
import com.mojang.blaze3d.platform.InputConstants
import com.mojang.blaze3d.systems.RenderSystem import com.mojang.blaze3d.systems.RenderSystem
import com.mojang.blaze3d.vertex.DefaultVertexFormat import com.mojang.blaze3d.vertex.DefaultVertexFormat
import com.mojang.blaze3d.vertex.VertexFormat 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.gui.screens.Screen
import net.minecraft.client.renderer.GameRenderer import net.minecraft.client.renderer.GameRenderer
import net.minecraft.network.chat.Component import net.minecraft.network.chat.Component
import net.minecraft.resources.ResourceLocation import net.minecraft.resources.ResourceLocation
import net.minecraft.world.inventory.InventoryMenu import net.minecraft.world.inventory.InventoryMenu
import net.minecraftforge.client.extensions.common.IClientFluidTypeExtensions import net.minecraftforge.client.extensions.common.IClientFluidTypeExtensions
import net.minecraftforge.fml.ModList
import org.lwjgl.opengl.GL11 import org.lwjgl.opengl.GL11
import ru.dbotthepony.mc.otm.OverdriveThatMatters 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.render.MGUIGraphics
import ru.dbotthepony.mc.otm.client.ShiftPressedCond import ru.dbotthepony.mc.otm.client.ShiftPressedCond
import ru.dbotthepony.mc.otm.client.minecraft import ru.dbotthepony.mc.otm.client.minecraft
import ru.dbotthepony.mc.otm.client.render.sprites.MatterySprite import ru.dbotthepony.mc.otm.client.render.sprites.MatterySprite
import ru.dbotthepony.mc.otm.client.render.tesselator 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.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.TextComponent
import ru.dbotthepony.mc.otm.core.TranslatableComponent import ru.dbotthepony.mc.otm.core.TranslatableComponent
import ru.dbotthepony.mc.otm.core.isNotEmpty import ru.dbotthepony.mc.otm.core.isNotEmpty
import ru.dbotthepony.mc.otm.core.math.RGBAColor import ru.dbotthepony.mc.otm.core.math.RGBAColor
import ru.dbotthepony.mc.otm.core.math.linearInterpolation 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.core.util.formatFluidLevel
import ru.dbotthepony.mc.otm.menu.widget.FluidGaugeWidget import ru.dbotthepony.mc.otm.menu.widget.FluidGaugeWidget
import kotlin.jvm.optionals.getOrNull
open class FluidGaugePanel<out S : Screen>( open class FluidGaugePanel<out S : Screen>(
screen: S, screen: S,
@ -31,16 +42,22 @@ open class FluidGaugePanel<out S : Screen>(
val widget: FluidGaugeWidget, val widget: FluidGaugeWidget,
x: Float = 0f, x: Float = 0f,
y: Float = 0f y: Float = 0f
) : EditablePanel<S>(screen, parent, x, y, width = GAUGE.width, height = GAUGE.height) { ) : AbstractButtonPanel<S>(screen, parent, x, y, width = GAUGE.width, height = GAUGE.height) {
init { init {
scissor = true scissor = true
} }
protected open fun makeTooltip(): MutableList<Component> { protected open fun makeTooltip(): MutableList<Component> {
return mutableListOf( val tooltip = mutableListOf<Component>(
if (widget.fluid.isEmpty) TranslatableComponent("otm.gui.empty") else TextComponent(String.format("%s: %.2f%%", widget.fluid.displayName.string, widget.percentage * 100.0)), 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) 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 { override fun innerRenderTooltips(graphics: MGUIGraphics, mouseX: Float, mouseY: Float, partialTick: Float): Boolean {
@ -52,6 +69,29 @@ open class FluidGaugePanel<out S : Screen>(
return false 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) { override fun innerRender(graphics: MGUIGraphics, mouseX: Float, mouseY: Float, partialTick: Float) {
if (widget.percentage > 0.01f && widget.fluid.isNotEmpty) { if (widget.percentage > 0.01f && widget.fluid.isNotEmpty) {
val data = IClientFluidTypeExtensions.of(widget.fluid.fluid) val data = IClientFluidTypeExtensions.of(widget.fluid.fluid)