mirror of
https://github.com/GTNewHorizons/waila.git
synced 2026-11-15 17:44:46 +00:00
Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
848d45d16e | ||
|
|
eaf618664e | ||
|
|
4e6e1a21ea | ||
|
|
54831dbbd3 | ||
|
|
f998f9ebfe | ||
|
|
6d0f162453 | ||
|
|
9e3ef39e30 |
No files matched your search
+1
-1
@@ -20,5 +20,5 @@ dependencies {
|
||||
runtimeOnlyNonPublishable(deobfCurse('thermal-expansion-69163:2388759'))
|
||||
runtimeOnlyNonPublishable(deobfCurse('thermal-dynamics-227443:2388756'))
|
||||
implementation(deobfCurse('cofh-core-69162:2388751'))
|
||||
api("com.github.GTNewHorizons:GTNHLib:0.9.54:dev")
|
||||
api("com.github.GTNewHorizons:GTNHLib:0.11.37:dev")
|
||||
}
|
||||
@@ -2,21 +2,29 @@ package mcp.mobius.waila.addons.vanillamc;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.tileentity.TileEntityFurnace;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import cpw.mods.fml.common.registry.GameData;
|
||||
import mcp.mobius.waila.api.IWailaConfigHandler;
|
||||
import mcp.mobius.waila.api.IWailaDataAccessor;
|
||||
import mcp.mobius.waila.api.IWailaDataProvider;
|
||||
import mcp.mobius.waila.api.SpecialChars;
|
||||
import mcp.mobius.waila.api.impl.ModuleRegistrar;
|
||||
import mcp.mobius.waila.overlay.tooltiprenderers.TTRenderBar;
|
||||
import mcp.mobius.waila.overlay.tooltiprenderers.TTRenderProgressBar;
|
||||
import mcp.mobius.waila.overlay.tooltiprenderers.TTRenderStack;
|
||||
import mcp.mobius.waila.utils.ColorUtils;
|
||||
|
||||
public class HUDHandlerFurnace implements IWailaDataProvider {
|
||||
|
||||
static Block furanace = Blocks.furnace;
|
||||
|
||||
@Override
|
||||
public ItemStack getWailaStack(IWailaDataAccessor accessor, IWailaConfigHandler config) {
|
||||
return null;
|
||||
@@ -31,45 +39,68 @@ public class HUDHandlerFurnace implements IWailaDataProvider {
|
||||
@Override
|
||||
public List<String> getWailaBody(ItemStack itemStack, List<String> currenttip, IWailaDataAccessor accessor,
|
||||
IWailaConfigHandler config) {
|
||||
int cookTime = accessor.getNBTData().getShort("CookTime");
|
||||
NBTTagList tag = accessor.getNBTData().getTagList("Items", 10);
|
||||
NBTTagCompound tag = accessor.getNBTData();
|
||||
NBTTagList items = accessor.getNBTData().getTagList("Items", 10);
|
||||
String itemsText = "";
|
||||
ItemStack inputStack = null;
|
||||
ItemStack fuelStack = null;
|
||||
ItemStack outputStack = null;
|
||||
|
||||
String renderStr = "";
|
||||
{
|
||||
ItemStack stack = ItemStack.loadItemStackFromNBT(tag.getCompoundTagAt(0));
|
||||
String name = GameData.getItemRegistry().getNameForObject(stack.getItem());
|
||||
renderStr += SpecialChars.getRenderString(
|
||||
"waila.stack",
|
||||
"1",
|
||||
name,
|
||||
String.valueOf(stack.stackSize),
|
||||
String.valueOf(stack.getItemDamage()));
|
||||
}
|
||||
{
|
||||
ItemStack stack = ItemStack.loadItemStackFromNBT(tag.getCompoundTagAt(1));
|
||||
String name = GameData.getItemRegistry().getNameForObject(stack.getItem());
|
||||
renderStr += SpecialChars.getRenderString(
|
||||
"waila.stack",
|
||||
"1",
|
||||
name,
|
||||
String.valueOf(stack.stackSize),
|
||||
String.valueOf(stack.getItemDamage()));
|
||||
int smeltTime = tag.getInteger("Smelt");
|
||||
int fuelTime = tag.getInteger("Fuel");
|
||||
int maxFuelTime = tag.getInteger("MaxFuel");
|
||||
|
||||
double smeltProgress = (double) smeltTime / 200;
|
||||
double fuelProgress = (double) fuelTime / maxFuelTime;
|
||||
|
||||
for (int i = 0; i < items.tagCount(); i++) {
|
||||
NBTTagCompound itemTag = items.getCompoundTagAt(i);
|
||||
byte slot = itemTag.getByte("Slot");
|
||||
ItemStack stack = ItemStack.loadItemStackFromNBT(itemTag);
|
||||
|
||||
if (slot == 0) {
|
||||
inputStack = stack;
|
||||
} else if (slot == 1) {
|
||||
fuelStack = stack;
|
||||
} else if (slot == 2) {
|
||||
outputStack = stack;
|
||||
}
|
||||
}
|
||||
|
||||
renderStr += SpecialChars.getRenderString("waila.progress", String.valueOf(cookTime), String.valueOf(200));
|
||||
|
||||
{
|
||||
ItemStack stack = ItemStack.loadItemStackFromNBT(tag.getCompoundTagAt(2));
|
||||
String name = GameData.getItemRegistry().getNameForObject(stack.getItem());
|
||||
renderStr += SpecialChars.getRenderString(
|
||||
"waila.stack",
|
||||
"1",
|
||||
name,
|
||||
String.valueOf(stack.stackSize),
|
||||
String.valueOf(stack.getItemDamage()));
|
||||
if (fuelProgress > 0) {
|
||||
String fuelBar = TTRenderBar.create(
|
||||
String.format("Fuel %ds / %ds", (maxFuelTime - fuelTime) / 20, maxFuelTime / 20),
|
||||
ColorUtils.fuelFurnaceBarTop.getColor(),
|
||||
ColorUtils.fuelFurnaceBarBottom.getColor(),
|
||||
1.0 - fuelProgress);
|
||||
currenttip.add(fuelBar);
|
||||
}
|
||||
|
||||
currenttip.add(renderStr);
|
||||
if (smeltProgress > 0) {
|
||||
String cookBar = TTRenderBar.create(
|
||||
String.format("Smelt %ds / %ds", smeltTime / 20, 200 / 20),
|
||||
ColorUtils.progressBarTop.getColor(),
|
||||
ColorUtils.progressBarBottom.getColor(),
|
||||
smeltProgress);
|
||||
currenttip.add(cookBar);
|
||||
}
|
||||
|
||||
if (inputStack != null) {
|
||||
itemsText += TTRenderStack.create(inputStack, inputStack.stackSize);
|
||||
}
|
||||
|
||||
if (fuelStack != null) {
|
||||
itemsText += TTRenderStack.create(fuelStack, fuelStack.stackSize);
|
||||
}
|
||||
|
||||
if (outputStack != null) {
|
||||
if (inputStack != null || fuelStack != null) {
|
||||
itemsText += TTRenderProgressBar.create(0, 1);
|
||||
}
|
||||
itemsText += TTRenderStack.create(outputStack, outputStack.stackSize);
|
||||
}
|
||||
|
||||
currenttip.add(itemsText);
|
||||
|
||||
return currenttip;
|
||||
}
|
||||
@@ -83,9 +114,19 @@ public class HUDHandlerFurnace implements IWailaDataProvider {
|
||||
@Override
|
||||
public NBTTagCompound getNBTData(EntityPlayerMP player, TileEntity te, NBTTagCompound tag, World world, int x,
|
||||
int y, int z) {
|
||||
if (te != null) te.writeToNBT(tag);
|
||||
if (te instanceof TileEntityFurnace furnace) {
|
||||
tag.setInteger("Smelt", furnace.furnaceCookTime);
|
||||
tag.setInteger("Fuel", furnace.furnaceBurnTime);
|
||||
tag.setInteger("MaxFuel", furnace.currentItemBurnTime);
|
||||
te.writeToNBT(tag);
|
||||
}
|
||||
return tag;
|
||||
}
|
||||
|
||||
public static void register() {}
|
||||
public static void register() {
|
||||
IWailaDataProvider provider = new HUDHandlerFurnace();
|
||||
|
||||
ModuleRegistrar.instance().registerBodyProvider(provider, furanace.getClass());
|
||||
ModuleRegistrar.instance().registerNBTProvider(provider, furanace.getClass());
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,9 @@ 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.BlockIconRenderer;
|
||||
import mcp.mobius.waila.overlay.tooltiprenderers.TTRenderAspectString;
|
||||
import mcp.mobius.waila.overlay.tooltiprenderers.TTRenderBar;
|
||||
import mcp.mobius.waila.overlay.tooltiprenderers.TTRenderFluidBar;
|
||||
import mcp.mobius.waila.overlay.tooltiprenderers.TTRenderHealth;
|
||||
import mcp.mobius.waila.overlay.tooltiprenderers.TTRenderProgressBar;
|
||||
@@ -52,9 +54,11 @@ 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", BlockIconRenderer.CFG_SHOW, true);
|
||||
|
||||
ModuleRegistrar.instance().registerTooltipRenderer("waila.health", new TTRenderHealth());
|
||||
ModuleRegistrar.instance().registerTooltipRenderer("waila.stack", new TTRenderStack());
|
||||
ModuleRegistrar.instance().registerTooltipRenderer("waila.bar", new TTRenderBar());
|
||||
ModuleRegistrar.instance().registerTooltipRenderer("waila.progress", new TTRenderProgressBar());
|
||||
ModuleRegistrar.instance().registerTooltipRenderer("waila.fluid", new TTRenderFluidBar());
|
||||
ModuleRegistrar.instance().registerTooltipRenderer("waila.rfenergy", new TTRenderRFBar());
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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() {
|
||||
@@ -69,7 +67,16 @@ public class OverlayRenderer {
|
||||
|
||||
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
|
||||
|
||||
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);
|
||||
|
||||
loadGLState();
|
||||
@@ -78,17 +85,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; 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);
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -49,6 +49,8 @@ public class Tooltip {
|
||||
Point pos;
|
||||
boolean hasIcon = false;
|
||||
ItemStack stack;
|
||||
boolean hasBlockPos = false;
|
||||
int blockX, blockY, blockZ;
|
||||
|
||||
IWailaCommonAccessor accessor = DataAccessorCommon.instance;
|
||||
|
||||
@@ -106,6 +108,16 @@ public class Tooltip {
|
||||
this.stack = stack;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
|
||||
if (hasIcon) hasIcon = ConfigHandler.instance().showIcon();
|
||||
|
||||
@@ -14,9 +14,11 @@ 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;
|
||||
@@ -97,6 +99,10 @@ public class WailaTickHandler {
|
||||
currenttip.addAll(currenttipTail);
|
||||
|
||||
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;
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
package mcp.mobius.waila.overlay.tooltiprenderers;
|
||||
|
||||
import java.awt.Dimension;
|
||||
|
||||
import net.minecraft.client.gui.Gui;
|
||||
|
||||
import mcp.mobius.waila.api.IWailaCommonAccessor;
|
||||
import mcp.mobius.waila.api.IWailaVariableWidthTooltipRenderer;
|
||||
import mcp.mobius.waila.api.SpecialChars;
|
||||
import mcp.mobius.waila.overlay.DisplayUtil;
|
||||
|
||||
public class TTRenderBar implements IWailaVariableWidthTooltipRenderer {
|
||||
|
||||
private int maxStringW;
|
||||
private static final int HEIGHT = 12;
|
||||
|
||||
@Override
|
||||
public Dimension getSize(String[] params, IWailaCommonAccessor accessor) {
|
||||
String text = params[0];
|
||||
|
||||
int displayWidth = DisplayUtil.getDisplayWidth(text);
|
||||
|
||||
return new Dimension(displayWidth + 4, HEIGHT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(String[] params, IWailaCommonAccessor accessor) {
|
||||
String text = params[0];
|
||||
int topColor = 0xFFFFEE55;
|
||||
int bottomColor = 0xFFFFA500;
|
||||
int fillWidth = maxStringW - 2;
|
||||
|
||||
if (params.length > 2) {
|
||||
try {
|
||||
topColor = Integer.parseInt(params[1]);
|
||||
bottomColor = Integer.parseInt(params[2]);
|
||||
|
||||
} catch (NumberFormatException ignored) {}
|
||||
}
|
||||
|
||||
if (params.length > 3) {
|
||||
try {
|
||||
double ratio = Double.parseDouble(params[3]);
|
||||
ratio = Math.max(0.0, Math.min(1.0, ratio));
|
||||
fillWidth = (int) ((maxStringW - 2) * ratio);
|
||||
} catch (NumberFormatException ignored) {}
|
||||
}
|
||||
|
||||
drawVerticalGradient(maxStringW - 1, 0xFF2A2A2A, 0xFF111111);
|
||||
|
||||
if (fillWidth > 0) {
|
||||
drawVerticalGradient(1 + fillWidth, topColor, bottomColor);
|
||||
}
|
||||
|
||||
DisplayUtil.drawThickBeveledBox(0, 0, maxStringW, HEIGHT, 1, 0xFF505050, 0xFF505050, -1);
|
||||
DisplayUtil.drawString(text, 2, 2, 0xFFFFFFFF, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxLineWidth(int width) {
|
||||
maxStringW = width;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxLineWidth() {
|
||||
return maxStringW;
|
||||
}
|
||||
|
||||
private void drawVerticalGradient(int x2, int topColor, int bottomColor) {
|
||||
int h = 11;
|
||||
if (x2 <= 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < h; i++) {
|
||||
float ratio = (float) i / (float) h;
|
||||
int color = blendColors(topColor, bottomColor, ratio);
|
||||
Gui.drawRect(1, i, x2, i + 1, color);
|
||||
}
|
||||
}
|
||||
|
||||
private int blendColors(int c1, int c2, float ratio) {
|
||||
int a1 = (c1 >> 24 & 0xFF), r1 = (c1 >> 16 & 0xFF), g1 = (c1 >> 8 & 0xFF), b1 = (c1 & 0xFF);
|
||||
int a2 = (c2 >> 24 & 0xFF), r2 = (c2 >> 16 & 0xFF), g2 = (c2 >> 8 & 0xFF), b2 = (c2 & 0xFF);
|
||||
|
||||
int a = (int) (a1 + (a2 - a1) * ratio);
|
||||
int r = (int) (r1 + (r2 - r1) * ratio);
|
||||
int g = (int) (g1 + (g2 - g1) * ratio);
|
||||
int b = (int) (b1 + (b2 - b1) * ratio);
|
||||
|
||||
return (a << 24) | (r << 16) | (g << 8) | b;
|
||||
}
|
||||
|
||||
public static String create(String text, int topColor, int bottomColor, double progress) {
|
||||
return SpecialChars.getRenderString(
|
||||
"waila.bar",
|
||||
text,
|
||||
String.valueOf(topColor),
|
||||
String.valueOf(bottomColor),
|
||||
String.valueOf(progress));
|
||||
}
|
||||
|
||||
public static String create(String text, int color, double progress) {
|
||||
return create(text, color, color, progress);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import mcp.mobius.waila.api.IWailaCommonAccessor;
|
||||
import mcp.mobius.waila.api.IWailaTooltipRenderer;
|
||||
import mcp.mobius.waila.api.SpecialChars;
|
||||
import mcp.mobius.waila.overlay.DisplayUtil;
|
||||
|
||||
public class TTRenderProgressBar implements IWailaTooltipRenderer {
|
||||
@@ -33,4 +34,8 @@ public class TTRenderProgressBar implements IWailaTooltipRenderer {
|
||||
|
||||
}
|
||||
|
||||
public static String create(int currentValue, int maxValue) {
|
||||
return SpecialChars.getRenderString("waila.progress", String.valueOf(currentValue), String.valueOf(maxValue));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -44,7 +44,7 @@ public class TTRenderStack implements IWailaTooltipRenderer {
|
||||
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
|
||||
GL11.glScaled(scale, scale, 1.0f);
|
||||
|
||||
DisplayUtil.renderStack(0, 0, stack);
|
||||
DisplayUtil.renderStack(0, -1, stack);
|
||||
|
||||
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
|
||||
GL11.glPopMatrix();
|
||||
@@ -69,4 +69,12 @@ public class TTRenderStack implements IWailaTooltipRenderer {
|
||||
public static String create(ItemStack itemStack, boolean small) {
|
||||
return create(itemStack, 1, small);
|
||||
}
|
||||
|
||||
public static String create(ItemStack itemStack) {
|
||||
return create(itemStack, false);
|
||||
}
|
||||
|
||||
public static String create(ItemStack itemStack, int amount) {
|
||||
return create(itemStack, amount, false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package mcp.mobius.waila.utils;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.color.ColorResource;
|
||||
|
||||
public class ColorUtils {
|
||||
|
||||
private static final ColorResource.Factory color = new ColorResource.Factory("waila");
|
||||
|
||||
public static final ColorResource
|
||||
// spotless:off
|
||||
fuelFurnaceBarTop = color.argb("fuelFurnaceBarTop", "0xFFFF8800"),
|
||||
fuelFurnaceBarBottom = color.argb("fuelFurnaceBarBottom", "0xFFFFCC00"),
|
||||
progressBarTop = color.argb("progressBarTop", "0xFFFF0000"),
|
||||
progressBarBottom = color.argb("progressBarBottom", "0xFF8B0000");
|
||||
// spotless:on
|
||||
|
||||
}
|
||||
@@ -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.showblockicon3d=Show 3D block icon
|
||||
option.thaumcraft.aspects=Show aspects
|
||||
|
||||
nei.options.keys.showenchant=Show enchanting values
|
||||
Reference in new issue
Block a user