Guest User

Untitled

a guest
Apr 9th, 2018
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.73 KB | None | 0 0
  1. /*
  2. ** 2011 December 10
  3. **
  4. ** The author disclaims copyright to this source code. In place of
  5. ** a legal notice, here is a blessing:
  6. ** May you do good and not evil.
  7. ** May you find forgiveness for yourself and forgive others.
  8. ** May you share freely, never taking more than you give.
  9. */
  10.  
  11. package com.TheRPGAdventurer.ROTD.client.model;
  12.  
  13. import com.TheRPGAdventurer.ROTD.client.model.anim.DragonAnimator;
  14. import com.TheRPGAdventurer.ROTD.server.entity.EntityTameableDragon;
  15. import com.TheRPGAdventurer.ROTD.server.entity.breeds.EnumDragonBreed;
  16. import com.TheRPGAdventurer.ROTD.util.math.MathX;
  17.  
  18. import net.minecraft.client.model.ModelBase;
  19. import net.minecraft.client.renderer.GlStateManager;
  20. import net.minecraft.entity.Entity;
  21. import net.minecraft.entity.EntityLivingBase;
  22.  
  23. /**
  24. * Generic model for all winged tetrapod dragons.
  25. *
  26. * @author Nico Bergemann <barracuda415 at yahoo.de>
  27. * @Modifier James Miller <TheRPGAdventurer.>
  28. */
  29. public class DragonModel extends ModelBase {
  30.  
  31. // model constants
  32. public static final int NECK_SIZE = 10;
  33. public static final int TAIL_SIZE = 10;
  34. public static final int VERTS_NECK = 7;
  35. public static final int VERTS_TAIL = 12;
  36. public static final int HEAD_OFS = -16;
  37.  
  38. // model parts
  39. public ModelPart head;
  40. public ModelPart neck;
  41. public ModelPart neckScale;
  42. public ModelPart tail;
  43. public ModelPart tailHornLeft;
  44. public ModelPart tailHornRight;
  45. public ModelPart tailScaleLeft;
  46. public ModelPart tailScaleMiddle;
  47. public ModelPart tailScaleRight;
  48. public ModelPart jaw;
  49. public ModelPart body;
  50. public ModelPart back;
  51. public ModelPart saddle;
  52. public ModelPart saddleFront;
  53. public ModelPart saddleBack;
  54. public ModelPart saddleTieL;
  55. public ModelPart saddleMetalL;
  56. public ModelPart saddleTieR;
  57. public ModelPart saddleMetalR;
  58. public ModelPart chestR;
  59. public ModelPart chestL;
  60. public ModelPart forethigh;
  61. public ModelPart forecrus;
  62. public ModelPart forefoot;
  63. public ModelPart foretoe;
  64. public ModelPart hindthigh;
  65. public ModelPart hindcrus;
  66. public ModelPart hindfoot;
  67. public ModelPart hindtoe;
  68. public ModelPart wingArm;
  69. public ModelPart wingForearm;
  70. public ModelPart[] wingFinger = new ModelPart[4];
  71.  
  72. // model attributes
  73. public ModelPartProxy[] neckProxy = new ModelPartProxy[VERTS_NECK];
  74. public ModelPartProxy[] tailProxy = new ModelPartProxy[VERTS_TAIL];
  75. public ModelPartProxy[] thighProxy = new ModelPartProxy[4];
  76.  
  77. public float offsetX;
  78. public float offsetY;
  79. public float offsetZ;
  80. public float pitch;
  81. public float size;
  82. private EnumDragonBreed breed;
  83. private DragonModelMode mode;
  84.  
  85. public DragonModel(EnumDragonBreed breed) {
  86. textureWidth = 256;
  87. textureHeight = 256;
  88.  
  89. this.breed = breed;
  90.  
  91. setTextureOffset("body.body", 0, 0);
  92. setTextureOffset("body.scale", 0, 32);
  93. setTextureOffset("body.saddle", 184, 98);
  94. setTextureOffset("body.saddleFront", 214, 120);
  95. setTextureOffset("body.saddleBack", 214, 120);
  96. setTextureOffset("body.saddleTieL", 220, 100);
  97. setTextureOffset("body.saddleTieR", 220, 100);
  98. setTextureOffset("body.saddleMetalL", 224, 132);
  99. setTextureOffset("body.saddleMetalR", 224, 132);
  100. setTextureOffset("body.chestL", 192, 132);
  101. setTextureOffset("body.chestR", 224, 132);
  102. setTextureOffset("head.nostril", 48, 0);
  103. setTextureOffset("head.upperhead", 0, 0);
  104. setTextureOffset("head.upperjaw", 56, 88);
  105. setTextureOffset("head.lowerjaw", 0, 88);
  106. setTextureOffset("head.horn", 28, 32);
  107. setTextureOffset("forethigh.main", 112, 0);
  108. setTextureOffset("forecrus.main", 148, 0);
  109. setTextureOffset("forefoot.main", 210, 0);
  110. setTextureOffset("foretoe.main", 176, 0);
  111. setTextureOffset("hindthigh.main", 112, 29);
  112. setTextureOffset("hindcrus.main", 152, 29);
  113. setTextureOffset("hindfoot.main", 180, 29);
  114. setTextureOffset("hindtoe.main", 215, 29);
  115. setTextureOffset("neck.box", 112, 88);
  116. setTextureOffset("neck.scale", 0, 0);
  117. setTextureOffset("tail.box", 152, 88);
  118. setTextureOffset("tail.scale", 0, 0);
  119. setTextureOffset("tail.horn", 0, 117);
  120. setTextureOffset("wingarm.bone", 0, 152);
  121. setTextureOffset("wingarm.skin", 116, 232);
  122. setTextureOffset("wingfinger.bone", 0, 172);
  123. setTextureOffset("wingfinger.shortskin", -32, 224);
  124. setTextureOffset("wingfinger.skin", -49, 176);
  125. setTextureOffset("wingforearm.bone", 0, 164);
  126.  
  127. buildBody();
  128. buildNeck();
  129. buildHead();
  130. buildTail();
  131. buildWing();
  132. buildLegs();
  133. }
  134.  
  135. public void setMode(DragonModelMode mode) {
  136. this.mode = mode;
  137. }
  138.  
  139. private void buildHead() {
  140. head = new ModelPart(this, "head");
  141. head.addBox("upperjaw", -6, -1, -8 + HEAD_OFS, 12, 5, 16);
  142. head.addBox("upperhead", -8, -8, 6 + HEAD_OFS, 16, 16, 16);
  143. head.addBox("nostril", -5, -3, -6 + HEAD_OFS, 2, 2, 4);
  144. head.mirror = true;
  145. head.addBox("nostril", 3, -3, -6 + HEAD_OFS, 2, 2, 4);
  146.  
  147. buildHorn(false);
  148. buildHorn(true);
  149.  
  150. jaw = head.addChildBox("lowerjaw", -6, 0, -16, 12, 4, 16);
  151. jaw.setRotationPoint(0, 4, 8 + HEAD_OFS);
  152. }
  153.  
  154. private void buildHorn(boolean mirror) {
  155. int hornThick = 3;
  156. int hornLength = 12;
  157.  
  158. float hornOfs = -(hornThick / 2f);
  159.  
  160. float hornPosX = -5;
  161. float hornPosY = -8;
  162. float hornPosZ = 0;
  163.  
  164. float hornRotX = MathX.toRadians(30);
  165. float hornRotY = MathX.toRadians(-30);
  166. float hornRotZ = 0;
  167.  
  168. if (mirror) {
  169. hornPosX *= -1;
  170. hornRotY *= -1;
  171. }
  172.  
  173. head.mirror = mirror;
  174. ModelPart horn = head.addChildBox("horn", hornOfs, hornOfs, hornOfs, hornThick, hornThick, hornLength);
  175. horn.setRotationPoint(hornPosX, hornPosY, hornPosZ);
  176. horn.setAngles(hornRotX, hornRotY, hornRotZ);
  177. }
  178.  
  179. private void buildNeck() {
  180. neck = new ModelPart(this, "neck");
  181. neck.addBox("box", -5, -5, -5, NECK_SIZE, NECK_SIZE, NECK_SIZE);
  182. neckScale = neck.addChildBox("scale", -1, -7, -3, 2, 4, 6);
  183.  
  184. // initialize model proxies
  185. for (int i = 0; i < neckProxy.length; i++) {
  186. neckProxy[i] = new ModelPartProxy(neck);
  187. }
  188. }
  189.  
  190. private void buildTail() {
  191. tail = new ModelPart(this, "tail");
  192. tail.addBox("box", -5, -5, -5, TAIL_SIZE, TAIL_SIZE, TAIL_SIZE);
  193. float scaleRotZ = MathX.toRadians(45);
  194. tailScaleLeft = tail.addChildBox("scale", -1, -8, -3, 2, 4, 6).setAngles(0, 0, scaleRotZ);
  195. tailScaleMiddle = tail.addChildBox("scale", -1, -8, -3, 2, 4, 6).setAngles(0, 0, 0);
  196. tailScaleRight = tail.addChildBox("scale", -1, -8, -3, 2, 4, 6).setAngles(0, 0, -scaleRotZ);
  197.  
  198. boolean sapphire = breed == EnumDragonBreed.SAPPHIRE;
  199.  
  200. tailScaleMiddle.showModel = !sapphire;
  201. tailScaleLeft.showModel = sapphire;
  202. tailScaleRight.showModel = sapphire;
  203.  
  204. buildTailHorn(false);
  205. buildTailHorn(true);
  206.  
  207. // initialize model proxies
  208. for (int i = 0; i < tailProxy.length; i++) {
  209. tailProxy[i] = new ModelPartProxy(tail);
  210. }
  211. }
  212.  
  213. private void buildTailHorn(boolean mirror) {
  214. int hornThick = 3;
  215. int hornLength = 32;
  216.  
  217. float hornOfs = -(hornThick / 2f);
  218.  
  219. float hornPosX = 0;
  220. float hornPosY = hornOfs;
  221. float hornPosZ = TAIL_SIZE / 2f;
  222.  
  223. float hornRotX = MathX.toRadians(-15);
  224. float hornRotY = MathX.toRadians(-145);
  225. float hornRotZ = 0;
  226.  
  227. if (mirror) {
  228. hornPosX *= -1;
  229. hornRotY *= -1;
  230. }
  231.  
  232. tail.mirror = mirror;
  233. ModelPart horn = tail.addChildBox("horn", hornOfs, hornOfs, hornOfs, hornThick, hornThick, hornLength);
  234. horn.setRotationPoint(hornPosX, hornPosY, hornPosZ);
  235. horn.setAngles(hornRotX, hornRotY, hornRotZ);
  236. horn.isHidden = true;
  237. horn.showModel = breed == EnumDragonBreed.JADE;
  238.  
  239. if (mirror) {
  240. tailHornLeft = horn;
  241. } else {
  242. tailHornRight = horn;
  243. }
  244. }
  245.  
  246. private void buildBody() {
  247. body = new ModelPart(this, "body");
  248.  
  249. body.setRotationPoint(0, 4, 8);
  250. body.addBox("body", -12, 0, -16, 24, 24, 64);
  251. body.addBox("scale", -1, -6, 10, 2, 6, 12);
  252. body.addBox("scale", -1, -6, 30, 2, 6, 12);
  253. back = body.addChildBox("scale", -1, -6, -10, 2, 6, 12);
  254. chestL = body.addChildBox("chestL", 12, 0, 18, 4, 12, 12);
  255. chestR = body.addChildBox("chestR", -15, 0, 18, 4, 12, 12);
  256. saddle = body.addChildBox("saddle", -7, -2, -15, 15, 3, 20);
  257. saddleFront = body.addChildBox("saddleFront", -3, -3, -14, 6, 1, 2);
  258. saddleBack = body.addChildBox("saddleBack", -6, -4, 2, 13, 2, 2);
  259. saddleTieL = body.addChildBox("saddleTieL", 12, 0, -14, 1, 14, 2);
  260. saddleMetalL = body.addChildBox("saddleMetalL", 12, 14, -15, 1, 5, 4);
  261. saddleTieR = body.addChildBox("saddleTieR", -13, 0, -14, 1, 10, 2);
  262. saddleMetalR = body.addChildBox("saddleMetalR", -13, 10, -15, 1, 5, 4);
  263. }
  264.  
  265. private void buildWing() {
  266. wingArm = new ModelPart(this, "wingarm");
  267. wingArm.setRotationPoint(-10, 5, 4);
  268. wingArm.setRenderScale(1.1f);
  269. wingArm.addBox("bone", -28, -3, -3, 28, 6, 6);
  270. wingArm.addBox("skin", -28, 0, 2, 28, 0, 24);
  271.  
  272. wingForearm = new ModelPart(this, "wingforearm");
  273. wingForearm.setRotationPoint(-28, 0, 0);
  274. wingForearm.addBox("bone", -48, -2, -2, 48, 4, 4);
  275. wingArm.addChild(wingForearm);
  276.  
  277. wingFinger[0] = buildWingFinger(false);
  278. wingFinger[1] = buildWingFinger(false);
  279. wingFinger[2] = buildWingFinger(false);
  280. wingFinger[3] = buildWingFinger(true);
  281. }
  282.  
  283. private ModelPart buildWingFinger(boolean small) {
  284. ModelPart finger = new ModelPart(this, "wingfinger");
  285. finger.setRotationPoint(-47, 0, 0);
  286. finger.addBox("bone", -70, -1, -1, 70, 2, 2);
  287. if (small) {
  288. finger.addBox("shortskin", -70, 0, 1, 70, 0, 32);
  289. } else {
  290. finger.addBox("skin", -70, 0, 1, 70, 0, 48);
  291. }
  292. wingForearm.addChild(finger);
  293.  
  294. return finger;
  295. }
  296.  
  297. private void buildLegs() {
  298. buildLeg(false);
  299. buildLeg(true);
  300.  
  301. // initialize model proxies
  302. for (int i = 0; i < 4; i++) {
  303. if (i % 2 == 0) {
  304. thighProxy[i] = new ModelPartProxy(forethigh);
  305. } else {
  306. thighProxy[i] = new ModelPartProxy(hindthigh);
  307. }
  308. }
  309. }
  310.  
  311. private void buildLeg(boolean hind) {
  312. // thinner legs for skeletons
  313.  
  314. float baseLength = 26;
  315. String baseName = hind ? "hind" : "fore";
  316.  
  317. // thigh variables
  318. float thighPosX = -11;
  319. float thighPosY = 18;
  320. float thighPosZ = 4;
  321.  
  322. int thighThick = 9;
  323. int thighLength = (int) (baseLength * (hind ? 0.9f : 0.77f));
  324.  
  325. if (hind) {
  326. thighThick++;
  327. thighPosY -= 5;
  328. }
  329.  
  330. float thighOfs = -(thighThick / 2f);
  331.  
  332. ModelPart thigh = new ModelPart(this, baseName + "thigh");
  333. thigh.setRotationPoint(thighPosX, thighPosY, thighPosZ);
  334. thigh.addBox("main", thighOfs, thighOfs, thighOfs, thighThick, thighLength, thighThick);
  335.  
  336. // crus variables
  337. float crusPosX = 0;
  338. float crusPosY = thighLength + thighOfs;
  339. float crusPosZ = 0;
  340.  
  341. int crusThick = thighThick - 2;
  342. int crusLength = (int) (baseLength * (hind ? 0.7f : 0.8f));
  343.  
  344. if (hind) {
  345. crusThick--;
  346. crusLength -= 2;
  347. }
  348.  
  349. float crusOfs = -(crusThick / 2f);
  350.  
  351. ModelPart crus = new ModelPart(this, baseName + "crus");
  352. crus.setRotationPoint(crusPosX, crusPosY, crusPosZ);
  353. crus.addBox("main", crusOfs, crusOfs, crusOfs, crusThick, crusLength, crusThick);
  354. thigh.addChild(crus);
  355.  
  356. // foot variables
  357. float footPosX = 0;
  358. float footPosY = crusLength + (crusOfs / 2f);
  359. float footPosZ = 0;
  360.  
  361. int footWidth = crusThick + 2;
  362. int footHeight = 4;
  363. int footLength = (int) (baseLength * (hind ? 0.67f : 0.34f));
  364.  
  365. float footOfsX = -(footWidth / 2f);
  366. float footOfsY = -(footHeight / 2f);
  367. float footOfsZ = footLength * -0.75f;
  368.  
  369. ModelPart foot = new ModelPart(this, baseName + "foot");
  370. foot.setRotationPoint(footPosX, footPosY, footPosZ);
  371. foot.addBox("main", footOfsX, footOfsY, footOfsZ, footWidth, footHeight, footLength);
  372. crus.addChild(foot);
  373.  
  374. // toe variables
  375. int toeWidth = footWidth;
  376. int toeHeight = footHeight;
  377. int toeLength = (int) (baseLength * (hind ? 0.27f : 0.33f));
  378.  
  379. float toePosX = 0;
  380. float toePosY = 0;
  381. float toePosZ = footOfsZ - (footOfsY / 2f);
  382.  
  383. float toeOfsX = -(toeWidth / 2f);
  384. float toeOfsY = -(toeHeight / 2f);
  385. float toeOfsZ = -toeLength;
  386.  
  387. ModelPart toe = new ModelPart(this, baseName + "toe");
  388. toe.setRotationPoint(toePosX, toePosY, toePosZ);
  389. toe.addBox("main", toeOfsX, toeOfsY, toeOfsZ, toeWidth, toeHeight, toeLength);
  390. foot.addChild(toe);
  391.  
  392. if (hind) {
  393. hindthigh = thigh;
  394. hindcrus = crus;
  395. hindfoot = foot;
  396. hindtoe = toe;
  397. } else {
  398. forethigh = thigh;
  399. forecrus = crus;
  400. forefoot = foot;
  401. foretoe = toe;
  402. }
  403. }
  404.  
  405. /**
  406. * Used for easily adding entity-dependent animations. The second and third float params here are the same second
  407. * and third as in the setRotationAngles method.
  408. */
  409. @Override
  410. public void setLivingAnimations(EntityLivingBase entity, float moveTime, float moveSpeed, float partialTicks) {
  411. setLivingAnimations((EntityTameableDragon) entity, moveTime, moveSpeed, partialTicks);
  412. }
  413.  
  414. public void setLivingAnimations(EntityTameableDragon dragon, float moveTime, float moveSpeed, float partialTicks) {
  415. DragonAnimator animator = dragon.getAnimator();
  416. animator.setPartialTicks(partialTicks);
  417. }
  418.  
  419. /**
  420. * Sets the models various rotation angles then renders the model.
  421. */
  422. @Override
  423. public void render(Entity entity, float moveTime, float moveSpeed, float ticksExisted, float lookYaw, float lookPitch, float scale) {
  424. render((EntityTameableDragon) entity, moveTime, moveSpeed, ticksExisted, lookYaw, lookPitch, scale);
  425. }
  426.  
  427. public void render(EntityTameableDragon dragon, float moveTime, float moveSpeed, float ticksExisted, float lookYaw, float lookPitch, float scale) {
  428. DragonAnimator animator = dragon.getAnimator();
  429. animator.setMovement(moveTime, moveSpeed * dragon.getScale());
  430. animator.setLook(lookYaw, lookPitch);
  431. animator.animate(this);
  432.  
  433. size = dragon.getScale();
  434.  
  435. renderModel(dragon, scale);
  436. }
  437.  
  438. /**
  439. * Renders the model after all animations are applied.
  440. */
  441. public void renderModel(EntityTameableDragon dragon, float scale) {
  442. if (mode == null) {
  443. return;
  444. }
  445.  
  446. GlStateManager.pushMatrix();
  447. GlStateManager.translate(offsetX, offsetY, offsetZ);
  448. GlStateManager.rotate(-pitch, 1, 0, 0);
  449.  
  450. switch (mode) {
  451. case BODY_ONLY:
  452. renderBody(scale);
  453. break;
  454. case WINGS_ONLY:
  455. renderWings(scale);
  456. break;
  457. default:
  458. renderHead(scale);
  459. renderNeck(scale);
  460. renderBody(scale);
  461. renderLegs(scale);
  462. renderTail(scale);
  463. if (mode != DragonModelMode.NO_WINGS) {
  464. renderWings(scale);
  465. }
  466. }
  467.  
  468. GlStateManager.popMatrix();
  469. }
  470.  
  471. protected void renderBody(float scale) {
  472. body.render(scale);
  473. }
  474.  
  475. protected void renderHead(float scale) {
  476. float headScale = 1.4f / (size + 0.4f);
  477.  
  478. if (this.isChild) // smaller heads for baby dragons unlike other animals
  479. {this.head.render(scale);}
  480. else
  481. {head.setRenderScale(headScale); // normal heads on adult dragons
  482. head.render(scale);}
  483. }
  484.  
  485. protected void renderNeck(float scale) {
  486. for (ModelPartProxy proxy : neckProxy) {
  487. proxy.render(scale);
  488. }
  489. }
  490.  
  491. protected void renderTail(float scale) {
  492. for (ModelPartProxy proxy : tailProxy) {
  493. proxy.render(scale);
  494. }
  495. }
  496.  
  497. protected void renderWings(float scale) {
  498. GlStateManager.pushMatrix();
  499. GlStateManager.enableCull();
  500. GlStateManager.cullFace(GlStateManager.CullFace.FRONT);
  501.  
  502. for (int i = 0; i < 2; i++) {
  503. wingArm.render(scale);
  504.  
  505. if (i == 0) {
  506. // mirror next wing
  507. GlStateManager.scale(-1, 1, 1);
  508. // switch to back face culling
  509. GlStateManager.cullFace(GlStateManager.CullFace.BACK);
  510. }
  511. }
  512.  
  513. GlStateManager.disableCull();
  514. GlStateManager.popMatrix();
  515. }
  516.  
  517. protected void renderLegs(float scale) {
  518. GlStateManager.enableCull();
  519. GlStateManager.cullFace(GlStateManager.CullFace.BACK);
  520.  
  521. for (int i = 0; i < thighProxy.length; i++) {
  522. thighProxy[i].render(scale);
  523.  
  524. if (i == 1) {
  525. // mirror next legs
  526. GlStateManager.scale(-1, 1, 1);
  527. // switch to front face culling
  528. GlStateManager.cullFace(GlStateManager.CullFace.FRONT);
  529. }
  530. }
  531.  
  532. GlStateManager.cullFace(GlStateManager.CullFace.BACK);
  533. GlStateManager.disableCull();
  534. }
  535. }
Add Comment
Please, Sign In to add comment