001package net.minecraft.client.model;
002
003import cpw.mods.fml.relauncher.Side;
004import cpw.mods.fml.relauncher.SideOnly;
005import net.minecraft.entity.Entity;
006import net.minecraft.entity.EntityLiving;
007import net.minecraft.entity.boss.EntityDragon;
008import org.lwjgl.opengl.GL11;
009
010@SideOnly(Side.CLIENT)
011public 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 f1 = -16.0F;
074        this.head = new ModelRenderer(this, "head");
075        this.head.addBox("upperlip", -6.0F, -1.0F, -8.0F + f1, 12, 5, 16);
076        this.head.addBox("upperhead", -8.0F, -8.0F, 6.0F + f1, 16, 16, 16);
077        this.head.mirror = true;
078        this.head.addBox("scale", -5.0F, -12.0F, 12.0F + f1, 2, 4, 6);
079        this.head.addBox("nostril", -5.0F, -3.0F, -6.0F + f1, 2, 2, 4);
080        this.head.mirror = false;
081        this.head.addBox("scale", 3.0F, -12.0F, 12.0F + f1, 2, 4, 6);
082        this.head.addBox("nostril", 3.0F, -3.0F, -6.0F + f1, 2, 2, 4);
083        this.jaw = new ModelRenderer(this, "jaw");
084        this.jaw.setRotationPoint(0.0F, 4.0F, 8.0F + f1);
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 entitydragon = (EntityDragon)par1Entity;
145        float f6 = entitydragon.prevAnimTime + (entitydragon.animTime - entitydragon.prevAnimTime) * this.partialTicks;
146        this.jaw.rotateAngleX = (float)(Math.sin((double)(f6 * (float)Math.PI * 2.0F)) + 1.0D) * 0.2F;
147        float f7 = (float)(Math.sin((double)(f6 * (float)Math.PI * 2.0F - 1.0F)) + 1.0D);
148        f7 = (f7 * f7 * 1.0F + f7 * 2.0F) * 0.05F;
149        GL11.glTranslatef(0.0F, f7 - 2.0F, -3.0F);
150        GL11.glRotatef(f7 * 2.0F, 1.0F, 0.0F, 0.0F);
151        float f8 = -30.0F;
152        float f9 = 0.0F;
153        float f10 = 1.5F;
154        double[] adouble = entitydragon.getMovementOffsets(6, this.partialTicks);
155        float f11 = this.updateRotations(entitydragon.getMovementOffsets(5, this.partialTicks)[0] - entitydragon.getMovementOffsets(10, this.partialTicks)[0]);
156        float f12 = this.updateRotations(entitydragon.getMovementOffsets(5, this.partialTicks)[0] + (double)(f11 / 2.0F));
157        f8 += 2.0F;
158        float f13 = f6 * (float)Math.PI * 2.0F;
159        f8 = 20.0F;
160        float f14 = -12.0F;
161        float f15;
162
163        for (int i = 0; i < 5; ++i)
164        {
165            double[] adouble1 = entitydragon.getMovementOffsets(5 - i, this.partialTicks);
166            f15 = (float)Math.cos((double)((float)i * 0.45F + f13)) * 0.15F;
167            this.neck.rotateAngleY = this.updateRotations(adouble1[0] - adouble[0]) * (float)Math.PI / 180.0F * f10;
168            this.neck.rotateAngleX = f15 + (float)(adouble1[1] - adouble[1]) * (float)Math.PI / 180.0F * f10 * 5.0F;
169            this.neck.rotateAngleZ = -this.updateRotations(adouble1[0] - (double)f12) * (float)Math.PI / 180.0F * f10;
170            this.neck.rotationPointY = f8;
171            this.neck.rotationPointZ = f14;
172            this.neck.rotationPointX = f9;
173            f8 = (float)((double)f8 + Math.sin((double)this.neck.rotateAngleX) * 10.0D);
174            f14 = (float)((double)f14 - Math.cos((double)this.neck.rotateAngleY) * Math.cos((double)this.neck.rotateAngleX) * 10.0D);
175            f9 = (float)((double)f9 - 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 = f8;
180        this.head.rotationPointZ = f14;
181        this.head.rotationPointX = f9;
182        double[] adouble2 = entitydragon.getMovementOffsets(0, this.partialTicks);
183        this.head.rotateAngleY = this.updateRotations(adouble2[0] - adouble[0]) * (float)Math.PI / 180.0F * 1.0F;
184        this.head.rotateAngleZ = -this.updateRotations(adouble2[0] - (double)f12) * (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(-f11 * f10 * 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 j = 0; j < 2; ++j)
194        {
195            GL11.glEnable(GL11.GL_CULL_FACE);
196            f15 = f6 * (float)Math.PI * 2.0F;
197            this.wing.rotateAngleX = 0.125F - (float)Math.cos((double)f15) * 0.2F;
198            this.wing.rotateAngleY = 0.25F;
199            this.wing.rotateAngleZ = (float)(Math.sin((double)f15) + 0.125D) * 0.8F;
200            this.wingTip.rotateAngleZ = -((float)(Math.sin((double)(f15 + 2.0F)) + 0.5D)) * 0.75F;
201            this.rearLeg.rotateAngleX = 1.0F + f7 * 0.1F;
202            this.rearLegTip.rotateAngleX = 0.5F + f7 * 0.1F;
203            this.rearFoot.rotateAngleX = 0.75F + f7 * 0.1F;
204            this.frontLeg.rotateAngleX = 1.3F + f7 * 0.1F;
205            this.frontLegTip.rotateAngleX = -0.5F - f7 * 0.1F;
206            this.frontFoot.rotateAngleX = 0.75F + f7 * 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 (j == 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 f16 = -((float)Math.sin((double)(f6 * (float)Math.PI * 2.0F))) * 0.0F;
222        f13 = f6 * (float)Math.PI * 2.0F;
223        f8 = 10.0F;
224        f14 = 60.0F;
225        f9 = 0.0F;
226        adouble = entitydragon.getMovementOffsets(11, this.partialTicks);
227
228        for (int k = 0; k < 12; ++k)
229        {
230            adouble2 = entitydragon.getMovementOffsets(12 + k, this.partialTicks);
231            f16 = (float)((double)f16 + Math.sin((double)((float)k * 0.45F + f13)) * 0.05000000074505806D);
232            this.neck.rotateAngleY = (this.updateRotations(adouble2[0] - adouble[0]) * f10 + 180.0F) * (float)Math.PI / 180.0F;
233            this.neck.rotateAngleX = f16 + (float)(adouble2[1] - adouble[1]) * (float)Math.PI / 180.0F * f10 * 5.0F;
234            this.neck.rotateAngleZ = this.updateRotations(adouble2[0] - (double)f12) * (float)Math.PI / 180.0F * f10;
235            this.neck.rotationPointY = f8;
236            this.neck.rotationPointZ = f14;
237            this.neck.rotationPointX = f9;
238            f8 = (float)((double)f8 + Math.sin((double)this.neck.rotateAngleX) * 10.0D);
239            f14 = (float)((double)f14 - Math.cos((double)this.neck.rotateAngleY) * Math.cos((double)this.neck.rotateAngleX) * 10.0D);
240            f9 = (float)((double)f9 - 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}