aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com
diff options
context:
space:
mode:
authorRaven Szewczyk <git@eigenraven.me>2024-07-27 07:12:04 +0100
committerGitHub <noreply@github.com>2024-07-27 13:12:04 +0700
commitc7b38c23c5b34a324256966f0a9335694fe8d63b (patch)
tree92aab6471745549a79c9f84f38c3076d9275ac4f /src/main/java/com
parentc55db9d91fa0a065d7565107a1eca679698eab04 (diff)
downloadGT5-Unofficial-c7b38c23c5b34a324256966f0a9335694fe8d63b.tar.gz
GT5-Unofficial-c7b38c23c5b34a324256966f0a9335694fe8d63b.tar.bz2
GT5-Unofficial-c7b38c23c5b34a324256966f0a9335694fe8d63b.zip
Optimize load time (#2774)
* Load time optimization: replace recipe reflection with mixin accessor * Save an inner loop allocation in StaticRecipeChangeLoaders * Move Bauble event handler from individual items to GT++ proxy * Update mobs info with more optimizations
Diffstat (limited to 'src/main/java/com')
-rw-r--r--src/main/java/com/elisis/gtnhlanth/loader/RecipeLoader.java137
-rw-r--r--src/main/java/com/github/bartimaeusnek/bartworks/common/loaders/StaticRecipeChangeLoaders.java3
-rw-r--r--src/main/java/com/github/bartimaeusnek/bartworks/system/material/GT_Enhancement/PlatinumSludgeOverHaul.java86
3 files changed, 29 insertions, 197 deletions
diff --git a/src/main/java/com/elisis/gtnhlanth/loader/RecipeLoader.java b/src/main/java/com/elisis/gtnhlanth/loader/RecipeLoader.java
index 14194af8f7..b3dea32ca7 100644
--- a/src/main/java/com/elisis/gtnhlanth/loader/RecipeLoader.java
+++ b/src/main/java/com/elisis/gtnhlanth/loader/RecipeLoader.java
@@ -118,26 +118,15 @@ import static gtPlusPlus.api.recipe.GTPPRecipeMaps.chemicalDehydratorRecipes;
import static gtPlusPlus.api.recipe.GTPPRecipeMaps.simpleWasherRecipes;
import static gtPlusPlus.api.recipe.GTPPRecipeMaps.vacuumFurnaceRecipes;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Field;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
import java.util.HashSet;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
-import net.minecraft.item.crafting.ShapedRecipes;
-import net.minecraft.item.crafting.ShapelessRecipes;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.oredict.OreDictionary;
-import net.minecraftforge.oredict.ShapedOreRecipe;
-import net.minecraftforge.oredict.ShapelessOreRecipe;
-
-import org.apache.commons.lang3.reflect.FieldUtils;
import com.elisis.gtnhlanth.Tags;
import com.elisis.gtnhlanth.common.item.MaskList;
@@ -156,6 +145,7 @@ import gregtech.api.enums.ItemList;
import gregtech.api.enums.Materials;
import gregtech.api.enums.OrePrefixes;
import gregtech.api.enums.TierEU;
+import gregtech.api.interfaces.IRecipeMutableAccess;
import gregtech.api.util.GT_Log;
import gregtech.api.util.GT_ModHandler;
import gregtech.api.util.GT_OreDictUnificator;
@@ -4280,133 +4270,26 @@ public class RecipeLoader {
GT_Log.out.print("Crafting Table done!\n");
}
- // below are taken from GoodGenerator
-
- // I don't understand. . .
- // I use and copy some private methods in Bartworks because his system runs well.
- // Bartworks is under MIT License
- /*
- * Copyright (c) 2018-2020 bartimaeusnek Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"), to deal in the Software without
- * restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute,
- * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
- * subject to the following conditions: The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
- * KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
- * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
- * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
- * IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
public static void replaceInCraftTable(Object obj) {
-
- Constructor<?> cs = null;
- PlatinumSludgeOverHaul BartObj = null;
- try {
- cs = PlatinumSludgeOverHaul.class.getDeclaredConstructor();
- cs.setAccessible(true);
- } catch (NoSuchMethodException e) {
- e.printStackTrace();
- }
-
- if (cs == null) return;
-
- try {
- BartObj = (PlatinumSludgeOverHaul) cs.newInstance();
- } catch (IllegalAccessException | InstantiationException | InvocationTargetException e) {
- e.printStackTrace();
- }
-
- Method recipeCheck = null;
-
- try {
- recipeCheck = PlatinumSludgeOverHaul.class.getDeclaredMethod("checkRecipe", Object.class, Materials.class);
- recipeCheck.setAccessible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- String inputName = "output";
- String inputItemName = "input";
- if (!(obj instanceof ShapedOreRecipe || obj instanceof ShapelessOreRecipe)) {
- if (obj instanceof ShapedRecipes || (obj instanceof ShapelessRecipes)) {
- inputName = "recipeOutput";
- inputItemName = "recipeItems";
- }
- }
IRecipe recipe = (IRecipe) obj;
ItemStack result = recipe.getRecipeOutput();
-
- Field out = FieldUtils.getDeclaredField(recipe.getClass(), inputName, true);
- if (out == null) out = FieldUtils.getField(recipe.getClass(), inputName, true);
-
- Field in = FieldUtils.getDeclaredField(recipe.getClass(), inputItemName, true);
- if (in == null) in = FieldUtils.getField(recipe.getClass(), inputItemName, true);
- if (in == null) return;
-
- // this part here is NOT MIT LICENSED BUT LICSENSED UNDER THE Apache License, Version 2.0!
- try {
- if (Modifier.isFinal(in.getModifiers())) {
- // Do all JREs implement Field with a private ivar called "modifiers"?
- Field modifiersField = Field.class.getDeclaredField("modifiers");
- boolean doForceAccess = !modifiersField.isAccessible();
- if (doForceAccess) {
- modifiersField.setAccessible(true);
- }
- try {
- modifiersField.setInt(in, in.getModifiers() & ~Modifier.FINAL);
- } finally {
- if (doForceAccess) {
- modifiersField.setAccessible(false);
- }
- }
- }
- } catch (NoSuchFieldException ignored) {
- // The field class contains always a modifiers field
- } catch (IllegalAccessException ignored) {
- // The modifiers field is made accessible
- }
- // END OF APACHE COMMONS COLLECTION COPY
-
- Object input;
- try {
- input = in.get(obj);
- } catch (IllegalAccessException e) {
- e.printStackTrace();
+ if (!(recipe instanceof IRecipeMutableAccess mutableRecipe)) {
return;
}
- if (out == null || recipeCheck == null) return;
+ Object input = mutableRecipe.gt5u$getRecipeInputs();
if (GT_Utility.areStacksEqual(result, Materials.Cerium.getDust(1), true)) {
-
- recipeCheck.setAccessible(true);
- boolean isOk = true;
-
- try {
- isOk = (boolean) recipeCheck.invoke(BartObj, input, Materials.Cerium);
- } catch (InvocationTargetException | IllegalAccessException ignored) {}
-
- if (isOk) return;
- try {
- out.set(recipe, WerkstoffMaterialPool.CeriumRichMixture.get(OrePrefixes.dust, 2));
- } catch (IllegalAccessException e) {
- e.printStackTrace();
+ if (PlatinumSludgeOverHaul.checkRecipe(input, Materials.Cerium)) {
+ return;
}
+ mutableRecipe.gt5u$setRecipeOutputItem(WerkstoffMaterialPool.CeriumRichMixture.get(OrePrefixes.dust, 2));
} else if (GT_Utility.areStacksEqual(result, Materials.Samarium.getDust(1), true)) {
-
- recipeCheck.setAccessible(true);
- boolean isOk = true;
-
- try {
- isOk = (boolean) recipeCheck.invoke(BartObj, input, Materials.Samarium);
- } catch (InvocationTargetException | IllegalAccessException ignored) {}
-
- if (isOk) return;
- try {
- out.set(recipe, WerkstoffMaterialPool.SamariumOreConcentrate.get(OrePrefixes.dust, 2));
- } catch (IllegalAccessException e) {
- e.printStackTrace();
+ if (PlatinumSludgeOverHaul.checkRecipe(input, Materials.Samarium)) {
+ return;
}
+ mutableRecipe
+ .gt5u$setRecipeOutputItem(WerkstoffMaterialPool.SamariumOreConcentrate.get(OrePrefixes.dust, 2));
}
}
diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/common/loaders/StaticRecipeChangeLoaders.java b/src/main/java/com/github/bartimaeusnek/bartworks/common/loaders/StaticRecipeChangeLoaders.java
index 91c077ccad..4271b43303 100644
--- a/src/main/java/com/github/bartimaeusnek/bartworks/common/loaders/StaticRecipeChangeLoaders.java
+++ b/src/main/java/com/github/bartimaeusnek/bartworks/common/loaders/StaticRecipeChangeLoaders.java
@@ -123,6 +123,7 @@ public class StaticRecipeChangeLoaders {
}
public static void unificationRecipeEnforcer() {
+ List<GT_Recipe> toRemove = new ArrayList<>();
for (Werkstoff werkstoff : Werkstoff.werkstoffHashSet) {
StaticRecipeChangeLoaders.runMaterialLinker(werkstoff);
if (werkstoff.getGenerationFeatures().enforceUnification) {
@@ -142,7 +143,7 @@ public class StaticRecipeChangeLoaders {
|| replacement == null
|| replacement.getItem() == null) continue;
for (RecipeMap<?> map : RecipeMap.ALL_RECIPE_MAPS.values()) {
- List<GT_Recipe> toRemove = new ArrayList<>();
+ toRemove.clear();
nextRecipe: for (GT_Recipe recipe : map.getAllRecipes()) {
boolean removal = map.equals(RecipeMaps.fluidExtractionRecipes)
|| map.equals(RecipeMaps.fluidSolidifierRecipes);
diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/system/material/GT_Enhancement/PlatinumSludgeOverHaul.java b/src/main/java/com/github/bartimaeusnek/bartworks/system/material/GT_Enhancement/PlatinumSludgeOverHaul.java
index 555d01684f..32aac70352 100644
--- a/src/main/java/com/github/bartimaeusnek/bartworks/system/material/GT_Enhancement/PlatinumSludgeOverHaul.java
+++ b/src/main/java/com/github/bartimaeusnek/bartworks/system/material/GT_Enhancement/PlatinumSludgeOverHaul.java
@@ -80,7 +80,6 @@ import static gregtech.api.util.GT_RecipeBuilder.TICKS;
import static gregtech.api.util.GT_RecipeConstants.COIL_HEAT;
import static gregtech.api.util.GT_RecipeConstants.UniversalChemical;
-import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
@@ -93,18 +92,11 @@ import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.item.crafting.IRecipe;
-import net.minecraft.item.crafting.ShapedRecipes;
-import net.minecraft.item.crafting.ShapelessRecipes;
-import net.minecraftforge.oredict.ShapedOreRecipe;
-import net.minecraftforge.oredict.ShapelessOreRecipe;
-
-import org.apache.commons.lang3.reflect.FieldUtils;
import com.github.bartimaeusnek.bartworks.MainMod;
import com.github.bartimaeusnek.bartworks.system.material.BW_MetaGenerated_Items;
import com.github.bartimaeusnek.bartworks.system.material.Werkstoff;
import com.github.bartimaeusnek.bartworks.util.BW_Util;
-import com.github.bartimaeusnek.bartworks.util.CachedReflectionUtils;
import com.github.bartimaeusnek.crossmod.BartWorksCrossmod;
import cpw.mods.fml.common.registry.GameRegistry;
@@ -113,6 +105,7 @@ import gregtech.api.enums.ItemList;
import gregtech.api.enums.Materials;
import gregtech.api.enums.OrePrefixes;
import gregtech.api.enums.TierEU;
+import gregtech.api.interfaces.IRecipeMutableAccess;
import gregtech.api.interfaces.ISubTagContainer;
import gregtech.api.items.GT_Generic_Block;
import gregtech.api.items.GT_Generic_Item;
@@ -779,12 +772,7 @@ public class PlatinumSludgeOverHaul {
.getRecipeList()
.forEach(PlatinumSludgeOverHaul::setnewMaterialInRecipe);
// gt crafting
- try {
- ((List<IRecipe>) FieldUtils.getDeclaredField(GT_ModHandler.class, "sBufferRecipeList", true)
- .get(null)).forEach(PlatinumSludgeOverHaul::setnewMaterialInRecipe);
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- }
+ GT_ModHandler.sBufferRecipeList.forEach(PlatinumSludgeOverHaul::setnewMaterialInRecipe);
// gt machines
maploop: for (RecipeMap<?> map : RecipeMap.ALL_RECIPE_MAPS.values()) {
if (map == fusionRecipes || map == unpackagerRecipes
@@ -984,76 +972,36 @@ public class PlatinumSludgeOverHaul {
}
}
- private static void setnewMaterialInRecipe(Object obj) {
- String inputName = "output";
- String inputItemName = "input";
- if (!(obj instanceof ShapedOreRecipe) && !(obj instanceof ShapelessOreRecipe)) {
- if (obj instanceof ShapedRecipes || obj instanceof ShapelessRecipes) {
- inputName = "recipeOutput";
- inputItemName = "recipeItems";
- } else {
- try {
- if (Class.forName("gtPlusPlus.api.objects.minecraft.ShapedRecipe")
- .isAssignableFrom(obj.getClass()))
- obj = CachedReflectionUtils.getField(obj.getClass(), "mRecipe")
- .get(obj);
- } catch (ClassNotFoundException | IllegalAccessException e) {
- e.printStackTrace();
- }
- }
- }
-
- IRecipe recipe = (IRecipe) obj;
+ private static void setnewMaterialInRecipe(IRecipe recipe) {
ItemStack otpt = recipe.getRecipeOutput();
- Field out = CachedReflectionUtils.getDeclaredField(recipe.getClass(), inputName);
- if (out == null) out = CachedReflectionUtils.getField(recipe.getClass(), inputName);
+ if (!(recipe instanceof IRecipeMutableAccess mutableRecipe)) {
+ return;
+ }
- Field in = CachedReflectionUtils.getDeclaredField(recipe.getClass(), inputItemName);
- if (in == null) in = CachedReflectionUtils.getField(recipe.getClass(), inputItemName);
- if (in == null) return;
+ Object input = mutableRecipe.gt5u$getRecipeInputs();
- Object input;
- try {
- input = in.get(obj);
- } catch (IllegalAccessException e) {
- e.printStackTrace();
+ if (input == null) {
return;
}
- if (out != null && GT_Utility.areStacksEqual(otpt, Materials.Platinum.getDust(1), true)) {
+ if (GT_Utility.areStacksEqual(otpt, Materials.Platinum.getDust(1), true)) {
if (PlatinumSludgeOverHaul.checkRecipe(input, Materials.Platinum)) return;
- try {
- out.set(recipe, PTMetallicPowder.get(dust, otpt.stackSize * 2));
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- }
- } else if (out != null && GT_Utility.areStacksEqual(otpt, Materials.Palladium.getDust(1), true)) {
+ mutableRecipe.gt5u$setRecipeOutputItem(PTMetallicPowder.get(dust, otpt.stackSize * 2));
+ } else if (GT_Utility.areStacksEqual(otpt, Materials.Palladium.getDust(1), true)) {
if (PlatinumSludgeOverHaul.checkRecipe(input, Materials.Palladium)) return;
- try {
- out.set(recipe, PDMetallicPowder.get(dust, otpt.stackSize * 2));
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- }
- } else if (out != null && GT_Utility.areStacksEqual(otpt, Materials.Iridium.getDust(1), true)) {
+ mutableRecipe.gt5u$setRecipeOutputItem(PDMetallicPowder.get(dust, otpt.stackSize * 2));
+ } else if (GT_Utility.areStacksEqual(otpt, Materials.Iridium.getDust(1), true)) {
if (PlatinumSludgeOverHaul.checkRecipe(input, Materials.Iridium)) return;
- try {
- out.set(recipe, IrLeachResidue.get(dust, otpt.stackSize));
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- }
- } else if (out != null && GT_Utility.areStacksEqual(otpt, Materials.Osmium.getDust(1), true)) {
+ mutableRecipe.gt5u$setRecipeOutputItem(IrLeachResidue.get(dust, otpt.stackSize));
+ } else if (GT_Utility.areStacksEqual(otpt, Materials.Osmium.getDust(1), true)) {
if (PlatinumSludgeOverHaul.checkRecipe(input, Materials.Osmium)) return;
- try {
- out.set(recipe, IrOsLeachResidue.get(dust, otpt.stackSize));
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- }
+ mutableRecipe.gt5u$setRecipeOutputItem(IrOsLeachResidue.get(dust, otpt.stackSize));
}
}
@SuppressWarnings({ "rawtypes", "unchecked" })
- private static boolean checkRecipe(Object input, Materials mat) {
+ public static boolean checkRecipe(Object input, Materials mat) {
if (input instanceof List || input instanceof Object[]) {
Set lists = new HashSet(), stacks = new HashSet();
List ip = input instanceof List ? (List) input : new ArrayList();