Compare commits

..
8 changed files with 203 additions and 194 deletions

No files matched your search

+2 -2
View File
@@ -3,9 +3,9 @@ name: Build and test
on:
pull_request:
branches: [ master, main, release/** ]
branches: [ master, main ]
push:
branches: [ master, main, release/** ]
branches: [ master, main ]
jobs:
build-and-test:
@@ -16,7 +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.BlockIconRenderer;
import mcp.mobius.waila.overlay.tooltiprenderers.TTRenderAspectString;
import mcp.mobius.waila.overlay.tooltiprenderers.TTRenderBar;
import mcp.mobius.waila.overlay.tooltiprenderers.TTRenderFluidBar;
@@ -54,7 +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().addConfig("General", BlockIconRenderer.CFG_SHOW, true);
ModuleRegistrar.instance().registerTooltipRenderer("waila.health", new TTRenderHealth());
ModuleRegistrar.instance().registerTooltipRenderer("waila.stack", new TTRenderStack());
@@ -0,0 +1,164 @@
package mcp.mobius.waila.overlay;
import java.util.HashSet;
import java.util.Set;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityChest;
import net.minecraft.world.World;
import net.minecraftforge.client.ForgeHooksClient;
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 the block in the world as the tooltip icon. Based on {@code GuiBlockDraw} of WDMla
* (https://github.com/GTNewHorizons/WDMla), which is based on the {@code WorldSceneRenderer} of BlockRenderer6343.
* <p>
* The block is drawn from the real world, so the icon shows the same state (facing, connections, TESR content) as the
* block that the player looks at.
*/
public final class BlockIconRenderer {
public static final String CFG_SHOW = "general.showblockicon3d";
/** Degrees per second */
private static final float TURN_SPEED = 45f;
private static final float PITCH = 30f;
private static final RenderBlocks renderBlocks = new RenderBlocks();
private static final Set<Class<?>> failedClasses = new HashSet<>();
private BlockIconRenderer() {}
public static boolean isEnabled() {
return ConfigHandler.instance().getConfig(CFG_SHOW, true);
}
/**
* Draws the block at (bx, by, bz) in the square with the top left corner (x, y) and the side length size.
*
* @return false if nothing was drawn, then the caller must draw the normal item icon.
*/
public static boolean render(int x, int y, int size, int bx, int by, int bz) {
final Minecraft mc = Minecraft.getMinecraft();
final World world = mc.theWorld;
if (world == null) return false;
Block block = world.getBlock(bx, by, bz);
if (block == null || block.isAir(world, bx, by, bz) || failedClasses.contains(block.getClass())) return false;
TileEntity tile = world.getTileEntity(bx, by, bz);
TileEntityRendererDispatcher tesr = TileEntityRendererDispatcher.instance;
boolean hasTesr = tile != null && tesr.hasSpecialRenderer(tile);
if (block.getRenderType() == -1 && !hasTesr) return false;
// A double chest is drawn as one large model by one of its halves, use the item icon for it
if (tile instanceof TileEntityChest chest && (chest.adjacentChestXNeg != null || chest.adjacentChestXPos != null
|| chest.adjacentChestZNeg != null
|| chest.adjacentChestZPos != null))
return false;
float angle = (Minecraft.getSystemTime() % 360000L) / 1000f * TURN_SPEED;
// A turning cube is at most about 1.6 blocks wide or high on the screen with this pitch
float scale = size / 1.6f;
Tessellator tessellator = Tessellator.instance;
int matrixDepth = GL11.glGetInteger(GL11.GL_MODELVIEW_STACK_DEPTH);
int attribDepth = GL11.glGetInteger(GL11.GL_ATTRIB_STACK_DEPTH);
GL11.glPushMatrix();
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
try {
// Some models are larger than one block, 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.glTranslatef(x + size / 2f, y + size / 2f, 150f);
GL11.glScalef(scale, -scale, scale);
GL11.glRotatef(PITCH, 1f, 0f, 0f);
GL11.glRotatef(angle, 0f, 1f, 0f);
GL11.glTranslated(-bx - 0.5d, -by - 0.5d, -bz - 0.5d);
GL11.glColor4f(1f, 1f, 1f, 1f);
GL11.glEnable(GL11.GL_DEPTH_TEST);
GL11.glDepthMask(true);
GL11.glDisable(GL11.GL_CULL_FACE);
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glEnable(GL11.GL_ALPHA_TEST);
GL11.glAlphaFunc(GL11.GL_GREATER, 0.1f);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
// Normal block model. The face shading of RenderBlocks gives the 3D look, so no GL lighting here.
if (block.getRenderType() != -1) {
RenderHelper.disableStandardItemLighting();
GL11.glDisable(GL11.GL_LIGHTING);
mc.renderEngine.bindTexture(TextureMap.locationBlocksTexture);
renderBlocks.blockAccess = world;
renderBlocks.renderAllFaces = true;
// The offsets of the tessellator are global and are not reset by draw
tessellator.setTranslation(0, 0, 0);
tessellator.startDrawingQuads();
try {
for (int pass = 0; pass < 2; pass++) {
if (!block.canRenderInPass(pass)) continue;
ForgeHooksClient.setRenderPass(pass);
renderBlocks.renderBlockByRenderType(block, bx, by, bz);
}
} finally {
ForgeHooksClient.setRenderPass(-1);
try {
tessellator.draw();
} catch (IllegalStateException alreadyDrawn) {
// A renderer can end the batch itself, draw would throw then
}
tessellator.setTranslation(0, 0, 0);
}
}
// Special renderer, also drawn on top of the block model above
if (hasTesr) {
RenderHelper.enableStandardItemLighting();
for (int pass = 0; pass < 2; pass++) {
if (!tile.shouldRenderInPass(pass)) continue;
ForgeHooksClient.setRenderPass(pass);
GL11.glColor4f(1f, 1f, 1f, 1f);
tesr.renderTileEntityAt(tile, bx, by, bz, 0f);
}
ForgeHooksClient.setRenderPass(-1);
RenderHelper.disableStandardItemLighting();
}
return true;
} catch (Exception e) {
failedClasses.add(block.getClass());
WailaExceptionHandler.handleErr(e, "BlockIconRenderer | " + block.getClass().getName(), null);
return false;
} finally {
renderBlocks.blockAccess = null;
renderBlocks.renderAllFaces = false;
// A renderer can leave unbalanced pushes behind, but should never pop the caller's. Query each
// stack once and pop down to where it started.
for (int i = GL11.glGetInteger(GL11.GL_ATTRIB_STACK_DEPTH) - attribDepth; i > 0; i--) GL11.glPopAttrib();
for (int i = GL11.glGetInteger(GL11.GL_MODELVIEW_STACK_DEPTH) - matrixDepth; i > 0; i--) GL11.glPopMatrix();
}
}
}
@@ -1,162 +0,0 @@
package mcp.mobius.waila.overlay;
import java.nio.FloatBuffer;
import java.util.HashSet;
import java.util.Set;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.ActiveRenderInfo;
import net.minecraft.client.renderer.GLAllocation;
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 static final FloatBuffer modelview = GLAllocation.createDirectFloatBuffer(16);
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;
float infoX = ActiveRenderInfo.rotationX, infoZ = ActiveRenderInfo.rotationZ;
float infoYZ = ActiveRenderInfo.rotationYZ, infoXZ = ActiveRenderInfo.rotationXZ,
infoXY = ActiveRenderInfo.rotationXY;
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);
int attribDepth = GL11.glGetInteger(GL11.GL_ATTRIB_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;
setBillboardAxes();
// Hide name tags
mc.gameSettings.hideGUI = true;
RenderManager.instance.renderEntityWithPosYaw(entity, 0d, 0d, 0d, 0f, 1f);
} catch (Exception e) {
failedClasses.add(entity.getClass());
WailaExceptionHandler.handleErr(e, "EntityIconRenderer | " + entity.getClass().getName(), null);
} finally {
mc.gameSettings.hideGUI = hideGui;
RenderManager.instance.playerViewY = playerViewY;
ActiveRenderInfo.rotationX = infoX;
ActiveRenderInfo.rotationZ = infoZ;
ActiveRenderInfo.rotationYZ = infoYZ;
ActiveRenderInfo.rotationXZ = infoXZ;
ActiveRenderInfo.rotationXY = infoXY;
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;
}
// A renderer can leave unbalanced pushes behind, but should never pop the caller's. Query each
// stack once and pop down to where it started.
for (int i = GL11.glGetInteger(GL11.GL_ATTRIB_STACK_DEPTH) - attribDepth; i > 0; i--) GL11.glPopAttrib();
for (int i = GL11.glGetInteger(GL11.GL_MODELVIEW_STACK_DEPTH) - matrixDepth; i > 0; i--) GL11.glPopMatrix();
}
}
/**
* Billboards (like Thaumcraft wisps) face the camera with the axes in {@link ActiveRenderInfo}, which belong to the
* world view. Point them at the screen of the icon instead.
*/
private static void setBillboardAxes() {
modelview.clear();
GL11.glGetFloat(GL11.GL_MODELVIEW_MATRIX, modelview);
// The rows of the rotation are the screen right and down axes in model space, all with the same length
float len = (float) Math.sqrt(
modelview.get(0) * modelview.get(0) + modelview.get(4) * modelview.get(4)
+ modelview.get(8) * modelview.get(8));
// Vanilla stores the left axis in rotationX/Z and the up axis in rotationYZ/XZ/XY
ActiveRenderInfo.rotationX = -modelview.get(0) / len;
ActiveRenderInfo.rotationZ = -modelview.get(8) / len;
ActiveRenderInfo.rotationYZ = -modelview.get(1) / len;
ActiveRenderInfo.rotationXZ = -modelview.get(5) / len;
ActiveRenderInfo.rotationXY = -modelview.get(9) / len;
}
}
@@ -2,7 +2,6 @@ package mcp.mobius.waila.overlay;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.entity.Entity;
import net.minecraft.util.MovingObjectPosition;
import org.lwjgl.opengl.GL11;
@@ -68,11 +67,17 @@ public class OverlayRenderer {
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
Entity entity = tooltip.entity;
if (tooltip.hasIcon && tooltip.stack != null && tooltip.stack.getItem() != null)
boolean drawn3D = tooltip.hasIcon && tooltip.hasBlockPos
&& BlockIconRenderer.isEnabled()
&& BlockIconRenderer.render(
tooltip.x + 5,
tooltip.y + tooltip.h / 2 - 8,
16,
tooltip.blockX,
tooltip.blockY,
tooltip.blockZ);
if (!drawn3D && 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 && entity != null)
EntityIconRenderer.render(tooltip.x + 5, tooltip.y + tooltip.h / 2 - 8, 16, entity);
loadGLState();
GL11.glPopMatrix();
@@ -81,7 +86,7 @@ public class OverlayRenderer {
private static void saveGLState() {
boundTexIndex = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D);
// Icons turn on lighting, lights, color material and rescale normal
// Icons turn on lighting, lights, color material and rescale normal; the box changes blend func and shade model
GL11.glPushAttrib(GL11.GL_CURRENT_BIT | GL11.GL_ENABLE_BIT | GL11.GL_LIGHTING_BIT | GL11.GL_COLOR_BUFFER_BIT);
}
@@ -14,7 +14,6 @@ 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;
@@ -50,7 +49,8 @@ public class Tooltip {
Point pos;
boolean hasIcon = false;
ItemStack stack;
Entity entity;
boolean hasBlockPos = false;
int blockX, blockY, blockZ;
IWailaCommonAccessor accessor = DataAccessorCommon.instance;
@@ -108,9 +108,14 @@ public class Tooltip {
this.stack = stack;
}
public Tooltip(List<String> textData, Entity entity) {
this(textData, entity != null && EntityIconRenderer.isEnabled());
this.entity = entity;
/**
* Sets the position of the block, so that the icon can show the block from the world.
*/
public void setBlockPos(int x, int y, int z) {
this.hasBlockPos = true;
this.blockX = x;
this.blockY = y;
this.blockZ = z;
}
public Tooltip(List<String> textData, boolean hasIcon) {
@@ -14,24 +14,20 @@ import net.minecraftforge.common.config.Configuration;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import mcp.mobius.waila.api.IWailaBlock;
import mcp.mobius.waila.api.impl.ConfigHandler;
import mcp.mobius.waila.api.impl.DataAccessorCommon;
import mcp.mobius.waila.api.impl.MetaDataProvider;
import mcp.mobius.waila.api.impl.ModuleRegistrar;
import mcp.mobius.waila.api.impl.TipList;
import mcp.mobius.waila.cbcore.Layout;
import mcp.mobius.waila.utils.Constants;
public class WailaTickHandler {
private static Tooltip tooltip = null;
private static World lastWorld = null;
private Tooltip tooltip = null;
private final MetaDataProvider handler = new MetaDataProvider();
private static void reset() {
tooltip = null;
RayTracing.instance().clear();
}
@SubscribeEvent
public void tickRender(TickEvent.RenderTickEvent event) {
if (event.phase == TickEvent.Phase.END) {
@@ -43,20 +39,17 @@ public class WailaTickHandler {
public void tickClient(TickEvent.ClientTickEvent event) {
if (event.phase == TickEvent.Phase.START) return;
Minecraft mc = Minecraft.getMinecraft();
World world = mc.theWorld;
// The tooltip and the ray trace target hold the entity, which holds the world
if (world != lastWorld) reset();
lastWorld = world;
if (!OverlayRenderer.isOverlayVisible()) {
reset();
this.tooltip = null;
RayTracing.instance().clear();
return;
}
RayTracing.instance().fire();
MovingObjectPosition target = RayTracing.instance().getTarget();
Minecraft mc = Minecraft.getMinecraft();
EntityPlayer player = mc.thePlayer;
World world = mc.theWorld;
List<String> currenttip;
List<String> currenttipHead;
@@ -105,7 +98,11 @@ public class WailaTickHandler {
currenttip.addAll(currenttipBody);
currenttip.addAll(currenttipTail);
tooltip = new Tooltip(currenttip, targetStack);
this.tooltip = new Tooltip(currenttip, targetStack);
// Only show the world block when no provider chose another stack (camo blocks, multiparts, ...)
if (!(accessor.getBlock() instanceof IWailaBlock)
&& !ModuleRegistrar.instance().hasStackProviders(accessor.getBlock()))
this.tooltip.setBlockPos(target.blockX, target.blockY, target.blockZ);
}
} else if (target != null && target.typeOfHit == MovingObjectPosition.MovingObjectType.ENTITY) {
DataAccessorCommon accessor = DataAccessorCommon.instance;
@@ -151,7 +148,7 @@ public class WailaTickHandler {
currenttip.addAll(currenttipBody);
currenttip.addAll(currenttipTail);
tooltip = new Tooltip(currenttip, targetEnt);
this.tooltip = new Tooltip(currenttip, false);
}
}
@@ -153,7 +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.general.showblockicon3d=Show 3D block icon
option.thaumcraft.aspects=Show aspects
nei.options.keys.showenchant=Show enchanting values