mirror of
https://github.com/GTNewHorizons/waila.git
synced 2026-11-15 09:34:53 +00:00
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
76406153ee | ||
|
|
cb1b75a17b | ||
|
|
f172a0dbb0 |
No files matched your search
@@ -6,7 +6,6 @@ dependencies {
|
||||
shadowImplementation('au.com.bytecode:opencsv:2.4')
|
||||
|
||||
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") {
|
||||
exclude group: 'com.github.GTNewHorizons', module: 'waila'
|
||||
|
||||
@@ -29,19 +29,17 @@ import mcp.mobius.waila.client.KeyEvent;
|
||||
import mcp.mobius.waila.commands.CommandDumpHandlers;
|
||||
import mcp.mobius.waila.network.NetworkHandler;
|
||||
import mcp.mobius.waila.network.WailaPacketHandler;
|
||||
import mcp.mobius.waila.overlay.DashboardHud;
|
||||
import mcp.mobius.waila.overlay.DecoratorRenderer;
|
||||
import mcp.mobius.waila.overlay.OverlayConfig;
|
||||
import mcp.mobius.waila.overlay.WailaTickHandler;
|
||||
import mcp.mobius.waila.server.ProxyServer;
|
||||
import mcp.mobius.waila.utils.LoadedMods;
|
||||
import mcp.mobius.waila.utils.ModIdentification;
|
||||
|
||||
@Mod(
|
||||
modid = "Waila",
|
||||
name = "Waila",
|
||||
version = Tags.GRADLETOKEN_VERSION,
|
||||
dependencies = "after:NotEnoughItems@[1.0.4.0,);after:dashboard@[1.0.2,)",
|
||||
dependencies = "after:NotEnoughItems@[1.0.4.0,)",
|
||||
acceptableRemoteVersions = "*",
|
||||
guiFactory = "mcp.mobius.waila.client.WailaGuiFactory")
|
||||
public class Waila {
|
||||
@@ -71,7 +69,6 @@ public class Waila {
|
||||
MinecraftForge.EVENT_BUS.register(new DecoratorRenderer());
|
||||
FMLCommonHandler.instance().bus().register(new KeyEvent());
|
||||
FMLCommonHandler.instance().bus().register(new WailaTickHandler());
|
||||
if (LoadedMods.DASHBOARD) DashboardHud.register();
|
||||
}
|
||||
FMLCommonHandler.instance().bus().register(new NetworkHandler());
|
||||
}
|
||||
|
||||
@@ -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.BreakProgressRenderer;
|
||||
import mcp.mobius.waila.overlay.tooltiprenderers.TTRenderAspectString;
|
||||
import mcp.mobius.waila.overlay.tooltiprenderers.TTRenderBar;
|
||||
import mcp.mobius.waila.overlay.tooltiprenderers.TTRenderFluidBar;
|
||||
@@ -53,6 +54,8 @@ 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", BreakProgressRenderer.CFG_ENABLED, true);
|
||||
ModuleRegistrar.instance().addConfig("General", BreakProgressRenderer.CFG_TOP, false);
|
||||
|
||||
ModuleRegistrar.instance().registerTooltipRenderer("waila.health", new TTRenderHealth());
|
||||
ModuleRegistrar.instance().registerTooltipRenderer("waila.stack", new TTRenderStack());
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,102 +0,0 @@
|
||||
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));
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,6 @@ import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL12;
|
||||
|
||||
import mcp.mobius.waila.api.impl.ConfigHandler;
|
||||
import mcp.mobius.waila.utils.LoadedMods;
|
||||
|
||||
public class OverlayRenderer {
|
||||
|
||||
@@ -24,8 +23,17 @@ public class OverlayRenderer {
|
||||
&& ConfigHandler.instance().showTooltip());
|
||||
}
|
||||
|
||||
public static void renderOverlay(Tooltip tooltip) {
|
||||
if (!isOverlayVisible() || RayTracing.instance().getTarget() == null) return;
|
||||
public static void renderOverlay(Tooltip tooltip, float partialTicks) {
|
||||
if (!isOverlayVisible()) 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
|
||||
&& RayTracing.instance().getTargetStack() != null) {
|
||||
@@ -38,32 +46,7 @@ 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) {
|
||||
if (!beginBox(tooltip.x, tooltip.y, tooltip.w + 1, tooltip.h + 1)) return;
|
||||
|
||||
GL11.glPushMatrix();
|
||||
saveGLState();
|
||||
@@ -84,6 +67,8 @@ public class OverlayRenderer {
|
||||
OverlayConfig.gradient1,
|
||||
OverlayConfig.gradient2);
|
||||
|
||||
BreakProgressRenderer.draw(tooltip.x, tooltip.y, tooltip.w, tooltip.h);
|
||||
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
tooltip.draw();
|
||||
@@ -100,7 +85,7 @@ public class OverlayRenderer {
|
||||
|
||||
loadGLState();
|
||||
GL11.glPopMatrix();
|
||||
endBox();
|
||||
|
||||
}
|
||||
|
||||
private static void saveGLState() {
|
||||
|
||||
@@ -29,7 +29,7 @@ public class WailaTickHandler {
|
||||
@SubscribeEvent
|
||||
public void tickRender(TickEvent.RenderTickEvent event) {
|
||||
if (event.phase == TickEvent.Phase.END) {
|
||||
OverlayRenderer.renderOverlay(tooltip);
|
||||
OverlayRenderer.renderOverlay(tooltip, event.renderTickTime);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,9 @@ public class ColorUtils {
|
||||
fuelFurnaceBarTop = color.argb("fuelFurnaceBarTop", "0xFFFF8800"),
|
||||
fuelFurnaceBarBottom = color.argb("fuelFurnaceBarBottom", "0xFFFFCC00"),
|
||||
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
|
||||
|
||||
}
|
||||
@@ -8,5 +8,4 @@ public class LoadedMods {
|
||||
public static boolean NEI = Loader.isModLoaded("NotEnoughItems");
|
||||
public static boolean GT5U = Loader.isModLoaded("gregtech_nh");
|
||||
public static boolean WAILA_PLUGINS = Loader.isModLoaded("wailaplugins");
|
||||
public static boolean DASHBOARD = Loader.isModLoaded("dashboard");
|
||||
}
|
||||
@@ -153,6 +153,8 @@ option.stevescarts.shifttoggle=Shift toggle
|
||||
option.general.showents=Show entities
|
||||
option.general.showhp=Show entities health
|
||||
option.general.showcrop=Show crop growth
|
||||
option.general.breakprogress=Show break progress
|
||||
option.general.breakprogresstop=Break progress on top
|
||||
option.thaumcraft.aspects=Show aspects
|
||||
|
||||
nei.options.keys.showenchant=Show enchanting values
|
||||
Reference in new issue
Block a user