1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
package kubatech.client.effect;
import static net.minecraft.client.renderer.entity.RenderManager.*;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import kubatech.Tags;
import kubatech.api.utils.MobUtils;
import kubatech.config.Config;
import net.minecraft.client.Minecraft;
import net.minecraft.client.particle.EntityFX;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.EntityLiving;
import net.minecraft.world.World;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
import org.lwjgl.util.glu.GLU;
@SideOnly(Side.CLIENT)
public class EntityRenderer extends EntityFX {
private static final Logger LOG = LogManager.getLogger(Tags.MODID + "[Entity Renderer]");
private EntityLiving entityToRender = null;
public EntityRenderer(World p_i1218_1_, double x, double y, double z, int age) {
super(p_i1218_1_, x + 0.5d, y, z + 0.5d);
this.particleMaxAge = age;
this.particleAge = 0;
}
public EntityRenderer(EntityRenderer r, int age) {
super(r.worldObj, r.posX, r.posY, r.posZ);
this.particleMaxAge = age;
this.particleAge = 0;
this.ticksExisted = r.ticksExisted;
this.entityToRender = r.entityToRender;
}
@Override
protected void entityInit() {}
@Override
public void onUpdate() {
if (this.entityToRender == null) return;
this.ticksExisted++;
if (ticksExisted % 20 == 0) entityToRender.hurtTime = 10;
else if (entityToRender.hurtTime > 0) entityToRender.hurtTime--;
if (this.particleAge++ == this.particleMaxAge) {
this.setDead();
}
}
@Override
public boolean shouldRenderInPass(int pass) {
return pass == 3;
}
@Override
public int getFXLayer() {
return 3;
}
public void setEntity(EntityLiving entity) {
this.entityToRender = entity;
}
@Override
public void renderParticle(
Tessellator p_70539_1_,
float p_70539_2_,
float p_70539_3_,
float p_70539_4_,
float p_70539_5_,
float p_70539_6_,
float p_70539_7_) {
if (entityToRender == null) return;
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_COLOR_MATERIAL);
entityToRender.worldObj = this.worldObj;
entityToRender.setPosition(this.posX, this.posY, this.posZ);
Minecraft mc = Minecraft.getMinecraft();
double rotation;
double headrotation;
{
double x1 = this.posX;
double x2 = mc.thePlayer.posX;
double y1 = this.posZ;
double y2 = mc.thePlayer.posZ;
double k = Math.toDegrees(Math.atan2(x2 - x1, y1 - y2));
if (k < 0d) k += 360d;
k -= 180d;
rotation = k;
}
{
double y1 = this.posY + entityToRender.getEyeHeight();
double y2 = mc.thePlayer.posY + mc.thePlayer.getEyeHeight();
double d = mc.thePlayer.getDistance(this.posX, y2, this.posZ);
double k = Math.toDegrees(Math.atan2(y1 - y2, d));
if (k < 0d) k += 360d;
headrotation = k;
}
entityToRender.prevRotationYawHead = entityToRender.rotationYawHead;
entityToRender.prevRenderYawOffset = entityToRender.renderYawOffset;
entityToRender.prevRotationPitch = entityToRender.rotationPitch;
entityToRender.renderYawOffset = (float) rotation;
entityToRender.rotationYawHead = (float) rotation;
entityToRender.rotationPitch = (float) headrotation;
float p_147936_2_ = 0.5f;
float f1 = entityToRender.prevRotationYaw
+ (entityToRender.rotationYaw - entityToRender.prevRotationYaw) * p_147936_2_;
int i = entityToRender.getBrightnessForRender(p_147936_2_);
if (entityToRender.isBurning()) {
i = 15728880;
}
int j = i % 65536;
int k = i / 65536;
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, (float) j, (float) k);
GL11.glColor4f(1f, 1f, 1f, 1F);
RenderHelper.enableStandardItemLighting();
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
int stackdepth = GL11.glGetInteger(GL11.GL_MODELVIEW_STACK_DEPTH);
GL11.glPushMatrix();
GL11.glTranslatef(
(float) (this.posX - renderPosX), (float) (this.posY - renderPosY), (float) (this.posZ - renderPosZ));
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
float desiredScale = MobUtils.getDesiredScale(entityToRender, 2f);
if (desiredScale < 1f) GL11.glScalef(desiredScale, desiredScale, desiredScale);
try {
instance.renderEntityWithPosYaw(entityToRender, 0f, 0f, 0f, f1, p_147936_2_);
} catch (Throwable ex) {
Tessellator tes = Tessellator.instance;
try {
tes.draw();
} catch (Exception ignored) {
}
}
GL11.glMatrixMode(GL11.GL_MODELVIEW_MATRIX);
stackdepth -= GL11.glGetInteger(GL11.GL_MODELVIEW_STACK_DEPTH);
if (stackdepth < 0) for (; stackdepth < 0; stackdepth++) GL11.glPopMatrix();
if (stackdepth > 0) for (; stackdepth > 0; stackdepth--) GL11.glPushMatrix();
GL11.glPopAttrib();
int err;
while ((err = GL11.glGetError()) != GL11.GL_NO_ERROR)
if (Config.Debug.showRenderErrors)
LOG.error(EntityList.getEntityString(entityToRender) + " | GL ERROR: " + err + " / "
+ GLU.gluErrorString(err));
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_COLOR_MATERIAL);
}
}
|