diff options
author | Raven Szewczyk <git@eigenraven.me> | 2024-07-27 07:12:04 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-27 13:12:04 +0700 |
commit | c7b38c23c5b34a324256966f0a9335694fe8d63b (patch) | |
tree | 92aab6471745549a79c9f84f38c3076d9275ac4f /src/main/java/goodgenerator | |
parent | c55db9d91fa0a065d7565107a1eca679698eab04 (diff) | |
download | GT5-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/goodgenerator')
-rw-r--r-- | src/main/java/goodgenerator/loader/NaquadahReworkRecipeLoader.java | 150 |
1 files changed, 12 insertions, 138 deletions
diff --git a/src/main/java/goodgenerator/loader/NaquadahReworkRecipeLoader.java b/src/main/java/goodgenerator/loader/NaquadahReworkRecipeLoader.java index 2354ec61c2..46521fcaa1 100644 --- a/src/main/java/goodgenerator/loader/NaquadahReworkRecipeLoader.java +++ b/src/main/java/goodgenerator/loader/NaquadahReworkRecipeLoader.java @@ -55,25 +55,14 @@ import static gregtech.api.util.GT_RecipeConstants.UniversalChemical; import static gregtech.common.items.GT_MetaGenerated_Item_01.registerCauldronCleaningFor; import static gtPlusPlus.api.recipe.GTPPRecipeMaps.quantumForceTransformerRecipes; -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.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.github.bartimaeusnek.bartworks.system.material.GT_Enhancement.PlatinumSludgeOverHaul; import com.github.bartimaeusnek.bartworks.system.material.WerkstoffLoader; @@ -86,6 +75,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.recipe.RecipeMaps; import gregtech.api.util.GT_Log; import gregtech.api.util.GT_OreDictUnificator; @@ -1260,146 +1250,30 @@ public class NaquadahReworkRecipeLoader { GT_Log.out.print("Crafting Table done!\n"); } - // 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.Naquadah.getDust(1), true)) { - - recipeCheck.setAccessible(true); - boolean isOk = true; - - try { - isOk = (boolean) recipeCheck.invoke(BartObj, input, Materials.Naquadah); - } catch (InvocationTargetException | IllegalAccessException ignored) {} - - if (isOk) return; - try { - out.set(recipe, naquadahEarth.get(OrePrefixes.dust, 2)); - } catch (IllegalAccessException e) { - e.printStackTrace(); + if (PlatinumSludgeOverHaul.checkRecipe(input, Materials.Naquadah)) { + return; } + mutableRecipe.gt5u$setRecipeOutputItem(naquadahEarth.get(OrePrefixes.dust, 2)); } else if (GT_Utility.areStacksEqual(result, Materials.NaquadahEnriched.getDust(1), true)) { - - recipeCheck.setAccessible(true); - boolean isOk = true; - - try { - isOk = (boolean) recipeCheck.invoke(BartObj, input, Materials.NaquadahEnriched); - } catch (InvocationTargetException | IllegalAccessException ignored) {} - - if (isOk) return; - try { - out.set(recipe, enrichedNaquadahEarth.get(OrePrefixes.dust, 2)); - } catch (IllegalAccessException e) { - e.printStackTrace(); + if (PlatinumSludgeOverHaul.checkRecipe(input, Materials.NaquadahEnriched)) { + return; } + mutableRecipe.gt5u$setRecipeOutputItem(enrichedNaquadahEarth.get(OrePrefixes.dust, 2)); } else if (GT_Utility.areStacksEqual(result, Materials.Naquadria.getDust(1), true)) { - - recipeCheck.setAccessible(true); - boolean isOk = true; - - try { - isOk = (boolean) recipeCheck.invoke(BartObj, input, Materials.Naquadria); - } catch (InvocationTargetException | IllegalAccessException ignored) {} - - if (isOk) return; - try { - out.set(recipe, naquadriaEarth.get(OrePrefixes.dust, 2)); - } catch (IllegalAccessException e) { - e.printStackTrace(); + if (PlatinumSludgeOverHaul.checkRecipe(input, Materials.Naquadria)) { + return; } + mutableRecipe.gt5u$setRecipeOutputItem(naquadriaEarth.get(OrePrefixes.dust, 2)); } } } |