Compare commits

..
13 changed files with 341 additions and 176 deletions

No files matched your search

+2 -2
View File
@@ -3,9 +3,9 @@ name: Build and test
on: on:
pull_request: pull_request:
branches: [ master, main ] branches: [ master, main, release/** ]
push: push:
branches: [ master, main ] branches: [ master, main, release/** ]
jobs: jobs:
build-and-test: build-and-test:
+1
View File
@@ -6,6 +6,7 @@ dependencies {
shadowImplementation('au.com.bytecode:opencsv:2.4') shadowImplementation('au.com.bytecode:opencsv:2.4')
compileOnly("com.github.GTNewHorizons:GT5-Unofficial:5.09.52.463:dev") { transitive = false } compileOnly("com.github.GTNewHorizons:GT5-Unofficial:5.09.52.463:dev") { transitive = false }
compileOnly("com.github.GTNewHorizons:Dashboard:1.0.2:api")
runtimeOnlyNonPublishable("com.github.GTNewHorizons:WAILAPlugins:0.7.2:dev") { runtimeOnlyNonPublishable("com.github.GTNewHorizons:WAILAPlugins:0.7.2:dev") {
exclude group: 'com.github.GTNewHorizons', module: 'waila' exclude group: 'com.github.GTNewHorizons', module: 'waila'
+7 -2
View File
@@ -29,17 +29,19 @@ import mcp.mobius.waila.client.KeyEvent;
import mcp.mobius.waila.commands.CommandDumpHandlers; import mcp.mobius.waila.commands.CommandDumpHandlers;
import mcp.mobius.waila.network.NetworkHandler; import mcp.mobius.waila.network.NetworkHandler;
import mcp.mobius.waila.network.WailaPacketHandler; import mcp.mobius.waila.network.WailaPacketHandler;
import mcp.mobius.waila.overlay.DashboardHud;
import mcp.mobius.waila.overlay.DecoratorRenderer; import mcp.mobius.waila.overlay.DecoratorRenderer;
import mcp.mobius.waila.overlay.OverlayConfig; import mcp.mobius.waila.overlay.OverlayConfig;
import mcp.mobius.waila.overlay.WailaTickHandler; import mcp.mobius.waila.overlay.WailaTickHandler;
import mcp.mobius.waila.server.ProxyServer; import mcp.mobius.waila.server.ProxyServer;
import mcp.mobius.waila.utils.LoadedMods;
import mcp.mobius.waila.utils.ModIdentification; import mcp.mobius.waila.utils.ModIdentification;
@Mod( @Mod(
modid = "Waila", modid = "Waila",
name = "Waila", name = "Waila",
version = Tags.GRADLETOKEN_VERSION, version = Tags.GRADLETOKEN_VERSION,
dependencies = "after:NotEnoughItems@[1.0.4.0,)", dependencies = "after:NotEnoughItems@[1.0.4.0,);after:dashboard@[1.0.2,)",
acceptableRemoteVersions = "*", acceptableRemoteVersions = "*",
guiFactory = "mcp.mobius.waila.client.WailaGuiFactory") guiFactory = "mcp.mobius.waila.client.WailaGuiFactory")
public class Waila { public class Waila {
@@ -68,7 +70,10 @@ public class Waila {
if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) { if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) {
MinecraftForge.EVENT_BUS.register(new DecoratorRenderer()); MinecraftForge.EVENT_BUS.register(new DecoratorRenderer());
FMLCommonHandler.instance().bus().register(new KeyEvent()); FMLCommonHandler.instance().bus().register(new KeyEvent());
FMLCommonHandler.instance().bus().register(new WailaTickHandler()); WailaTickHandler tickHandler = new WailaTickHandler();
FMLCommonHandler.instance().bus().register(tickHandler);
MinecraftForge.EVENT_BUS.register(tickHandler);
if (LoadedMods.DASHBOARD) DashboardHud.register();
} }
FMLCommonHandler.instance().bus().register(new NetworkHandler()); FMLCommonHandler.instance().bus().register(new NetworkHandler());
} }
@@ -16,7 +16,7 @@ import mcp.mobius.waila.handlers.HUDHandlerBlocks;
import mcp.mobius.waila.handlers.HUDHandlerEntities; import mcp.mobius.waila.handlers.HUDHandlerEntities;
import mcp.mobius.waila.handlers.VanillaTooltipHandler; import mcp.mobius.waila.handlers.VanillaTooltipHandler;
import mcp.mobius.waila.handlers.nei.NEIHandler; import mcp.mobius.waila.handlers.nei.NEIHandler;
import mcp.mobius.waila.overlay.BreakProgressRenderer; import mcp.mobius.waila.overlay.EntityIconRenderer;
import mcp.mobius.waila.overlay.tooltiprenderers.TTRenderAspectString; import mcp.mobius.waila.overlay.tooltiprenderers.TTRenderAspectString;
import mcp.mobius.waila.overlay.tooltiprenderers.TTRenderBar; import mcp.mobius.waila.overlay.tooltiprenderers.TTRenderBar;
import mcp.mobius.waila.overlay.tooltiprenderers.TTRenderFluidBar; import mcp.mobius.waila.overlay.tooltiprenderers.TTRenderFluidBar;
@@ -54,8 +54,7 @@ public class ProxyClient extends ProxyServer {
ModuleRegistrar.instance().addConfig("General", "general.showents"); ModuleRegistrar.instance().addConfig("General", "general.showents");
ModuleRegistrar.instance().addConfig("General", "general.showhp"); ModuleRegistrar.instance().addConfig("General", "general.showhp");
ModuleRegistrar.instance().addConfig("General", "general.showcrop"); ModuleRegistrar.instance().addConfig("General", "general.showcrop");
ModuleRegistrar.instance().addConfig("General", BreakProgressRenderer.CFG_ENABLED, true); ModuleRegistrar.instance().addConfig("General", EntityIconRenderer.CFG_SHOW, true);
ModuleRegistrar.instance().addConfig("General", BreakProgressRenderer.CFG_TOP, false);
ModuleRegistrar.instance().registerTooltipRenderer("waila.health", new TTRenderHealth()); ModuleRegistrar.instance().registerTooltipRenderer("waila.health", new TTRenderHealth());
ModuleRegistrar.instance().registerTooltipRenderer("waila.stack", new TTRenderStack()); ModuleRegistrar.instance().registerTooltipRenderer("waila.stack", new TTRenderStack());
@@ -1,131 +0,0 @@
package mcp.mobius.waila.overlay;
import java.lang.reflect.Field;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.PlayerControllerMP;
import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeHooks;
import cpw.mods.fml.relauncher.ReflectionHelper;
import mcp.mobius.waila.Waila;
import mcp.mobius.waila.api.impl.ConfigHandler;
import mcp.mobius.waila.utils.ColorUtils;
/**
* Draws the block break progress as a thin line on the edge of the tooltip box (Jade style). Based on the break
* progress of WDMla (https://github.com/GTNewHorizons/WDMla).
*/
public final class BreakProgressRenderer {
public static final String CFG_ENABLED = "general.breakprogress";
public static final String CFG_TOP = "general.breakprogresstop";
/** Alpha change per game tick */
private static final float FADE_PER_TICK = 0.1f;
/** Alpha while mining. The line is fully opaque only in the last tick before the block breaks. */
private static final float MAX_ALPHA = 0.6f;
private static float progress;
private static float alpha;
private static boolean canHarvest = true;
private static long lastFrame;
private static World lastWorld;
private static int lastX, lastY, lastW, lastH;
private static Field curBlockDamageField;
private static boolean fieldFailed;
private BreakProgressRenderer() {}
private static boolean isEnabled() {
return ConfigHandler.instance().getConfig(CFG_ENABLED, true);
}
/**
* Updates the progress state. Call this one time per frame before you draw.
*/
public static void update(float partialTicks) {
final Minecraft mc = Minecraft.getMinecraft();
long now = Minecraft.getSystemTime();
// A paused or lagging client must not fade out in one step
float deltaTicks = Math.min((now - lastFrame) / 50f, 1f);
lastFrame = now;
if (mc.theWorld != lastWorld) {
lastWorld = mc.theWorld;
progress = alpha = 0;
}
if (!isEnabled() || mc.playerController == null || mc.theWorld == null || mc.thePlayer == null) {
progress = alpha = 0;
return;
}
float damage = getBlockDamage(mc.playerController);
MovingObjectPosition target = RayTracing.instance().getTarget();
if (damage <= 0 || target == null || target.typeOfHit != MovingObjectPosition.MovingObjectType.BLOCK) {
// Not mining (anymore), fade out the last progress
alpha = Math.max(alpha - deltaTicks * FADE_PER_TICK, 0f);
return;
}
int x = target.blockX, y = target.blockY, z = target.blockZ;
Block block = mc.theWorld.getBlock(x, y, z);
canHarvest = ForgeHooks.canHarvestBlock(block, mc.thePlayer, mc.theWorld.getBlockMetadata(x, y, z));
alpha = Math.min(alpha + deltaTicks * FADE_PER_TICK, MAX_ALPHA);
float perTick = block.getPlayerRelativeBlockHardness(mc.thePlayer, mc.theWorld, x, y, z);
if (damage + perTick >= 1f) {
// The block breaks in the next tick
alpha = progress = 1f;
} else {
progress = MathHelper.clamp_float(damage + partialTicks * perTick, 0f, 1f);
}
}
private static float getBlockDamage(PlayerControllerMP controller) {
if (fieldFailed) return 0f;
try {
if (curBlockDamageField == null) {
curBlockDamageField = ReflectionHelper
.findField(PlayerControllerMP.class, "curBlockDamageMP", "field_78770_f");
}
return curBlockDamageField.getFloat(controller);
} catch (Exception e) {
fieldFailed = true;
Waila.log.error("Cannot read the block damage, break progress is disabled", e);
return 0f;
}
}
/**
* Draws the line on the outer row of the tooltip box. The arguments are the box geometry from {@link Tooltip}.
*/
public static void draw(int x, int y, int w, int h) {
lastX = x;
lastY = y;
lastW = w;
lastH = h;
if (!isEnabled() || alpha <= 0) return;
int width = (int) ((w - 1) * progress);
if (width <= 0) return;
// Transparent as the box background
float boxAlpha = (OverlayConfig.alpha >>> 24) / 255f;
int base = canHarvest ? ColorUtils.breakProgress.getColor() : ColorUtils.breakProgressFailure.getColor();
int color = ((int) (((base >>> 24) & 0xFF) * alpha * boxAlpha) << 24) | (base & 0xFFFFFF);
boolean top = ConfigHandler.instance().getConfig(CFG_TOP, false);
DisplayUtil.drawGradientRect(x + 1, top ? y : y + h, width, 1, color, color);
}
/**
* Draws only the fading line, for when the tooltip itself is already gone.
*/
public static void drawLast() {
draw(lastX, lastY, lastW, lastH);
}
}
@@ -0,0 +1,102 @@
package mcp.mobius.waila.overlay;
import java.util.Arrays;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting;
import com.gtnewhorizons.dashboard.api.HudBounds;
import com.gtnewhorizons.dashboard.api.HudElement;
import com.gtnewhorizons.dashboard.api.HudRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/**
* Lets players move, resize and hide the info box in Dashboard's HUD editor. The only class using Dashboard, so only
* call it while Dashboard is loaded.
*/
@SideOnly(Side.CLIENT)
public final class DashboardHud {
private static final long SAMPLE_REUSE_MILLIS = 1000;
private static final HudElement INFO_BOX = new HudElement("waila:info_box", DashboardHud::getBounds)
.setOwnSettings("dashboard.element.waila.info_box.own_settings", "waila.keybind.wailaconfig");
private static Tooltip sample;
private static long lastSampleTime;
/** The box drawn last, before scaling, so the element follows its size and Waila's position setting. */
private static boolean boxDrawn;
private static int boxX;
private static int boxY;
private static int boxWidth;
private static int boxHeight;
private DashboardHud() {}
public static void register() {
INFO_BOX.setPreview((screenWidth, screenHeight) -> OverlayRenderer.drawPreview(getSample()));
HudRegistry.register(INFO_BOX);
}
/** The mod that drew the box, if not Waila, is shown next to Waila's name in the editor. */
static boolean beginBox(String drawnBy, int x, int y, int width, int height) {
INFO_BOX.setModNameAddon(drawnBy);
boxDrawn = true;
boxX = x;
boxY = y;
boxWidth = width;
boxHeight = height;
return HudRegistry.beginRender(INFO_BOX);
}
static void endBox() {
HudRegistry.endRender();
}
/**
* The same sample is kept while the editor is open, since a box drawn by another mod may start over for every new
* one. A new one is made after a break, so it follows changed Waila settings.
*/
private static Tooltip getSample() {
long now = System.currentTimeMillis();
if (sample == null || now - lastSampleTime > SAMPLE_REUSE_MILLIS) {
sample = createSample();
}
lastSampleTime = now;
return sample;
}
/** Stone, like looking at a block. */
private static Tooltip createSample() {
ItemStack stone = new ItemStack(Blocks.stone);
return new Tooltip(
Arrays.asList(
EnumChatFormatting.WHITE + stone.getDisplayName(),
EnumChatFormatting.BLUE.toString() + EnumChatFormatting.ITALIC + "Minecraft"),
stone);
}
/** Before the first box is drawn, the sample's place and size. */
private static HudBounds getBounds(int screenWidth, int screenHeight) {
if (!boxDrawn) {
if (sample == null) {
sample = createSample();
}
return getBounds(sample.x, sample.y, sample.w + 1, sample.h + 1);
}
return getBounds(boxX, boxY, boxWidth, boxHeight);
}
private static HudBounds getBounds(int x, int y, int width, int height) {
float scale = OverlayConfig.scale;
return new HudBounds(
Math.round(x * scale),
Math.round(y * scale),
Math.round(width * scale),
Math.round(height * scale));
}
}
@@ -0,0 +1,162 @@
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,17 +2,17 @@ package mcp.mobius.waila.overlay;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.RenderHelper; import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.entity.Entity;
import net.minecraft.util.MovingObjectPosition; import net.minecraft.util.MovingObjectPosition;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12; import org.lwjgl.opengl.GL12;
import mcp.mobius.waila.api.impl.ConfigHandler; import mcp.mobius.waila.api.impl.ConfigHandler;
import mcp.mobius.waila.utils.LoadedMods;
public class OverlayRenderer { public class OverlayRenderer {
private static boolean hasBlending;
private static boolean hasDepthTest;
private static int boundTexIndex; private static int boundTexIndex;
public static boolean isOverlayVisible() { public static boolean isOverlayVisible() {
@@ -23,17 +23,8 @@ public class OverlayRenderer {
&& ConfigHandler.instance().showTooltip()); && ConfigHandler.instance().showTooltip());
} }
public static void renderOverlay(Tooltip tooltip, float partialTicks) { public static void renderOverlay(Tooltip tooltip) {
if (!isOverlayVisible()) return; if (!isOverlayVisible() || RayTracing.instance().getTarget() == null) return;
BreakProgressRenderer.update(partialTicks);
if (RayTracing.instance().getTarget() == null
|| RayTracing.instance().getTarget().typeOfHit == MovingObjectPosition.MovingObjectType.MISS) {
// Keep drawing the progress bar while it fades out after the block was broken
BreakProgressRenderer.drawLast();
return;
}
if (RayTracing.instance().getTarget().typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK if (RayTracing.instance().getTarget().typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK
&& RayTracing.instance().getTargetStack() != null) { && RayTracing.instance().getTargetStack() != null) {
@@ -46,7 +37,32 @@ public class OverlayRenderer {
} }
} }
/** Draws a sample box, for previews like a HUD editor's. */
static void drawPreview(Tooltip tooltip) {
doRenderOverlay(tooltip);
}
/**
* Call right before drawing the info box, with its place and size before scaling, also when another mod draws the
* box. Lets a HUD editor move, resize or hide it. False means the box is hidden, so skip drawing it and do not call
* {@link #endBox()}.
*/
public static boolean beginBox(int x, int y, int width, int height) {
return beginBox(null, x, y, width, height);
}
/** Like {@link #beginBox(int, int, int, int)}, for a mod that draws the box itself, so a HUD editor can name it. */
public static boolean beginBox(String drawnBy, int x, int y, int width, int height) {
return !LoadedMods.DASHBOARD || DashboardHud.beginBox(drawnBy, x, y, width, height);
}
/** Call right after drawing the info box, only if {@link #beginBox} returned true. */
public static void endBox() {
if (LoadedMods.DASHBOARD) DashboardHud.endBox();
}
private static void doRenderOverlay(Tooltip tooltip) { private static void doRenderOverlay(Tooltip tooltip) {
if (!beginBox(tooltip.x, tooltip.y, tooltip.w + 1, tooltip.h + 1)) return;
GL11.glPushMatrix(); GL11.glPushMatrix();
saveGLState(); saveGLState();
@@ -67,8 +83,6 @@ public class OverlayRenderer {
OverlayConfig.gradient1, OverlayConfig.gradient1,
OverlayConfig.gradient2); OverlayConfig.gradient2);
BreakProgressRenderer.draw(tooltip.x, tooltip.y, tooltip.w, tooltip.h);
GL11.glEnable(GL11.GL_BLEND); GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
tooltip.draw(); tooltip.draw();
@@ -80,26 +94,24 @@ public class OverlayRenderer {
GL11.glEnable(GL12.GL_RESCALE_NORMAL); GL11.glEnable(GL12.GL_RESCALE_NORMAL);
Entity entity = tooltip.entity;
if (tooltip.hasIcon && tooltip.stack != null && tooltip.stack.getItem() != null) if (tooltip.hasIcon && tooltip.stack != null && tooltip.stack.getItem() != null)
DisplayUtil.renderStack(tooltip.x + 5, tooltip.y + tooltip.h / 2 - 8, tooltip.stack); 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(); loadGLState();
GL11.glPopMatrix(); GL11.glPopMatrix();
endBox();
} }
private static void saveGLState() { 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); 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() { 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.glBindTexture(GL11.GL_TEXTURE_2D, boundTexIndex);
GL11.glPopAttrib(); GL11.glPopAttrib();
} }
@@ -14,6 +14,7 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraftforge.common.config.Configuration; import net.minecraftforge.common.config.Configuration;
@@ -49,6 +50,7 @@ public class Tooltip {
Point pos; Point pos;
boolean hasIcon = false; boolean hasIcon = false;
ItemStack stack; ItemStack stack;
Entity entity;
IWailaCommonAccessor accessor = DataAccessorCommon.instance; IWailaCommonAccessor accessor = DataAccessorCommon.instance;
@@ -106,6 +108,11 @@ public class Tooltip {
this.stack = stack; this.stack = stack;
} }
public Tooltip(List<String> textData, Entity entity) {
this(textData, entity != null && EntityIconRenderer.isEnabled());
this.entity = entity;
}
public Tooltip(List<String> textData, boolean hasIcon) { public Tooltip(List<String> textData, boolean hasIcon) {
if (hasIcon) hasIcon = ConfigHandler.instance().showIcon(); if (hasIcon) hasIcon = ConfigHandler.instance().showIcon();
@@ -10,6 +10,7 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.MovingObjectPosition; import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.common.config.Configuration; import net.minecraftforge.common.config.Configuration;
import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.eventhandler.SubscribeEvent;
@@ -23,13 +24,19 @@ import mcp.mobius.waila.utils.Constants;
public class WailaTickHandler { public class WailaTickHandler {
private Tooltip tooltip = null; private static Tooltip tooltip = null;
private static World lastWorld = null;
private final MetaDataProvider handler = new MetaDataProvider(); private final MetaDataProvider handler = new MetaDataProvider();
private static void reset() {
tooltip = null;
RayTracing.instance().clear();
}
@SubscribeEvent @SubscribeEvent
public void tickRender(TickEvent.RenderTickEvent event) { public void onRenderOverlay(RenderGameOverlayEvent.Post event) {
if (event.phase == TickEvent.Phase.END) { if (event.type == RenderGameOverlayEvent.ElementType.ALL) {
OverlayRenderer.renderOverlay(tooltip, event.renderTickTime); OverlayRenderer.renderOverlay(tooltip);
} }
} }
@@ -37,17 +44,20 @@ public class WailaTickHandler {
public void tickClient(TickEvent.ClientTickEvent event) { public void tickClient(TickEvent.ClientTickEvent event) {
if (event.phase == TickEvent.Phase.START) return; 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()) { if (!OverlayRenderer.isOverlayVisible()) {
this.tooltip = null; reset();
RayTracing.instance().clear();
return; return;
} }
RayTracing.instance().fire(); RayTracing.instance().fire();
MovingObjectPosition target = RayTracing.instance().getTarget(); MovingObjectPosition target = RayTracing.instance().getTarget();
Minecraft mc = Minecraft.getMinecraft();
EntityPlayer player = mc.thePlayer; EntityPlayer player = mc.thePlayer;
World world = mc.theWorld;
List<String> currenttip; List<String> currenttip;
List<String> currenttipHead; List<String> currenttipHead;
@@ -96,7 +106,7 @@ public class WailaTickHandler {
currenttip.addAll(currenttipBody); currenttip.addAll(currenttipBody);
currenttip.addAll(currenttipTail); currenttip.addAll(currenttipTail);
this.tooltip = new Tooltip(currenttip, targetStack); tooltip = new Tooltip(currenttip, targetStack);
} }
} else if (target != null && target.typeOfHit == MovingObjectPosition.MovingObjectType.ENTITY) { } else if (target != null && target.typeOfHit == MovingObjectPosition.MovingObjectType.ENTITY) {
DataAccessorCommon accessor = DataAccessorCommon.instance; DataAccessorCommon accessor = DataAccessorCommon.instance;
@@ -142,7 +152,7 @@ public class WailaTickHandler {
currenttip.addAll(currenttipBody); currenttip.addAll(currenttipBody);
currenttip.addAll(currenttipTail); currenttip.addAll(currenttipTail);
this.tooltip = new Tooltip(currenttip, false); tooltip = new Tooltip(currenttip, targetEnt);
} }
} }
@@ -11,9 +11,7 @@ public class ColorUtils {
fuelFurnaceBarTop = color.argb("fuelFurnaceBarTop", "0xFFFF8800"), fuelFurnaceBarTop = color.argb("fuelFurnaceBarTop", "0xFFFF8800"),
fuelFurnaceBarBottom = color.argb("fuelFurnaceBarBottom", "0xFFFFCC00"), fuelFurnaceBarBottom = color.argb("fuelFurnaceBarBottom", "0xFFFFCC00"),
progressBarTop = color.argb("progressBarTop", "0xFFFF0000"), progressBarTop = color.argb("progressBarTop", "0xFFFF0000"),
progressBarBottom = color.argb("progressBarBottom", "0xFF8B0000"), progressBarBottom = color.argb("progressBarBottom", "0xFF8B0000");
breakProgress = color.argb("breakProgress", "0xFFFFFFFF"),
breakProgressFailure = color.argb("breakProgressFailure", "0xFFAA0000");
// spotless:on // spotless:on
} }
@@ -8,4 +8,5 @@ public class LoadedMods {
public static boolean NEI = Loader.isModLoaded("NotEnoughItems"); public static boolean NEI = Loader.isModLoaded("NotEnoughItems");
public static boolean GT5U = Loader.isModLoaded("gregtech_nh"); public static boolean GT5U = Loader.isModLoaded("gregtech_nh");
public static boolean WAILA_PLUGINS = Loader.isModLoaded("wailaplugins"); public static boolean WAILA_PLUGINS = Loader.isModLoaded("wailaplugins");
public static boolean DASHBOARD = Loader.isModLoaded("dashboard");
} }
@@ -153,8 +153,7 @@ option.stevescarts.shifttoggle=Shift toggle
option.general.showents=Show entities option.general.showents=Show entities
option.general.showhp=Show entities health option.general.showhp=Show entities health
option.general.showcrop=Show crop growth option.general.showcrop=Show crop growth
option.general.breakprogress=Show break progress option.general.showentityicon=Show entity icon
option.general.breakprogresstop=Break progress on top
option.thaumcraft.aspects=Show aspects option.thaumcraft.aspects=Show aspects
nei.options.keys.showenchant=Show enchanting values nei.options.keys.showenchant=Show enchanting values