mirror of
https://github.com/GTNewHorizons/waila.git
synced 2026-11-22 13:10:10 +00:00
Add 3D entity icon to the tooltip
This commit is contained in:
7 files changed
+150
-11
No files matched your search
@@ -16,6 +16,7 @@ import mcp.mobius.waila.handlers.HUDHandlerBlocks;
|
||||
import mcp.mobius.waila.handlers.HUDHandlerEntities;
|
||||
import mcp.mobius.waila.handlers.VanillaTooltipHandler;
|
||||
import mcp.mobius.waila.handlers.nei.NEIHandler;
|
||||
import mcp.mobius.waila.overlay.EntityIconRenderer;
|
||||
import mcp.mobius.waila.overlay.tooltiprenderers.TTRenderAspectString;
|
||||
import mcp.mobius.waila.overlay.tooltiprenderers.TTRenderBar;
|
||||
import mcp.mobius.waila.overlay.tooltiprenderers.TTRenderFluidBar;
|
||||
@@ -53,6 +54,7 @@ public class ProxyClient extends ProxyServer {
|
||||
ModuleRegistrar.instance().addConfig("General", "general.showents");
|
||||
ModuleRegistrar.instance().addConfig("General", "general.showhp");
|
||||
ModuleRegistrar.instance().addConfig("General", "general.showcrop");
|
||||
ModuleRegistrar.instance().addConfig("General", EntityIconRenderer.CFG_SHOW, true);
|
||||
|
||||
ModuleRegistrar.instance().registerTooltipRenderer("waila.health", new TTRenderHealth());
|
||||
ModuleRegistrar.instance().registerTooltipRenderer("waila.stack", new TTRenderStack());
|
||||
|
||||
@@ -78,7 +78,7 @@ public class DisplayUtil {
|
||||
try {
|
||||
renderItem.renderItemAndEffectIntoGUI(fontRenderer, textureManager, stack, x, y);
|
||||
renderItem.renderItemOverlayIntoGUI(fontRenderer, textureManager, stack, x, y);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
String stackStr = stack != null ? stack.toString() : "NullStack";
|
||||
WailaExceptionHandler.handleErr(e, "renderStack | " + stackStr, null);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
package mcp.mobius.waila.overlay;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.ScaledResolution;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.client.renderer.entity.RenderManager;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL12;
|
||||
|
||||
import mcp.mobius.waila.api.impl.ConfigHandler;
|
||||
import mcp.mobius.waila.utils.WailaExceptionHandler;
|
||||
|
||||
/**
|
||||
* Draws a small turning 3D model of an entity as the tooltip icon. Based on {@code GuiInventory.func_147046_a} and the
|
||||
* entity icon of WDMla (https://github.com/GTNewHorizons/WDMla).
|
||||
*/
|
||||
public final class EntityIconRenderer {
|
||||
|
||||
public static final String CFG_SHOW = "general.showentityicon";
|
||||
|
||||
/** Degrees per second */
|
||||
private static final float TURN_SPEED = 45f;
|
||||
|
||||
private static final Set<Class<?>> failedClasses = new HashSet<>();
|
||||
|
||||
private EntityIconRenderer() {}
|
||||
|
||||
public static boolean isEnabled() {
|
||||
return ConfigHandler.instance().getConfig(CFG_SHOW, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the entity in the square with the top left corner (x, y) and the side length size.
|
||||
*/
|
||||
public static void render(int x, int y, int size, Entity entity) {
|
||||
if (entity == null || failedClasses.contains(entity.getClass())) return;
|
||||
|
||||
final Minecraft mc = Minecraft.getMinecraft();
|
||||
// The body of most mobs is longer than the bounding box is wide, and the model turns
|
||||
float extent = Math.max(Math.max(entity.height, entity.width * 1.5f), 0.1f);
|
||||
float scale = size / extent;
|
||||
float angle = (Minecraft.getSystemTime() % 360000L) / 1000f * TURN_SPEED;
|
||||
|
||||
float yaw = entity.rotationYaw;
|
||||
float prevYaw = entity.prevRotationYaw;
|
||||
float pitch = entity.rotationPitch;
|
||||
float prevPitch = entity.prevRotationPitch;
|
||||
float bodyYaw = 0, prevBodyYaw = 0, headYaw = 0, prevHeadYaw = 0;
|
||||
EntityLivingBase living = entity instanceof EntityLivingBase l ? l : null;
|
||||
if (living != null) {
|
||||
bodyYaw = living.renderYawOffset;
|
||||
prevBodyYaw = living.prevRenderYawOffset;
|
||||
headYaw = living.rotationYawHead;
|
||||
prevHeadYaw = living.prevRotationYawHead;
|
||||
}
|
||||
float playerViewY = RenderManager.instance.playerViewY;
|
||||
boolean hideGui = mc.gameSettings.hideGUI;
|
||||
|
||||
// Entity renderers change blend, depth, alpha and lighting state (so save all of it)
|
||||
int matrixDepth = GL11.glGetInteger(GL11.GL_MODELVIEW_STACK_DEPTH);
|
||||
GL11.glPushMatrix();
|
||||
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
|
||||
try {
|
||||
// Models can be larger than their bounding box, do not draw over the text
|
||||
ScaledResolution res = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
|
||||
float factor = res.getScaleFactor() * OverlayConfig.scale;
|
||||
int margin = 3;
|
||||
GL11.glEnable(GL11.GL_SCISSOR_TEST);
|
||||
GL11.glScissor(
|
||||
(int) ((x - margin) * factor),
|
||||
(int) (mc.displayHeight - (y + size + margin) * factor),
|
||||
(int) ((size + 2 * margin) * factor),
|
||||
(int) ((size + 2 * margin) * factor));
|
||||
|
||||
GL11.glEnable(GL11.GL_COLOR_MATERIAL);
|
||||
GL11.glEnable(GL11.GL_DEPTH_TEST);
|
||||
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
|
||||
GL11.glColor4f(1f, 1f, 1f, 1f);
|
||||
|
||||
GL11.glTranslatef(x + size / 2f, y + size / 2f + entity.height * scale / 2f, 100f);
|
||||
GL11.glScalef(-scale, scale, scale);
|
||||
GL11.glRotatef(180f, 0f, 0f, 1f);
|
||||
GL11.glRotatef(-15f, 1f, 0f, 0f);
|
||||
GL11.glRotatef(135f, 0f, 1f, 0f);
|
||||
RenderHelper.enableStandardItemLighting();
|
||||
GL11.glRotatef(-135f + angle, 0f, 1f, 0f);
|
||||
GL11.glTranslatef(0f, entity.yOffset, 0f);
|
||||
|
||||
entity.rotationYaw = entity.prevRotationYaw = 0f;
|
||||
entity.rotationPitch = entity.prevRotationPitch = 0f;
|
||||
if (living != null) {
|
||||
living.renderYawOffset = living.prevRenderYawOffset = 0f;
|
||||
living.rotationYawHead = living.prevRotationYawHead = 0f;
|
||||
}
|
||||
RenderManager.instance.playerViewY = 180f;
|
||||
// Hide name tags
|
||||
mc.gameSettings.hideGUI = true;
|
||||
|
||||
RenderManager.instance.renderEntityWithPosYaw(entity, 0d, 0d, 0d, 0f, 1f);
|
||||
} catch (Throwable e) {
|
||||
failedClasses.add(entity.getClass());
|
||||
WailaExceptionHandler.handleErr(e, "EntityIconRenderer | " + entity.getClass().getName(), null);
|
||||
} finally {
|
||||
mc.gameSettings.hideGUI = hideGui;
|
||||
RenderManager.instance.playerViewY = playerViewY;
|
||||
entity.rotationYaw = yaw;
|
||||
entity.prevRotationYaw = prevYaw;
|
||||
entity.rotationPitch = pitch;
|
||||
entity.prevRotationPitch = prevPitch;
|
||||
if (living != null) {
|
||||
living.renderYawOffset = bodyYaw;
|
||||
living.prevRenderYawOffset = prevBodyYaw;
|
||||
living.rotationYawHead = headYaw;
|
||||
living.prevRotationYawHead = prevHeadYaw;
|
||||
}
|
||||
|
||||
// Also restores lighting, the active texture unit and the lightmap enable
|
||||
GL11.glPopAttrib();
|
||||
// A renderer that failed can leave a pushed matrix behind, but should never pop the callers
|
||||
while (GL11.glGetInteger(GL11.GL_MODELVIEW_STACK_DEPTH) > matrixDepth) GL11.glPopMatrix();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,8 +11,6 @@ import mcp.mobius.waila.api.impl.ConfigHandler;
|
||||
|
||||
public class OverlayRenderer {
|
||||
|
||||
private static boolean hasBlending;
|
||||
private static boolean hasDepthTest;
|
||||
private static int boundTexIndex;
|
||||
|
||||
public static boolean isOverlayVisible() {
|
||||
@@ -71,6 +69,8 @@ public class OverlayRenderer {
|
||||
|
||||
if (tooltip.hasIcon && tooltip.stack != null && tooltip.stack.getItem() != null)
|
||||
DisplayUtil.renderStack(tooltip.x + 5, tooltip.y + tooltip.h / 2 - 8, tooltip.stack);
|
||||
else if (tooltip.hasIcon && tooltip.getEntity() != null)
|
||||
EntityIconRenderer.render(tooltip.x + 5, tooltip.y + tooltip.h / 2 - 8, 16, tooltip.getEntity());
|
||||
|
||||
loadGLState();
|
||||
GL11.glPopMatrix();
|
||||
@@ -78,17 +78,12 @@ public class OverlayRenderer {
|
||||
}
|
||||
|
||||
private static void saveGLState() {
|
||||
hasBlending = GL11.glGetBoolean(GL11.GL_BLEND);
|
||||
hasDepthTest = GL11.glGetBoolean(GL11.GL_DEPTH_TEST);
|
||||
boundTexIndex = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D);
|
||||
GL11.glPushAttrib(GL11.GL_CURRENT_BIT);
|
||||
// Icons turn on lighting, lights, color material and rescale normal
|
||||
GL11.glPushAttrib(GL11.GL_CURRENT_BIT | GL11.GL_ENABLE_BIT | GL11.GL_LIGHTING_BIT | GL11.GL_COLOR_BUFFER_BIT);
|
||||
}
|
||||
|
||||
private static void loadGLState() {
|
||||
if (hasBlending) GL11.glEnable(GL11.GL_BLEND);
|
||||
else GL11.glDisable(GL11.GL_BLEND);
|
||||
if (hasDepthTest) GL11.glEnable(GL11.GL_DEPTH_TEST);
|
||||
else GL11.glDisable(GL11.GL_DEPTH_TEST);
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, boundTexIndex);
|
||||
GL11.glPopAttrib();
|
||||
}
|
||||
|
||||
@@ -9,11 +9,13 @@ import static mcp.mobius.waila.api.SpecialChars.patternTab;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Point;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
|
||||
@@ -49,6 +51,7 @@ public class Tooltip {
|
||||
Point pos;
|
||||
boolean hasIcon = false;
|
||||
ItemStack stack;
|
||||
WeakReference<Entity> entity;
|
||||
|
||||
IWailaCommonAccessor accessor = DataAccessorCommon.instance;
|
||||
|
||||
@@ -106,6 +109,15 @@ public class Tooltip {
|
||||
this.stack = stack;
|
||||
}
|
||||
|
||||
public Tooltip(List<String> textData, Entity entity) {
|
||||
this(textData, entity != null && EntityIconRenderer.isEnabled());
|
||||
this.entity = entity == null ? null : new WeakReference<>(entity);
|
||||
}
|
||||
|
||||
Entity getEntity() {
|
||||
return entity == null ? null : entity.get();
|
||||
}
|
||||
|
||||
public Tooltip(List<String> textData, boolean hasIcon) {
|
||||
|
||||
if (hasIcon) hasIcon = ConfigHandler.instance().showIcon();
|
||||
|
||||
@@ -142,7 +142,7 @@ public class WailaTickHandler {
|
||||
currenttip.addAll(currenttipBody);
|
||||
currenttip.addAll(currenttipTail);
|
||||
|
||||
this.tooltip = new Tooltip(currenttip, false);
|
||||
this.tooltip = new Tooltip(currenttip, targetEnt);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -153,6 +153,7 @@ option.stevescarts.shifttoggle=Shift toggle
|
||||
option.general.showents=Show entities
|
||||
option.general.showhp=Show entities health
|
||||
option.general.showcrop=Show crop growth
|
||||
option.general.showentityicon=Show entity icon
|
||||
option.thaumcraft.aspects=Show aspects
|
||||
|
||||
nei.options.keys.showenchant=Show enchanting values
|
||||
Reference in new issue
Block a user