package org.pfaa.chemica.model;

import net.minecraft.world.EnumSkyBlock;
import net.minecraft.world.World;
import net.minecraft.world.biome.BiomeGenBase;

public class Condition {
	public double temperature;
	public double pressure;
	
	public Condition(double temperature, double pressure) {
		super();
		this.temperature = temperature;
		this.pressure = pressure;
	}
	
	public static Condition ofWorldCoordinates(World world, int x, int y, int z) {
		double temperature = getTemperatureAt(world, x, y, z);
		
		double pressure = getPressureAt(world, x, y, z);
		return new Condition(temperature, pressure);
	}
	
	private static double getPressureAt(World world, int x, int y, int z) {
		int sealevel = world.provider.hasNoSky ? world.provider.getActualHeight() : 
			world.provider.getAverageGroundLevel();
		return Constants.STANDARD_PRESSURE - 
				(y - sealevel) * (2/3) * Constants.STANDARD_PRESSURE / 
				                 (world.provider.getHeight() - sealevel);
	}

	private static float getTemperatureAt(World world, int x, int y, int z) {
		BiomeGenBase biomegenbase = world.getBiomeGenForCoords(x, z);
		float biometemp = biomegenbase.getFloatTemperature(x, y, z);
		double temperature = (biometemp - 0.15F) * 45 / (2.0F - 0.15F);
		boolean isHeated = world.getSavedLightValue(EnumSkyBlock.Block, x, y, z) == 10;
		if (isHeated) {
			temperature = Math.max(temperature, Constants.STANDARD_TEMPERATURE);
		}
		// TODO: if near fire, we are >=100C; if near a fluid, we consider its temperature somehow. 
		// But how to determine "near" 3x3? But should we allow for heat insulation somehow? 
		// Maybe if surrounded by insulating blocks (or the same fluid)? 
		return (float)temperature;
	}

	public static Condition STP = new Condition(Constants.STANDARD_TEMPERATURE, Constants.STANDARD_PRESSURE);

	@Override
	public boolean equals(Object obj) {
		if (!(obj instanceof Condition)) {
			return false;
		}
		Condition other = (Condition)obj;
		return this.pressure == other.pressure && this.temperature == other.temperature;
	}

	@Override
	public int hashCode() {
		return (int)(this.pressure) ^ ((int)this.temperature);
	}
}

@@ -182,22 +182,19 @@
 %09public 
-double
+int
  tempera
@@ -244,22 +244,19 @@
 ndition(
-double
+int
  tempera
@@ -358,16 +358,108 @@
 e;%0A%09%7D%0A%09%0A
+%09public Condition(int temperature) %7B%0A%09%09this(temperature, Constants.STANDARD_PRESSURE);%0A%09%7D%0A%09%0A
 %09public 
@@ -532,22 +532,19 @@
  z) %7B%0A%09%09
-double
+int
  tempera
@@ -588,11 +588,8 @@
 z);%0A
-%09%09%0A
 %09%09do
@@ -1064,20 +1064,18 @@
  static 
-floa
+in
 t getTem
@@ -1250,22 +1250,19 @@
 , z);%0A%09%09
-double
+int
  tempera
@@ -1268,16 +1268,22 @@
 ature = 
+(int)(
 (biomete
@@ -1315,16 +1315,17 @@
 - 0.15F)
+)
 ;%0A%09%09bool
@@ -1745,16 +1745,16 @@
 luid)? %0A
+
 %09%09return
@@ -1758,15 +1758,8 @@
 urn 
-(float)
 temp

change temp to int