From d8ca2fbd5442e2a8eef2cdfd69a84282d287932c Mon Sep 17 00:00:00 2001 From: Charles Howard Date: Thu, 9 Feb 2017 22:27:59 -0500 Subject: [PATCH] All display are now working along with config options --- .../config/ConfigurationHandler.java | 4 +- .../torohealthmod/display/BarDisplay.java | 92 ++++++++++++++++++ .../torohealthmod/display/EntityDisplay.java | 47 ++++----- .../torohealthmod/display/HeartsDisplay.java | 23 +---- .../torohealthmod/display/NumericDisplay.java | 2 +- .../torohealthmod/gui/GuiEntityStatus.java | 78 ++++++++++----- .../torohealthmod/textures/gui/bars.png | Bin 0 -> 1550 bytes 7 files changed, 178 insertions(+), 68 deletions(-) create mode 100644 java/net/torocraft/torohealthmod/display/BarDisplay.java create mode 100644 resources/assets/torohealthmod/textures/gui/bars.png diff --git a/java/net/torocraft/torohealthmod/config/ConfigurationHandler.java b/java/net/torocraft/torohealthmod/config/ConfigurationHandler.java index 27aca1a..5f2d1ac 100644 --- a/java/net/torocraft/torohealthmod/config/ConfigurationHandler.java +++ b/java/net/torocraft/torohealthmod/config/ConfigurationHandler.java @@ -32,8 +32,8 @@ public static void loadConfiguration() { try { showEntityModel = config.getBoolean("Show 3D Model of Entity", Configuration.CATEGORY_CLIENT, true, "Shows a 3D model of the entity being targeted"); showDamageParticles = config.getBoolean("Show Damage Particles", Configuration.CATEGORY_CLIENT, true, "Show Damage Indicators"); - entityStatusDisplay = config.getString("Health Bar Display", Configuration.CATEGORY_CLIENT, "HEARTS", "Display Health Bars", new String[] { "HEARTS", "NUMERIC", "OFF" }); - statusDisplayPosition = config.getString("Health Bar Position", Configuration.CATEGORY_CLIENT, "TOP LEFT", "Location of Health Bar", new String[] { "TOP LEFT", "TOP CENTER", "TOP RIGHT", "BOTTOM LEFT", "BOTTOM RIGHT", "CUSTOM" }); + entityStatusDisplay = config.getString("Health Bar Display", Configuration.CATEGORY_CLIENT, "HEARTS", "Display Health Bars", new String[] { "HEARTS", "NUMERIC", "BAR", "OFF" }); + statusDisplayPosition = config.getString("Health Bar Position", Configuration.CATEGORY_CLIENT, "TOP LEFT", "Location of Health Bar", new String[] { "TOP LEFT", "TOP CENTER", "TOP RIGHT", "BOTTOM LEFT", "BOTTOM RIGHT" }); statusDisplayX = config.getInt("Health Bar X", Configuration.CATEGORY_CLIENT, 0, -20000, 20000, "With CUSTOM position, sets X position of Health Bar"); statusDisplayY = config.getInt("Health Bar Y", Configuration.CATEGORY_CLIENT, 0, -20000, 20000, "With CUSTOM position, sets Y position of Health Bar"); damageColor = mapColor(config.getString("Damage Color", Configuration.CATEGORY_CLIENT, "RED", "Damage Text Color", acceptedColors)); diff --git a/java/net/torocraft/torohealthmod/display/BarDisplay.java b/java/net/torocraft/torohealthmod/display/BarDisplay.java new file mode 100644 index 0000000..2563028 --- /dev/null +++ b/java/net/torocraft/torohealthmod/display/BarDisplay.java @@ -0,0 +1,92 @@ +package net.torocraft.torohealthmod.display; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.monster.EntityMob; +import net.minecraft.entity.monster.EntitySlime; +import net.minecraft.entity.passive.EntityAmbientCreature; +import net.minecraft.entity.passive.EntityAnimal; +import net.minecraft.util.ResourceLocation; +import net.torocraft.torohealthmod.ToroHealthMod; + +public class BarDisplay implements ToroHealthDisplay { + + private static final ResourceLocation GUI_BARS_TEXTURES = new ResourceLocation(ToroHealthMod.MODID, "textures/gui/bars.png"); + + private static final int BAR_WIDTH = 92; + + private final Minecraft mc; + private final Gui gui; + private int y; + private int barX; + private int barY; + + private EntityLivingBase entity; + + public BarDisplay(Minecraft mc, Gui gui) { + this.mc = mc; + this.gui = gui; + } + + @Override + public void setPosition(int x, int y) { + this.y = y; + barX = x + 2; + barY = y + 12; + } + + @Override + public void draw() { + if (entity == null) { + return; + } + renderBossHealth(); + } + + public void renderBossHealth() { + String name = entity.getDisplayName().getFormattedText(); + String health = (int) Math.ceil(entity.getHealth()) + "/" + (int) entity.getMaxHealth(); + + GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); + mc.getTextureManager().bindTexture(GUI_BARS_TEXTURES); + renderHealthBar(); + mc.fontRendererObj.drawStringWithShadow(name, barX, y + 2, 16777215); + mc.fontRendererObj.drawStringWithShadow(health, barX, y + 20, 16777215); + } + + public static enum Color { + PINK, BLUE, RED, GREEN, YELLOW, PURPLE, WHITE; + } + + private void renderHealthBar() { + Color color = determineColor(); + float percent = entity.getHealth() / entity.getMaxHealth(); + gui.drawTexturedModalRect(barX, barY, 0, color.ordinal() * 5 * 2, BAR_WIDTH, 5); + int healthWidth = (int) (percent * BAR_WIDTH); + if (healthWidth > 0) { + gui.drawTexturedModalRect(barX, barY, 0, color.ordinal() * 5 * 2 + 5, healthWidth, 5); + } + } + + private Color determineColor() { + if (entity instanceof EntityMob) { + return Color.RED; + } else if (entity instanceof EntitySlime) { + return Color.RED; + } else if (entity instanceof EntityAnimal) { + return Color.GREEN; + } else if (entity instanceof EntityAmbientCreature) { + return Color.GREEN; + }else { + return Color.WHITE; + } + } + + @Override + public void setEntity(EntityLivingBase entity) { + this.entity = entity; + } + +} \ No newline at end of file diff --git a/java/net/torocraft/torohealthmod/display/EntityDisplay.java b/java/net/torocraft/torohealthmod/display/EntityDisplay.java index 1bb67f5..8fb6f54 100644 --- a/java/net/torocraft/torohealthmod/display/EntityDisplay.java +++ b/java/net/torocraft/torohealthmod/display/EntityDisplay.java @@ -1,7 +1,6 @@ package net.torocraft.torohealthmod.display; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.Gui; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.renderer.RenderHelper; @@ -9,22 +8,22 @@ import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityLivingBase; -import net.minecraft.util.ResourceLocation; +import net.minecraft.entity.monster.EntityGhast; import net.minecraft.util.math.MathHelper; -import net.torocraft.torohealthmod.ToroHealthMod; public class EntityDisplay implements ToroHealthDisplay { - private static final ResourceLocation TEXTURE = new ResourceLocation(ToroHealthMod.MODID, "textures/gui/entityStatus.png"); - private static final int RENDER_HEIGHT = 20; + private static final int RENDER_HEIGHT = 30; + private static final int RENDER_WIDTH = 18; + private static final int PADDING = 2; private static final int WIDTH = 40; - private static final int HEIGHT = 40; + private static final int HEIGHT = WIDTH; - private final Minecraft mc; - private final Gui gui; - private int x = 50; private int y = 50; + private float glX = 50; + private float glY = 50; + private EntityLivingBase entity; private Entity leashedToEntity; private float prevYawOffset; @@ -34,15 +33,14 @@ public class EntityDisplay implements ToroHealthDisplay { private float prevPrevYahHead; private int scale = 1; - public EntityDisplay(Minecraft mc, Gui gui) { - this.mc = mc; - this.gui = gui; + public EntityDisplay(Minecraft mc) { } @Override public void setPosition(int x, int y) { - this.x = x; this.y = y; + this.glX = (float) x + WIDTH / 2; + this.glY = (float) y + HEIGHT - PADDING; } @Override @@ -54,31 +52,36 @@ public void setEntity(EntityLivingBase entity) { @Override public void draw() { try { + pushEntityLeasedTo(); pushEntityRotations(); glDraw(); popEntityRotations(); popEntityLeasedTo(); - - mc.renderEngine.bindTexture(TEXTURE); - Gui.drawModalRectWithCustomSizedTexture(x, y, 0.0f, 0.0f, WIDTH, HEIGHT, 200.0f, 200.0f); + } catch (Throwable ignore) { } } private void updateScale() { - scale = MathHelper.ceil(RENDER_HEIGHT / entity.height); - } + int scaleY = MathHelper.ceil(RENDER_HEIGHT / entity.height); + int scaleX = MathHelper.ceil(RENDER_WIDTH / entity.width); + scale = Math.min(scaleX, scaleY); - private void glDraw() { + glY = (float) y + (HEIGHT / 2 + RENDER_HEIGHT / 2); - + if (entity instanceof EntityGhast) { + glY -= 10; + } + + } + private void glDraw() { GlStateManager.enableColorMaterial(); GlStateManager.pushMatrix(); - GlStateManager.translate((float) x, (float) y, 50.0F); + GlStateManager.translate(glX, glY, 50.0F); GlStateManager.scale((float) (-scale), (float) scale, (float) scale); GlStateManager.rotate(180.0F, 0.0F, 0.0F, 1.0F); GlStateManager.rotate(135.0F, 0.0F, 1.0F, 0.0F); @@ -93,8 +96,6 @@ private void glDraw() { rendermanager.setRenderShadow(false); rendermanager.doRenderEntity(entity, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F, false); rendermanager.setRenderShadow(true); - - GlStateManager.popMatrix(); RenderHelper.disableStandardItemLighting(); diff --git a/java/net/torocraft/torohealthmod/display/HeartsDisplay.java b/java/net/torocraft/torohealthmod/display/HeartsDisplay.java index 119be1b..5e5dd3c 100644 --- a/java/net/torocraft/torohealthmod/display/HeartsDisplay.java +++ b/java/net/torocraft/torohealthmod/display/HeartsDisplay.java @@ -3,23 +3,16 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; import net.minecraft.entity.EntityLivingBase; -import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.MathHelper; -import net.torocraft.torohealthmod.ToroHealthMod; import net.torocraft.torohealthmod.gui.GuiEntityStatus; public class HeartsDisplay implements ToroHealthDisplay { - - private static final ResourceLocation TEXTURE = new ResourceLocation(ToroHealthMod.MODID, "textures/gui/entityStatus.png"); - private static final int WIDTH = 100; - private static final int HEIGHT = 34; - private final Minecraft mc; private final Gui gui; private int x, originX = 100; private int y, originY = 100; private EntityLivingBase entity; - + public HeartsDisplay(Minecraft mc, Gui gui) { this.mc = mc; this.gui = gui; @@ -37,23 +30,17 @@ public void draw() { if (entity == null) { return; } - - + resetToOrigin(); - - - - mc.renderEngine.bindTexture(TEXTURE); - Gui.drawModalRectWithCustomSizedTexture(x, y , 0.0f, 0.0f, WIDTH, HEIGHT, 200.0f, 200.0f); - + x += 2; y += 2; - + drawName(); drawHearts(); drawArmor(); } - + @Override public void setEntity(EntityLivingBase entity) { this.entity = entity; diff --git a/java/net/torocraft/torohealthmod/display/NumericDisplay.java b/java/net/torocraft/torohealthmod/display/NumericDisplay.java index 03a6dc9..fd9b060 100644 --- a/java/net/torocraft/torohealthmod/display/NumericDisplay.java +++ b/java/net/torocraft/torohealthmod/display/NumericDisplay.java @@ -11,7 +11,7 @@ public class NumericDisplay implements ToroHealthDisplay { private static final ResourceLocation TEXTURE = new ResourceLocation(ToroHealthMod.MODID, "textures/gui/entityStatus.png"); private static final int WIDTH = 100; private static final int HEIGHT = 34; - + private final Minecraft mc; private final Gui gui; private int x = 220; diff --git a/java/net/torocraft/torohealthmod/gui/GuiEntityStatus.java b/java/net/torocraft/torohealthmod/gui/GuiEntityStatus.java index 3856163..9f8f887 100644 --- a/java/net/torocraft/torohealthmod/gui/GuiEntityStatus.java +++ b/java/net/torocraft/torohealthmod/gui/GuiEntityStatus.java @@ -8,6 +8,7 @@ import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.torocraft.torohealthmod.config.ConfigurationHandler; +import net.torocraft.torohealthmod.display.BarDisplay; import net.torocraft.torohealthmod.display.EntityDisplay; import net.torocraft.torohealthmod.display.HeartsDisplay; import net.torocraft.torohealthmod.display.NumericDisplay; @@ -15,12 +16,13 @@ public class GuiEntityStatus extends Gui { - private static final int PADDING_FROM_EDGE = 2; + private static final int PADDING_FROM_EDGE = 3; private final Minecraft mc; private final ToroHealthDisplay entityDisplay; private final ToroHealthDisplay heartsDisplay; private final ToroHealthDisplay numericDisplay; + private final ToroHealthDisplay barDisplay; private EntityLivingBase entity; private int age = 0; @@ -32,20 +34,23 @@ public class GuiEntityStatus extends Gui { int displayHeight; int displayWidth; + int x, y; + public GuiEntityStatus() { this(Minecraft.getMinecraft()); } public GuiEntityStatus(Minecraft mc) { this.mc = mc; - entityDisplay = new EntityDisplay(mc, this); + entityDisplay = new EntityDisplay(mc); heartsDisplay = new HeartsDisplay(mc, this); numericDisplay = new NumericDisplay(mc, this); + barDisplay = new BarDisplay(mc, this); entityDisplay.setPosition(50, 50); - - heartsDisplay.setPosition(100, 150); - numericDisplay.setPosition(210, 150); + heartsDisplay.setPosition(25, 150); + numericDisplay.setPosition(130, 150); + barDisplay.setPosition(25, 200); } @SubscribeEvent @@ -54,6 +59,7 @@ public void drawHealthBar(RenderGameOverlayEvent.Pre event) { return; } updateGuiAge(); + updatePositions(); draw(); } @@ -65,37 +71,57 @@ private void updateGuiAge() { } } - private void draw() { - + private void updatePositions() { adjustForDisplayPositionSetting(); + x = screenX; + y = screenY; + + if (ConfigurationHandler.showEntityModel) { + entityDisplay.setPosition(x, y); + x += 40; + } + + if (ConfigurationHandler.statusDisplayPosition.contains("BOTTOM")) { + y += 6; + } + + numericDisplay.setPosition(x, y); + barDisplay.setPosition(x, y); + heartsDisplay.setPosition(x, y); + } + + private void draw() { if (ConfigurationHandler.showEntityModel) { entityDisplay.draw(); } - // if("NUMERIC".equals(ConfigurationHandler.entityStatusDisplay)){ - numericDisplay.draw(); - // }else{ - heartsDisplay.draw(); - // } + if ("NUMERIC".equals(ConfigurationHandler.entityStatusDisplay)) { + numericDisplay.draw(); + } else if ("BAR".equals(ConfigurationHandler.entityStatusDisplay)) { + barDisplay.draw(); + } else if ("HEARTS".equals(ConfigurationHandler.entityStatusDisplay)) { + heartsDisplay.draw(); + } } private void adjustForDisplayPositionSetting() { - ScaledResolution viewport = new ScaledResolution(mc); - int entityRenderWidth = 0; + if (ConfigurationHandler.showEntityModel) { + displayHeight = 40; + displayWidth = 140; + } else { + displayHeight = 32; + displayWidth = 100; + } + + ScaledResolution viewport = new ScaledResolution(mc); String displayPosition = ConfigurationHandler.statusDisplayPosition; int sh = viewport.getScaledHeight(); int sw = viewport.getScaledWidth(); - if (displayPosition.equals("CUSTOM")) { - screenX = ConfigurationHandler.statusDisplayX + entityRenderWidth; - screenY = ConfigurationHandler.statusDisplayY; - return; - } - - if (displayPosition.contains("TOP")) { + if (displayPosition.contains("TOP") || displayPosition.equals("CUSTOM")) { screenY = PADDING_FROM_EDGE; } @@ -103,17 +129,20 @@ private void adjustForDisplayPositionSetting() { screenY = sh - displayHeight - PADDING_FROM_EDGE; } - if (displayPosition.contains("LEFT")) { - screenX = entityRenderWidth + PADDING_FROM_EDGE; + if (displayPosition.contains("LEFT") || displayPosition.equals("CUSTOM")) { + screenX = PADDING_FROM_EDGE; } if (displayPosition.contains("RIGHT")) { - screenX = sw - displayWidth - PADDING_FROM_EDGE - entityRenderWidth - 10; + screenX = sw - displayWidth - PADDING_FROM_EDGE; } if (displayPosition.contains("CENTER")) { screenX = (sw - displayWidth) / 2; } + + screenX += ConfigurationHandler.statusDisplayX; + screenY += ConfigurationHandler.statusDisplayY; } private void showHealthBar() { @@ -134,5 +163,6 @@ public void setEntity(EntityLivingBase entityToTrack) { entityDisplay.setEntity(entity); heartsDisplay.setEntity(entity); numericDisplay.setEntity(entity); + barDisplay.setEntity(entity); } } diff --git a/resources/assets/torohealthmod/textures/gui/bars.png b/resources/assets/torohealthmod/textures/gui/bars.png new file mode 100644 index 0000000000000000000000000000000000000000..f24921a485f433089a2d577e7d7f96bb3b20d789 GIT binary patch literal 1550 zcmdT^`&ZI;82)?_G%aT*GbcLd7TWLvUI??CVv30ccnc*Rc7xPOIxk3R^|c?$S#t&6 z02Q2?Wr}&D3@_}M8Rms7>!@X#rDs~sEKAXJxS#ef>^F+E~mm|@>?4U7PX-bw;cW@YP znKQ?7eGu_1>cMB~aZk^z536aj?-wwXNe_JKT}g}dI>JfRm(0Ss_7jz!lMUHn8n$@i zBPE0YiQ@pJUhS(GVi(ZuLwuy$d-HgfD#wHYwzz8?OKwF1s;Ceugyznb0Bwp#ulW)k zeb}3LDnRgjs_dwSqZjd-%bZk3O{P@^KRVb(7u0v}!NQ6yD(2a%Gb=K5I)3)Z?ET6$ z3d>;wmk6h>UOhN^!=HS6N%Fm>h$3*DR}?}|q)^rxK?E367b%K~T18cT+Qp8p^gLOU zexes%6pc}G=a+)XRbkEhwG$ZZsdL*=8V2G)2PXzddG;Y4!L`i;iF$lDOKC`3d7ddC zu(Qghk|i+SXQfh&)GVmYE0+>n@U=Rl{DA}T&U%~IV(Xxu z=uWI^_DO-&w-`#c9Vyuj?tQEQJT%Gdi(hiZxW4lq zs}dd4K~u1OX9Q*}1OQl$+&YH~{+8SbQ!jnh=mupF>(0=)9365*4xTgPlY zM`HltlaZ!3GzTZBr)F==oK6|Si8h%d%&71r2lPwoAU?h3G0-0Wqj?}sZ&#shg%Gf8 zAlL%70EAp%cP7c1Wso?w8*V*iU8~3E+1k_);WBdfO?J|BpsI=(P7%z<+M+ZOh+Urh zd2;0QwdFwqb|McpkR!_n_2*h>UXiHkX>}glxOgQ{P)5$SAbqib7wJO7v2Z13=DqvR zi+wouqYI69lBfz(uh!O6O_>qz{Ck(jv%Y2O(yKdq*kbb zLx@GKW3$5W&e|)QaQPS0xqEi&M@gTmrCbDKp^QpG6DWd&ZT}Gy@0MmXhgdDKG=>!{ zsI8|Zqxe!rACX?SA*kcX-2=%*7_zCX*+PYrcyc6_5vXdNqA6kr9jaG@)ioiQ-T|ET zob})fTSx_7XD%Fry>g&W?1J9KShFksma1@OZuAM!%X{{Rspoohu{2>)pvFAF@p$-q zoza~H0})4}bYU`4<+=pB%w){1W!@aVXK(XPgi(hxx4OYvH}GCcjD{w0sOr)+X}<{$ zRoJW&#Vd*p4DQN#|zkFAq|9krl= zc~}0ywnhqM*ok782t}V?cS-j5a#6`wmB7s$@wS)KvUzNE)XwHNBHVd2IR7CVhvy=m zrljtSN5~of;uaMbzZtH8m+`YHVx{tkPTUH(aTq+ENo6=l;GHiGZNi-%INUP{=et`QF3l{{hB#Y0>}y literal 0 HcmV?d00001