ModelRenderer .java

net.minecraft.client.model.ModelRenderer (class): members: renderWithRotation, setRotationPoint, rotationPointX, rotationPointY, rotationPointZ, showModel.

net.minecraft.client.modelclass314 linesclient11.0 KB

API Surface (11)

void addChild(ModelRenderer renderer)
ModelRenderer setTextureOffset(int x, int y)
ModelRenderer addBox(String partName, float offX, float offY, float offZ, int width, int height, int depth)
ModelRenderer addBox(float offX, float offY, float offZ, int width, int height, int depth)
ModelRenderer addBox(float p_178769_1_, float p_178769_2_, float p_178769_3_, int p_178769_4_, int p_178769_5_, int p_178769_6_, boolean p_178769_7_)
void addBox(float p_78790_1_, float p_78790_2_, float p_78790_3_, int width, int height, int depth, float scaleFactor)
void setRotationPoint(float rotationPointXIn, float rotationPointYIn, float rotationPointZIn)
void render(float p_78785_1_)
void renderWithRotation(float p_78791_1_)
void postRender(float scale)
ModelRenderer setTextureSize(int textureWidthIn, int textureHeightIn)

Fields & Constants (22)

textureWidth
textureHeight
textureOffsetX
textureOffsetY
rotationPointX
rotationPointY
rotationPointZ
rotateAngleX
rotateAngleY
rotateAngleZ
compiled
displayList
mirror
showModel
isHidden
cubeList
childModels
boxName
baseModel
offsetX
offsetY
offsetZ

Code Graph: Dependencies (6)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

ModelRenderer.java314 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.client.model;
2
3
import com.google.common.collect.Lists;
4
import java.util.List;
5
import net.minecraft.client.renderer.GLAllocation;
6
import net.minecraft.client.renderer.GlStateManager;
7
import net.minecraft.client.renderer.Tessellator;
8
import net.minecraft.client.renderer.WorldRenderer;
9
import org.lwjgl.opengl.GL11;
10
11
public class ModelRenderer
12
{
13
    /** The size of the texture file's width in pixels. */
14
    public float textureWidth;
15
16
    /** The size of the texture file's height in pixels. */
17
    public float textureHeight;
18
19
    /** The X offset into the texture used for displaying this model */
20
    private int textureOffsetX;
21
22
    /** The Y offset into the texture used for displaying this model */
23
    private int textureOffsetY;
24
    public float rotationPointX;
25
    public float rotationPointY;
26
    public float rotationPointZ;
27
    public float rotateAngleX;
28
    public float rotateAngleY;
29
    public float rotateAngleZ;
30
    private boolean compiled;
31
32
    /** The GL display list rendered by the Tessellator for this model */
33
    private int displayList;
34
    public boolean mirror;
35
    public boolean showModel;
36
37
    /** Hides the model. */
38
    public boolean isHidden;
39
    public List<ModelBox> cubeList;
40
    public List<ModelRenderer> childModels;
41
    public final String boxName;
42
    private ModelBase baseModel;
43
    public float offsetX;
44
    public float offsetY;
45
    public float offsetZ;
46
47
    public ModelRenderer(ModelBase model, String boxNameIn)
48
    {
49
        this.textureWidth = 64.0F;
50
        this.textureHeight = 32.0F;
51
        this.showModel = true;
52
        this.cubeList = Lists.<ModelBox>newArrayList();
53
        this.baseModel = model;
54
        model.boxList.add(this);
55
        this.boxName = boxNameIn;
56
        this.setTextureSize(model.textureWidth, model.textureHeight);
57
    }
58
59
    public ModelRenderer(ModelBase model)
60
    {
61
        this(model, (String)null);
62
    }
63
64
    public ModelRenderer(ModelBase model, int texOffX, int texOffY)
65
    {
66
        this(model);
67
        this.setTextureOffset(texOffX, texOffY);
68
    }
69
70
    /**
71
     * Sets the current box's rotation points and rotation angles to another box.
72
     */
73
    public void addChild(ModelRenderer renderer)
74
    {
75
        if (this.childModels == null)
76
        {
77
            this.childModels = Lists.<ModelRenderer>newArrayList();
78
        }
79
80
        this.childModels.add(renderer);
81
    }
82
83
    public ModelRenderer setTextureOffset(int x, int y)
84
    {
85
        this.textureOffsetX = x;
86
        this.textureOffsetY = y;
87
        return this;
88
    }
89
90
    public ModelRenderer addBox(String partName, float offX, float offY, float offZ, int width, int height, int depth)
91
    {
92
        partName = this.boxName + "." + partName;
93
        TextureOffset textureoffset = this.baseModel.getTextureOffset(partName);
94
        this.setTextureOffset(textureoffset.textureOffsetX, textureoffset.textureOffsetY);
95
        this.cubeList.add((new ModelBox(this, this.textureOffsetX, this.textureOffsetY, offX, offY, offZ, width, height, depth, 0.0F)).setBoxName(partName));
96
        return this;
97
    }
98
99
    public ModelRenderer addBox(float offX, float offY, float offZ, int width, int height, int depth)
100
    {
101
        this.cubeList.add(new ModelBox(this, this.textureOffsetX, this.textureOffsetY, offX, offY, offZ, width, height, depth, 0.0F));
102
        return this;
103
    }
104
105
    public ModelRenderer addBox(float p_178769_1_, float p_178769_2_, float p_178769_3_, int p_178769_4_, int p_178769_5_, int p_178769_6_, boolean p_178769_7_)
106
    {
107
        this.cubeList.add(new ModelBox(this, this.textureOffsetX, this.textureOffsetY, p_178769_1_, p_178769_2_, p_178769_3_, p_178769_4_, p_178769_5_, p_178769_6_, 0.0F, p_178769_7_));
108
        return this;
109
    }
110
111
    /**
112
     * Creates a textured box. Args: originX, originY, originZ, width, height, depth, scaleFactor.
113
     */
114
    public void addBox(float p_78790_1_, float p_78790_2_, float p_78790_3_, int width, int height, int depth, float scaleFactor)
115
    {
116
        this.cubeList.add(new ModelBox(this, this.textureOffsetX, this.textureOffsetY, p_78790_1_, p_78790_2_, p_78790_3_, width, height, depth, scaleFactor));
117
    }
118
119
    public void setRotationPoint(float rotationPointXIn, float rotationPointYIn, float rotationPointZIn)
120
    {
121
        this.rotationPointX = rotationPointXIn;
122
        this.rotationPointY = rotationPointYIn;
123
        this.rotationPointZ = rotationPointZIn;
124
    }
125
126
    public void render(float p_78785_1_)
127
    {
128
        if (!this.isHidden)
129
        {
130
            if (this.showModel)
131
            {
132
                if (!this.compiled)
133
                {
134
                    this.compileDisplayList(p_78785_1_);
135
                }
136
137
                GlStateManager.translate(this.offsetX, this.offsetY, this.offsetZ);
138
139
                if (this.rotateAngleX == 0.0F && this.rotateAngleY == 0.0F && this.rotateAngleZ == 0.0F)
140
                {
141
                    if (this.rotationPointX == 0.0F && this.rotationPointY == 0.0F && this.rotationPointZ == 0.0F)
142
                    {
143
                        GlStateManager.callList(this.displayList);
144
145
                        if (this.childModels != null)
146
                        {
147
                            for (int k = 0; k < this.childModels.size(); ++k)
148
                            {
149
                                ((ModelRenderer)this.childModels.get(k)).render(p_78785_1_);
150
                            }
151
                        }
152
                    }
153
                    else
154
                    {
155
                        GlStateManager.translate(this.rotationPointX * p_78785_1_, this.rotationPointY * p_78785_1_, this.rotationPointZ * p_78785_1_);
156
                        GlStateManager.callList(this.displayList);
157
158
                        if (this.childModels != null)
159
                        {
160
                            for (int j = 0; j < this.childModels.size(); ++j)
161
                            {
162
                                ((ModelRenderer)this.childModels.get(j)).render(p_78785_1_);
163
                            }
164
                        }
165
166
                        GlStateManager.translate(-this.rotationPointX * p_78785_1_, -this.rotationPointY * p_78785_1_, -this.rotationPointZ * p_78785_1_);
167
                    }
168
                }
169
                else
170
                {
171
                    GlStateManager.pushMatrix();
172
                    GlStateManager.translate(this.rotationPointX * p_78785_1_, this.rotationPointY * p_78785_1_, this.rotationPointZ * p_78785_1_);
173
174
                    if (this.rotateAngleZ != 0.0F)
175
                    {
176
                        GlStateManager.rotate(this.rotateAngleZ * (180F / (float)Math.PI), 0.0F, 0.0F, 1.0F);
177
                    }
178
179
                    if (this.rotateAngleY != 0.0F)
180
                    {
181
                        GlStateManager.rotate(this.rotateAngleY * (180F / (float)Math.PI), 0.0F, 1.0F, 0.0F);
182
                    }
183
184
                    if (this.rotateAngleX != 0.0F)
185
                    {
186
                        GlStateManager.rotate(this.rotateAngleX * (180F / (float)Math.PI), 1.0F, 0.0F, 0.0F);
187
                    }
188
189
                    GlStateManager.callList(this.displayList);
190
191
                    if (this.childModels != null)
192
                    {
193
                        for (int i = 0; i < this.childModels.size(); ++i)
194
                        {
195
                            ((ModelRenderer)this.childModels.get(i)).render(p_78785_1_);
196
                        }
197
                    }
198
199
                    GlStateManager.popMatrix();
200
                }
201
202
                GlStateManager.translate(-this.offsetX, -this.offsetY, -this.offsetZ);
203
            }
204
        }
205
    }
206
207
    public void renderWithRotation(float p_78791_1_)
208
    {
209
        if (!this.isHidden)
210
        {
211
            if (this.showModel)
212
            {
213
                if (!this.compiled)
214
                {
215
                    this.compileDisplayList(p_78791_1_);
216
                }
217
218
                GlStateManager.pushMatrix();
219
                GlStateManager.translate(this.rotationPointX * p_78791_1_, this.rotationPointY * p_78791_1_, this.rotationPointZ * p_78791_1_);
220
221
                if (this.rotateAngleY != 0.0F)
222
                {
223
                    GlStateManager.rotate(this.rotateAngleY * (180F / (float)Math.PI), 0.0F, 1.0F, 0.0F);
224
                }
225
226
                if (this.rotateAngleX != 0.0F)
227
                {
228
                    GlStateManager.rotate(this.rotateAngleX * (180F / (float)Math.PI), 1.0F, 0.0F, 0.0F);
229
                }
230
231
                if (this.rotateAngleZ != 0.0F)
232
                {
233
                    GlStateManager.rotate(this.rotateAngleZ * (180F / (float)Math.PI), 0.0F, 0.0F, 1.0F);
234
                }
235
236
                GlStateManager.callList(this.displayList);
237
                GlStateManager.popMatrix();
238
            }
239
        }
240
    }
241
242
    /**
243
     * Allows the changing of Angles after a box has been rendered
244
     */
245
    public void postRender(float scale)
246
    {
247
        if (!this.isHidden)
248
        {
249
            if (this.showModel)
250
            {
251
                if (!this.compiled)
252
                {
253
                    this.compileDisplayList(scale);
254
                }
255
256
                if (this.rotateAngleX == 0.0F && this.rotateAngleY == 0.0F && this.rotateAngleZ == 0.0F)
257
                {
258
                    if (this.rotationPointX != 0.0F || this.rotationPointY != 0.0F || this.rotationPointZ != 0.0F)
259
                    {
260
                        GlStateManager.translate(this.rotationPointX * scale, this.rotationPointY * scale, this.rotationPointZ * scale);
261
                    }
262
                }
263
                else
264
                {
265
                    GlStateManager.translate(this.rotationPointX * scale, this.rotationPointY * scale, this.rotationPointZ * scale);
266
267
                    if (this.rotateAngleZ != 0.0F)
268
                    {
269
                        GlStateManager.rotate(this.rotateAngleZ * (180F / (float)Math.PI), 0.0F, 0.0F, 1.0F);
270
                    }
271
272
                    if (this.rotateAngleY != 0.0F)
273
                    {
274
                        GlStateManager.rotate(this.rotateAngleY * (180F / (float)Math.PI), 0.0F, 1.0F, 0.0F);
275
                    }
276
277
                    if (this.rotateAngleX != 0.0F)
278
                    {
279
                        GlStateManager.rotate(this.rotateAngleX * (180F / (float)Math.PI), 1.0F, 0.0F, 0.0F);
280
                    }
281
                }
282
            }
283
        }
284
    }
285
286
    /**
287
     * Compiles a GL display list for this model
288
     */
289
    private void compileDisplayList(float scale)
290
    {
291
        this.displayList = GLAllocation.generateDisplayLists(1);
292
        GL11.glNewList(this.displayList, GL11.GL_COMPILE);
293
        WorldRenderer worldrenderer = Tessellator.getInstance().getWorldRenderer();
294
295
        for (int i = 0; i < this.cubeList.size(); ++i)
296
        {
297
            ((ModelBox)this.cubeList.get(i)).render(worldrenderer, scale);
298
        }
299
300
        GL11.glEndList();
301
        this.compiled = true;
302
    }
303
304
    /**
305
     * Returns the model renderer with the new texture parameters.
306
     */
307
    public ModelRenderer setTextureSize(int textureWidthIn, int textureHeightIn)
308
    {
309
        this.textureWidth = (float)textureWidthIn;
310
        this.textureHeight = (float)textureHeightIn;
311
        return this;
312
    }
313
}
314

Deobfuscated MCP 1.8.9 source of ModelRenderer from Marcelektro/MavenMCP-1.8.9 (net/minecraft/client/model/ModelRenderer.java), stored verbatim.