summaryrefslogtreecommitdiff
path: root/ihl/model/IHLModelRenderer.java
blob: a9168f8dbe29bde7112d59f15459253d359d5516 (plain)
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
package ihl.model;

import java.util.ArrayList;
import java.util.List;

import org.lwjgl.opengl.GL11;

import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.client.model.TextureOffset;
import net.minecraft.client.renderer.GLAllocation;
import net.minecraft.client.renderer.Tessellator;
import net.minecraftforge.common.util.ForgeDirection;

public class IHLModelRenderer {
	    /** The size of the texture file's width in pixels. */
	    public float textureWidth;

	    /** The size of the texture file's height in pixels. */
	    public float textureHeight;

	    /** The X offset into the texture used for displaying this model */
	    private int textureOffsetX;

	    /** The Y offset into the texture used for displaying this model */
	    private int textureOffsetY;
	    public float rotationPointX;
	    public float rotationPointY;
	    public float rotationPointZ;
	    public float rotateAngleX;
	    public float rotateAngleY;
	    public float rotateAngleZ;
	    private boolean compiled;

	    /** The GL display list rendered by the Tessellator for this model */
	    private int displayList;
	    public boolean mirror;
	    public boolean showModel;

	    /** Hides the model. */
	    public boolean isHidden;
	    public List<Object> cubeList;
	    public List<ModelRenderer> childModels;
	    public final String boxName;
	    private ModelBase baseModel;
	    public float offsetX;
	    public float offsetY;
	    public float offsetZ;

		public boolean drawFromInside=false;
		
	    @SuppressWarnings("unchecked")
		public IHLModelRenderer(ModelBase par1ModelBase, String par2Str)
	    {
	        this.textureWidth = 64.0F;
	        this.textureHeight = 32.0F;
	        this.showModel = true;
	        this.cubeList = new ArrayList<Object>();
	        this.baseModel = par1ModelBase;
	        par1ModelBase.boxList.add(this);
	        this.boxName = par2Str;
	        this.setTextureSize(par1ModelBase.textureWidth, par1ModelBase.textureHeight);
	    }

	    public IHLModelRenderer(ModelBase par1ModelBase)
	    {
	        this(par1ModelBase, (String)null);
	    }

	    public IHLModelRenderer(ModelBase par1ModelBase, int par2, int par3)
	    {
	        this(par1ModelBase);
	        this.setTextureOffset(par2, par3);
	    }

	    /**
	     * Sets the current box's rotation points and rotation angles to another box.
	     */
	    public void addChild(ModelRenderer par1ModelRenderer)
	    {
	        if (this.childModels == null)
	        {
	            this.childModels = new ArrayList<ModelRenderer>();
	        }

	        this.childModels.add(par1ModelRenderer);
	    }

	    public IHLModelRenderer setTextureOffset(int par1, int par2)
	    {
	        this.textureOffsetX = par1;
	        this.textureOffsetY = par2;
	        return this;
	    }

	    public IHLModelRenderer addBox(String par1Str, float par2, float par3, float par4, int par5, int par6, int par7, boolean inverted, boolean[] renderFace)
	    {
	        par1Str = this.boxName + "." + par1Str;
	        TextureOffset var8 = this.baseModel.getTextureOffset(par1Str);
	        this.setTextureOffset(var8.textureOffsetX, var8.textureOffsetY);
	        this.cubeList.add((new ModelToplessBox(this, this.textureOffsetX, this.textureOffsetY, par2, par3, par4, par5, par6, par7, 0.0F, inverted, renderFace)).func_78244_a(par1Str));
	        return this;
	    }
	    
	    public IHLModelRenderer addBox(String par1Str, float par2, float par3, float par4, int par5, int par6, int par7, boolean inverted)
	    {
	    	boolean[] renderFace={true,true,true,true,true,true};
	        par1Str = this.boxName + "." + par1Str;
	        TextureOffset var8 = this.baseModel.getTextureOffset(par1Str);
	        this.setTextureOffset(var8.textureOffsetX, var8.textureOffsetY);
	        this.cubeList.add((new ModelToplessBox(this, this.textureOffsetX, this.textureOffsetY, par2, par3, par4, par5, par6, par7, 0.0F, inverted, renderFace)).func_78244_a(par1Str));
	        return this;
	    }

	    public IHLModelRenderer addBox(float par1, float par2, float par3, int par4, int par5, int par6, boolean inverted, boolean[] renderFace)
	    {
	        this.cubeList.add(new ModelToplessBox(this, this.textureOffsetX, this.textureOffsetY, par1, par2, par3, par4, par5, par6, 0.0F, inverted, renderFace));
	        return this;
	    }
	    
	    public IHLModelRenderer addTube(String par1Str, float par1, float par2, float par3, int par4, int par5, int par6, float radius1, float radius2, ForgeDirection direction)
	    {
	        par1Str = this.boxName + "." + par1Str;
	        TextureOffset var8 = this.baseModel.getTextureOffset(par1Str);
	        this.setTextureOffset(var8.textureOffsetX, var8.textureOffsetY);
	        this.cubeList.add(new ModelTube(this, this.textureOffsetX, this.textureOffsetY, par1, par2, par3, par4, par5, par6, 0.0F, radius1,radius2, direction));
	        return this;
	    }
	    
	    public IHLModelRenderer addKnee(String par1Str, float par1, float par2, float par3, int par4, int par5, int par6, float radius1, float radius2, ForgeDirection direction, ForgeDirection direction2)
	    {
	        par1Str = this.boxName + "." + par1Str;
	        TextureOffset var8 = this.baseModel.getTextureOffset(par1Str);
	        this.setTextureOffset(var8.textureOffsetX, var8.textureOffsetY);
	        this.cubeList.add(new ModelKnee(this, this.textureOffsetX, this.textureOffsetY, par1, par2, par3, par4, par5, par6, 0.0F, radius1,radius2, direction, direction2));
	        return this;
	    }
	    
	    public IHLModelRenderer addBox(float par1, float par2, float par3, int par4, int par5, int par6)
	    {
	    	boolean[] renderFace={true,true,true,true,true,true};
	        this.cubeList.add(new ModelToplessBox(this, this.textureOffsetX, this.textureOffsetY, par1, par2, par3, par4, par5, par6, 0.0F, false, renderFace));
	        return this;
	    }

	    /**
	     * Creates a textured box. Args: originX, originY, originZ, width, height, depth, scaleFactor.
	     */
	    public void addBox(float par1, float par2, float par3, int par4, int par5, int par6, float par7, boolean inverted, boolean[] renderFace)
	    {
	        this.cubeList.add(new ModelToplessBox(this, this.textureOffsetX, this.textureOffsetY, par1, par2, par3, par4, par5, par6, par7, inverted, renderFace));
	    }

	    public void setRotationPoint(float par1, float par2, float par3)
	    {
	        this.rotationPointX = par1;
	        this.rotationPointY = par2;
	        this.rotationPointZ = par3;
	    }

	    public void render(float par1)
	    {
	        if (!this.isHidden)
	        {
	            if (this.showModel)
	            {
	                if (!this.compiled)
	                {
	                    this.compileDisplayList(par1);
	                }

	                GL11.glTranslatef(this.offsetX, this.offsetY, this.offsetZ);
	                int var2;

	                if (this.rotateAngleX == 0.0F && this.rotateAngleY == 0.0F && this.rotateAngleZ == 0.0F)
	                {
	                    if (this.rotationPointX == 0.0F && this.rotationPointY == 0.0F && this.rotationPointZ == 0.0F)
	                    {
	                        GL11.glCallList(this.displayList);

	                        if (this.childModels != null)
	                        {
	                            for (var2 = 0; var2 < this.childModels.size(); ++var2)
	                            {
	                                ((ModelRenderer)this.childModels.get(var2)).render(par1);
	                            }
	                        }
	                    }
	                    else
	                    {
	                        GL11.glTranslatef(this.rotationPointX * par1, this.rotationPointY * par1, this.rotationPointZ * par1);
	                        GL11.glCallList(this.displayList);

	                        if (this.childModels != null)
	                        {
	                            for (var2 = 0; var2 < this.childModels.size(); ++var2)
	                            {
	                                ((ModelRenderer)this.childModels.get(var2)).render(par1);
	                            }
	                        }

	                        GL11.glTranslatef(-this.rotationPointX * par1, -this.rotationPointY * par1, -this.rotationPointZ * par1);
	                    }
	                }
	                else
	                {
	                    GL11.glPushMatrix();
	                    GL11.glTranslatef(this.rotationPointX * par1, this.rotationPointY * par1, this.rotationPointZ * par1);

	                    if (this.rotateAngleZ != 0.0F)
	                    {
	                        GL11.glRotatef(this.rotateAngleZ * (180F / (float)Math.PI), 0.0F, 0.0F, 1.0F);
	                    }

	                    if (this.rotateAngleY != 0.0F)
	                    {
	                        GL11.glRotatef(this.rotateAngleY * (180F / (float)Math.PI), 0.0F, 1.0F, 0.0F);
	                    }

	                    if (this.rotateAngleX != 0.0F)
	                    {
	                        GL11.glRotatef(this.rotateAngleX * (180F / (float)Math.PI), 1.0F, 0.0F, 0.0F);
	                    }

	                    GL11.glCallList(this.displayList);

	                    if (this.childModels != null)
	                    {
	                        for (var2 = 0; var2 < this.childModels.size(); ++var2)
	                        {
	                            ((ModelRenderer)this.childModels.get(var2)).render(par1);
	                        }
	                    }

	                    GL11.glPopMatrix();
	                }

	                GL11.glTranslatef(-this.offsetX, -this.offsetY, -this.offsetZ);
	            }
	        }
	    }

	    public void renderWithRotation(float par1)
	    {
	        if (!this.isHidden)
	        {
	            if (this.showModel)
	            {
	                if (!this.compiled)
	                {
	                    this.compileDisplayList(par1);
	                }

	                GL11.glPushMatrix();
	                GL11.glTranslatef(this.rotationPointX * par1, this.rotationPointY * par1, this.rotationPointZ * par1);

	                if (this.rotateAngleY != 0.0F)
	                {
	                    GL11.glRotatef(this.rotateAngleY * (180F / (float)Math.PI), 0.0F, 1.0F, 0.0F);
	                }

	                if (this.rotateAngleX != 0.0F)
	                {
	                    GL11.glRotatef(this.rotateAngleX * (180F / (float)Math.PI), 1.0F, 0.0F, 0.0F);
	                }

	                if (this.rotateAngleZ != 0.0F)
	                {
	                    GL11.glRotatef(this.rotateAngleZ * (180F / (float)Math.PI), 0.0F, 0.0F, 1.0F);
	                }

	                GL11.glCallList(this.displayList);
	                GL11.glPopMatrix();
	            }
	        }
	    }

	    /**
	     * Allows the changing of Angles after a box has been rendered
	     */
	    public void postRender(float par1)
	    {
	        if (!this.isHidden)
	        {
	            if (this.showModel)
	            {
	                if (!this.compiled)
	                {
	                    this.compileDisplayList(par1);
	                }

	                if (this.rotateAngleX == 0.0F && this.rotateAngleY == 0.0F && this.rotateAngleZ == 0.0F)
	                {
	                    if (this.rotationPointX != 0.0F || this.rotationPointY != 0.0F || this.rotationPointZ != 0.0F)
	                    {
	                        GL11.glTranslatef(this.rotationPointX * par1, this.rotationPointY * par1, this.rotationPointZ * par1);
	                    }
	                }
	                else
	                {
	                    GL11.glTranslatef(this.rotationPointX * par1, this.rotationPointY * par1, this.rotationPointZ * par1);

	                    if (this.rotateAngleZ != 0.0F)
	                    {
	                        GL11.glRotatef(this.rotateAngleZ * (180F / (float)Math.PI), 0.0F, 0.0F, 1.0F);
	                    }

	                    if (this.rotateAngleY != 0.0F)
	                    {
	                        GL11.glRotatef(this.rotateAngleY * (180F / (float)Math.PI), 0.0F, 1.0F, 0.0F);
	                    }

	                    if (this.rotateAngleX != 0.0F)
	                    {
	                        GL11.glRotatef(this.rotateAngleX * (180F / (float)Math.PI), 1.0F, 0.0F, 0.0F);
	                    }
	                }
	            }
	        }
	    }

	    /**
	     * Compiles a GL display list for this model
	     */
	    private void compileDisplayList(float par1)
	    {
	        this.displayList = GLAllocation.generateDisplayLists(1);
	        GL11.glNewList(this.displayList, GL11.GL_COMPILE);
	        Tessellator var2 = Tessellator.instance;

	        for (int var3 = 0; var3 < this.cubeList.size(); ++var3)
	        {
	        	if(this.cubeList.get(var3) instanceof ModelToplessBox)
	        	{
	        		((ModelToplessBox)this.cubeList.get(var3)).render(var2, par1);
	        	}
	        	else if(this.cubeList.get(var3) instanceof ModelTube)
	        	{
	        		((ModelTube)this.cubeList.get(var3)).render(var2, par1);
	        	}
	        	else if(this.cubeList.get(var3) instanceof ModelKnee)
	        	{
	        		((ModelKnee)this.cubeList.get(var3)).render(var2, par1);
	        	}
	        }

	        GL11.glEndList();
	        this.compiled = true;
	    }

	    /**
	     * Returns the model renderer with the new texture parameters.
	     */
	    public IHLModelRenderer setTextureSize(int par1, int par2)
	    {
	        this.textureWidth = par1;
	        this.textureHeight = par2;
	        return this;
	    }

		public void addBox(String string, float f, float g, float h, int i,	int j, int k) {
			this.addBox(string, f, g, h, i, j, k, false);
		}


}