Skip to content

Commit

Permalink
All display are now working along with config options
Browse files Browse the repository at this point in the history
  • Loading branch information
frodare committed Feb 10, 2017
1 parent 888c7ee commit d8ca2fb
Show file tree
Hide file tree
Showing 7 changed files with 178 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
92 changes: 92 additions & 0 deletions java/net/torocraft/torohealthmod/display/BarDisplay.java
Original file line number Diff line number Diff line change
@@ -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;
}

}
47 changes: 24 additions & 23 deletions java/net/torocraft/torohealthmod/display/EntityDisplay.java
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
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;
import net.minecraft.client.renderer.entity.RenderManager;
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;
Expand All @@ -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
Expand All @@ -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);
Expand All @@ -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();
Expand Down
23 changes: 5 additions & 18 deletions java/net/torocraft/torohealthmod/display/HeartsDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit d8ca2fb

Please sign in to comment.