- 4
- 1
Java:
package net.narutoswords.listener;
import net.minecraftforge.client.event.*;
import net.minecraft.client.*;
import net.narutoswords.util.neat.*;
import net.minecraft.client.renderer.culling.*;
import net.minecraft.client.multiplayer.*;
import cpw.mods.fml.relauncher.*;
import java.util.*;
import cpw.mods.fml.common.eventhandler.*;
import net.minecraft.entity.boss.*;
import net.minecraft.entity.player.*;
import org.lwjgl.opengl.*;
import net.minecraft.client.renderer.*;
import net.minecraft.entity.monster.*;
import net.minecraft.init.*;
import java.awt.*;
import net.minecraft.util.*;
import net.minecraft.client.renderer.texture.*;
import net.minecraft.client.renderer.entity.*;
import net.minecraft.item.*;
import net.minecraft.entity.*;
public class NeatListener
{
@SubscribeEvent
public void onRenderWorldLast(final RenderWorldLastEvent event) {
final Minecraft mc = Minecraft.getMinecraft();
if (NeatConfig.renderInF1 || Minecraft.isGuiEnabled()) {
final EntityLivingBase cameraEntity = mc.renderViewEntity;
final Vec3 renderingVector = cameraEntity.getPosition(event.partialTicks);
final Frustrum frustrum = new Frustrum();
final double viewX = cameraEntity.lastTickPosX + (cameraEntity.posX - cameraEntity.lastTickPosX) * event.partialTicks;
final double viewY = cameraEntity.lastTickPosY + (cameraEntity.posY - cameraEntity.lastTickPosY) * event.partialTicks;
final double viewZ = cameraEntity.lastTickPosZ + (cameraEntity.posZ - cameraEntity.lastTickPosZ) * event.partialTicks;
frustrum.setPosition(viewX, viewY, viewZ);
final WorldClient client = mc.theWorld;
final Set entities = (Set)ReflectionHelper.getPrivateValue((Class)WorldClient.class, (Object)client, new String[] { "entityList", "field_73032_d", "J" });
for (final Entity entity : entities) {
if (entity != null && entity instanceof EntityLiving && entity.isInRangeToRender3d(renderingVector.xCoord, renderingVector.yCoord, renderingVector.zCoord) && (entity.ignoreFrustumCheck || frustrum.isBoundingBoxInFrustum(entity.boundingBox))) {
if (!entity.isEntityAlive()) {
continue;
}
this.renderHealthBar((EntityLivingBase)entity, event.partialTicks, (Entity)cameraEntity);
}
}
}
}
public void renderHealthBar(final EntityLivingBase passedEntity, final float partialTicks, final Entity viewPoint) {
if (passedEntity.riddenByEntity == null) {
EntityLivingBase entity;
for (entity = passedEntity; entity.ridingEntity != null && entity.ridingEntity instanceof EntityLivingBase; entity = (EntityLivingBase)entity.ridingEntity) {}
final Minecraft mc = Minecraft.getMinecraft();
float pastTranslate = 0.0f;
while (entity != null) {
final float distance = passedEntity.getDistanceToEntity(viewPoint);
if (distance <= 4.0f && passedEntity.canEntityBeSeen(viewPoint) && !entity.isInvisible() && (NeatConfig.showOnBosses || !(entity instanceof IBossDisplayData)) && (NeatConfig.showOnPlayers || !(entity instanceof EntityPlayer))) {
final double x = passedEntity.lastTickPosX + (passedEntity.posX - passedEntity.lastTickPosX) * partialTicks;
final double y = passedEntity.lastTickPosY + (passedEntity.posY - passedEntity.lastTickPosY) * partialTicks;
final double z = passedEntity.lastTickPosZ + (passedEntity.posZ - passedEntity.lastTickPosZ) * partialTicks;
final float scale = 0.026666673f;
final float maxHealth = entity.getMaxHealth();
final float health = Math.min(maxHealth, entity.getHealth());
if (maxHealth > 0.0f) {
final float percent = (float)(int)(health / maxHealth * 100.0f);
GL11.glPushMatrix();
GL11.glTranslatef((float)(x - RenderManager.renderPosX), (float)(y - RenderManager.renderPosY + passedEntity.height + NeatConfig.heightAbove), (float)(z - RenderManager.renderPosZ));
GL11.glNormal3f(0.0f, 1.0f, 0.0f);
GL11.glRotatef(-RenderManager.instance.playerViewY, 0.0f, 1.0f, 0.0f);
GL11.glRotatef(RenderManager.instance.playerViewX, 1.0f, 0.0f, 0.0f);
GL11.glScalef(-scale, -scale, scale);
GL11.glDisable(2896);
GL11.glDepthMask(false);
GL11.glDisable(2929);
GL11.glDisable(3553);
GL11.glEnable(3042);
GL11.glBlendFunc(770, 771);
final Tessellator tessellator = Tessellator.instance;
final float padding = (float)NeatConfig.backgroundPadding;
final int bgHeight = NeatConfig.backgroundHeight;
final int barHeight = NeatConfig.barHeight;
float size = (float)NeatConfig.plateSize;
int r = 0;
int g = 255;
int b = 0;
ItemStack stack = null;
if (entity instanceof IMob) {
r = 255;
g = 0;
final EnumCreatureAttribute attr = entity.getCreatureAttribute();
switch (attr) {
case ARTHROPOD: {
stack = new ItemStack(Items.spider_eye);
break;
}
case UNDEAD: {
stack = new ItemStack(Items.rotten_flesh);
break;
}
default: {
stack = new ItemStack(Items.skull, 1, 4);
break;
}
}
}
if (entity instanceof IBossDisplayData) {
stack = new ItemStack(Items.skull);
size = (float)NeatConfig.plateSizeBoss;
r = 128;
g = 0;
b = 128;
}
final int armor = entity.getTotalArmorValue();
final boolean useHue = !NeatConfig.colorByType;
if (useHue) {
final float s = Math.max(0.0f, health / maxHealth / 3.0f - 0.07f);
final Color color = Color.getHSBColor(s, 1.0f, 1.0f);
r = color.getRed();
g = color.getGreen();
b = color.getBlue();
}
GL11.glTranslatef(0.0f, pastTranslate, 0.0f);
final float s = 0.5f;
String name = StatCollector.translateToLocal("entity." + EntityList.getEntityString((Entity)entity) + ".name");
if (entity instanceof EntityLiving && ((EntityLiving)entity).hasCustomNameTag()) {
name = EnumChatFormatting.ITALIC + ((EntityLiving)entity).getCustomNameTag();
}
final float namel = mc.fontRenderer.getStringWidth(name) * s;
if (namel + 20.0f > size * 2.0f) {
size = namel / 2.0f + 10.0f;
}
final float healthSize = size * (health / maxHealth);
if (NeatConfig.drawBackground) {
tessellator.startDrawingQuads();
tessellator.setColorRGBA(0, 0, 0, 64);
tessellator.addVertex((double)(-size - padding), (double)(-bgHeight), 0.0);
tessellator.addVertex((double)(-size - padding), (double)(barHeight + padding), 0.0);
tessellator.addVertex((double)(size + padding), (double)(barHeight + padding), 0.0);
tessellator.addVertex((double)(size + padding), (double)(-bgHeight), 0.0);
tessellator.draw();
}
tessellator.startDrawingQuads();
tessellator.setColorRGBA(127, 127, 127, 127);
tessellator.addVertex((double)(-size), 0.0, 0.0);
tessellator.addVertex((double)(-size), (double)barHeight, 0.0);
tessellator.addVertex((double)size, (double)barHeight, 0.0);
tessellator.addVertex((double)size, 0.0, 0.0);
tessellator.draw();
tessellator.startDrawingQuads();
tessellator.setColorRGBA(r, g, b, 127);
tessellator.addVertex((double)(-size), 0.0, 0.0);
tessellator.addVertex((double)(-size), (double)barHeight, 0.0);
tessellator.addVertex((double)(healthSize * 2.0f - size), (double)barHeight, 0.0);
tessellator.addVertex((double)(healthSize * 2.0f - size), 0.0, 0.0);
tessellator.draw();
GL11.glEnable(3553);
GL11.glPushMatrix();
GL11.glTranslatef(-size, -4.5f, 0.0f);
GL11.glScalef(s, s, s);
mc.fontRenderer.drawString(name, 0, 0, 16777215);
GL11.glPushMatrix();
float s2 = 0.75f;
GL11.glScalef(s2, s2, s2);
final int h = NeatConfig.hpTextHeight;
String maxHpStr = EnumChatFormatting.BOLD + "" + Math.round(maxHealth * 100.0) / 100.0;
String hpStr = "" + Math.round(health * 100.0) / 100.0;
final String percStr = (int)percent + "%";
if (maxHpStr.endsWith(".0")) {
maxHpStr = maxHpStr.substring(0, maxHpStr.length() - 2);
}
if (hpStr.endsWith(".0")) {
hpStr = hpStr.substring(0, hpStr.length() - 2);
}
if (NeatConfig.showCurrentHP) {
mc.fontRenderer.drawString(hpStr, 2, h, 16777215);
}
if (NeatConfig.showMaxHP) {
mc.fontRenderer.drawString(maxHpStr, (int)(size / (s * s2) * 2.0f) - 2 - mc.fontRenderer.getStringWidth(maxHpStr), h, 16777215);
}
if (NeatConfig.showPercentage) {
mc.fontRenderer.drawString(percStr, (int)(size / (s * s2)) - mc.fontRenderer.getStringWidth(percStr) / 2, h, -1);
}
GL11.glPopMatrix();
GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
int off = 0;
s2 = 0.5f;
GL11.glScalef(s2, s2, s2);
GL11.glTranslatef(size / (s * s2) * 2.0f - 16.0f, 0.0f, 0.0f);
mc.renderEngine.bindTexture(TextureMap.locationItemsTexture);
if (stack != null && NeatConfig.showAttributes) {
RenderItem.getInstance().renderIcon(off, 0, stack.getIconIndex(), 16, 16);
off -= 16;
}
if (armor > 0 && NeatConfig.showArmor) {
int ironArmor = armor % 5;
int diamondArmor = armor / 5;
if (!NeatConfig.groupArmor) {
ironArmor = armor;
diamondArmor = 0;
}
stack = new ItemStack((Item)Items.iron_chestplate);
for (int i = 0; i < ironArmor; ++i) {
RenderItem.getInstance().renderIcon(off, 0, stack.getIconIndex(), 16, 16);
off -= 4;
}
stack = new ItemStack((Item)Items.diamond_chestplate);
for (int i = 0; i < diamondArmor; ++i) {
RenderItem.getInstance().renderIcon(off, 0, stack.getIconIndex(), 16, 16);
off -= 4;
}
}
GL11.glPopMatrix();
GL11.glEnable(2929);
GL11.glDepthMask(true);
GL11.glEnable(2896);
GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
GL11.glPopMatrix();
pastTranslate = -(bgHeight + barHeight + padding);
}
}
final Entity riddenBy = entity.riddenByEntity;
if (!(riddenBy instanceof EntityLivingBase)) {
return;
}
entity = (EntityLivingBase)riddenBy;
}
}
}
}
Ругается на строку
Java:
for (final Entity entity : entities) {