aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com
diff options
context:
space:
mode:
authorbartimaeusnek <33183715+bartimaeusnek@users.noreply.github.com>2021-03-03 19:02:06 +0100
committerDreamMasterXXL <dream-master@gmx.net>2021-03-03 19:35:41 +0100
commit208e3044d9dbd39957e65d73bfc22b0c755affbf (patch)
treeaca67276e7d9963c1cd644e8b17212371beeaa18 /src/main/java/com
parent029ac0f5f4df8b18810642db139ddd385e484962 (diff)
downloadGT5-Unofficial-208e3044d9dbd39957e65d73bfc22b0c755affbf.tar.gz
GT5-Unofficial-208e3044d9dbd39957e65d73bfc22b0c755affbf.tar.bz2
GT5-Unofficial-208e3044d9dbd39957e65d73bfc22b0c755affbf.zip
Added TGregworks integration (#126)
(cherry picked from commit e6f4a1453afece3e68c750684a225be415b40584 [formerly 44aa12c5de2f8e1487e5f5d140668ba559d31ab1]) Former-commit-id: 08379a6fa1c8961e288f6da614ba536d4af7af21
Diffstat (limited to 'src/main/java/com')
-rw-r--r--src/main/java/com/github/bartimaeusnek/bartworks/API/LoaderReference.java2
-rw-r--r--src/main/java/com/github/bartimaeusnek/crossmod/BartWorksCrossmod.java4
-rw-r--r--src/main/java/com/github/bartimaeusnek/crossmod/tgregworks/MaterialsInjector.java145
3 files changed, 151 insertions, 0 deletions
diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/API/LoaderReference.java b/src/main/java/com/github/bartimaeusnek/bartworks/API/LoaderReference.java
index 16ec04b43e..4cc8ad45c1 100644
--- a/src/main/java/com/github/bartimaeusnek/bartworks/API/LoaderReference.java
+++ b/src/main/java/com/github/bartimaeusnek/bartworks/API/LoaderReference.java
@@ -56,6 +56,7 @@ public class LoaderReference {
public static boolean EnderIO;
public static boolean HardcoreEnderExpension;
public static boolean betterloadingscreen;
+ public static boolean TGregworks;
public static void init() {
Natura = Loader.isModLoaded("Natura");
@@ -84,5 +85,6 @@ public class LoaderReference {
EnderIO = Loader.isModLoaded("EnderIO");
HardcoreEnderExpension = Loader.isModLoaded("HardcoreEnderExpension");
betterloadingscreen = Loader.isModLoaded("betterloadingscreen");
+ TGregworks = Loader.isModLoaded("TGregworks");
}
}
diff --git a/src/main/java/com/github/bartimaeusnek/crossmod/BartWorksCrossmod.java b/src/main/java/com/github/bartimaeusnek/crossmod/BartWorksCrossmod.java
index c5376dbf3b..ee6f09d4ee 100644
--- a/src/main/java/com/github/bartimaeusnek/crossmod/BartWorksCrossmod.java
+++ b/src/main/java/com/github/bartimaeusnek/crossmod/BartWorksCrossmod.java
@@ -28,6 +28,7 @@ import com.github.bartimaeusnek.crossmod.GTpp.loader.RadioHatchCompat;
import com.github.bartimaeusnek.crossmod.galacticraft.GalacticraftProxy;
import com.github.bartimaeusnek.crossmod.tectech.TecTechResearchLoader;
import com.github.bartimaeusnek.crossmod.tectech.tileentites.multi.GT_Replacement.*;
+import com.github.bartimaeusnek.crossmod.tgregworks.MaterialsInjector;
import com.github.bartimaeusnek.crossmod.thaumcraft.CustomAspects;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.event.FMLInitializationEvent;
@@ -46,6 +47,7 @@ import java.io.StringReader;
dependencies = "required-after:IC2; "
+ "required-after:gregtech; "
+ "required-after:bartworks;"
+ + "before:TGregworks; "
+ "after:GalacticraftMars; "
+ "after:GalacticraftCore; "
+ "after:Micdoodlecore; "
@@ -87,6 +89,8 @@ public class BartWorksCrossmod {
new BW_TT_HeatExchanger(null, null);
}
+ if (LoaderReference.TGregworks)
+ MaterialsInjector.run();
}
@Mod.EventHandler
diff --git a/src/main/java/com/github/bartimaeusnek/crossmod/tgregworks/MaterialsInjector.java b/src/main/java/com/github/bartimaeusnek/crossmod/tgregworks/MaterialsInjector.java
new file mode 100644
index 0000000000..2234347045
--- /dev/null
+++ b/src/main/java/com/github/bartimaeusnek/crossmod/tgregworks/MaterialsInjector.java
@@ -0,0 +1,145 @@
+package com.github.bartimaeusnek.crossmod.tgregworks;
+
+import com.github.bartimaeusnek.bartworks.MainMod;
+import com.github.bartimaeusnek.bartworks.system.material.Werkstoff;
+import cpw.mods.fml.common.FMLCommonHandler;
+import gregtech.api.enums.Materials;
+import gregtech.api.enums.OrePrefixes;
+import net.minecraftforge.common.config.Property;
+import tconstruct.library.TConstructRegistry;
+import vexatos.tgregworks.TGregworks;
+import vexatos.tgregworks.integration.TGregRegistry;
+import vexatos.tgregworks.item.ItemTGregPart;
+import vexatos.tgregworks.reference.Config;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.HashMap;
+
+@SuppressWarnings("unchecked")
+public class MaterialsInjector {
+ private static HashMap<Materials, Property> configProps;
+ private static ArrayList<Integer> configIDs;
+ private static Method getGlobalMultiplierMethod;
+ private static Method getGlobalMultiplierMethodTwoArguments;
+ private static Method getMultiplierMethod;
+ private static Method getMaterialIDMethod;
+ private static Method getReinforcedLevelMethod;
+ private static Method getStoneboundLevelMethod;
+
+ static {
+ try {
+ getFields();
+ getMethodes();
+ } catch (
+ IllegalArgumentException
+ | IllegalAccessException
+ | NoSuchFieldException
+ | NoSuchMethodException
+ | SecurityException
+ e) {
+ MainMod.LOGGER.catching(e);
+ FMLCommonHandler.instance().exitJava(1, true);
+ }
+ }
+
+ private static void getFields() throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException {
+ Field configPropsField = TGregRegistry.class.getDeclaredField("configProps");
+ configPropsField.setAccessible(true);
+ configProps = (HashMap<Materials, Property>) configPropsField.get(TGregworks.registry);
+
+ Field configIDsField = TGregRegistry.class.getDeclaredField("configIDs");
+ configIDsField.setAccessible(true);
+ configIDs = (ArrayList<Integer>) configIDsField.get(TGregworks.registry);
+ }
+
+ private static void getMethodes() throws NoSuchMethodException, SecurityException {
+ getGlobalMultiplierMethod = TGregRegistry.class.getDeclaredMethod("getGlobalMultiplier", String.class);
+ getGlobalMultiplierMethod.setAccessible(true);
+
+ getGlobalMultiplierMethodTwoArguments = TGregRegistry.class.getDeclaredMethod("getGlobalMultiplier", String.class, double.class);
+ getGlobalMultiplierMethodTwoArguments.setAccessible(true);
+
+ getMultiplierMethod = TGregRegistry.class.getDeclaredMethod("getMultiplier", Materials.class, String.class);
+ getMultiplierMethod.setAccessible(true);
+
+ getMaterialIDMethod = TGregRegistry.class.getDeclaredMethod("getMaterialID", Materials.class);
+ getMaterialIDMethod.setAccessible(true);
+
+ getReinforcedLevelMethod = TGregRegistry.class.getDeclaredMethod("getReinforcedLevel", Materials.class);
+ getReinforcedLevelMethod.setAccessible(true);
+
+ getStoneboundLevelMethod = TGregRegistry.class.getDeclaredMethod("getStoneboundLevel", Materials.class);
+ getStoneboundLevelMethod.setAccessible(true);
+ }
+
+ public static void run() {
+ MainMod.LOGGER.info("Registering TGregworks - BartWorks tool parts.");
+ Werkstoff.werkstoffHashSet.stream()
+ .filter(x -> x.hasItemType(OrePrefixes.gem) || x.hasItemType(OrePrefixes.plate))
+ .map(Werkstoff::getBridgeMaterial)
+ .filter(x -> x.mMetaItemSubID == -1)
+ .filter(x -> x.mDurability != 0)
+ .forEach(m -> {
+ setConfigProps(m);
+ registerParts(m);
+ });
+
+ configProps.clear();
+ configIDs.clear();
+
+ ItemTGregPart.toolMaterialNames = TGregworks.registry.toolMaterialNames;
+ }
+
+ private static void registerParts(Materials m) {
+ try {
+ TGregworks.registry.toolMaterialNames.add(m.mDefaultLocalName);
+ int matID = (int) getMaterialIDMethod.invoke(TGregworks.registry, m);
+
+ addToolMaterial(matID, m);
+ addBowMaterial(matID, m);
+ addArrowMaterial(matID, m);
+
+ TGregworks.registry.matIDs.put(m, matID);
+ TGregworks.registry.materialIDMap.put(matID, m);
+ } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
+ MainMod.LOGGER.catching(e);
+ FMLCommonHandler.instance().exitJava(1, true);
+ }
+ }
+
+ private static void setConfigProps(Materials m){
+ if (TGregworks.config.get(Config.Category.Enable, m.mName, true).getBoolean(true)) {
+ TGregworks.registry.toolMaterials.add(m);
+ Property configProp = TGregworks.config.get(Config.onMaterial(Config.MaterialID), m.mName, 0, null, 0, 100000);
+ configProps.put(m, configProp);
+ configIDs.add(configProp.getInt());
+ }
+ }
+
+ private static void addToolMaterial(int matID, Materials m)
+ throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
+ TConstructRegistry.addToolMaterial(matID, m.mName, m.mLocalizedName, m.mToolQuality,
+ (int) (m.mDurability * (float) getGlobalMultiplierMethod.invoke(TGregworks.registry, Config.Durability) * (float) getMultiplierMethod.invoke(TGregworks.registry, m, Config.Durability)), // Durability
+ (int) (m.mToolSpeed * 100F * (float) getGlobalMultiplierMethod.invoke(TGregworks.registry, Config.MiningSpeed) * (float) getMultiplierMethod.invoke(TGregworks.registry, m, Config.MiningSpeed)), // Mining speed
+ (int) (m.mToolQuality * (float) getGlobalMultiplierMethod.invoke(TGregworks.registry, Config.Attack) * (float) getMultiplierMethod.invoke(TGregworks.registry, m, Config.Attack)), // Attack
+ (m.mToolQuality - 0.5F) * (float) getGlobalMultiplierMethod.invoke(TGregworks.registry, Config.HandleModifier) * (float) getMultiplierMethod.invoke(TGregworks.registry, m, Config.HandleModifier), // Handle Modifier
+ (int) getReinforcedLevelMethod.invoke(TGregworks.registry, m), (float) getStoneboundLevelMethod.invoke(TGregworks.registry, m), "", (m.getRGBA()[0] << 16) | (m.getRGBA()[1] << 8) | (m.getRGBA()[2]));
+ }
+
+ private static void addBowMaterial(int matID, Materials m)
+ throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
+ TConstructRegistry.addBowMaterial(matID,
+ (int) ((float) m.mToolQuality * 10F * (float) getGlobalMultiplierMethod.invoke(TGregworks.registry, Config.BowDrawSpeed) * (float) getMultiplierMethod.invoke(TGregworks.registry, m, Config.BowDrawSpeed)),
+ (((float) m.mToolQuality) - 0.5F) * (float) getGlobalMultiplierMethod.invoke(TGregworks.registry, Config.BowFlightSpeed) * (float) getMultiplierMethod.invoke(TGregworks.registry, m, Config.BowFlightSpeed));
+ }
+
+ private static void addArrowMaterial(int matID, Materials m)
+ throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
+ TConstructRegistry.addArrowMaterial(matID,
+ (float) ((((double) m.getMass()) / 10F) * (float) getGlobalMultiplierMethod.invoke(TGregworks.registry, Config.ArrowMass) * (float) getMultiplierMethod.invoke(TGregworks.registry, m, Config.ArrowMass)),
+ (float) getGlobalMultiplierMethodTwoArguments.invoke(TGregworks.registry, Config.ArrowBreakChance, 0.9) * (float) getMultiplierMethod.invoke(TGregworks.registry, m, Config.ArrowBreakChance));
+ }
+}