123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- package me.km.environment;
- import java.util.HashMap;
- import java.util.UUID;
- import me.km.effects.Effect;
- import me.km.effects.EffectUtils;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.util.math.BlockPos;
- import net.minecraft.world.EnumSkyBlock;
- import net.minecraft.world.World;
- public class EnvironmentAPI
- {
- private static HashMap<UUID, Integer> thirst;
- private static HashMap<UUID, Integer> energy;
- private static HashMap<UUID, Integer> cold;
- private static HashMap<UUID, Integer> mana;
-
- public static void initStatusAPI()
- {
- thirst = new HashMap<>();
- energy = new HashMap<>();
- cold = new HashMap<>();
- mana = new HashMap<>();
- }
- // ---------------------------------
- // Allgemein
- // ---------------------------------
-
- private static void changeStat(HashMap<UUID, Integer> map, int limit, EntityPlayer p, int amount)
- {
- Integer i = map.get(p.getUniqueID());
- if(i == null)
- {
- i = limit;
- }
- i += amount;
- if(i < 0)
- {
- i = 0;
- }
- else if(i > limit)
- {
- i = limit;
- }
- map.put(p.getUniqueID(), i);
- }
-
- private static void resetStat(HashMap<UUID, Integer> map, int limit, EntityPlayer p)
- {
- map.put(p.getUniqueID(), limit);
- }
-
- private static int getStat(HashMap<UUID, Integer> map, int limit, EntityPlayer p)
- {
- Integer i = map.get(p.getUniqueID());
- if(i == null)
- {
- map.put(p.getUniqueID(), limit);
- return limit;
- }
- return i;
- }
-
- // ---------------------------------
- // Durst
- // ---------------------------------
-
- private final static int THIRST = 10000;
-
- public static void changeThirst(EntityPlayer p, int amount)
- {
- if(amount < 0)
- {
- amount /= EffectUtils.getEffectLevel(p, Effect.LESS_THIRST) + 1;
- }
- changeStat(thirst, THIRST, p, amount);
- }
-
- public static void resetThirst(EntityPlayer p)
- {
- resetStat(thirst, THIRST, p);
- }
-
- public static int getThirst(EntityPlayer p)
- {
- return getStat(thirst, THIRST, p);
- }
-
- // ---------------------------------
- // Energie
- // ---------------------------------
-
- private final static int ENERGY = 10000;
-
- public static void changeEnergy(EntityPlayer p, int amount)
- {
- if(amount < 0)
- {
- amount /= EffectUtils.getEffectLevel(p, Effect.LESS_ENERGY_USE) + 1;
- }
- changeStat(energy, ENERGY, p, amount);
- }
-
- public static void resetEnergy(EntityPlayer p)
- {
- resetStat(energy, ENERGY, p);
- }
-
- public static int getEnergy(EntityPlayer p)
- {
- return getStat(energy, ENERGY, p);
- }
-
- // ---------------------------------
- // Kälte
- // ---------------------------------
-
- private final static int COLD = 100;
-
- public static void changeCold(EntityPlayer p, int amount)
- {
- if(amount < 0)
- {
- amount += EffectUtils.getEffectLevel(p, Effect.LESS_COLD) * 2;
- }
- changeStat(cold, COLD, p, amount);
- }
-
- public static void resetCold(EntityPlayer p)
- {
- resetStat(cold, COLD, p);
- }
-
- public static int getCold(EntityPlayer p)
- {
- return getStat(cold, COLD, p);
- }
-
- // ---------------------------------
- // Mana
- // ---------------------------------
-
- private final static int MANA = 100;
-
- public static void changeMana(EntityPlayer p, int amount)
- {
- if(amount > 0)
- {
- amount += EffectUtils.getEffectLevel(p, Effect.FASTER_MANA) * 2;
- }
- changeStat(mana, MANA, p, amount);
- }
-
- public static void resetMana(EntityPlayer p)
- {
- resetStat(mana, MANA, p);
- }
-
- public static int getMana(EntityPlayer p)
- {
- return getStat(mana, MANA, p);
- }
-
- // ---------------------------------
- // Temperatur
- // ---------------------------------
-
- public static int getTemperature(World w, BlockPos pos)
- {
- double d = w.getBiome(pos).getTemperature();
- d -= (((pos.getY() - 65) * 0.05) / 30) + 0.3;
- d += (w.getLightFromNeighbors(pos) * 0.3) / 15;
- try
- {
- d += (w.getLightFor(EnumSkyBlock.BLOCK, pos) * 0.3) / 15;
- }
- catch(Exception ex)
- {
- }
- return (int) (-7.08578 * Math.pow(d, 2) + 37.50072 * d - 5.46568);
- }
- }
|