package com.elytradev.correlated;

import com.elytradev.correlated.init.CConfig;
import com.elytradev.correlated.C28n;

public class EnergyHelper {

	public static double convertToPotential(double input, EnergyUnit unit) {
		switch (unit) {
			case DANKS:
			case TESLA:
				return (input / CConfig.teslaConversionRate);
			case ENERGY_UNITS:
				return (input / CConfig.euConversionRate);
			case FORGE_UNITS:
			case FORGE_ENERGY:
				return (input / CConfig.fuConversionRate);
			case JOULES:
				return (input / CConfig.jConversionRate); 
			case MINECRAFT_JOULES:
				return (input / CConfig.mjConversionRate);
			case REDSTONE_FLUX:
				return (input / CConfig.rfConversionRate);
			case POTENTIAL:
			default:
				return input;
			
		}
	}

	public static double convertFromPotential(double input, EnergyUnit unit) {
		switch (unit) {
			case DANKS:
			case TESLA:
				return (int)(input * CConfig.teslaConversionRate);
			case ENERGY_UNITS:
				return (int)(input * CConfig.euConversionRate);
			case FORGE_UNITS:
			case FORGE_ENERGY:
				return (int)(input * CConfig.fuConversionRate);
			case JOULES:
				return (int)(input * CConfig.jConversionRate); 
			case MINECRAFT_JOULES:
				return (int)(input * CConfig.mjConversionRate);
			case REDSTONE_FLUX:
				return (int)(input * CConfig.rfConversionRate);
			case POTENTIAL:
			default:
				return input;
			
		}
	}

	public static String formatPotentialUsage(double p) {
		return C28n.format("tooltip.correlated.energy_usage_tip", convertFromPotential(p, CConfig.preferredUnit), CConfig.preferredUnit.abbreviation);
	}

}

@@ -74,16 +74,49 @@
 Config;%0A
+%0Aimport java.text.NumberFormat;%0A%0A
 import c
@@ -175,16 +175,92 @@
 lper %7B%0A%0A
+%09private static final NumberFormat nf = NumberFormat.getNumberInstance();%0A%09%0A
 %09public 
@@ -976,37 +976,32 @@
 SLA:%0A%09%09%09%09return 
-(int)
 (input * CConfig
@@ -1048,37 +1048,32 @@
 ITS:%0A%09%09%09%09return 
-(int)
 (input * CConfig
@@ -1138,37 +1138,32 @@
 RGY:%0A%09%09%09%09return 
-(int)
 (input * CConfig
@@ -1201,37 +1201,32 @@
 LES:%0A%09%09%09%09return 
-(int)
 (input * CConfig
@@ -1274,37 +1274,32 @@
 LES:%0A%09%09%09%09return 
-(int)
 (input * CConfig
@@ -1356,13 +1356,8 @@
 urn 
-(int)
 (inp
@@ -1564,16 +1564,26 @@
 e_tip%22, 
+nf.format(
 convertF
@@ -1620,16 +1620,17 @@
 redUnit)
+)
 , CConfi

Fix double usage for Potential, add number formatter to elide ".0"