diff --git a/java/net/torocraft/torohealthmod/ClientProxy.java b/java/net/torocraft/torohealthmod/ClientProxy.java index ba24305..13097f5 100644 --- a/java/net/torocraft/torohealthmod/ClientProxy.java +++ b/java/net/torocraft/torohealthmod/ClientProxy.java @@ -10,7 +10,6 @@ import net.minecraft.nbt.NBTTagInt; import net.minecraft.util.EntitySelectors; import net.minecraft.util.math.AxisAlignedBB; -import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; @@ -114,7 +113,6 @@ public RayTraceResult getMouseOver(float partialTicks) { Vec3d lookVectorFromEyePosition = observerPositionEyes.addVector(lookVector.xCoord * reachDistance, lookVector.yCoord * reachDistance, lookVector.zCoord * reachDistance); this.pointedEntity = null; Vec3d hitVector = null; - float f = 1.0F; List list = this.mc.world.getEntitiesInAABBexcluding(observer, observer.getEntityBoundingBox().addCoord(lookVector.xCoord * reachDistance, lookVector.yCoord * reachDistance, lookVector.zCoord * reachDistance).expand(1.0D, 1.0D, 1.0D), EntitySelectors.NOT_SPECTATING); double d2 = distance; @@ -157,8 +155,4 @@ public RayTraceResult getMouseOver(float partialTicks) { return objectMouseOver; } - private boolean isSolidBlock(BlockPos pos, BlockPos prevPos) { - return prevPos.compareTo(pos) == 0; - } - } \ No newline at end of file diff --git a/java/net/torocraft/torohealthmod/gui/GuiConfigToroHealth.java b/java/net/torocraft/torohealthmod/config/GuiConfigToroHealth.java similarity index 85% rename from java/net/torocraft/torohealthmod/gui/GuiConfigToroHealth.java rename to java/net/torocraft/torohealthmod/config/GuiConfigToroHealth.java index a90a4cd..a061867 100644 --- a/java/net/torocraft/torohealthmod/gui/GuiConfigToroHealth.java +++ b/java/net/torocraft/torohealthmod/config/GuiConfigToroHealth.java @@ -1,11 +1,10 @@ -package net.torocraft.torohealthmod.gui; +package net.torocraft.torohealthmod.config; import net.minecraft.client.gui.GuiScreen; import net.minecraftforge.common.config.ConfigElement; import net.minecraftforge.common.config.Configuration; import net.minecraftforge.fml.client.config.GuiConfig; import net.torocraft.torohealthmod.ToroHealthMod; -import net.torocraft.torohealthmod.config.ConfigurationHandler; public class GuiConfigToroHealth extends GuiConfig { diff --git a/java/net/torocraft/torohealthmod/display/EntityDisplay.java b/java/net/torocraft/torohealthmod/display/EntityDisplay.java new file mode 100644 index 0000000..8a9592a --- /dev/null +++ b/java/net/torocraft/torohealthmod/display/EntityDisplay.java @@ -0,0 +1,122 @@ +package net.torocraft.torohealthmod.display; + +import net.minecraft.client.Minecraft; +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.math.MathHelper; + +public class EntityDisplay implements ToroHealthDisplay { + + private static final int RENDER_HEIGHT = 20; + + private int x = 50; + private int y = 50; + + private EntityLivingBase entity; + private Entity leashedToEntity; + private float prevYawOffset; + private float prevYaw; + private float prevPitch; + private float prevYawHead; + private float prevPrevYahHead; + private int scale = 1; + + @Override + public void setPosition(int x, int y) { + this.x = x; + this.y = y; + } + + @Override + public void setEntity(EntityLivingBase entity) { + this.entity = entity; + updateScale(); + } + + @Override + public void draw() { + try { + pushEntityLeasedTo(); + pushEntityRotations(); + glDraw(); + popEntityRotations(); + popEntityLeasedTo(); + } catch (Throwable ignore) { + + } + } + + private void updateScale() { + scale = MathHelper.ceil(RENDER_HEIGHT / entity.height); + } + + private void glDraw() { + GlStateManager.enableColorMaterial(); + GlStateManager.pushMatrix(); + + GlStateManager.translate((float) x, (float) y, 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); + GlStateManager.rotate(-100.0F, 0.0F, 1.0F, 0.0F); + GlStateManager.rotate(0.0f, 1.0F, 0.0F, 0.0F); + + RenderHelper.enableStandardItemLighting(); + + GlStateManager.translate(0.0F, 0.0F, 0.0F); + RenderManager rendermanager = Minecraft.getMinecraft().getRenderManager(); + rendermanager.setPlayerViewY(180.0F); + rendermanager.setRenderShadow(false); + rendermanager.doRenderEntity(entity, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F, false); + rendermanager.setRenderShadow(true); + + GlStateManager.popMatrix(); + RenderHelper.disableStandardItemLighting(); + GlStateManager.disableRescaleNormal(); + GlStateManager.setActiveTexture(OpenGlHelper.lightmapTexUnit); + GlStateManager.disableTexture2D(); + GlStateManager.setActiveTexture(OpenGlHelper.defaultTexUnit); + } + + private void popEntityLeasedTo() { + if (entity instanceof EntityLiving && leashedToEntity != null) { + ((EntityLiving) entity).setLeashedToEntity(leashedToEntity, false); + leashedToEntity = null; + } + } + + private void pushEntityLeasedTo() { + if (entity instanceof EntityLiving) { + if (((EntityLiving) entity).getLeashed()) { + leashedToEntity = ((EntityLiving) entity).getLeashedToEntity(); + ((EntityLiving) entity).setLeashedToEntity(null, false); + } + } + } + + private void popEntityRotations() { + entity.renderYawOffset = prevYawOffset; + entity.rotationYaw = prevYaw; + entity.rotationPitch = prevPitch; + entity.rotationYawHead = prevYawHead; + entity.prevRotationYawHead = prevPrevYahHead; + } + + private void pushEntityRotations() { + prevYawOffset = entity.renderYawOffset; + prevYaw = entity.rotationYaw; + prevPitch = entity.rotationPitch; + prevYawHead = entity.rotationYawHead; + prevPrevYahHead = entity.prevRotationYawHead; + entity.renderYawOffset = 0.0f; + entity.rotationYaw = 0.0f; + entity.rotationPitch = 0.0f; + entity.rotationYawHead = 0.0f; + entity.prevRotationYawHead = 0.0f; + } +} \ No newline at end of file diff --git a/java/net/torocraft/torohealthmod/display/HeartsDisplay.java b/java/net/torocraft/torohealthmod/display/HeartsDisplay.java new file mode 100644 index 0000000..f8dd7c2 --- /dev/null +++ b/java/net/torocraft/torohealthmod/display/HeartsDisplay.java @@ -0,0 +1,148 @@ +package net.torocraft.torohealthmod.display; + +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 = 84; + 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; + } + + @Override + public void setPosition(int x, int y) { + originX = x; + originY = y; + resetToOrigin(); + } + + @Override + 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); + + drawName(); + drawHearts(); + drawArmor(); + } + + @Override + public void setEntity(EntityLivingBase entity) { + this.entity = entity; + } + + private void resetToOrigin() { + x = originX; + y = originY; + } + + private void drawName() { + gui.drawString(mc.fontRendererObj, entity.getDisplayName().getFormattedText(), x, y, 0xFFFFFF); + y += 10; + } + + private int drawHearts() { + mc.renderEngine.bindTexture(GuiEntityStatus.ICONS); + int currentHealth = MathHelper.ceil(entity.getHealth()); + + int absorptionAmount = MathHelper.ceil(entity.getAbsorptionAmount()); + int remainingAbsorption = absorptionAmount; + + float maxHealth = entity.getMaxHealth(); + + int numRowsOfHearts = MathHelper.ceil((maxHealth + (float) absorptionAmount) / 2.0F / 10.0F); + int j2 = Math.max(10 - (numRowsOfHearts - 2), 3); + + for (int currentHeartBeingDrawn = MathHelper.ceil((maxHealth + (float) absorptionAmount) / 2.0F) + - 1; currentHeartBeingDrawn >= 0; --currentHeartBeingDrawn) { + int texturePosX = 16; + int flashingHeartOffset = 0; + + int rowsOfHearts = MathHelper.ceil((float) (currentHeartBeingDrawn + 1) / 10.0F) - 1; + int heartToDrawX = x + currentHeartBeingDrawn % 10 * 8; + int heartToDrawY = y + rowsOfHearts * j2; + + int hardcoreModeOffset = 0; + + if (entity.world.getWorldInfo().isHardcoreModeEnabled()) { + hardcoreModeOffset = 5; + } + + gui.drawTexturedModalRect(heartToDrawX, heartToDrawY, 16 + flashingHeartOffset * 9, 9 * hardcoreModeOffset, 9, 9); + + if (remainingAbsorption > 0) { + if (remainingAbsorption == absorptionAmount && absorptionAmount % 2 == 1) { + gui.drawTexturedModalRect(heartToDrawX, heartToDrawY, texturePosX + 153, 9 * hardcoreModeOffset, 9, 9); + --remainingAbsorption; + } else { + gui.drawTexturedModalRect(heartToDrawX, heartToDrawY, texturePosX + 144, 9 * hardcoreModeOffset, 9, 9); + remainingAbsorption -= 2; + } + } else { + if (currentHeartBeingDrawn * 2 + 1 < currentHealth) { + gui.drawTexturedModalRect(heartToDrawX, heartToDrawY, texturePosX + 36, 9 * hardcoreModeOffset, 9, 9); + } + + if (currentHeartBeingDrawn * 2 + 1 == currentHealth) { + gui.drawTexturedModalRect(heartToDrawX, heartToDrawY, texturePosX + 45, 9 * hardcoreModeOffset, 9, 9); + } + } + } + + y += (numRowsOfHearts - 1) * j2 + 10; + + return remainingAbsorption; + } + + private void drawArmor() { + mc.renderEngine.bindTexture(GuiEntityStatus.ICONS); + + int armor = entity.getTotalArmorValue(); + + for (int i = 0; i < 10; ++i) { + if (armor > 0) { + int armorIconX = x + i * 8; + + /* + * determines whether armor is full, half, or empty icon + */ + if (i * 2 + 1 < armor) { + gui.drawTexturedModalRect(armorIconX, y, 34, 9, 9, 9); + } + + if (i * 2 + 1 == armor) { + gui.drawTexturedModalRect(armorIconX, y, 25, 9, 9, 9); + } + + if (i * 2 + 1 > armor) { + gui.drawTexturedModalRect(armorIconX, y, 16, 9, 9, 9); + } + } + } + + y += 10; + } + +} \ No newline at end of file diff --git a/java/net/torocraft/torohealthmod/display/NumericDisplay.java b/java/net/torocraft/torohealthmod/display/NumericDisplay.java new file mode 100644 index 0000000..6968c6a --- /dev/null +++ b/java/net/torocraft/torohealthmod/display/NumericDisplay.java @@ -0,0 +1,66 @@ +package net.torocraft.torohealthmod.display; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Gui; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.util.ResourceLocation; +import net.torocraft.torohealthmod.ToroHealthMod; + +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 = 100; + private int y = 140; + private EntityLivingBase entity; + + public NumericDisplay(Minecraft mc, Gui gui) { + this.mc = mc; + this.gui = gui; + } + + @Override + public void setPosition(int x, int y) { + this.x = x; + this.y = y; + + } + + @Override + public void draw() { + if (entity == null) { + return; + } + + mc.renderEngine.bindTexture(TEXTURE); + + /* + * defines positions of each element from the top left position of + * status display + */ + int bgX = 0, bgY = 0, healthBarX = 2, healthBarY = 16, nameX = 50, nameY = 4, healthX = 50, healthY = 20; + + Gui.drawModalRectWithCustomSizedTexture(x + bgX, y + bgY, 0.0f, 0.0f, WIDTH, HEIGHT, 200.0f, 200.0f); + + Gui.drawModalRectWithCustomSizedTexture(x + healthBarX, y + healthBarY, 0.0f, 150.0f, 96, 16, 200.0f, 200.0f); + + int currentHealthWidth = (int) Math.ceil(96 * (entity.getHealth() / entity.getMaxHealth())); + Gui.drawModalRectWithCustomSizedTexture(x + healthBarX, y + healthBarY, 0.0f, 100.0f, currentHealthWidth, 16, 200.0f, 200.0f); + + String name = entity.getDisplayName().getFormattedText(); + + gui.drawCenteredString(mc.fontRendererObj, name, x + nameX, y + nameY, 0xFFFFFF); + gui.drawCenteredString(mc.fontRendererObj, (int) Math.ceil(entity.getHealth()) + "/" + (int) entity.getMaxHealth(), x + healthX, y + healthY, + 0xFFFFFF); + } + + @Override + public void setEntity(EntityLivingBase entity) { + this.entity = entity; + } + +} \ No newline at end of file diff --git a/java/net/torocraft/torohealthmod/display/ToroHealthDisplay.java b/java/net/torocraft/torohealthmod/display/ToroHealthDisplay.java new file mode 100644 index 0000000..9e7aaea --- /dev/null +++ b/java/net/torocraft/torohealthmod/display/ToroHealthDisplay.java @@ -0,0 +1,9 @@ +package net.torocraft.torohealthmod.display; + +import net.minecraft.entity.EntityLivingBase; + +public interface ToroHealthDisplay { + void setEntity(EntityLivingBase entity); + void setPosition(int x, int y); + void draw(); +} \ No newline at end of file diff --git a/java/net/torocraft/torohealthmod/gui/GuiEntityStatus.java b/java/net/torocraft/torohealthmod/gui/GuiEntityStatus.java index 2614c99..9e9cdbe 100644 --- a/java/net/torocraft/torohealthmod/gui/GuiEntityStatus.java +++ b/java/net/torocraft/torohealthmod/gui/GuiEntityStatus.java @@ -1,338 +1,86 @@ package net.torocraft.torohealthmod.gui; -import java.util.Random; - import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.ScaledResolution; -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.util.math.MathHelper; import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import net.torocraft.torohealthmod.ToroHealthMod; import net.torocraft.torohealthmod.config.ConfigurationHandler; +import net.torocraft.torohealthmod.display.EntityDisplay; +import net.torocraft.torohealthmod.display.HeartsDisplay; +import net.torocraft.torohealthmod.display.NumericDisplay; +import net.torocraft.torohealthmod.display.ToroHealthDisplay; public class GuiEntityStatus extends Gui { - private Minecraft mc; + private static final int PADDING_FROM_EDGE = 2; + + private final Minecraft mc; + private final ToroHealthDisplay entityDisplay; + private final ToroHealthDisplay heartsDisplay; + private final ToroHealthDisplay numericDisplay; + private EntityLivingBase entity; private int age = 0; private boolean showHealthBar = false; - private ScaledResolution viewport; - private final int PADDING_FROM_EDGE = 2; + int screenX = PADDING_FROM_EDGE; + int screenY = PADDING_FROM_EDGE; - String displayPosition; - int screenX = PADDING_FROM_EDGE, screenY = PADDING_FROM_EDGE; int displayHeight; int displayWidth; - /* - * Entity drawing - */ - private int entityRenderWidth; - private final int entityRenderHeightUnit = 20; - private final int entityRenderX = 20; - private Entity leashedToEntity; - - /* - * for hearts drawing - */ - private int entityHealth = 0; - private int lastEntityHealth = 0; - private long lastSystemTime = 0L; - private int updateCounter; - private long healthUpdateCounter = 0L; - private Random rand = new Random(); - public GuiEntityStatus() { this(Minecraft.getMinecraft()); } public GuiEntityStatus(Minecraft mc) { - super(); this.mc = mc; - } - - public void setEntity(EntityLivingBase entityToTrack) { - showHealthBar(); - age = 0; - if (entity != null && entity.getUniqueID().equals(entityToTrack.getUniqueID())) { - return; - } - entity = entityToTrack; + entityDisplay = new EntityDisplay(); + heartsDisplay = new HeartsDisplay(mc, this); + numericDisplay = new NumericDisplay(mc, this); } @SubscribeEvent public void drawHealthBar(RenderGameOverlayEvent.Pre event) { - if (!showHealthBar) { - return; - } - - if (event.getType() != ElementType.CHAT) { + if (!showHealthBar || event.getType() != ElementType.CHAT) { return; } + updateGuiAge(); + draw(); + } + private void updateGuiAge() { String entityStatusDisplay = ConfigurationHandler.entityStatusDisplay; age = age + 15; if (age > ConfigurationHandler.hideDelay || entityStatusDisplay.equals("OFF")) { hideHealthBar(); } - - boolean showEntityModel = ConfigurationHandler.showEntityModel; - if (showEntityModel) { - entityRenderWidth = 40; - } else { - entityRenderWidth = 0; - } - - viewport = new ScaledResolution(mc); - displayPosition = ConfigurationHandler.statusDisplayPosition; - - if (isUnsupportedDisplayType(entityStatusDisplay)) { - entityStatusDisplay = "HEARTS"; - } - - if (entityStatusDisplay.equals("NUMERIC")) { - drawNumericDisplayStyle(); - } else if (entityStatusDisplay.equals("HEARTS")) { - drawHeartsDisplay(); - } - - if (showEntityModel) { - try { - drawEntityOnScreen(); - } catch (Throwable ignore) { - } - } } - public void drawEntityOnScreen() { - - int sw = viewport.getScaledWidth(), sh = viewport.getScaledHeight(); - - int entityRenderHeight = 20; - - double h = entityRenderHeight / entity.height; - - if (displayPosition.contains("TOP")) { - screenY = entityRenderHeight + 5; - } - - if (displayPosition.contains("BOTTOM")) { - screenY = sh - displayHeight + entityRenderHeight; - } - - if (displayPosition.contains("LEFT")) { - screenX = entityRenderX; - } - - if (displayPosition.contains("RIGHT")) { - screenX = sw - entityRenderWidth + 10; - } - - if (displayPosition.contains("CENTER")) { - screenX = ((sw - entityRenderWidth - displayWidth) / 2); - } - - if (displayPosition.equals("CUSTOM")) { - screenX = ConfigurationHandler.statusDisplayX + (entityRenderWidth / 2); - screenY = ConfigurationHandler.statusDisplayY + entityRenderHeight + 10; - } - - int scale = MathHelper.ceil(h); - - if (entity instanceof EntityLiving) { - if (((EntityLiving) entity).getLeashed()) { - leashedToEntity = ((EntityLiving) entity).getLeashedToEntity(); - ((EntityLiving) entity).setLeashedToEntity(null, false); - } - } - - float prevYawOffset = entity.renderYawOffset; - float prevYaw = entity.rotationYaw; - float prevPitch = entity.rotationPitch; - float prevYawHead = entity.rotationYawHead; - float prevPrevYahHead = entity.prevRotationYawHead; - GlStateManager.enableColorMaterial(); - GlStateManager.pushMatrix(); - GlStateManager.translate((float) screenX, (float) screenY, 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); - RenderHelper.enableStandardItemLighting(); - GlStateManager.rotate(-100.0F, 0.0F, 1.0F, 0.0F); - GlStateManager.rotate(0.0f, 1.0F, 0.0F, 0.0F); - entity.renderYawOffset = 0.0f; - entity.rotationYaw = 0.0f; - entity.rotationPitch = 0.0f; - entity.rotationYawHead = 0.0f; - entity.prevRotationYawHead = 0.0f; - GlStateManager.translate(0.0F, 0.0F, 0.0F); - RenderManager rendermanager = Minecraft.getMinecraft().getRenderManager(); - rendermanager.setPlayerViewY(180.0F); - rendermanager.setRenderShadow(false); - rendermanager.doRenderEntity(entity, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F, false); - rendermanager.setRenderShadow(true); - entity.renderYawOffset = prevYawOffset; - entity.rotationYaw = prevYaw; - entity.rotationPitch = prevPitch; - entity.rotationYawHead = prevYawHead; - entity.prevRotationYawHead = prevPrevYahHead; - GlStateManager.popMatrix(); - RenderHelper.disableStandardItemLighting(); - GlStateManager.disableRescaleNormal(); - GlStateManager.setActiveTexture(OpenGlHelper.lightmapTexUnit); - GlStateManager.disableTexture2D(); - GlStateManager.setActiveTexture(OpenGlHelper.defaultTexUnit); - - if (entity instanceof EntityLiving && leashedToEntity != null) { - ((EntityLiving) entity).setLeashedToEntity(leashedToEntity, false); - leashedToEntity = null; - } - } - - private boolean isUnsupportedDisplayType(String entityStatusDisplay) { - return !entityStatusDisplay.equals("HEARTS") && !entityStatusDisplay.equals("NUMERIC"); - } - - private void drawNumericDisplayStyle() { - ResourceLocation spriteLoc = new ResourceLocation(ToroHealthMod.MODID, "textures/gui/entityStatus.png"); - mc.renderEngine.bindTexture(spriteLoc); - - /* - * defines positions of each element from the top left position of - * status display - */ - int bgX = 0, bgY = 0, healthBarX = 2, healthBarY = 16, nameX = 50, nameY = 4, healthX = 50, healthY = 20; - - displayWidth = 100; - displayHeight = 34; - - adjustForDisplayPositionSetting(); - - Gui.drawModalRectWithCustomSizedTexture(screenX + bgX, screenY + bgY, 0.0f, 0.0f, displayWidth, displayHeight, 200.0f, 200.0f); - - Gui.drawModalRectWithCustomSizedTexture(screenX + healthBarX, screenY + healthBarY, 0.0f, 150.0f, 96, 16, 200.0f, 200.0f); - - int currentHealthWidth = (int) Math.ceil(96 * (entity.getHealth() / entity.getMaxHealth())); - Gui.drawModalRectWithCustomSizedTexture(screenX + healthBarX, screenY + healthBarY, 0.0f, 100.0f, currentHealthWidth, 16, 200.0f, 200.0f); - - String name = getDisplayName(); - - drawCenteredString(mc.fontRendererObj, name, screenX + nameX, screenY + nameY, 0xFFFFFF); - drawCenteredString(mc.fontRendererObj, (int) Math.ceil(entity.getHealth()) + "/" + (int) entity.getMaxHealth(), screenX + healthX, screenY + healthY, 0xFFFFFF); - } - - private void drawHeartsDisplay() { - screenX = PADDING_FROM_EDGE; - screenY = PADDING_FROM_EDGE; - displayHeight = 74; - displayWidth = 84; + private void draw() { adjustForDisplayPositionSetting(); - drawName(); - drawHearts(); - drawArmor(); - } - - private void drawName() { - String name = getDisplayName(); - drawString(mc.fontRendererObj, name, screenX, screenY, 0xFFFFFF); - screenY += 10; - } - - private int drawHearts() { - mc.renderEngine.bindTexture(ICONS); - int currentHealth = MathHelper.ceil(entity.getHealth()); - entityHealth = currentHealth; - int absorptionAmount = MathHelper.ceil(entity.getAbsorptionAmount()); - int remainingAbsorption = absorptionAmount; - - float maxHealth = entity.getMaxHealth(); - - int numRowsOfHearts = MathHelper.ceil((maxHealth + (float) absorptionAmount) / 2.0F / 10.0F); - int j2 = Math.max(10 - (numRowsOfHearts - 2), 3); - - for (int currentHeartBeingDrawn = MathHelper.ceil((maxHealth + (float) absorptionAmount) / 2.0F) - 1; currentHeartBeingDrawn >= 0; --currentHeartBeingDrawn) { - int texturePosX = 16; - int flashingHeartOffset = 0; - - int rowsOfHearts = MathHelper.ceil((float) (currentHeartBeingDrawn + 1) / 10.0F) - 1; - int heartToDrawX = screenX + currentHeartBeingDrawn % 10 * 8; - int heartToDrawY = screenY + rowsOfHearts * j2; - - int hardcoreModeOffset = 0; - - if (entity.world.getWorldInfo().isHardcoreModeEnabled()) { - hardcoreModeOffset = 5; - } - - this.drawTexturedModalRect(heartToDrawX, heartToDrawY, 16 + flashingHeartOffset * 9, 9 * hardcoreModeOffset, 9, 9); - - if (remainingAbsorption > 0) { - if (remainingAbsorption == absorptionAmount && absorptionAmount % 2 == 1) { - this.drawTexturedModalRect(heartToDrawX, heartToDrawY, texturePosX + 153, 9 * hardcoreModeOffset, 9, 9); - --remainingAbsorption; - } else { - this.drawTexturedModalRect(heartToDrawX, heartToDrawY, texturePosX + 144, 9 * hardcoreModeOffset, 9, 9); - remainingAbsorption -= 2; - } - } else { - if (currentHeartBeingDrawn * 2 + 1 < currentHealth) { - this.drawTexturedModalRect(heartToDrawX, heartToDrawY, texturePosX + 36, 9 * hardcoreModeOffset, 9, 9); - } - - if (currentHeartBeingDrawn * 2 + 1 == currentHealth) { - this.drawTexturedModalRect(heartToDrawX, heartToDrawY, texturePosX + 45, 9 * hardcoreModeOffset, 9, 9); - } - } + if (ConfigurationHandler.showEntityModel) { + entityDisplay.draw(); } - screenY += (numRowsOfHearts - 1) * j2 + 10; - - return remainingAbsorption; + // if("NUMERIC".equals(ConfigurationHandler.entityStatusDisplay)){ + numericDisplay.draw(); + // }else{ + heartsDisplay.draw(); + // } } - private void drawArmor() { - mc.renderEngine.bindTexture(ICONS); - - int armor = entity.getTotalArmorValue(); - - for (int i = 0; i < 10; ++i) { - if (armor > 0) { - int armorIconX = screenX + i * 8; - - /* - * determines whether armor is full, half, or empty icon - */ - if (i * 2 + 1 < armor) { - this.drawTexturedModalRect(armorIconX, screenY, 34, 9, 9, 9); - } - - if (i * 2 + 1 == armor) { - this.drawTexturedModalRect(armorIconX, screenY, 25, 9, 9, 9); - } - - if (i * 2 + 1 > armor) { - this.drawTexturedModalRect(armorIconX, screenY, 16, 9, 9, 9); - } - } - } + private void adjustForDisplayPositionSetting() { + ScaledResolution viewport = new ScaledResolution(mc); + int entityRenderWidth = 0; - screenY += 10; - } + String displayPosition = ConfigurationHandler.statusDisplayPosition; - private void adjustForDisplayPositionSetting() { int sh = viewport.getScaledHeight(); int sw = viewport.getScaledWidth(); @@ -363,23 +111,6 @@ private void adjustForDisplayPositionSetting() { } } - private boolean isHealthUpdateOver() { - return Minecraft.getSystemTime() - lastSystemTime > 1000L; - } - - private boolean isBeingHealed(int currentHealth) { - return currentHealth > entityHealth && entity.hurtResistantTime > 0; - } - - private boolean isBeingDamaged(int currentHealth) { - return currentHealth < entityHealth && entity.hurtResistantTime > 0; - } - - private String getDisplayName() { - String name = entity.getDisplayName().getFormattedText(); - return name; - } - private void showHealthBar() { showHealthBar = true; } @@ -387,4 +118,16 @@ private void showHealthBar() { private void hideHealthBar() { showHealthBar = false; } + + public void setEntity(EntityLivingBase entityToTrack) { + showHealthBar(); + age = 0; + if (entity != null && entity.getUniqueID().equals(entityToTrack.getUniqueID())) { + return; + } + entity = entityToTrack; + entityDisplay.setEntity(entity); + heartsDisplay.setEntity(entity); + numericDisplay.setEntity(entity); + } } diff --git a/java/net/torocraft/torohealthmod/gui/GuiFactoryToroHealth.java b/java/net/torocraft/torohealthmod/gui/GuiFactoryToroHealth.java index 4ea3009..3f7a432 100644 --- a/java/net/torocraft/torohealthmod/gui/GuiFactoryToroHealth.java +++ b/java/net/torocraft/torohealthmod/gui/GuiFactoryToroHealth.java @@ -5,6 +5,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; import net.minecraftforge.fml.client.IModGuiFactory; +import net.torocraft.torohealthmod.config.GuiConfigToroHealth; public class GuiFactoryToroHealth implements IModGuiFactory { @@ -23,6 +24,7 @@ public Set runtimeGuiCategories() { return null; } + @SuppressWarnings("deprecation") @Override public RuntimeOptionGuiHandler getHandlerFor(RuntimeOptionCategoryElement element) { return null;