forked from Electrical-Age/ElectricalAge
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
35 changed files
with
898 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package mods.eln.api; | ||
|
||
import cpw.mods.fml.common.FMLLog; | ||
import net.minecraft.item.ItemStack; | ||
|
||
import java.lang.reflect.Field; | ||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
import java.util.Arrays; | ||
import java.util.Map; | ||
|
||
public class Fuel { | ||
/** | ||
* Gives the energy equivalent of a fuel in J. Returns 0 if the item cannot be burned. | ||
* @param fuel The ItemStack of fuel to determine the energy equivalent of. | ||
* @return fuel's energy equivalent in J. | ||
*/ | ||
public static double getEnergyEquivalent(ItemStack fuel){ | ||
try { | ||
Class<?> c = Class.forName("mods.eln.misc.Utils"); | ||
Method energy = c.getDeclaredMethod("getItemEnergie", ItemStack.class); | ||
return Double.valueOf(energy.invoke(c, fuel).toString()); | ||
} | ||
catch(ClassNotFoundException e){ | ||
FMLLog.warning("ELN isn't loaded. Someone just tried to use its API."); | ||
e.printStackTrace(); | ||
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { | ||
e.printStackTrace(); | ||
} | ||
return 0; | ||
} | ||
|
||
/** | ||
* Add a fuel to the gasoline fuels list (turbine and fuel generator). | ||
* @param name The name of the fuel in the fuel registry | ||
* @param heatingValue The energy for 1L of the fuel | ||
* @return true if the addition succeeded, false otherwise. | ||
*/ | ||
public static boolean addGasolineFuel(String name, Double heatingValue) { | ||
try { | ||
Class<?> FuelRegistry = Class.forName("mods.eln.fluid.FuelRegistry"); | ||
Field gasolineList = FuelRegistry.getDeclaredField("gasolineList"); | ||
Utilities.makeModifiable(gasolineList); | ||
String[] gasolineArray = ((String[]) gasolineList.get(null)); | ||
String[] newArray = Arrays.copyOf(gasolineArray, gasolineArray.length + 1); | ||
newArray[newArray.length - 1] = name; | ||
gasolineList.set(null, newArray); | ||
|
||
Field gasolineFuels = FuelRegistry.getDeclaredField("gasolineFuels"); | ||
Utilities.makeModifiable(gasolineFuels); | ||
Map<String, Double> gasolineMap = (Map<String, Double>) gasolineFuels.get(null); | ||
gasolineMap.put(name, heatingValue); | ||
return true; | ||
} catch (ClassNotFoundException | NoSuchFieldException | IllegalAccessException e) { | ||
e.printStackTrace(); | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* Add a fuel to the gas fuels list (gas turbine). | ||
* @param name The name of the fuel in the fuel registry | ||
* @param heatingValue The energy of the fuel in MJ per cubic meter | ||
* @return true if the addition succeeded, false otherwise. | ||
*/ | ||
public static boolean addGasFuel(String name, Double heatingValue) { | ||
try { | ||
Class<?> FuelRegistry = Class.forName("mods.eln.fluid.FuelRegistry"); | ||
Field gasList = FuelRegistry.getDeclaredField("gasList"); | ||
Utilities.makeModifiable(gasList); | ||
String[] gasArray = (String[]) gasList.get(null); | ||
String[] newList = Arrays.copyOf(gasArray, gasArray.length + 1); | ||
newList[newList.length - 1] = name; | ||
gasList.set(null, newList); | ||
|
||
Field gasFuels = FuelRegistry.getDeclaredField("gasFuels"); | ||
Utilities.makeModifiable(gasFuels); | ||
Map<String, Double> gasMap = (Map<String, Double>) gasFuels.get(null); | ||
gasMap.put(name, heatingValue); | ||
gasFuels.set(null, gasMap); | ||
return true; | ||
} catch (ClassNotFoundException | NoSuchFieldException | IllegalAccessException e) { | ||
e.printStackTrace(); | ||
} | ||
return false; | ||
} | ||
|
||
|
||
/** | ||
* Add a fuel to the diesels list. | ||
* @param name The name of the fuel in the fuel registry | ||
* @param heatingValue Energy for 1L of the fuel | ||
* @return true if the addition succeeded, false otherwise. | ||
*/ | ||
public static boolean addDieselFuel(String name, Double heatingValue) { | ||
try { | ||
Class<?> FuelRegistry = Class.forName("mods.eln.fluid.FuelRegistry"); | ||
Field dieselFuels = FuelRegistry.getDeclaredField("dieselFuels"); | ||
Utilities.makeModifiable(dieselFuels); | ||
Map<String, Double> dieselMap = (Map<String, Double>) dieselFuels.get(null); | ||
dieselMap.put(name, heatingValue); | ||
dieselFuels.set(null, dieselMap); | ||
|
||
Field dieselList = FuelRegistry.getDeclaredField("dieselList"); | ||
Utilities.makeModifiable(dieselList); | ||
String[] dieselArray = (String[]) dieselList.get(null); | ||
String[] newList = Arrays.copyOf(dieselArray, dieselArray.length + 1); | ||
newList[newList.length - 1] = name; | ||
dieselList.set(null, newList); | ||
return true; | ||
} catch (ClassNotFoundException | NoSuchFieldException | IllegalAccessException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package mods.eln.api; | ||
|
||
import java.lang.reflect.Field; | ||
|
||
/** | ||
* Created by Gregory Maddra on 2016-11-16. | ||
*/ | ||
public class Misc { | ||
|
||
public static Object getRecipeList(String list){ | ||
try { | ||
Class<?> Eln = getEln(); | ||
Object instanceObject = getElnInstance(Eln); | ||
Field recipeList = Eln.getDeclaredField(list); | ||
recipeList.setAccessible(true); | ||
return Eln != null ? recipeList.get(instanceObject) : null; | ||
} catch (NoSuchFieldException | IllegalAccessException e) { | ||
e.printStackTrace(); | ||
} | ||
return null; | ||
} | ||
|
||
public static Double getElectricalFurnaceProcessEnergyNeededPerSmelt(){ | ||
try { | ||
Class<?> ElectricalFurnaceProcess = Class.forName("mods.eln.transparentnode.electricalfurnace.ElectricalFurnaceProcess"); | ||
return ElectricalFurnaceProcess.getDeclaredField("energyNeededPerSmelt").getDouble(null); | ||
} catch (ClassNotFoundException | NoSuchFieldException | IllegalAccessException e) { | ||
e.printStackTrace(); | ||
} | ||
return 0D; | ||
} | ||
|
||
public static Class<?> getEln(){ | ||
try { | ||
return Class.forName("mods.eln.Eln"); | ||
} catch (ClassNotFoundException e) { | ||
return null; | ||
} | ||
} | ||
|
||
public static Object getElnInstance(Class<?> Eln){ | ||
try { | ||
return Eln.getDeclaredField("instance").get(null); | ||
} catch (NoSuchFieldException | IllegalAccessException e) { | ||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package mods.eln.api; | ||
|
||
import net.minecraft.item.ItemStack; | ||
import net.minecraftforge.oredict.OreDictionary; | ||
|
||
import java.lang.reflect.Field; | ||
import java.lang.reflect.Modifier; | ||
|
||
/** | ||
* Utilities | ||
* @author Gregory Maddra | ||
* 2016-11-18 | ||
*/ | ||
public class Utilities { | ||
|
||
public static void makeModifiable(Field field){ | ||
field.setAccessible(true); | ||
int modifiers = field.getModifiers(); | ||
try { | ||
Field modifiersField = field.getClass().getDeclaredField("modifiers"); | ||
modifiers = modifiers & ~Modifier.FINAL; | ||
modifiersField.setAccessible(true); | ||
modifiersField.setInt(field, modifiers); | ||
} catch (NoSuchFieldException | IllegalAccessException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
} | ||
|
||
public static boolean areSame(ItemStack stack, ItemStack output) { | ||
try { | ||
if (stack.getItem() == output.getItem() && stack.getItemDamage() == output.getItemDamage()) return true; | ||
int[] stackIds = OreDictionary.getOreIDs(stack); | ||
int[] outputIds = OreDictionary.getOreIDs(output); | ||
// System.out.println(Arrays.toString(stackIds) + " " + Arrays.toString(outputIds)); | ||
for (int i : outputIds) { | ||
for (int j : stackIds) { | ||
if (i == j) return true; | ||
} | ||
} | ||
} catch (Exception ignored) { | ||
} | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@API(owner = "Eln", apiVersion = "1.0", provides="ElectricalAge|API") | ||
package mods.eln.api; | ||
import cpw.mods.fml.common.API; |
Oops, something went wrong.