Guest User

Model

a guest
Dec 11th, 2014
192
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package ruirui.minecraft.livelyanimals;
  2.  
  3. import java.util.HashMap;
  4. import java.util.Map;
  5. import java.util.Random;
  6. import java.util.UUID;
  7.  
  8. import org.lwjgl.opengl.GL11;
  9.  
  10. import net.minecraft.client.model.ModelBase;
  11. import net.minecraft.client.model.ModelRenderer;
  12. import net.minecraft.entity.Entity;
  13. import net.minecraft.entity.EntityLivingBase;
  14. import net.minecraft.util.MathHelper;
  15.  
  16. public class LAModelPig extends ModelBase
  17. {
  18. //fields
  19. ModelRenderer body;
  20. ModelRenderer FRleg_top;
  21. ModelRenderer FRleg_bot;
  22. ModelRenderer FLleg_top;
  23. ModelRenderer FLleg_bot;
  24. ModelRenderer BRleg_top;
  25. ModelRenderer BRleg_bot;
  26. ModelRenderer BLleg_top;
  27. ModelRenderer BLleg_bot;
  28. ModelRenderer belly;
  29. ModelRenderer tail_base;
  30. ModelRenderer tail_tip;
  31. ModelRenderer head;
  32. ModelRenderer R_ear;
  33. ModelRenderer L_ear;
  34. ModelRenderer snout_top;
  35. ModelRenderer snout_bot;
  36.  
  37. Random rand;
  38. EntityLivingBase entityliving;
  39. float startingBreath;
  40. float breath;
  41. Map uniqueEntities = new HashMap();
  42.  
  43. public LAModelPig()
  44. {
  45. textureWidth = 64;
  46. textureHeight = 64;
  47.  
  48. body = new ModelRenderer(this, 0, 0);
  49. body.addBox(-5F, -5F, -9F, 10, 10, 18);
  50. body.setRotationPoint(0F, 13F, 2F);
  51. body.setTextureSize(64, 64);
  52. body.mirror = true;
  53. setRotation(body, 0F, 0F, 0F);
  54. FRleg_top = new ModelRenderer(this, 50, 28);
  55. FRleg_top.addBox(-1.5F, 0F, -1.5F, 3, 7, 3);
  56. FRleg_top.setRotationPoint(-2.5F, 15F, -4.5F);
  57. FRleg_top.setTextureSize(64, 64);
  58. FRleg_top.mirror = true;
  59. setRotation(FRleg_top, 0F, 0F, 0F);
  60. FRleg_bot = new ModelRenderer(this, 50, 38);
  61. FRleg_bot.addBox(-1.5F, 0F, -1.5F, 3, 3, 3);
  62. FRleg_bot.setRotationPoint(0F, 6F, 0F);
  63. FRleg_bot.setTextureSize(64, 64);
  64. FRleg_bot.mirror = true;
  65. setRotation(FRleg_bot, 0F, 0F, 0F);
  66. this.FRleg_top.addChild(FRleg_bot);
  67. FLleg_top = new ModelRenderer(this, 50, 28);
  68. FLleg_top.addBox(-1.5F, 0F, -1.5F, 3, 7, 3);
  69. FLleg_top.setRotationPoint(2.5F, 15F, -4.5F);
  70. FLleg_top.setTextureSize(64, 64);
  71. FLleg_top.mirror = true;
  72. setRotation(FLleg_top, 0F, 0F, 0F);
  73. FLleg_bot = new ModelRenderer(this, 50, 38);
  74. FLleg_bot.addBox(-1.5F, 0F, -1.5F, 3, 3, 3);
  75. FLleg_bot.setRotationPoint(0F, 6F, 0F);
  76. FLleg_bot.setTextureSize(64, 64);
  77. FLleg_bot.mirror = true;
  78. setRotation(FLleg_bot, 0F, 0F, 0F);
  79. this.FLleg_top.addChild(FLleg_bot);
  80. BRleg_top = new ModelRenderer(this, 50, 44);
  81. BRleg_top.addBox(-1.5F, 0F, -1.5F, 3, 4, 3);
  82. BRleg_top.setRotationPoint(-2.5F, 16F, 9F);
  83. BRleg_top.setTextureSize(64, 32);
  84. BRleg_top.mirror = true;
  85. setRotation(BRleg_top, 0F, 0F, 0F);
  86. BRleg_bot = new ModelRenderer(this, 50, 51);
  87. BRleg_bot.addBox(-1.5F, 0F, -1.5F, 3, 5, 3);
  88. BRleg_bot.setRotationPoint(0F, 3F, 0F);
  89. BRleg_bot.setTextureSize(64, 32);
  90. BRleg_bot.mirror = true;
  91. setRotation(BRleg_bot, 0F, 0F, 0F);
  92. this.BRleg_top.addChild(BRleg_bot);
  93. BLleg_top = new ModelRenderer(this, 50, 44);
  94. BLleg_top.addBox(-1.5F, 0F, -1.5F, 3, 4, 3);
  95. BLleg_top.setRotationPoint(2.473333F, 16F, 9F);
  96. BLleg_top.setTextureSize(64, 32);
  97. BLleg_top.mirror = true;
  98. setRotation(BLleg_top, 0F, 0F, 0F);
  99. BLleg_bot = new ModelRenderer(this, 50, 51);
  100. BLleg_bot.addBox(-1.5F, 0F, -1.5F, 3, 5, 3);
  101. BLleg_bot.setRotationPoint(0F, 3F, 0F);
  102. BLleg_bot.setTextureSize(64, 32);
  103. BLleg_bot.mirror = true;
  104. setRotation(BLleg_bot, 0F, 0F, 0F);
  105. this.BLleg_top.addChild(BLleg_bot);
  106. belly = new ModelRenderer(this, 32, 28);
  107. belly.addBox(-3F, -4.5F, -1F, 6, 10, 3);
  108. belly.setRotationPoint(0F, 5F, 1.75F);
  109. belly.setTextureSize(64, 64);
  110. belly.mirror = true;
  111. setRotation(belly, 1.570796F, 0F, 0F);
  112. this.body.addChild(belly);
  113. tail_base = new ModelRenderer(this, 20, 44);
  114. tail_base.addBox(-0.5F, -0.5F, 0F, 1, 1, 3);
  115. tail_base.setRotationPoint(0F, 10F, 10.5F);
  116. tail_base.setTextureSize(64, 64);
  117. tail_base.mirror = true;
  118. setRotation(tail_base, -1.01F, 0F, 0F);
  119. tail_tip = new ModelRenderer(this, 20, 48);
  120. tail_tip.addBox(-0.5F, -0.5F, 0F, 1, 1, 3);
  121. tail_tip.setRotationPoint(0F, 0F, 2.5F);
  122. tail_tip.setTextureSize(64, 64);
  123. tail_tip.mirror = true;
  124. setRotation(tail_tip, -0.347828F, 0F, 0F);
  125. this.tail_base.addChild(tail_tip);
  126. head = new ModelRenderer(this, 0, 28);
  127. head.addBox(-4F, -4F, -8F, 8, 8, 8);
  128. head.setRotationPoint(0F, 14F, -6F);
  129. head.setTextureSize(64, 64);
  130. head.mirror = true;
  131. setRotation(head, 0F, 0F, 0F);
  132. R_ear = new ModelRenderer(this, 0, 44);
  133. R_ear.addBox(-4F, -0.5F, 0F, 4, 1, 6);
  134. R_ear.setRotationPoint(-3F, -6F, -7F);
  135. R_ear.setTextureSize(64, 64);
  136. R_ear.mirror = true;
  137. setRotation(R_ear, 0.4758862F, 3.004032F, 2.389431F);
  138. this.head.addChild(R_ear);
  139. L_ear = new ModelRenderer(this, 0, 44);
  140. L_ear.addBox(0F, -0.5F, 0F, 4, 1, 6);
  141. L_ear.setRotationPoint(3F, -6F, -7F);
  142. L_ear.setTextureSize(64, 64);
  143. L_ear.mirror = true;
  144. setRotation(L_ear, -2.617384F, -0.2082002F, 0.781577F);
  145. this.head.addChild(L_ear);
  146. snout_top = new ModelRenderer(this, 0, 51);
  147. snout_top.addBox(-2.5F, -1.5F, -4F, 5, 3, 4);
  148. snout_top.setRotationPoint(0F, 1F, -8F);
  149. snout_top.setTextureSize(64, 64);
  150. snout_top.mirror = true;
  151. setRotation(snout_top, 0F, 0F, 0F);
  152. this.head.addChild(snout_top);
  153. snout_bot = new ModelRenderer(this, 0, 58);
  154. snout_bot.addBox(-2.5F, 0F, -4F, 5, 1, 4);
  155. snout_bot.setRotationPoint(0F, 2.5F, -8F);
  156. snout_bot.setTextureSize(64, 64);
  157. snout_bot.mirror = true;
  158. setRotation(snout_bot, 0F, 0F, 0F);
  159. this.head.addChild(snout_bot);
  160. }
  161.  
  162. public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5)
  163. {
  164. super.render(entity, f, f1, f2, f3, f4, f5);
  165. setRotationAngles(f, f1, f2, f3, f4, f5, entity);
  166.  
  167. // Breathing animation
  168. if(((EntityLivingBase) entity).getHealth() != 0) {
  169. GL11.glPushMatrix();
  170. breath = MathHelper.cos(entity.ticksExisted * .1F + randomHelper(entity)) * 0.035F + 1F;
  171. GL11.glScalef(breath, breath, breath); // Expansion of body
  172. GL11.glTranslatef(0.0F, 1.0F - breath, 0.0F); // Keeps body centered
  173. }
  174. body.render(f5);
  175. if(((EntityLivingBase) entity).getHealth() != 0) {
  176. GL11.glPopMatrix();
  177. }
  178.  
  179. FRleg_top.render(f5);
  180. FLleg_top.render(f5);
  181. BRleg_top.render(f5);
  182. BLleg_top.render(f5);
  183. tail_base.render(f5);
  184. head.render(f5);
  185. }
  186.  
  187. private void setRotation(ModelRenderer model, float x, float y, float z)
  188. {
  189. model.rotateAngleX = x;
  190. model.rotateAngleY = y;
  191. model.rotateAngleZ = z;
  192. }
  193.  
  194. public void setRotationAngles (float p_78087_1_, float p_78087_2_, float p_78087_3_, float p_78087_4_, float p_78087_5_, float p_78087_6_, Entity p_78087_7_)
  195. {
  196. this.head.rotateAngleX = p_78087_5_ / (180F / (float)Math.PI);
  197. this.head.rotateAngleY = p_78087_4_ / (180F / (float)Math.PI);
  198.  
  199. this.head.rotateAngleX += MathHelper.cos(p_78087_7_.ticksExisted * 0.1F + randomHelper(p_78087_7_)) * 0.025F + 0.025F;
  200. this.tail_base.rotateAngleX -= MathHelper.cos(p_78087_7_.ticksExisted * 0.1F + randomHelper(p_78087_7_)) * 0.003F;
  201.  
  202. float leg_angle = MathHelper.cos(p_78087_1_ * 2.F * 0.6662F) * 1.4F * p_78087_2_;
  203. float leg_angle2 = MathHelper.cos(p_78087_1_ * 0.6662F * 2.F + (float)Math.PI) * 1.4F * p_78087_2_;
  204. float leg_angle3 = MathHelper.cos(p_78087_1_ * 2.F ) * p_78087_2_ * 3.F;
  205. float leg_angle4 = leg_angle3;
  206. if (leg_angle3 < leg_angle) { leg_angle3 = 0; }
  207. if (leg_angle4 > leg_angle) { leg_angle4 = 0; }
  208.  
  209. this.FLleg_top.rotateAngleX = leg_angle;
  210. this.FLleg_bot.rotateAngleX = leg_angle3;
  211. this.FRleg_top.rotateAngleX = leg_angle2;
  212. this.FRleg_bot.rotateAngleX = leg_angle3;
  213. this.BLleg_top.rotateAngleX = leg_angle2 + 0.2F;
  214. this.BLleg_bot.rotateAngleX = leg_angle4 - 0.2F;
  215. this.BRleg_top.rotateAngleX = leg_angle + 0.2F;
  216. this.BRleg_bot.rotateAngleX = leg_angle4 - 0.2F;
  217. }
  218.  
  219. public void setLivingAnimations(EntityLivingBase p_78086_1_, float p_78086_2_, float p_78086_3_, float p_78086_4_) {
  220.  
  221. }
  222.  
  223. /*
  224. * This function creates a value using each unique entity's
  225. * Random object. A Hashmap needs to be kept to differentiate
  226. * between entities. Gonna go back later and try to figure out
  227. * something more efficient.
  228. */
  229. private float randomHelper(Entity entity) {
  230. if (!uniqueEntities.containsKey(entity.getUniqueID())) {
  231. if (entity instanceof EntityLivingBase) {
  232. rand = ((EntityLivingBase) entity).getRNG();
  233. startingBreath = rand.nextFloat() * (rand.nextInt(5) + 1);
  234. //System.out.println(startingBreath);
  235.  
  236. uniqueEntities.put(entity.getUniqueID(), startingBreath);
  237. }
  238. }
  239.  
  240. //float test = (Float) uniqueEntities.get(entity.getUniqueID());
  241. //System.out.println(test);
  242. return (Float) uniqueEntities.get(entity.getUniqueID());
  243. }
  244. }
RAW Paste Data