001    package net.minecraft.client.model;
002    
003    import cpw.mods.fml.relauncher.Side;
004    import cpw.mods.fml.relauncher.SideOnly;
005    import net.minecraft.entity.Entity;
006    import net.minecraft.entity.EntityLiving;
007    import net.minecraft.entity.boss.EntityDragon;
008    import org.lwjgl.opengl.GL11;
009    
010    @SideOnly(Side.CLIENT)
011    public class ModelDragon extends ModelBase
012    {
013        /** The head Model renderer of the dragon */
014        private ModelRenderer head;
015    
016        /** The neck Model renderer of the dragon */
017        private ModelRenderer neck;
018    
019        /** The jaw Model renderer of the dragon */
020        private ModelRenderer jaw;
021    
022        /** The body Model renderer of the dragon */
023        private ModelRenderer body;
024    
025        /** The rear leg Model renderer of the dragon */
026        private ModelRenderer rearLeg;
027    
028        /** The front leg Model renderer of the dragon */
029        private ModelRenderer frontLeg;
030    
031        /** The rear leg tip Model renderer of the dragon */
032        private ModelRenderer rearLegTip;
033    
034        /** The front leg tip Model renderer of the dragon */
035        private ModelRenderer frontLegTip;
036    
037        /** The rear foot Model renderer of the dragon */
038        private ModelRenderer rearFoot;
039    
040        /** The front foot Model renderer of the dragon */
041        private ModelRenderer frontFoot;
042    
043        /** The wing Model renderer of the dragon */
044        private ModelRenderer wing;
045    
046        /** The wing tip Model renderer of the dragon */
047        private ModelRenderer wingTip;
048        private float partialTicks;
049    
050        public ModelDragon(float par1)
051        {
052            this.textureWidth = 256;
053            this.textureHeight = 256;
054            this.setTextureOffset("body.body", 0, 0);
055            this.setTextureOffset("wing.skin", -56, 88);
056            this.setTextureOffset("wingtip.skin", -56, 144);
057            this.setTextureOffset("rearleg.main", 0, 0);
058            this.setTextureOffset("rearfoot.main", 112, 0);
059            this.setTextureOffset("rearlegtip.main", 196, 0);
060            this.setTextureOffset("head.upperhead", 112, 30);
061            this.setTextureOffset("wing.bone", 112, 88);
062            this.setTextureOffset("head.upperlip", 176, 44);
063            this.setTextureOffset("jaw.jaw", 176, 65);
064            this.setTextureOffset("frontleg.main", 112, 104);
065            this.setTextureOffset("wingtip.bone", 112, 136);
066            this.setTextureOffset("frontfoot.main", 144, 104);
067            this.setTextureOffset("neck.box", 192, 104);
068            this.setTextureOffset("frontlegtip.main", 226, 138);
069            this.setTextureOffset("body.scale", 220, 53);
070            this.setTextureOffset("head.scale", 0, 0);
071            this.setTextureOffset("neck.scale", 48, 0);
072            this.setTextureOffset("head.nostril", 112, 0);
073            float var2 = -16.0F;
074            this.head = new ModelRenderer(this, "head");
075            this.head.addBox("upperlip", -6.0F, -1.0F, -8.0F + var2, 12, 5, 16);
076            this.head.addBox("upperhead", -8.0F, -8.0F, 6.0F + var2, 16, 16, 16);
077            this.head.mirror = true;
078            this.head.addBox("scale", -5.0F, -12.0F, 12.0F + var2, 2, 4, 6);
079            this.head.addBox("nostril", -5.0F, -3.0F, -6.0F + var2, 2, 2, 4);
080            this.head.mirror = false;
081            this.head.addBox("scale", 3.0F, -12.0F, 12.0F + var2, 2, 4, 6);
082            this.head.addBox("nostril", 3.0F, -3.0F, -6.0F + var2, 2, 2, 4);
083            this.jaw = new ModelRenderer(this, "jaw");
084            this.jaw.setRotationPoint(0.0F, 4.0F, 8.0F + var2);
085            this.jaw.addBox("jaw", -6.0F, 0.0F, -16.0F, 12, 4, 16);
086            this.head.addChild(this.jaw);
087            this.neck = new ModelRenderer(this, "neck");
088            this.neck.addBox("box", -5.0F, -5.0F, -5.0F, 10, 10, 10);
089            this.neck.addBox("scale", -1.0F, -9.0F, -3.0F, 2, 4, 6);
090            this.body = new ModelRenderer(this, "body");
091            this.body.setRotationPoint(0.0F, 4.0F, 8.0F);
092            this.body.addBox("body", -12.0F, 0.0F, -16.0F, 24, 24, 64);
093            this.body.addBox("scale", -1.0F, -6.0F, -10.0F, 2, 6, 12);
094            this.body.addBox("scale", -1.0F, -6.0F, 10.0F, 2, 6, 12);
095            this.body.addBox("scale", -1.0F, -6.0F, 30.0F, 2, 6, 12);
096            this.wing = new ModelRenderer(this, "wing");
097            this.wing.setRotationPoint(-12.0F, 5.0F, 2.0F);
098            this.wing.addBox("bone", -56.0F, -4.0F, -4.0F, 56, 8, 8);
099            this.wing.addBox("skin", -56.0F, 0.0F, 2.0F, 56, 0, 56);
100            this.wingTip = new ModelRenderer(this, "wingtip");
101            this.wingTip.setRotationPoint(-56.0F, 0.0F, 0.0F);
102            this.wingTip.addBox("bone", -56.0F, -2.0F, -2.0F, 56, 4, 4);
103            this.wingTip.addBox("skin", -56.0F, 0.0F, 2.0F, 56, 0, 56);
104            this.wing.addChild(this.wingTip);
105            this.frontLeg = new ModelRenderer(this, "frontleg");
106            this.frontLeg.setRotationPoint(-12.0F, 20.0F, 2.0F);
107            this.frontLeg.addBox("main", -4.0F, -4.0F, -4.0F, 8, 24, 8);
108            this.frontLegTip = new ModelRenderer(this, "frontlegtip");
109            this.frontLegTip.setRotationPoint(0.0F, 20.0F, -1.0F);
110            this.frontLegTip.addBox("main", -3.0F, -1.0F, -3.0F, 6, 24, 6);
111            this.frontLeg.addChild(this.frontLegTip);
112            this.frontFoot = new ModelRenderer(this, "frontfoot");
113            this.frontFoot.setRotationPoint(0.0F, 23.0F, 0.0F);
114            this.frontFoot.addBox("main", -4.0F, 0.0F, -12.0F, 8, 4, 16);
115            this.frontLegTip.addChild(this.frontFoot);
116            this.rearLeg = new ModelRenderer(this, "rearleg");
117            this.rearLeg.setRotationPoint(-16.0F, 16.0F, 42.0F);
118            this.rearLeg.addBox("main", -8.0F, -4.0F, -8.0F, 16, 32, 16);
119            this.rearLegTip = new ModelRenderer(this, "rearlegtip");
120            this.rearLegTip.setRotationPoint(0.0F, 32.0F, -4.0F);
121            this.rearLegTip.addBox("main", -6.0F, -2.0F, 0.0F, 12, 32, 12);
122            this.rearLeg.addChild(this.rearLegTip);
123            this.rearFoot = new ModelRenderer(this, "rearfoot");
124            this.rearFoot.setRotationPoint(0.0F, 31.0F, 4.0F);
125            this.rearFoot.addBox("main", -9.0F, 0.0F, -20.0F, 18, 6, 24);
126            this.rearLegTip.addChild(this.rearFoot);
127        }
128    
129        /**
130         * Used for easily adding entity-dependent animations. The second and third float params here are the same second
131         * and third as in the setRotationAngles method.
132         */
133        public void setLivingAnimations(EntityLiving par1EntityLiving, float par2, float par3, float par4)
134        {
135            this.partialTicks = par4;
136        }
137    
138        /**
139         * Sets the models various rotation angles then renders the model.
140         */
141        public void render(Entity par1Entity, float par2, float par3, float par4, float par5, float par6, float par7)
142        {
143            GL11.glPushMatrix();
144            EntityDragon var8 = (EntityDragon)par1Entity;
145            float var9 = var8.prevAnimTime + (var8.animTime - var8.prevAnimTime) * this.partialTicks;
146            this.jaw.rotateAngleX = (float)(Math.sin((double)(var9 * (float)Math.PI * 2.0F)) + 1.0D) * 0.2F;
147            float var10 = (float)(Math.sin((double)(var9 * (float)Math.PI * 2.0F - 1.0F)) + 1.0D);
148            var10 = (var10 * var10 * 1.0F + var10 * 2.0F) * 0.05F;
149            GL11.glTranslatef(0.0F, var10 - 2.0F, -3.0F);
150            GL11.glRotatef(var10 * 2.0F, 1.0F, 0.0F, 0.0F);
151            float var11 = -30.0F;
152            float var13 = 0.0F;
153            float var14 = 1.5F;
154            double[] var15 = var8.getMovementOffsets(6, this.partialTicks);
155            float var16 = this.updateRotations(var8.getMovementOffsets(5, this.partialTicks)[0] - var8.getMovementOffsets(10, this.partialTicks)[0]);
156            float var17 = this.updateRotations(var8.getMovementOffsets(5, this.partialTicks)[0] + (double)(var16 / 2.0F));
157            var11 += 2.0F;
158            float var18 = var9 * (float)Math.PI * 2.0F;
159            var11 = 20.0F;
160            float var12 = -12.0F;
161            float var21;
162    
163            for (int var19 = 0; var19 < 5; ++var19)
164            {
165                double[] var20 = var8.getMovementOffsets(5 - var19, this.partialTicks);
166                var21 = (float)Math.cos((double)((float)var19 * 0.45F + var18)) * 0.15F;
167                this.neck.rotateAngleY = this.updateRotations(var20[0] - var15[0]) * (float)Math.PI / 180.0F * var14;
168                this.neck.rotateAngleX = var21 + (float)(var20[1] - var15[1]) * (float)Math.PI / 180.0F * var14 * 5.0F;
169                this.neck.rotateAngleZ = -this.updateRotations(var20[0] - (double)var17) * (float)Math.PI / 180.0F * var14;
170                this.neck.rotationPointY = var11;
171                this.neck.rotationPointZ = var12;
172                this.neck.rotationPointX = var13;
173                var11 = (float)((double)var11 + Math.sin((double)this.neck.rotateAngleX) * 10.0D);
174                var12 = (float)((double)var12 - Math.cos((double)this.neck.rotateAngleY) * Math.cos((double)this.neck.rotateAngleX) * 10.0D);
175                var13 = (float)((double)var13 - Math.sin((double)this.neck.rotateAngleY) * Math.cos((double)this.neck.rotateAngleX) * 10.0D);
176                this.neck.render(par7);
177            }
178    
179            this.head.rotationPointY = var11;
180            this.head.rotationPointZ = var12;
181            this.head.rotationPointX = var13;
182            double[] var23 = var8.getMovementOffsets(0, this.partialTicks);
183            this.head.rotateAngleY = this.updateRotations(var23[0] - var15[0]) * (float)Math.PI / 180.0F * 1.0F;
184            this.head.rotateAngleZ = -this.updateRotations(var23[0] - (double)var17) * (float)Math.PI / 180.0F * 1.0F;
185            this.head.render(par7);
186            GL11.glPushMatrix();
187            GL11.glTranslatef(0.0F, 1.0F, 0.0F);
188            GL11.glRotatef(-var16 * var14 * 1.0F, 0.0F, 0.0F, 1.0F);
189            GL11.glTranslatef(0.0F, -1.0F, 0.0F);
190            this.body.rotateAngleZ = 0.0F;
191            this.body.render(par7);
192    
193            for (int var22 = 0; var22 < 2; ++var22)
194            {
195                GL11.glEnable(GL11.GL_CULL_FACE);
196                var21 = var9 * (float)Math.PI * 2.0F;
197                this.wing.rotateAngleX = 0.125F - (float)Math.cos((double)var21) * 0.2F;
198                this.wing.rotateAngleY = 0.25F;
199                this.wing.rotateAngleZ = (float)(Math.sin((double)var21) + 0.125D) * 0.8F;
200                this.wingTip.rotateAngleZ = -((float)(Math.sin((double)(var21 + 2.0F)) + 0.5D)) * 0.75F;
201                this.rearLeg.rotateAngleX = 1.0F + var10 * 0.1F;
202                this.rearLegTip.rotateAngleX = 0.5F + var10 * 0.1F;
203                this.rearFoot.rotateAngleX = 0.75F + var10 * 0.1F;
204                this.frontLeg.rotateAngleX = 1.3F + var10 * 0.1F;
205                this.frontLegTip.rotateAngleX = -0.5F - var10 * 0.1F;
206                this.frontFoot.rotateAngleX = 0.75F + var10 * 0.1F;
207                this.wing.render(par7);
208                this.frontLeg.render(par7);
209                this.rearLeg.render(par7);
210                GL11.glScalef(-1.0F, 1.0F, 1.0F);
211    
212                if (var22 == 0)
213                {
214                    GL11.glCullFace(GL11.GL_FRONT);
215                }
216            }
217    
218            GL11.glPopMatrix();
219            GL11.glCullFace(GL11.GL_BACK);
220            GL11.glDisable(GL11.GL_CULL_FACE);
221            float var24 = -((float)Math.sin((double)(var9 * (float)Math.PI * 2.0F))) * 0.0F;
222            var18 = var9 * (float)Math.PI * 2.0F;
223            var11 = 10.0F;
224            var12 = 60.0F;
225            var13 = 0.0F;
226            var15 = var8.getMovementOffsets(11, this.partialTicks);
227    
228            for (int var25 = 0; var25 < 12; ++var25)
229            {
230                var23 = var8.getMovementOffsets(12 + var25, this.partialTicks);
231                var24 = (float)((double)var24 + Math.sin((double)((float)var25 * 0.45F + var18)) * 0.05000000074505806D);
232                this.neck.rotateAngleY = (this.updateRotations(var23[0] - var15[0]) * var14 + 180.0F) * (float)Math.PI / 180.0F;
233                this.neck.rotateAngleX = var24 + (float)(var23[1] - var15[1]) * (float)Math.PI / 180.0F * var14 * 5.0F;
234                this.neck.rotateAngleZ = this.updateRotations(var23[0] - (double)var17) * (float)Math.PI / 180.0F * var14;
235                this.neck.rotationPointY = var11;
236                this.neck.rotationPointZ = var12;
237                this.neck.rotationPointX = var13;
238                var11 = (float)((double)var11 + Math.sin((double)this.neck.rotateAngleX) * 10.0D);
239                var12 = (float)((double)var12 - Math.cos((double)this.neck.rotateAngleY) * Math.cos((double)this.neck.rotateAngleX) * 10.0D);
240                var13 = (float)((double)var13 - Math.sin((double)this.neck.rotateAngleY) * Math.cos((double)this.neck.rotateAngleX) * 10.0D);
241                this.neck.render(par7);
242            }
243    
244            GL11.glPopMatrix();
245        }
246    
247        /**
248         * Updates the rotations in the parameters for rotations greater than 180 degrees or less than -180 degrees. It adds
249         * or subtracts 360 degrees, so that the appearance is the same, although the numbers are then simplified to range
250         * -180 to 180
251         */
252        private float updateRotations(double par1)
253        {
254            while (par1 >= 180.0D)
255            {
256                par1 -= 360.0D;
257            }
258    
259            while (par1 < -180.0D)
260            {
261                par1 += 360.0D;
262            }
263    
264            return (float)par1;
265        }
266    }