diff options
Diffstat (limited to 'src/main/java/com/elisis/gtnhlanth')
-rw-r--r-- | src/main/java/com/elisis/gtnhlanth/loader/RecipeLoader.java | 137 |
1 files changed, 10 insertions, 127 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)); } } |