Guest User

Untitled

a guest
Sep 25th, 2018
119
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package de.krokoyt.gswords.Skills;
  2.  
  3. import de.krokoyt.gswords.GiantSword;
  4. import de.krokoyt.gswords.events.AddPackets;
  5. import de.krokoyt.gswords.events.Skills;
  6. import net.minecraft.client.Minecraft;
  7. import net.minecraft.entity.Entity;
  8. import net.minecraft.entity.player.EntityPlayer;
  9. import net.minecraft.entity.player.EntityPlayerMP;
  10. import net.minecraft.nbt.NBTTagCompound;
  11. import net.minecraft.world.World;
  12. import net.minecraftforge.common.IExtendedEntityProperties;
  13.  
  14. public class HealthHelper implements IExtendedEntityProperties{
  15.  
  16. private EntityPlayer player;
  17. private float exp;
  18. private int level;
  19.  
  20. public HealthHelper(EntityPlayer player) {
  21. this.player = player;
  22. this.level = 1;
  23. this.exp = 0.0F;
  24.  
  25. }
  26.  
  27.  
  28.  
  29.  
  30.  
  31. @Override
  32. public void saveNBTData(NBTTagCompound compound) {
  33. NBTTagCompound tag = this.player.getEntityData().getCompoundTag("PlayerPersisted");
  34. tag.setInteger("HeLevel", this.level);
  35. tag.setFloat("HeExp", this.exp);
  36. compound.setTag("HealthSkill", tag);
  37. this.player.getEntityData().setTag("PlayerPersisted", tag);
  38.  
  39. }
  40.  
  41. public static void addProperties(EntityPlayer player)
  42. {
  43. player.registerExtendedProperties("HealthSkill", new HealthHelper(player));
  44. }
  45.  
  46. public static HealthHelper getProperties(EntityPlayer player)
  47. {
  48. return (HealthHelper)player.getExtendedProperties("HealthSkill");
  49. }
  50.  
  51.  
  52. @Override
  53. public void loadNBTData(NBTTagCompound compound) {
  54. NBTTagCompound tag = this.player.getEntityData().getCompoundTag("PlayerPersisted");
  55. if (!tag.equals("HeLevel")) {
  56. return;
  57. }
  58. this.level = tag.getInteger("HeLevel");
  59. this.exp = tag.getFloat("HeExp");
  60. this.player.getEntityData().setTag("PlayerPersisted", tag);
  61.  
  62. }
  63.  
  64. public int getExpAdded()
  65. {
  66. if (this.level <= 4) {
  67. return (int)(Math.pow(1.1D, this.level - 1) * 50.0D / 6.0D);
  68. }
  69. if (this.level <= 14) {
  70. return (int)(Math.pow(1.1D, this.level - 1) * 50.0D / 14.0D);
  71. }
  72. if (this.level <= 29) {
  73. return (int)(Math.pow(1.1D, this.level - 1) * 50.0D / 30.0D);
  74. }
  75. if (this.level <= 44) {
  76. return (int)(Math.pow(1.1D, this.level - 1) * 50.0D / 60.0D);
  77. }
  78. if (this.level <= 59) {
  79. return (int)(Math.pow(1.1D, this.level - 1) * 50.0D / 100.0D);
  80. }
  81. if (this.level <= 74) {
  82. return (int)(Math.pow(1.1D, this.level - 1) * 50.0D / 160.0D);
  83. }
  84. if (this.level <= 89) {
  85. return (int)(Math.pow(1.1D, this.level - 1) * 50.0D / 250.0D);
  86. }
  87. if (this.level <= 94) {
  88. return (int)(Math.pow(1.1D, this.level - 1) * 50.0D / 310.0D);
  89. }
  90. return (int)(Math.pow(1.1D, this.level - 1) * 50.0D / 400.0D);
  91. }
  92.  
  93. public int getLevel()
  94. {
  95. return this.level;
  96. }
  97.  
  98. public float getExperience()
  99. {
  100. return this.exp;
  101. }
  102.  
  103. public float getExpRequired()
  104. {
  105. return (float)(Math.pow(1.1D, this.level - 1) * 50.0D);
  106. }
  107.  
  108. public void setExperience(float i)
  109. {
  110. this.exp = i;
  111. if ((this.player instanceof EntityPlayerMP)) {
  112. AddPackets.network.sendTo(new HealthMessage(this.level, progressPercentage()), (EntityPlayerMP)this.player);
  113. }
  114. }
  115.  
  116. public void setLevel(int i)
  117. {
  118. this.level = i;
  119. if ((this.player instanceof EntityPlayerMP)) {
  120. AddPackets.network.sendTo(new HealthMessage(this.level, progressPercentage()), (EntityPlayerMP)this.player);
  121. }
  122. }
  123.  
  124. public int progressPercentage()
  125. {
  126. return (int)Math.floor(this.exp / getExpRequired() * 100.0F);
  127. }
  128. ///playsound gswords:LevelUp @a
  129. public void levelUp()
  130. {
  131. if (this.level != 100) {
  132. Minecraft.getMinecraft().thePlayer.playSound("gswords:LevelUp", 3.85F, 1.0F);
  133. }
  134. this.level += 1;
  135. if (this.level == 100) {
  136. Minecraft.getMinecraft().thePlayer.playSound("gswords:Level100", 3.85F, 1.0F);
  137. }
  138. if (this.level == 101) {
  139. this.level = 100;
  140. }
  141. this.exp = 0.0F;
  142. if ((this.player instanceof EntityPlayerMP)) {
  143. AddPackets.network.sendTo(new HealthMessage(this.level, progressPercentage()), (EntityPlayerMP)this.player);
  144. }
  145. }
  146.  
  147. public float getExpLeft()
  148. {
  149. return (float)(Math.pow(1.1D, this.level - 1) * 50.0D) - this.exp;
  150. }
  151.  
  152. public void addExperience(float i)
  153. {
  154. if (i > getExpLeft())
  155. {
  156. float x = i;
  157. boolean run = true;
  158. while (run) {
  159. if (x > getExpLeft())
  160. {
  161. x -= getExpLeft();
  162. levelUp();
  163. }
  164. else
  165. {
  166. this.exp += x;
  167. run = false;
  168. if ((this.player instanceof EntityPlayerMP)) {
  169. AddPackets.network.sendTo(new HealthMessage(this.level, progressPercentage()), (EntityPlayerMP)this.player);
  170. }
  171. }
  172. }
  173. }
  174. else
  175. {
  176. this.exp += i;
  177. if (this.exp >= getExpRequired()) {
  178. levelUp();
  179. } else if ((this.player instanceof EntityPlayerMP)) {
  180. AddPackets.network.sendTo(new HealthMessage(this.level, progressPercentage()), (EntityPlayerMP)this.player);
  181. }
  182. }
  183. }
  184.  
  185. @Override
  186. public void init(Entity entity, World world) {
  187.  
  188. }
  189.  
  190. }
RAW Paste Data