Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. /*
  2. ** 2012 August 23
  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. package com.TheRPGAdventurer.ROTD.server.entity.helper;
  11.  
  12. import com.TheRPGAdventurer.ROTD.util.math.Interpolation;
  13. import net.minecraft.util.math.MathHelper;
  14.  
  15. /**
  16. * Enum for dragon life stages. Used as aliases for the age value of dragons.
  17. *
  18. * @author Nico Bergemann <barracuda415 at yahoo.de>
  19. */
  20. public enum EnumDragonLifeStage {
  21.  
  22. EGG(0.25f),
  23. HATCHLING(0.10f),
  24. JUVENILE(0.88f),
  25. ADULT(1.7f);
  26.  
  27. public static final int TICKS_PER_STAGE = 42000;
  28. public static final EnumDragonLifeStage[] VALUES = values(); // cached for speed
  29.  
  30. public static int clampTickCount(int ticksSinceCreation) {
  31. return MathHelper.clamp(ticksSinceCreation, 0, VALUES.length * TICKS_PER_STAGE);
  32. }
  33.  
  34. public static EnumDragonLifeStage fromTickCount(int ticksSinceCreation) {
  35. return VALUES[clampTickCount(ticksSinceCreation) / TICKS_PER_STAGE];
  36. }
  37.  
  38. public static float progressFromTickCount(int ticksSinceCreation) {
  39. EnumDragonLifeStage lifeStage = fromTickCount(ticksSinceCreation);
  40. int lifeStageTicks = ticksSinceCreation - lifeStage.startTicks();
  41. return lifeStageTicks / (float) TICKS_PER_STAGE;
  42. }
  43.  
  44. public static float scaleFromTickCount(int ticksSinceCreation) {
  45. EnumDragonLifeStage lifeStage = fromTickCount(ticksSinceCreation);
  46.  
  47. // constant size for egg and adult stage end growth if adult
  48. if (lifeStage == EGG || lifeStage == ADULT) {
  49. return lifeStage.scale;
  50. }
  51.  
  52. // interpolated size between current and next stage
  53. return Interpolation.linear(lifeStage.scale, lifeStage.next().scale,
  54. progressFromTickCount(ticksSinceCreation));
  55. }
  56.  
  57. public final float scale;
  58.  
  59. EnumDragonLifeStage(float scale) {
  60. this.scale = scale;
  61. }
  62.  
  63. public int startTicks() {
  64. return ordinal() * TICKS_PER_STAGE;
  65. }
  66.  
  67. public EnumDragonLifeStage next() {
  68. return this == ADULT ? null : VALUES[ordinal() + 1];
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement