private void renderSkull(Render3DPosedEvent e) {
if (target == null) return;
MatrixStack ms = e.getMatrix();
ms.push();
ActiveRenderInfo cam = mc.getRenderManager().info;
Vector3d interpolated = Mathf.interpolate(target.getPositionVec(),
new Vector3d(target.lastTickPosX, target.lastTickPosY, target.lastTickPosZ),
e.getPartialTicks());
double entX = interpolated.x - cam.getProjectedView().x;
double entY = interpolated.y - cam.getProjectedView().y + target.getHeight() / 2f;
double entZ = interpolated.z - cam.getProjectedView().z;
float currentHP = target.getHealth();
float maxHP = target.getMaxHealth();
float hpPercent = currentHP / maxHP;
int hurtTicks = target.hurtTime;
boolean isHurt = hurtTicks > 0;
float lowHpShake = (1f - hpPercent) * 0.08f;
float hurtShake = isHurt ? (hurtTicks / 8f) * 0.2f : 0;
float totalShake = lowHpShake + hurtShake;
if (totalShake > 0.001f) {
entX += (Math.random() - 0.4) * totalShake;
entY += (Math.random() - 0.4) * totalShake;
entZ += (Math.random() - 0.4) * totalShake;
}
ms.translate(entX, entY, entZ);
float alphaPC = (float)alpha.get();
ResourceLocation skullTexture;
if (hpPercent > 0.6f) {
skullTexture = new Namespaced("texture/skull_state_0.png");
} else if (hpPercent > 0.3f) {
skullTexture = new Namespaced("texture/skull_state_1.png");
} else {
skullTexture = new Namespaced("texture/skull_state_2.png");
}
RenderSystem.enableBlend();
RenderSystem.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
glDisable(GL_CULL_FACE);
glDisable(GL_DEPTH_TEST);
depthMask(false);
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder buffer = tessellator.getBuffer();
mc.getTextureManager().bindTexture(skullTexture);
Matrix4f matrix = ms.getLast().getMatrix();
float skullSize = 0.6f;
int baseColor = InterFace.getInstance().clientColor();
int redColor = ColorUtil.getColor(255, 50, 50, (int)(alphaPC * 255));
int skullColor;
if (isHurt) {
float hurtPC = (float) sin((double)hurtTicks * (Math.PI / 10D));
skullColor = ColorUtil.overCol(baseColor, redColor, hurtPC);
} else if (hpPercent < 0.3f) {
skullColor = ColorUtil.overCol(baseColor, redColor, (1f - hpPercent / 0.3f) * 0.4f);
} else {
skullColor = baseColor;
}
int finalColor = ColorUtil.setAlpha(skullColor, (int)(alphaPC * 255));
Quaternion cameraRotation = cam.getRotation().copy();
ms.rotate(cameraRotation);
ms.rotate(Vector3f.YP.rotationDegrees(0f));
buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR_TEX);
int r = ColorUtil.getRed(finalColor);
int g = ColorUtil.getGreen(finalColor);
int b = ColorUtil.getBlue(finalColor);
int a = ColorUtil.getAlpha(finalColor);
buffer.pos(matrix, -skullSize, -skullSize, 0).color(r, g, b, a).tex(0, 1).lightmap(0, 240).endVertex();
buffer.pos(matrix, skullSize, -skullSize, 0).color(r, g, b, a).tex(1, 1).lightmap(0, 240).endVertex();
buffer.pos(matrix, skullSize, skullSize, 0).color(r, g, b, a).tex(1, 0).lightmap(0, 240).endVertex();
buffer.pos(matrix, -skullSize, skullSize, 0).color(r, g, b, a).tex(0, 0).lightmap(0, 240).endVertex();
tessellator.draw();
mc.getTextureManager().bindTexture(new Namespaced("texture/glow.png"));
float glowSize = skullSize * (1.5f + (1f - hpPercent) * 0.5f);
int glowAlpha = (int)(alphaPC * (100 + (1f - hpPercent) * 50));
int glowColor = ColorUtil.setAlpha(skullColor, glowAlpha);
int gr = ColorUtil.getRed(glowColor);
int gg = ColorUtil.getGreen(glowColor);
int gb = ColorUtil.getBlue(glowColor);
int ga = ColorUtil.getAlpha(glowColor);
buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR_TEX);
buffer.pos(matrix, -glowSize, -glowSize, 0).color(gr, gg, gb, ga).tex(0, 0).lightmap(0, 240).endVertex();
buffer.pos(matrix, glowSize, -glowSize, 0).color(gr, gg, gb, ga).tex(1, 0).lightmap(0, 240).endVertex();
buffer.pos(matrix, glowSize, glowSize, 0).color(gr, gg, gb, ga).tex(1, 1).lightmap(0, 240).endVertex();
buffer.pos(matrix, -glowSize, glowSize, 0).color(gr, gg, gb, ga).tex(0, 1).lightmap(0, 240).endVertex();
tessellator.draw();
RenderSystem.defaultBlendFunc();
glEnable(GL_DEPTH_TEST);
depthMask(true);
glEnable(GL_CULL_FACE);
ms.pop();
}