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 thirst; private static HashMap energy; private static HashMap cold; private static HashMap mana; public static void initStatusAPI() { thirst = new HashMap<>(); energy = new HashMap<>(); cold = new HashMap<>(); mana = new HashMap<>(); } // --------------------------------- // Allgemein // --------------------------------- private static void changeStat(HashMap 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 map, int limit, EntityPlayer p) { map.put(p.getUniqueID(), limit); } private static int getStat(HashMap 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); } }