From 8dd36f1c4ac706947643c4fb32afd44f60313eb3 Mon Sep 17 00:00:00 2001 From: glowredman <35727266+glowredman@users.noreply.github.com> Date: Sun, 29 Dec 2024 06:00:02 +0100 Subject: [PATCH] Add RenderTooltipEvent Compat (#574) Co-authored-by: Martin Robertz Co-authored-by: Maya <10861407+serenibyss@users.noreply.github.com> --- dependencies.gradle | 2 + .../java/codechicken/nei/NEIModContainer.java | 14 +++- .../nei/guihook/GuiContainerManager.java | 48 +++++++++++- .../nei/util/RenderTooltipEventHelper.java | 78 +++++++++++++++++++ 4 files changed, 137 insertions(+), 5 deletions(-) create mode 100644 src/main/java/codechicken/nei/util/RenderTooltipEventHelper.java diff --git a/dependencies.gradle b/dependencies.gradle index bc1b969df..47d19c113 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -2,5 +2,7 @@ dependencies { api('com.github.GTNewHorizons:CodeChickenCore:1.4.0:dev') + implementation('com.github.GTNewHorizons:GTNHLib:0.6.0:dev') + shadowImplementation('org.apache.commons:commons-csv:1.10.0') } diff --git a/src/main/java/codechicken/nei/NEIModContainer.java b/src/main/java/codechicken/nei/NEIModContainer.java index 81724b29c..8e18ef029 100644 --- a/src/main/java/codechicken/nei/NEIModContainer.java +++ b/src/main/java/codechicken/nei/NEIModContainer.java @@ -1,6 +1,7 @@ package codechicken.nei; import java.io.File; +import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.LinkedList; @@ -38,6 +39,7 @@ public class NEIModContainer extends DummyModContainer { public static LinkedList plugins = new LinkedList<>(); private static boolean gregTech5Loaded; + private static boolean gtnhLibLoaded; public NEIModContainer() { super(getModMetadata()); @@ -59,16 +61,23 @@ public static boolean isGT5Loaded() { return gregTech5Loaded; } + public static boolean isGTNHLibLoaded() { + return gtnhLibLoaded; + } + @Override public Set getRequirements() { Set deps = new HashSet<>(); - deps.add(VersionParser.parseVersionReference("CodeChickenCore@[" + CodeChickenCorePlugin.version + ",)")); + deps.add(VersionParser.parseVersionReference("CodeChickenCore@[" + codechicken.core.asm.Tags.VERSION + ",)")); return deps; } @Override public List getDependencies() { - return new LinkedList<>(getRequirements()); + List deps = new ArrayList<>(); + deps.add(VersionParser.parseVersionReference("CodeChickenCore@[" + codechicken.core.asm.Tags.VERSION + ",)")); + deps.add(VersionParser.parseVersionReference("gtnhlib@[0.6.0,)")); + return deps; } private String description; @@ -106,6 +115,7 @@ public boolean registerBus(EventBus bus, LoadController controller) { @Subscribe public void preInit(FMLPreInitializationEvent event) { gregTech5Loaded = Loader.isModLoaded("gregtech") && !Loader.isModLoaded("gregapi_post"); + gtnhLibLoaded = Loader.isModLoaded("gtnhlib"); if (CommonUtils.isClient()) ClientHandler.preInit(); } diff --git a/src/main/java/codechicken/nei/guihook/GuiContainerManager.java b/src/main/java/codechicken/nei/guihook/GuiContainerManager.java index 555d7499c..acb738254 100644 --- a/src/main/java/codechicken/nei/guihook/GuiContainerManager.java +++ b/src/main/java/codechicken/nei/guihook/GuiContainerManager.java @@ -16,6 +16,7 @@ import java.util.Map; import java.util.StringJoiner; import java.util.concurrent.CopyOnWriteArrayList; +import java.util.function.Consumer; import java.util.regex.Pattern; import javax.annotation.Nullable; @@ -24,6 +25,7 @@ import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.client.renderer.RenderHelper; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.entity.RenderItem; import net.minecraft.client.resources.IResourceManager; @@ -38,15 +40,18 @@ import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL12; import codechicken.lib.gui.GuiDraw; import codechicken.nei.ItemStackSet; import codechicken.nei.NEIClientConfig; import codechicken.nei.NEIClientUtils; +import codechicken.nei.NEIModContainer; import codechicken.nei.SearchField; import codechicken.nei.recipe.StackInfo; import codechicken.nei.search.TooltipFilter; import codechicken.nei.util.ReadableNumberConverter; +import codechicken.nei.util.RenderTooltipEventHelper; public class GuiContainerManager { @@ -552,8 +557,8 @@ public void renderToolTips(int mousex, int mousey) { tooltip = handler.handleTooltip(window, mousex, mousey, tooltip); } + ItemStack stack = getStackMouseOver(window); if (tooltip.isEmpty() && shouldShowTooltip(window)) { // mouseover tip, not holding an item - ItemStack stack = getStackMouseOver(window); font = getFontRenderer(stack); if (stack != null) { tooltip = itemDisplayNameMultiline(stack, window, true); @@ -600,7 +605,32 @@ public void renderToolTips(int mousex, int mousey) { } } - drawPagedTooltip(font, mousex + 12, mousey - 12, tooltip); + if (NEIModContainer.isGTNHLibLoaded() && !tooltip.isEmpty()) { + if (RenderTooltipEventHelper.post(stack, this.window, mousex, mousey, font)) { + return; + } + Consumer> alternativeRenderer = RenderTooltipEventHelper.getAlternativeRenderer(); + if (alternativeRenderer == null) { + drawPagedTooltip( + RenderTooltipEventHelper.getFont(), + RenderTooltipEventHelper.getX() + 12, + RenderTooltipEventHelper.getY() - 12, + tooltip); + } else { + GL11.glDisable(GL12.GL_RESCALE_NORMAL); + RenderHelper.disableStandardItemLighting(); + GL11.glDisable(GL11.GL_DEPTH_TEST); + GuiDraw.gui.incZLevel(300.0f); + alternativeRenderer.accept(tooltip); + GuiDraw.gui.incZLevel(-300.0f); + GL11.glEnable(GL11.GL_DEPTH_TEST); + RenderHelper.enableStandardItemLighting(); + GL11.glEnable(GL12.GL_RESCALE_NORMAL); + } + RenderTooltipEventHelper.flush(); + } else { + drawPagedTooltip(font, mousex + 12, mousey - 12, tooltip); + } for (IContainerDrawHandler drawHandler : drawHandlers) { drawHandler.postRenderTooltips(window, mousex, mousey, tooltip); @@ -625,6 +655,18 @@ public static void drawPagedTooltip(FontRenderer font, int x, int y, List> getAlternativeRenderer() { + return event.alternativeRenderer; + } +}