// 0.192916

function getBiomeGroundMaterial(%biome) {
	switch$ (%biome) {
		case "desert": return "Sand";
		case "grass_desert": return "GrassBlock";
		case "tundra": return "Snow";
		case "taiga": return "Snow";
		case "woods": return "GrassBlock";
		case "forest": return "GrassBlock";
		case "seasonal_forest": return "GrassBlock";
	}

	return "GrassBlock";
}

function getBiomeTreeLimits(%biome) {
	switch$ (%biome) {
		case "desert": return "0 0";
		case "grass_desert": return "-5 1";
		case "tundra": return "0 0";
		case "taiga": return "0 0";
		case "woods": return "-6 2";
		case "forest": return "-4 3";
		case "seasonal_forest": return "-4 4";
	}
}

function SimSet::getBiome(%this, %x, %y) {
	return "forest"; // lol

	%temp = %this.getTemperature(%x, %y);
	%humi = %this.getHumidity(%x, %y);

	if (%temp < 0) {
		%temp = 0;
	}

	if (%temp > 1) {
		%temp = 1;
	}

	if (%humi < 0) {
		%humi = 0;
	}

	if (%humi > 1) {
		%humi = 1;
	}

	if (%temp <= 0.25 && %humi <= 0.5) {
		return "tundra";
	}

	if (%temp <= 0.63 && %humi <= 0.25) {
		return "grass_desert";
	}

	if (%humi <= 0.25) {
		return "desert";
	}

	if (%temp >= 0.25 && %temp <= 0.5 && %humi >= 0.25 && %humi <= 0.75) {
		return "taiga";
	}

	if (%temp >= 0.5 && %temp <= 0.75 && %humi >= 0.25 && %humi <= 0.5) {
		return "woods";
	}

	if (%temp >= 0.75 && %humi >= 0.25 && %humi <= 0.5) {
		return "savanna";
	}

	if (%temp >= 0.5 && %temp <= 0.75 && %humi >= 0.5 && %humi <= 0.75) {
		return "forest";
	}

	if (%temp >= 0.75 && %humi >= 0.5 && %humi <= 0.75) {
		return "seasonal_forest";
	}

	if (%temp >= 0.5 && %temp <= 0.75 && %humi >= 0.75) {
		return "swamp";
	}

	if (%temp >= 0.75 && %humi >= 0.75) {
		return "rain_forest";
	}

	return "forest";
}

function fancy_math(%cx,%cy,%x,%y,%z)
{
	%x += %cx * 16;
	%y += %cy * 16;

	//%m = 24;
	//%f = vectorLen( %x SPC %y SPC 0 );
	//return %f / %m;
	//%f -= 24 * mFloor( %f / 24 );
	//return %f / 24;
	%xs = 50;
	%ys = 50;
	%max = ( %xs - 1 ) + ( %ys - 1 );
	%val = %x + %y;
	%fac = %val / %max;
	return %fac;

	%val = %x - ( %xs / ( 1 + getRandom() ) );
	%val /= %y - ( %ys / ( 1 + getRandom() ) );
	%val /=  %xs * %ys ;
	return %val;
}

function SimSet::getTemperature( %this, %x, %y )
{
	//return 0.65;
	%x = getWord(%this.position, 0) * 16 + %x;
	%y = getWord(%this.position, 1) * 16 + %y;

	if(!isObject($perlin))
		$perlin = new ScriptObject() {
			class = Perlin;
		};

	%quality = 512 + MCWorld.seed;
	%noise = $perlin.noise((%x / MCWorld.seed) / %quality, (%y / MCWorld.seed) / %quality, 1 + MCWorld.seed);
	return (%noise + 1) / 2;
	//return 0.65;
	//return getrandom();
	//return %x / 25;
	return fancy_math(getword(%this.position,1),getword(%this.position,1),%x,%y);
	return 0.65;
}

function SimSet::getHumidity( %this, %x, %y )
{
	//return 0.65;
	%x = getWord(%this.position, 0) * 16 + %x;
	%y = getWord(%this.position, 1) * 16 + %y;

	if(!isObject($perlin))
		$perlin = new ScriptObject() {
			class = Perlin;
		};

	%quality = 512 + MCWorld.seed;
	%noise = $perlin.noise((%x / MCWorld.seed) / %quality, (%y / MCWorld.seed) / %quality, 2 + MCWorld.seed);
	return (%noise + 1) / 2;
	//return 0.65;
	//return getrandom();
	//return %y / 25;
	return fancy_math(getword(%this.position,1),getword(%this.position,1),%x,%y);
	return 0.65;
}
