package org.pfaa.chemica.client.fluid;

import net.minecraft.block.Block;
import net.minecraftforge.client.event.EntityViewRenderEvent.FogColors;
import net.minecraftforge.fluids.BlockFluidBase;

import org.pfaa.chemica.block.IndustrialFluidBlock;

import cpw.mods.fml.common.eventhandler.SubscribeEvent;

public class FogHandler {

	public static FogHandler INSTANCE = new FogHandler();

	private FogHandler() {
	}


	@SubscribeEvent
	public void onFogColors(FogColors event) {
		int x = (int)event.entity.posX;
		int y = (int)event.entity.posY;
		int z = (int)event.entity.posZ;
		Block block = event.entity.worldObj.getBlock(x, y, z);
		if (block instanceof IndustrialFluidBlock) {
			int color = ((BlockFluidBase)block).getFluid().getColor();
			event.red = (color >> 16 & 255) / 255.0F;
			event.green = (color >> 8 & 255) / 255.0F;
	        event.blue = (color & 255) / 255.0F;
		}
	}
}

@@ -91,162 +91,488 @@
 raft
-forge.client.event.EntityViewRenderEvent.FogColors;%0Aimport net.minecraftforge.fluids.BlockFluidBase;%0A%0Aimport org.pfaa.chemica.block.IndustrialFluidBlock;%0A
+.enchantment.EnchantmentHelper;%0Aimport net.minecraft.potion.Potion;%0Aimport net.minecraftforge.client.event.EntityViewRenderEvent.FogColors;%0Aimport net.minecraftforge.client.event.EntityViewRenderEvent.FogDensity;%0Aimport net.minecraftforge.fluids.BlockFluidBase;%0Aimport net.minecraftforge.fluids.Fluid;%0A%0Aimport org.lwjgl.opengl.GL11;%0Aimport org.pfaa.chemica.block.IndustrialFluidBlock;%0A%0Aimport codechicken.lib.math.MathHelper;%0A%0Aimport cpw.mods.fml.common.eventhandler.Event.Result;
 %0Aimp
@@ -1209,11 +1209,722 @@
 ;%0A%09%09%7D%0A%09%7D
+%0A%0A%09@SubscribeEvent%0A%09public void onFogDensity(FogDensity event) %7B%0A%09%09int x = (int)MathHelper.floor_double(event.entity.posX);%0A%09%09int y = (int)MathHelper.floor_double(event.entity.posY);%0A%09%09int z = (int)MathHelper.floor_double(event.entity.posZ);%0A%09%09Block block = event.entity.worldObj.getBlock(x, y, z);%0A%09%09if (block instanceof IndustrialFluidBlock) %7B%0A%09%09%09Fluid fluid = ((BlockFluidBase)block).getFluid();%0A%09%09%09GL11.glFogi(GL11.GL_FOG_MODE, GL11.GL_EXP);%0A%09%09%09if (!fluid.isGaseous() && event.entity.isPotionActive(Potion.waterBreathing))%0A%09%09%09%7B%0A%09%09%09%09event.density = 0.05F;%0A%09%09%09%7D%0A%09%09%09else%0A%09%09%09%7B%0A%09%09%09%09event.density = 0.1F - (float)EnchantmentHelper.getRespiration(event.entity) * 0.03F;%0A%09%09%09%7D%0A%09%09%09event.setCanceled(true);%0A%09%09%7D%0A%09%7D%0A    
 %0A%7D%0A

fix fog handling; overrides density (and mode) now