Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
bloxgate committed Nov 28, 2022
1 parent 8a4ba7a commit 089cead
Show file tree
Hide file tree
Showing 35 changed files with 898 additions and 96 deletions.
77 changes: 25 additions & 52 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
buildscript {
ext.prometheus_version = "0.1.0"
repositories {
mavenCentral()
maven {
name = "forge"
url = "https://files.minecraftforge.net/maven"
url = "https://maven.minecraftforge.net"
}
maven {
name = "GTNH Maven"
url = "http://jenkins.usrv.eu:8081/nexus/content/groups/public/"
}
maven {
name = "sonatype"
Expand All @@ -12,9 +17,8 @@ buildscript {
jcenter()
}
dependencies {
classpath 'net.minecraftforge.gradle:ForgeGradle:1.2-SNAPSHOT'
classpath 'net.minecraftforge.gradle:ForgeGradle:1.2.11'
classpath 'de.undercouch:gradle-download-task:1.2'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.6'
}
}

Expand All @@ -26,7 +30,6 @@ plugins {
apply plugin: 'forge'
apply plugin: 'de.undercouch.download'
apply plugin: 'java'
apply plugin: 'com.jfrog.bintray'
apply plugin: 'maven-publish'

apply from: 'gradle.properties'
Expand Down Expand Up @@ -65,6 +68,9 @@ minecraft {
replace "@BUILD_DATE@", BUILD_DATE
replace "@JAVA_VERSION@", JAVA_VERSION
replace "@GIT_REVISION@", GIT_REVISION

replaceIn "Eln.java"
replace "@VERSION@", project.version
}

configurations {
Expand All @@ -84,12 +90,26 @@ repositories {
name = "mobiusstrip"
url = "http://default.mobiusstrip.eu/maven/"
}
maven {
name = "GTNH Maven"
url = "https://jenkins.usrv.eu:8081/nexus/content/groups/public/"
}
maven {
name 'Overmind forge mirror'
url 'https://gregtech.overminddl1.com/'
}
}

dependencies {
external files("libs/commons-math3-3.3.jar")
// Kotlin
shade "org.jetbrains.kotlin:kotlin-stdlib-jdk8"

// Used for MNA matrix decompositions
external files("libs/commons-math3-3.3.jar")

// Waila Support
compile "mcp.mobius.waila:Waila:1.5.11-RC2-NONEI_1.7.10:dev"
compile files("libs/CraftTweaker-1.7.10-3.2.9-dev.jar")
compile "com.fazecast:jSerialComm:2.6.2"
}

Expand Down Expand Up @@ -250,51 +270,4 @@ task updateMasterLanguageFile(type: JavaExec, dependsOn: 'classes') {
// Please be pedantic about making further edits to the language file.
// jar.dependsOn(updateMasterLanguageFile)

publishing {
publications {
mod(MavenPublication) {
from components.java
groupId GROUP
artifactId ARCHIVE_NAME
version project.version
}
}
}

bintrayUpload {}.dependsOn(build)

bintray {
user = System.getenv('BINTRAY_USER')
key = System.getenv('BINTRAY_KEY')
publications = ['mod']
pkg {
repo = 'eln'
name = 'ElectricalAge'
userOrg = 'electrical-age'
licenses = ['LGPL V3.0', 'CC BY-NC-SA 3.0']
vcsUrl = 'https://github.com/Electrical-Age/ElectricalAge.git'
version {
name = project.version
}
}
}

curseforge {
// Put this in ~/.gradle/gradle.properties, absolutely not in the repository.
apiKey = project.hasProperty('curseForgeApiKey') ? project.curseForgeApiKey : ""
project {
id = '253045'
changelogType = 'markdown'
changelog = file('changelog.md')
releaseType = 'release'
addGameVersion "1.7.10"
mainArtifact(jar) {
displayName = "Electrical Age $project.version"
}
// addArtifact(sourcesJar) {
// displayName = "Electrical Age $project.version Sources"
// }
}
}

idea { module { inheritOutputDirs = true } }
Binary file added libs/CraftTweaker-1.7.10-3.2.9-dev.jar
Binary file not shown.
13 changes: 9 additions & 4 deletions src/main/java/mods/eln/Eln.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
import cpw.mods.fml.common.registry.EntityRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import mods.eln.api.Utilities;
import mods.eln.api.recipe.Recipe;
import mods.eln.api.recipe.RecipesList;
import mods.eln.block.ArcClayBlock;
import mods.eln.block.ArcClayItemBlock;
import mods.eln.block.ArcMetalBlock;
Expand All @@ -32,6 +35,7 @@
import mods.eln.gridnode.electricalpole.Kind;
import mods.eln.gridnode.transformer.GridTransformerDescriptor;
import mods.eln.i18n.I18N;
import mods.eln.integration.minetweaker.MinetweakerIntegration;
import mods.eln.item.*;
import mods.eln.item.electricalinterface.ItemEnergyInventoryProcess;
import mods.eln.item.electricalitem.*;
Expand Down Expand Up @@ -61,9 +65,6 @@
import mods.eln.sim.ThermalLoadInitializerByPowerDrop;
import mods.eln.sim.mna.component.Resistor;
import mods.eln.sim.nbt.NbtElectricalLoad;
import mods.eln.simplenode.DeviceProbeBlock;
import mods.eln.simplenode.DeviceProbeEntity;
import mods.eln.simplenode.DeviceProbeNode;
import mods.eln.simplenode.computerprobe.ComputerProbeBlock;
import mods.eln.simplenode.computerprobe.ComputerProbeEntity;
import mods.eln.simplenode.computerprobe.ComputerProbeNode;
Expand Down Expand Up @@ -1103,7 +1104,7 @@ private boolean recipeExists(ItemStack stack) {
IRecipe r = (IRecipe) o;
if (r.getRecipeOutput() == null)
continue;
if (Utils.areSame(stack, r.getRecipeOutput()))
if (Utilities.areSame(stack, r.getRecipeOutput()))
return true;
}
}
Expand All @@ -1119,6 +1120,10 @@ public void postInit(FMLPostInitializationEvent event) {

serverEventListener = new ServerEventListener();

if (Loader.isModLoaded("MineTweaker3")) {
MinetweakerIntegration.INSTANCE.initialize();
}

}

/*
Expand Down
118 changes: 118 additions & 0 deletions src/main/java/mods/eln/api/Fuel.java
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;
}

}
48 changes: 48 additions & 0 deletions src/main/java/mods/eln/api/Misc.java
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;
}
}
}
45 changes: 45 additions & 0 deletions src/main/java/mods/eln/api/Utilities.java
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;
}
}
3 changes: 3 additions & 0 deletions src/main/java/mods/eln/api/package-info.java
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;
Loading

0 comments on commit 089cead

Please sign in to comment.