<commit_before><commit_msg>Adding main mod file - replacing vanilla water<commit_after>package com.vidaj.tfcwatercompatibility;


import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.HashMap;

import com.bioxx.tfc.Core.TFCFluid;

import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.Fluid;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;

@Mod(
		modid = "tfcwatercompatibility", 
		version = "1.0", 
		dependencies = "required-after:terrafirmacraft;"
				+ "before:Railcraft;"
				+ "before:RotaryCraft;"
				+ "before:ElectriCraft;"
				+ "before:Steamcraft;"
				+ "before:Forestry")
public class TFCWaterCompatibility {

	@EventHandler
	public void preInit(FMLPreInitializationEvent event) {
		replaceWaterInFluidRegistryMap();
		replaceWaterInFluidRegistryStaticField();
	}

	private void replaceWaterInFluidRegistryMap() {
		try {
			Field fluidsField = FluidRegistry.class.getDeclaredField("fluids");
			fluidsField.setAccessible(true);
			
			HashMap<String, Fluid> fluids = (HashMap<String, Fluid>) fluidsField.get(null);
			fluids.put("water", getFreshWater());
		} catch (Exception e) {
			throw new IllegalStateException("Cannot find fluids");
		}
	}

	private void replaceWaterInFluidRegistryStaticField() {
		try {
			Field field = FluidRegistry.class.getDeclaredField("WATER");
			field.setAccessible(true);
			
			setFieldFinalState(field, false);
			
			field.set(null, getFreshWater());
			
			setFieldFinalState(field, true);
		} catch (Exception e) {
			throw new IllegalStateException("Cannot inject custom water", e);
		}
	}
	
	private void setFieldFinalState(Field field, boolean isFinal) throws Exception
	{
		Field modifiersField = Field.class.getDeclaredField("modifiers");
		modifiersField.setAccessible(true);
		int modifiers = modifiersField.getInt(field);
		
		if (isFinal) 
		{
			modifiers &= Modifier.FINAL;
		} else 
		{
			modifiers &= ~Modifier.FINAL;
		}
		
		modifiersField.setInt(field, modifiers);
	}
	
	private Fluid getFreshWater() 
	{
		return TFCFluid.FRESHWATER;
	}
}
{'fraction_non_alphanumeric': 0.11388888888888889, 'fraction_numerical': 0.000925925925925926, 'mean_word_length': 4.809139784946237, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3438138', 'n_tokens_mistral': 804, 'n_tokens_neox': 703, 'n_words': 125}