EnvironmentAPI.java 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. package me.km.environment;
  2. import java.util.HashMap;
  3. import java.util.UUID;
  4. import me.km.effects.Effect;
  5. import me.km.effects.EffectUtils;
  6. import net.minecraft.entity.player.EntityPlayer;
  7. import net.minecraft.util.math.BlockPos;
  8. import net.minecraft.world.EnumSkyBlock;
  9. import net.minecraft.world.World;
  10. public class EnvironmentAPI
  11. {
  12. private static HashMap<UUID, Integer> thirst;
  13. private static HashMap<UUID, Integer> energy;
  14. private static HashMap<UUID, Integer> cold;
  15. private static HashMap<UUID, Integer> mana;
  16. public static void initStatusAPI()
  17. {
  18. thirst = new HashMap<>();
  19. energy = new HashMap<>();
  20. cold = new HashMap<>();
  21. mana = new HashMap<>();
  22. }
  23. // ---------------------------------
  24. // Allgemein
  25. // ---------------------------------
  26. private static void changeStat(HashMap<UUID, Integer> map, int limit, EntityPlayer p, int amount)
  27. {
  28. Integer i = map.get(p.getUniqueID());
  29. if(i == null)
  30. {
  31. i = limit;
  32. }
  33. i += amount;
  34. if(i < 0)
  35. {
  36. i = 0;
  37. }
  38. else if(i > limit)
  39. {
  40. i = limit;
  41. }
  42. map.put(p.getUniqueID(), i);
  43. }
  44. private static void resetStat(HashMap<UUID, Integer> map, int limit, EntityPlayer p)
  45. {
  46. map.put(p.getUniqueID(), limit);
  47. }
  48. private static int getStat(HashMap<UUID, Integer> map, int limit, EntityPlayer p)
  49. {
  50. Integer i = map.get(p.getUniqueID());
  51. if(i == null)
  52. {
  53. map.put(p.getUniqueID(), limit);
  54. return limit;
  55. }
  56. return i;
  57. }
  58. // ---------------------------------
  59. // Durst
  60. // ---------------------------------
  61. private final static int THIRST = 10000;
  62. public static void changeThirst(EntityPlayer p, int amount)
  63. {
  64. if(amount < 0)
  65. {
  66. amount /= EffectUtils.getEffectLevel(p, Effect.LESS_THIRST) + 1;
  67. }
  68. changeStat(thirst, THIRST, p, amount);
  69. }
  70. public static void resetThirst(EntityPlayer p)
  71. {
  72. resetStat(thirst, THIRST, p);
  73. }
  74. public static int getThirst(EntityPlayer p)
  75. {
  76. return getStat(thirst, THIRST, p);
  77. }
  78. // ---------------------------------
  79. // Energie
  80. // ---------------------------------
  81. private final static int ENERGY = 10000;
  82. public static void changeEnergy(EntityPlayer p, int amount)
  83. {
  84. if(amount < 0)
  85. {
  86. amount /= EffectUtils.getEffectLevel(p, Effect.LESS_ENERGY_USE) + 1;
  87. }
  88. changeStat(energy, ENERGY, p, amount);
  89. }
  90. public static void resetEnergy(EntityPlayer p)
  91. {
  92. resetStat(energy, ENERGY, p);
  93. }
  94. public static int getEnergy(EntityPlayer p)
  95. {
  96. return getStat(energy, ENERGY, p);
  97. }
  98. // ---------------------------------
  99. // Kälte
  100. // ---------------------------------
  101. private final static int COLD = 100;
  102. public static void changeCold(EntityPlayer p, int amount)
  103. {
  104. if(amount < 0)
  105. {
  106. amount += EffectUtils.getEffectLevel(p, Effect.LESS_COLD) * 2;
  107. }
  108. changeStat(cold, COLD, p, amount);
  109. }
  110. public static void resetCold(EntityPlayer p)
  111. {
  112. resetStat(cold, COLD, p);
  113. }
  114. public static int getCold(EntityPlayer p)
  115. {
  116. return getStat(cold, COLD, p);
  117. }
  118. // ---------------------------------
  119. // Mana
  120. // ---------------------------------
  121. private final static int MANA = 100;
  122. public static void changeMana(EntityPlayer p, int amount)
  123. {
  124. if(amount > 0)
  125. {
  126. amount += EffectUtils.getEffectLevel(p, Effect.FASTER_MANA) * 2;
  127. }
  128. changeStat(mana, MANA, p, amount);
  129. }
  130. public static void resetMana(EntityPlayer p)
  131. {
  132. resetStat(mana, MANA, p);
  133. }
  134. public static int getMana(EntityPlayer p)
  135. {
  136. return getStat(mana, MANA, p);
  137. }
  138. // ---------------------------------
  139. // Temperatur
  140. // ---------------------------------
  141. public static int getTemperature(World w, BlockPos pos)
  142. {
  143. double d = w.getBiome(pos).getTemperature();
  144. d -= (((pos.getY() - 65) * 0.05) / 30) + 0.3;
  145. d += (w.getLightFromNeighbors(pos) * 0.3) / 15;
  146. try
  147. {
  148. d += (w.getLightFor(EnumSkyBlock.BLOCK, pos) * 0.3) / 15;
  149. }
  150. catch(Exception ex)
  151. {
  152. }
  153. return (int) (-7.08578 * Math.pow(d, 2) + 37.50072 * d - 5.46568);
  154. }
  155. }