Guest User

Render

a guest
Dec 14th, 2014
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.65 KB | None | 0 0
  1. package ruirui.minecraft.livelyanimals.client;
  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.entity.passive.EntityPig;
  15. import net.minecraft.util.MathHelper;
  16.  
  17. public class LAModelPig extends ModelBase
  18. {
  19. //fields
  20. ModelRenderer body;
  21. ModelRenderer FRleg_top;
  22. ModelRenderer FRleg_bot;
  23. ModelRenderer FLleg_top;
  24. ModelRenderer FLleg_bot;
  25. ModelRenderer BRleg_top;
  26. ModelRenderer BRleg_bot;
  27. ModelRenderer BLleg_top;
  28. ModelRenderer BLleg_bot;
  29. ModelRenderer belly;
  30. ModelRenderer tail_base;
  31. ModelRenderer tail_tip;
  32. ModelRenderer head;
  33. ModelRenderer R_ear;
  34. ModelRenderer L_ear;
  35. ModelRenderer snout_top;
  36. ModelRenderer snout_bot;
  37.  
  38. // Saddle here //
  39. ModelRenderer saddle_base;
  40. ModelRenderer seat_back;
  41. ModelRenderer seat_lback;
  42. ModelRenderer seat_rback;
  43. ModelRenderer seat_piece;
  44. ModelRenderer seat_lpiece;
  45. ModelRenderer seat_rpiece;
  46. ModelRenderer seat_front;
  47. ModelRenderer left_flap;
  48. ModelRenderer right_flap;
  49. ModelRenderer left_belt;
  50. ModelRenderer right_belt;
  51. ModelRenderer right_low_belt;
  52. ModelRenderer left_low_belt;
  53. ModelRenderer lower_belt;
  54.  
  55. Random rand;
  56. EntityLivingBase entityliving;
  57. float startingBreath;
  58. float breath;
  59. Map uniqueEntities = new HashMap();
  60.  
  61. public LAModelPig()
  62. {
  63. textureWidth = 128;
  64. textureHeight = 64;
  65.  
  66. body = new ModelRenderer(this, 0, 0);
  67. body.addBox(-5F, -5F, -9F, 10, 10, 18);
  68. body.setRotationPoint(0F, 13F, 2F);
  69. body.setTextureSize(64, 128);
  70. body.mirror = true;
  71. setRotation(body, 0F, 0F, 0F);
  72. FRleg_top = new ModelRenderer(this, 50, 28);
  73. FRleg_top.addBox(-1.5F, 0F, -1.5F, 3, 7, 3);
  74. FRleg_top.setRotationPoint(-2.5F, 15F, -4.5F);
  75. FRleg_top.setTextureSize(64, 128);
  76. FRleg_top.mirror = true;
  77. setRotation(FRleg_top, 0F, 0F, 0F);
  78. FRleg_bot = new ModelRenderer(this, 50, 38);
  79. FRleg_bot.addBox(-1.5F, 0F, -1.5F, 3, 3, 3);
  80. FRleg_bot.setRotationPoint(0F, 6F, 0F);
  81. FRleg_bot.setTextureSize(64, 128);
  82. FRleg_bot.mirror = true;
  83. setRotation(FRleg_bot, 0F, 0F, 0F);
  84. this.FRleg_top.addChild(FRleg_bot);
  85. FLleg_top = new ModelRenderer(this, 50, 28);
  86. FLleg_top.addBox(-1.5F, 0F, -1.5F, 3, 7, 3);
  87. FLleg_top.setRotationPoint(2.5F, 15F, -4.5F);
  88. FLleg_top.setTextureSize(64, 128);
  89. FLleg_top.mirror = true;
  90. setRotation(FLleg_top, 0F, 0F, 0F);
  91. FLleg_bot = new ModelRenderer(this, 50, 38);
  92. FLleg_bot.addBox(-1.5F, 0F, -1.5F, 3, 3, 3);
  93. FLleg_bot.setRotationPoint(0F, 6F, 0F);
  94. FLleg_bot.setTextureSize(64, 128);
  95. FLleg_bot.mirror = true;
  96. setRotation(FLleg_bot, 0F, 0F, 0F);
  97. this.FLleg_top.addChild(FLleg_bot);
  98. BRleg_top = new ModelRenderer(this, 50, 44);
  99. BRleg_top.addBox(-1.5F, 0F, -1.5F, 3, 4, 3);
  100. BRleg_top.setRotationPoint(-2.5F, 16F, 9F);
  101. BRleg_top.setTextureSize(64, 128);
  102. BRleg_top.mirror = true;
  103. setRotation(BRleg_top, 0F, 0F, 0F);
  104. BRleg_bot = new ModelRenderer(this, 50, 51);
  105. BRleg_bot.addBox(-1.5F, 0F, -1.5F, 3, 5, 3);
  106. BRleg_bot.setRotationPoint(0F, 3F, 0F);
  107. BRleg_bot.setTextureSize(64, 128);
  108. BRleg_bot.mirror = true;
  109. setRotation(BRleg_bot, 0F, 0F, 0F);
  110. this.BRleg_top.addChild(BRleg_bot);
  111. BLleg_top = new ModelRenderer(this, 50, 44);
  112. BLleg_top.addBox(-1.5F, 0F, -1.5F, 3, 4, 3);
  113. BLleg_top.setRotationPoint(2.473333F, 16F, 9F);
  114. BLleg_top.setTextureSize(64, 128);
  115. BLleg_top.mirror = true;
  116. setRotation(BLleg_top, 0F, 0F, 0F);
  117. BLleg_bot = new ModelRenderer(this, 50, 51);
  118. BLleg_bot.addBox(-1.5F, 0F, -1.5F, 3, 5, 3);
  119. BLleg_bot.setRotationPoint(0F, 3F, 0F);
  120. BLleg_bot.setTextureSize(64, 128);
  121. BLleg_bot.mirror = true;
  122. setRotation(BLleg_bot, 0F, 0F, 0F);
  123. this.BLleg_top.addChild(BLleg_bot);
  124. belly = new ModelRenderer(this, 32, 28);
  125. belly.addBox(-3F, -4.5F, -1F, 6, 10, 3);
  126. belly.setRotationPoint(0F, 5F, 1.75F);
  127. belly.setTextureSize(64, 128);
  128. belly.mirror = true;
  129. setRotation(belly, 1.570796F, 0F, 0F);
  130. this.body.addChild(belly);
  131. tail_base = new ModelRenderer(this, 20, 44);
  132. tail_base.addBox(-0.5F, -0.5F, 0F, 1, 1, 3);
  133. tail_base.setRotationPoint(0F, 10F, 10.5F);
  134. tail_base.setTextureSize(64, 128);
  135. tail_base.mirror = true;
  136. setRotation(tail_base, 0F, 0F, 0F);
  137. tail_tip = new ModelRenderer(this, 20, 48);
  138. tail_tip.addBox(-0.5F, -0.5F, 0F, 1, 1, 3);
  139. tail_tip.setRotationPoint(0F, 0F, 2.5F);
  140. tail_tip.setTextureSize(64, 128);
  141. tail_tip.mirror = true;
  142. setRotation(tail_tip, -0.347828F, 0F, 0F);
  143. this.tail_base.addChild(tail_tip);
  144. head = new ModelRenderer(this, 0, 28);
  145. head.addBox(-4F, -4F, -8F, 8, 8, 8);
  146. head.setRotationPoint(0F, 14F, -6F);
  147. head.setTextureSize(64, 128);
  148. head.mirror = true;
  149. setRotation(head, 0F, 0F, 0F);
  150. R_ear = new ModelRenderer(this, 0, 44);
  151. R_ear.addBox(-4F, -0.5F, 0F, 4, 1, 6);
  152. R_ear.setRotationPoint(-3F, -6F, -7F);
  153. R_ear.setTextureSize(64, 128);
  154. R_ear.mirror = true;
  155. setRotation(R_ear, 0.4758862F, 3.004032F, 2.389431F);
  156. this.head.addChild(R_ear);
  157. L_ear = new ModelRenderer(this, 0, 44);
  158. L_ear.addBox(0F, -0.5F, 0F, 4, 1, 6);
  159. L_ear.setRotationPoint(3F, -6F, -7F);
  160. L_ear.setTextureSize(64, 128);
  161. L_ear.mirror = true;
  162. setRotation(L_ear, -2.617384F, -0.2082002F, 0.781577F);
  163. this.head.addChild(L_ear);
  164. snout_top = new ModelRenderer(this, 0, 51);
  165. snout_top.addBox(-2.5F, -1.5F, -4F, 5, 3, 4);
  166. snout_top.setRotationPoint(0F, 1F, -8F);
  167. snout_top.setTextureSize(64, 128);
  168. snout_top.mirror = true;
  169. setRotation(snout_top, 0F, 0F, 0F);
  170. this.head.addChild(snout_top);
  171. snout_bot = new ModelRenderer(this, 0, 58);
  172. snout_bot.addBox(-2.5F, 0F, -4F, 5, 1, 4);
  173. snout_bot.setRotationPoint(0F, 2.5F, -8F);
  174. snout_bot.setTextureSize(64, 128);
  175. snout_bot.mirror = true;
  176. setRotation(snout_bot, 0F, 0F, 0F);
  177. this.head.addChild(snout_bot);
  178.  
  179. // Saddle here //
  180. saddle_base = new ModelRenderer(this, 68, 0);
  181. saddle_base.addBox(-5F, 0F, -5.5F, 10, 1, 11);
  182. saddle_base.setRotationPoint(0F, 7F, 3F);
  183. saddle_base.setTextureSize(64, 128);
  184. saddle_base.mirror = true;
  185. setRotation(saddle_base, 0F, 0F, 0F);
  186. seat_back = new ModelRenderer(this, 68, 12);
  187. seat_back.addBox(-3F, 0F, -0.5F, 6, 3, 1);
  188. seat_back.setRotationPoint(0F, 4F, 8F);
  189. seat_back.setTextureSize(64, 128);
  190. seat_back.mirror = true;
  191. setRotation(seat_back, 0F, 0F, 0F);
  192. seat_lback = new ModelRenderer(this, 82, 12);
  193. seat_lback.addBox(-1F, 0F, -0.5F, 2, 2, 1);
  194. seat_lback.setRotationPoint(4F, 5F, 8F);
  195. seat_lback.setTextureSize(64, 128);
  196. seat_lback.mirror = true;
  197. setRotation(seat_lback, 0F, 0F, 0F);
  198. seat_rback = new ModelRenderer(this, 82, 12);
  199. seat_rback.addBox(-1F, 0F, -0.5F, 2, 2, 1);
  200. seat_rback.setRotationPoint(-4F, 5F, 8F);
  201. seat_rback.setTextureSize(64, 128);
  202. seat_rback.mirror = true;
  203. setRotation(seat_rback, 0F, 0F, 0F);
  204. seat_piece = new ModelRenderer(this, 88, 12);
  205. seat_piece.addBox(-4F, 0F, -0.5F, 8, 1, 1);
  206. seat_piece.setRotationPoint(0F, 6F, 7F);
  207. seat_piece.setTextureSize(64, 128);
  208. seat_piece.mirror = true;
  209. setRotation(seat_piece, 0F, 0F, 0F);
  210. seat_lpiece = new ModelRenderer(this, 82, 15);
  211. seat_lpiece.addBox(-0.5F, 0F, -1F, 1, 1, 2);
  212. seat_lpiece.setRotationPoint(4.5F, 6F, 6.5F);
  213. seat_lpiece.setTextureSize(64, 128);
  214. seat_lpiece.mirror = true;
  215. setRotation(seat_lpiece, 0F, 0F, 0F);
  216. seat_rpiece = new ModelRenderer(this, 82, 15);
  217. seat_rpiece.addBox(-0.5F, 0F, -1F, 1, 1, 2);
  218. seat_rpiece.setRotationPoint(-4.5F, 6F, 6.5F);
  219. seat_rpiece.setTextureSize(64, 128);
  220. seat_rpiece.mirror = true;
  221. setRotation(seat_rpiece, 0F, 0F, 0F);
  222. seat_front = new ModelRenderer(this, 88, 14);
  223. seat_front.addBox(-4F, 0F, -1F, 8, 1, 2);
  224. seat_front.setRotationPoint(0F, 6F, -2.5F);
  225. seat_front.setTextureSize(64, 128);
  226. seat_front.mirror = true;
  227. setRotation(seat_front, 0F, 0F, 0F);
  228. left_flap = new ModelRenderer(this, 110, 0);
  229. left_flap.addBox(0F, -3F, -4F, 1, 7, 8);
  230. left_flap.setRotationPoint(5F, 10F, 1.5F);
  231. left_flap.setTextureSize(64, 128);
  232. left_flap.mirror = true;
  233. setRotation(left_flap, 0F, 0F, 0F);
  234. right_flap = new ModelRenderer(this, 110, 0);
  235. right_flap.addBox(-0.5F, -3.5F, -4F, 1, 7, 8);
  236. right_flap.setRotationPoint(-5.5F, 10.5F, 1.5F);
  237. right_flap.setTextureSize(64, 128);
  238. right_flap.mirror = true;
  239. setRotation(right_flap, 0F, 3.141593F, 0F);
  240. left_belt = new ModelRenderer(this, 110, 18);
  241. left_belt.addBox(0F, 0F, -1F, 1, 4, 2);
  242. left_belt.setRotationPoint(5F, 14F, -1F);
  243. left_belt.setTextureSize(64, 128);
  244. left_belt.mirror = true;
  245. setRotation(left_belt, 0F, 0F, 0F);
  246. right_belt = new ModelRenderer(this, 110, 18);
  247. right_belt.addBox(-0.5F, 0F, -1F, 1, 4, 2);
  248. right_belt.setRotationPoint(-5.5F, 14F, -1F);
  249. right_belt.setTextureSize(64, 128);
  250. right_belt.mirror = true;
  251. setRotation(right_belt, 0F, 3.141593F, 0F);
  252. right_low_belt = new ModelRenderer(this, 116, 18);
  253. right_low_belt.addBox(0F, 0F, -1F, 1, 3, 2);
  254. right_low_belt.setRotationPoint(5.3F, 17.2F, -1F);
  255. right_low_belt.setTextureSize(64, 128);
  256. right_low_belt.mirror = true;
  257. setRotation(right_low_belt, 0F, 0F, 0.9220296F);
  258. left_low_belt = new ModelRenderer(this, 116, 18);
  259. left_low_belt.addBox(-0.5F, -1.5F, -1F, 1, 3, 2);
  260. left_low_belt.setRotationPoint(-4.5F, 18.6F, -1F);
  261. left_low_belt.setTextureSize(64, 128);
  262. left_low_belt.mirror = true;
  263. setRotation(left_low_belt, 0F, 0F, 2.2493F);
  264. lower_belt = new ModelRenderer(this, 110, 15);
  265. lower_belt.addBox(-3.5F, 0F, -1F, 7, 1, 2);
  266. lower_belt.setRotationPoint(0F, 19F, -1F);
  267. lower_belt.setTextureSize(64, 128);
  268. lower_belt.mirror = true;
  269. setRotation(lower_belt, 0F, 0F, 0F);
  270. }
  271.  
  272. public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5)
  273. {
  274. super.render(entity, f, f1, f2, f3, f4, f5);
  275. setRotationAngles(f, f1, f2, f3, f4, f5, entity);
  276.  
  277. // Breathing animation
  278. if(((EntityLivingBase) entity).getHealth() != 0) {
  279. GL11.glPushMatrix();
  280. breath = MathHelper.cos(entity.ticksExisted * .1F + randomHelper(entity)) * 0.035F + 1F;
  281. GL11.glScalef(breath, breath, breath); // Expansion of body
  282. GL11.glTranslatef(0.0F, 1.0F - breath, 0.0F); // Keeps body centered
  283. }
  284. body.render(f5);
  285. if(((EntityLivingBase) entity).getHealth() != 0) {
  286. GL11.glPopMatrix();
  287. }
  288.  
  289. FRleg_top.render(f5);
  290. FLleg_top.render(f5);
  291. BRleg_top.render(f5);
  292. BLleg_top.render(f5);
  293. tail_base.render(f5);
  294. head.render(f5);
  295.  
  296. // Saddle
  297. if(((EntityPig) entity).getSaddled()) {
  298. saddle_base.render(f5);
  299. seat_back.render(f5);
  300. seat_lback.render(f5);
  301. seat_rback.render(f5);
  302. seat_piece.render(f5);
  303. seat_lpiece.render(f5);
  304. seat_rpiece.render(f5);
  305. seat_front.render(f5);
  306. left_flap.render(f5);
  307. right_flap.render(f5);
  308. left_belt.render(f5);
  309. right_belt.render(f5);
  310. right_low_belt.render(f5);
  311. left_low_belt.render(f5);
  312. lower_belt.render(f5);
  313. }
  314. }
  315.  
  316. private void setRotation(ModelRenderer model, float x, float y, float z)
  317. {
  318. model.rotateAngleX = x;
  319. model.rotateAngleY = y;
  320. model.rotateAngleZ = z;
  321. }
  322.  
  323. 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_)
  324. {
  325. this.head.rotateAngleX = p_78087_5_ / (180F / (float)Math.PI);
  326. this.head.rotateAngleY = p_78087_4_ / (180F / (float)Math.PI);
  327. this.tail_base.rotateAngleX = -1.01F;
  328.  
  329. this.head.rotateAngleX += MathHelper.cos(p_78087_7_.ticksExisted * 0.1F + randomHelper(p_78087_7_)) * 0.025F;
  330. this.tail_base.rotateAngleX += MathHelper.cos(p_78087_7_.ticksExisted * 0.1F + randomHelper(p_78087_7_)) * 0.1F;
  331.  
  332. float leg_angle = MathHelper.cos(p_78087_1_ * 2.F * 0.6662F) * 1.4F * p_78087_2_;
  333. float leg_angle2 = MathHelper.cos(p_78087_1_ * 0.6662F * 2.F + (float)Math.PI) * 1.4F * p_78087_2_;
  334. float leg_angle3 = MathHelper.cos(p_78087_1_ * 2.F ) * p_78087_2_ * 3.F;
  335. float leg_angle4 = leg_angle3;
  336. if (leg_angle3 < leg_angle) { leg_angle3 = 0; }
  337. if (leg_angle4 > leg_angle) { leg_angle4 = 0; }
  338.  
  339. this.FLleg_top.rotateAngleX = leg_angle;
  340. this.FLleg_bot.rotateAngleX = leg_angle3;
  341. this.FRleg_top.rotateAngleX = leg_angle2;
  342. this.FRleg_bot.rotateAngleX = leg_angle3;
  343. this.BLleg_top.rotateAngleX = leg_angle2 + 0.2F;
  344. this.BLleg_bot.rotateAngleX = leg_angle4 - 0.2F;
  345. this.BRleg_top.rotateAngleX = leg_angle + 0.2F;
  346. this.BRleg_bot.rotateAngleX = leg_angle4 - 0.2F;
  347. }
  348.  
  349. /*
  350. * This function creates a value using each unique entity's
  351. * Random object. A Hashmap needs to be kept to differentiate
  352. * between entities. Gonna go back later and try to figure out
  353. * something more efficient.
  354. */
  355. private float randomHelper(Entity entity) {
  356. if (!uniqueEntities.containsKey(entity.getUniqueID())) {
  357. if (entity instanceof EntityLivingBase) {
  358. rand = ((EntityLivingBase) entity).getRNG();
  359. startingBreath = rand.nextFloat() * (rand.nextInt(5) + 1);
  360. //System.out.println(startingBreath);
  361.  
  362. uniqueEntities.put(entity.getUniqueID(), startingBreath);
  363. }
  364. }
  365.  
  366. //float test = (Float) uniqueEntities.get(entity.getUniqueID());
  367. //System.out.println(test);
  368. return (Float) uniqueEntities.get(entity.getUniqueID());
  369. }
  370. }
Advertisement
Add Comment
Please, Sign In to add comment