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