aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/com/github/bartimaeusnek/bartworks/system/material/CircuitGeneration/CircuitImprintLoader.java67
-rw-r--r--src/main/java/com/github/bartimaeusnek/bartworks/util/BW_Util.java249
2 files changed, 275 insertions, 41 deletions
diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/system/material/CircuitGeneration/CircuitImprintLoader.java b/src/main/java/com/github/bartimaeusnek/bartworks/system/material/CircuitGeneration/CircuitImprintLoader.java
index 403556f4eb..361648f276 100644
--- a/src/main/java/com/github/bartimaeusnek/bartworks/system/material/CircuitGeneration/CircuitImprintLoader.java
+++ b/src/main/java/com/github/bartimaeusnek/bartworks/system/material/CircuitGeneration/CircuitImprintLoader.java
@@ -22,6 +22,7 @@
package com.github.bartimaeusnek.bartworks.system.material.CircuitGeneration;
+import com.github.bartimaeusnek.ASM.BWCoreStaticReplacementMethodes;
import com.github.bartimaeusnek.bartworks.common.configs.ConfigHandler;
import com.github.bartimaeusnek.bartworks.system.material.WerkstoffLoader;
import com.github.bartimaeusnek.bartworks.util.BWRecipes;
@@ -38,8 +39,11 @@ import gregtech.api.util.GT_OreDictUnificator;
import gregtech.api.util.GT_Recipe;
import gregtech.api.util.GT_Utility;
import net.minecraft.item.ItemStack;
+import net.minecraft.item.crafting.CraftingManager;
+import net.minecraft.item.crafting.IRecipe;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.oredict.OreDictionary;
+import net.minecraftforge.oredict.ShapedOreRecipe;
import java.util.HashSet;
import java.util.Iterator;
@@ -142,7 +146,7 @@ public class CircuitImprintLoader {
GT_Recipe.GT_Recipe_Map.sCircuitAssemblerRecipes.mRecipeList.removeAll(toRem);
}
- makeCircuitImprints();
+ makeCircuitImprintRecipes();
}
@SuppressWarnings("deprecation")
@@ -215,8 +219,29 @@ public class CircuitImprintLoader {
return false;
}
- private static void makeCircuitImprints() {
- //TODO: cache and remove recipes if new world is loaded.
+ private static HashSet<IRecipe> recipeWorldCache = new HashSet<>();
+ private static HashSet<GT_Recipe> gtrecipeWorldCache = new HashSet<>();
+
+ private static void removeOldRecipesFromRegistries(){
+ recipeWorldCache.forEach(CraftingManager.getInstance().getRecipeList()::remove);
+ BWCoreStaticReplacementMethodes.RECENTLYUSEDRECIPES.clear();
+ gtrecipeWorldCache.forEach(GT_Recipe.GT_Recipe_Map.sSlicerRecipes.mRecipeList::remove);
+ recipeWorldCache.forEach( r ->
+ {
+ try {
+ BW_Util.getGTBufferedRecipeList().remove(r);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ );
+ recipeWorldCache.clear();
+ gtrecipeWorldCache.clear();
+ }
+
+ private static void makeCircuitImprintRecipes() {
+
+ removeOldRecipesFromRegistries();
for (NBTTagCompound tag : CircuitImprintLoader.recipeTagMap.keySet()){
ItemStack stack = CircuitImprintLoader.getStackFromTag(tag);
@@ -228,44 +253,20 @@ public class CircuitImprintLoader {
eut = Math.min(eut, BW_Util.getMachineVoltageFromTier(BW_Util.getCircuitTierFromOreDictName(OreDictionary.getOreName(OreDictionary.getOreIDs(stack)[0]))));
GT_Recipe slicingRecipe = new BWRecipes.DynamicGTRecipe(true,new ItemStack[]{stack,ItemList.Shape_Slicer_Flat.get(0)},new ItemStack[]{BW_Meta_Items.getNEWCIRCUITS().getStackWithNBT(tag,1,1)},null,null,null,null,300,eut, BW_Util.CLEANROOM);
+ gtrecipeWorldCache.add(slicingRecipe);
GT_Recipe.GT_Recipe_Map.sSlicerRecipes.add(slicingRecipe);
- GameRegistry.addRecipe(new BWRecipes.BWNBTDependantCraftingRecipe(BW_Meta_Items.getNEWCIRCUITS().getStackWithNBT(tag,0,1),
- " X ",
- "GPG",
- " X ",
- 'P', BW_Meta_Items.getNEWCIRCUITS().getStackWithNBT(tag,1,1),
- 'G', WerkstoffLoader.Prasiolite.get(OrePrefixes.gemExquisite,1),
- 'X', BW_Meta_Items.getNEWCIRCUITS().getStack(3)));
-
- GT_ModHandler.addCraftingRecipe(BW_Meta_Items.getNEWCIRCUITS().getStackWithNBT(tag,0,1), GT_ModHandler.RecipeBits.DO_NOT_CHECK_FOR_COLLISIONS | GT_ModHandler.RecipeBits.KEEPNBT | GT_ModHandler.RecipeBits.BUFFERED, new Object[]{
+ ShapedOreRecipe gtrecipe = BW_Util.createGTCraftingRecipe(BW_Meta_Items.getNEWCIRCUITS().getStackWithNBT(tag,0,1), GT_ModHandler.RecipeBits.DO_NOT_CHECK_FOR_COLLISIONS | GT_ModHandler.RecipeBits.KEEPNBT | GT_ModHandler.RecipeBits.BUFFERED, new Object[]{
" X ",
"GPG",
" X ",
'P', BW_Meta_Items.getNEWCIRCUITS().getStackWithNBT(tag,1,1),
'G', WerkstoffLoader.Prasiolite.get(OrePrefixes.gemExquisite,1),
'X', BW_Meta_Items.getNEWCIRCUITS().getStack(3)});
+ recipeWorldCache.add(gtrecipe);
+ GameRegistry.addRecipe(gtrecipe);
+
}
-// for (ItemStack stack : CircuitImprintLoader.bwCircuitTagMap.values()){
-// NBTTagCompound tag = CircuitImprintLoader.getTagFromStack(stack);
-// CircuitData data = CircuitImprintLoader.bwCircuitTagMap.inverse().get(stack);
-// GT_Recipe slicingRecipe = new BWRecipes.DynamicGTRecipe(true,new ItemStack[]{stack,ItemList.Shape_Slicer_Flat.get(0)},new ItemStack[]{BW_Meta_Items.getNEWCIRCUITS().getStackWithNBT(tag,1,1)},null,null,null,null,300, Math.toIntExact(data.getaVoltage()),data.getaSpecial());
-// GT_Recipe.GT_Recipe_Map.sSlicerRecipes.add(slicingRecipe);
-// GameRegistry.addRecipe(new BWRecipes.BWNBTDependantCraftingRecipe(BW_Meta_Items.getNEWCIRCUITS().getStackWithNBT(tag,0,1),
-// " X ",
-// "GPG",
-// " X ",
-// 'P', BW_Meta_Items.getNEWCIRCUITS().getStackWithNBT(tag,1,1),
-// 'G', WerkstoffLoader.Prasiolite.get(OrePrefixes.gemExquisite,1),
-// 'X', BW_Meta_Items.getNEWCIRCUITS().getStack(3)));
-// GT_ModHandler.addCraftingRecipe(BW_Meta_Items.getNEWCIRCUITS().getStackWithNBT(tag,0,1),GT_ModHandler.RecipeBits.KEEPNBT | GT_ModHandler.RecipeBits.BUFFERED | GT_ModHandler.RecipeBits.DO_NOT_CHECK_FOR_COLLISIONS ,new Object[]{
-// " X ",
-// "GPG",
-// " X ",
-// 'P', BW_Meta_Items.getNEWCIRCUITS().getStackWithNBT(tag,1,1),
-// 'G', WerkstoffLoader.Prasiolite.get(OrePrefixes.gemExquisite,1),
-// 'X', BW_Meta_Items.getNEWCIRCUITS().getStack(3)
-// });
-// }
+
}
} \ No newline at end of file
diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/util/BW_Util.java b/src/main/java/com/github/bartimaeusnek/bartworks/util/BW_Util.java
index 703c3b66da..89d4eea19a 100644
--- a/src/main/java/com/github/bartimaeusnek/bartworks/util/BW_Util.java
+++ b/src/main/java/com/github/bartimaeusnek/bartworks/util/BW_Util.java
@@ -26,31 +26,38 @@ import com.github.bartimaeusnek.bartworks.API.BioVatLogicAdder;
import com.github.bartimaeusnek.bartworks.common.loaders.ItemRegistry;
import gregtech.api.enums.Element;
import gregtech.api.enums.Materials;
+import gregtech.api.enums.OreDictNames;
+import gregtech.api.enums.ToolDictNames;
+import gregtech.api.interfaces.IItemContainer;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Energy;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Input;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_InputBus;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_MultiBlockBase;
-import gregtech.api.util.GT_LanguageManager;
-import gregtech.api.util.GT_OreDictUnificator;
-import gregtech.api.util.GT_Recipe;
-import gregtech.api.util.GT_Utility;
+import gregtech.api.objects.ItemData;
+import gregtech.api.util.*;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
+import net.minecraft.enchantment.Enchantment;
import net.minecraft.init.Blocks;
+import net.minecraft.init.Items;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack;
+import net.minecraft.item.crafting.CraftingManager;
+import net.minecraft.item.crafting.IRecipe;
import net.minecraftforge.common.util.EnumHelper;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidStack;
+import net.minecraftforge.oredict.ShapedOreRecipe;
+import org.apache.commons.lang3.reflect.FieldUtils;
import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
+import java.lang.reflect.Field;
+import java.util.*;
+
+import static gregtech.api.enums.GT_Values.*;
-import static gregtech.api.enums.GT_Values.V;
@SuppressWarnings("unused")
public class BW_Util {
@@ -528,4 +535,230 @@ public class BW_Util {
return 0;
}
+
+ private static Field sBufferedRecipeList;
+ public static List<IRecipe> getGTBufferedRecipeList() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException{
+ if (sBufferedRecipeList == null) {
+ sBufferedRecipeList = FieldUtils.getDeclaredField(GT_ModHandler.class,"sBufferRecipeList",true);
+ }
+ if (sBufferedRecipeList == null) {
+ sBufferedRecipeList = FieldUtils.getField(GT_ModHandler.class,"sBufferRecipeList",true);
+ }
+ return (List<IRecipe>) sBufferedRecipeList.get(null);
+ }
+
+ public static ShapedOreRecipe createGTCraftingRecipe(ItemStack aResult, long aBitMask, Object[] aRecipe) {
+ return createGTCraftingRecipe(aResult, new Enchantment[0], new int[0], (aBitMask & GT_ModHandler.RecipeBits.MIRRORED) != 0L, (aBitMask & GT_ModHandler.RecipeBits.BUFFERED) != 0L, (aBitMask & GT_ModHandler.RecipeBits.KEEPNBT) != 0L, (aBitMask & GT_ModHandler.RecipeBits.DISMANTLEABLE) != 0L, (aBitMask & GT_ModHandler.RecipeBits.NOT_REMOVABLE) == 0L, (aBitMask & GT_ModHandler.RecipeBits.REVERSIBLE) != 0L, (aBitMask & GT_ModHandler.RecipeBits.DELETE_ALL_OTHER_RECIPES) != 0L, (aBitMask & GT_ModHandler.RecipeBits.DELETE_ALL_OTHER_RECIPES_IF_SAME_NBT) != 0L, (aBitMask & GT_ModHandler.RecipeBits.DELETE_ALL_OTHER_SHAPED_RECIPES) != 0L, (aBitMask & GT_ModHandler.RecipeBits.DELETE_ALL_OTHER_NATIVE_RECIPES) != 0L, (aBitMask & GT_ModHandler.RecipeBits.DO_NOT_CHECK_FOR_COLLISIONS) == 0L, (aBitMask & GT_ModHandler.RecipeBits.ONLY_ADD_IF_THERE_IS_ANOTHER_RECIPE_FOR_IT) != 0L, (aBitMask & GT_ModHandler.RecipeBits.ONLY_ADD_IF_RESULT_IS_NOT_NULL) != 0L, aRecipe);
+ }
+
+ public static ShapedOreRecipe createGTCraftingRecipe(ItemStack aResult, Enchantment[] aEnchantmentsAdded, int[] aEnchantmentLevelsAdded, boolean aMirrored, boolean aBuffered, boolean aKeepNBT, boolean aDismantleable, boolean aRemovable, boolean aReversible, boolean aRemoveAllOthersWithSameOutput, boolean aRemoveAllOthersWithSameOutputIfTheyHaveSameNBT, boolean aRemoveAllOtherShapedsWithSameOutput, boolean aRemoveAllOtherNativeRecipes, boolean aCheckForCollisions, boolean aOnlyAddIfThereIsAnyRecipeOutputtingThis, boolean aOnlyAddIfResultIsNotNull, Object[] aRecipe) {
+ aResult = GT_OreDictUnificator.get(true, aResult);
+ if (aOnlyAddIfResultIsNotNull && aResult == null) return null;
+ if (aResult != null && Items.feather.getDamage(aResult) == W) Items.feather.setDamage(aResult, 0);
+ if (aRecipe == null || aRecipe.length <= 0) return null;
+
+ boolean tThereWasARecipe = false;
+
+ for (byte i = 0; i < aRecipe.length; i++) {
+ if (aRecipe[i] instanceof IItemContainer)
+ aRecipe[i] = ((IItemContainer) aRecipe[i]).get(1);
+ else if (aRecipe[i] instanceof Enum)
+ aRecipe[i] = ((Enum) aRecipe[i]).name();
+ else if (!(aRecipe[i] == null || aRecipe[i] instanceof ItemStack || aRecipe[i] instanceof ItemData || aRecipe[i] instanceof String || aRecipe[i] instanceof Character))
+ aRecipe[i] = aRecipe[i].toString();
+ }
+
+ try {
+ StringBuilder shape = new StringBuilder(E);
+ int idx = 0;
+ if (aRecipe[idx] instanceof Boolean) {
+ throw new IllegalArgumentException();
+ }
+
+ ArrayList<Object> tRecipeList = new ArrayList<Object>(Arrays.asList(aRecipe));
+
+ while (aRecipe[idx] instanceof String) {
+ StringBuilder s = new StringBuilder((String) aRecipe[idx++]);
+ shape.append(s);
+ while (s.length() < 3) s.append(" ");
+ if (s.length() > 3) throw new IllegalArgumentException();
+
+ for (char c : s.toString().toCharArray()) {
+ switch (c) {
+ case 'b':
+ tRecipeList.add(c);
+ tRecipeList.add(ToolDictNames.craftingToolBlade.name());
+ break;
+ case 'c':
+ tRecipeList.add(c);
+ tRecipeList.add(ToolDictNames.craftingToolCrowbar.name());
+ break;
+ case 'd':
+ tRecipeList.add(c);
+ tRecipeList.add(ToolDictNames.craftingToolScrewdriver.name());
+ break;
+ case 'f':
+ tRecipeList.add(c);
+ tRecipeList.add(ToolDictNames.craftingToolFile.name());
+ break;
+ case 'h':
+ tRecipeList.add(c);
+ tRecipeList.add(ToolDictNames.craftingToolHardHammer.name());
+ break;
+ case 'i':
+ tRecipeList.add(c);
+ tRecipeList.add(ToolDictNames.craftingToolSolderingIron.name());
+ break;
+ case 'j':
+ tRecipeList.add(c);
+ tRecipeList.add(ToolDictNames.craftingToolSolderingMetal.name());
+ break;
+ case 'k':
+ tRecipeList.add(c);
+ tRecipeList.add(ToolDictNames.craftingToolKnife.name());
+ break;
+ case 'm':
+ tRecipeList.add(c);
+ tRecipeList.add(ToolDictNames.craftingToolMortar.name());
+ break;
+ case 'p':
+ tRecipeList.add(c);
+ tRecipeList.add(ToolDictNames.craftingToolDrawplate.name());
+ break;
+ case 'r':
+ tRecipeList.add(c);
+ tRecipeList.add(ToolDictNames.craftingToolSoftHammer.name());
+ break;
+ case 's':
+ tRecipeList.add(c);
+ tRecipeList.add(ToolDictNames.craftingToolSaw.name());
+ break;
+ case 'w':
+ tRecipeList.add(c);
+ tRecipeList.add(ToolDictNames.craftingToolWrench.name());
+ break;
+ case 'x':
+ tRecipeList.add(c);
+ tRecipeList.add(ToolDictNames.craftingToolWireCutter.name());
+ break;
+ }
+ }
+ }
+
+ aRecipe = tRecipeList.toArray();
+
+ if (aRecipe[idx] instanceof Boolean) {
+ idx++;
+ }
+ Map<Character, ItemStack> tItemStackMap = new HashMap<>();
+ Map<Character, ItemData> tItemDataMap = new HashMap<>();
+ tItemStackMap.put(' ', null);
+
+ boolean tRemoveRecipe = true;
+
+ for (; idx < aRecipe.length; idx += 2) {
+ if (aRecipe[idx] == null || aRecipe[idx + 1] == null) {
+ if (D1) {
+ GT_Log.err.println("WARNING: Missing Item for shaped Recipe: " + (aResult == null ? "null" : aResult.getDisplayName()));
+ for (Object tContent : aRecipe) GT_Log.err.println(tContent);
+ }
+ return null;
+ }
+ Character chr = (Character) aRecipe[idx];
+ Object in = aRecipe[idx + 1];
+ if (in instanceof ItemStack) {
+ tItemStackMap.put(chr, GT_Utility.copy(in));
+ tItemDataMap.put(chr, GT_OreDictUnificator.getItemData((ItemStack) in));
+ } else if (in instanceof ItemData) {
+ String tString = in.toString();
+ switch (tString) {
+ case "plankWood":
+ tItemDataMap.put(chr, new ItemData(Materials.Wood, M));
+ break;
+ case "stoneNetherrack":
+ tItemDataMap.put(chr, new ItemData(Materials.Netherrack, M));
+ break;
+ case "stoneObsidian":
+ tItemDataMap.put(chr, new ItemData(Materials.Obsidian, M));
+ break;
+ case "stoneEndstone":
+ tItemDataMap.put(chr, new ItemData(Materials.Endstone, M));
+ break;
+ default:
+ tItemDataMap.put(chr, (ItemData) in);
+ break;
+ }
+ ItemStack tStack = GT_OreDictUnificator.getFirstOre(in, 1);
+ if (tStack == null) tRemoveRecipe = false;
+ else tItemStackMap.put(chr, tStack);
+ in = aRecipe[idx + 1] = in.toString();
+ } else if (in instanceof String) {
+ if (in.equals(OreDictNames.craftingChest.toString()))
+ tItemDataMap.put(chr, new ItemData(Materials.Wood, M * 8));
+ else if (in.equals(OreDictNames.craftingBook.toString()))
+ tItemDataMap.put(chr, new ItemData(Materials.Paper, M * 3));
+ else if (in.equals(OreDictNames.craftingPiston.toString()))
+ tItemDataMap.put(chr, new ItemData(Materials.Stone, M * 4, Materials.Wood, M * 3));
+ else if (in.equals(OreDictNames.craftingFurnace.toString()))
+ tItemDataMap.put(chr, new ItemData(Materials.Stone, M * 8));
+ else if (in.equals(OreDictNames.craftingIndustrialDiamond.toString()))
+ tItemDataMap.put(chr, new ItemData(Materials.Diamond, M));
+ else if (in.equals(OreDictNames.craftingAnvil.toString()))
+ tItemDataMap.put(chr, new ItemData(Materials.Iron, M * 10));
+ ItemStack tStack = GT_OreDictUnificator.getFirstOre(in, 1);
+ if (tStack == null) tRemoveRecipe = false;
+ else tItemStackMap.put(chr, tStack);
+ } else {
+ throw new IllegalArgumentException();
+ }
+ }
+
+ if (aReversible && aResult != null) {
+ ItemData[] tData = new ItemData[9];
+ int x = -1;
+ for (char chr : shape.toString().toCharArray()) tData[++x] = tItemDataMap.get(chr);
+ if (GT_Utility.arrayContainsNonNull(tData))
+ GT_OreDictUnificator.addItemData(aResult, new ItemData(tData));
+ }
+
+ if (aCheckForCollisions && tRemoveRecipe) {
+ ItemStack[] tRecipe = new ItemStack[9];
+ int x = -1;
+ for (char chr : shape.toString().toCharArray()) {
+ tRecipe[++x] = tItemStackMap.get(chr);
+ if (tRecipe[x] != null && Items.feather.getDamage(tRecipe[x]) == W)
+ Items.feather.setDamage(tRecipe[x], 0);
+ }
+ tThereWasARecipe = GT_ModHandler.removeRecipe(tRecipe) != null;
+ }
+ } catch (Throwable e) {
+ e.printStackTrace(GT_Log.err);
+ }
+
+ if (aResult == null || aResult.stackSize <= 0) return null;
+
+ if (aRemoveAllOthersWithSameOutput || aRemoveAllOthersWithSameOutputIfTheyHaveSameNBT || aRemoveAllOtherShapedsWithSameOutput || aRemoveAllOtherNativeRecipes)
+ tThereWasARecipe = GT_ModHandler.removeRecipeByOutput(aResult, !aRemoveAllOthersWithSameOutputIfTheyHaveSameNBT, aRemoveAllOtherShapedsWithSameOutput, aRemoveAllOtherNativeRecipes) || tThereWasARecipe;
+
+ if (aOnlyAddIfThereIsAnyRecipeOutputtingThis && !tThereWasARecipe) {
+ ArrayList<IRecipe> tList = (ArrayList<IRecipe>) CraftingManager.getInstance().getRecipeList();
+ int tList_sS=tList.size();
+ for (int i = 0; i < tList_sS && !tThereWasARecipe; i++) {
+ IRecipe tRecipe = tList.get(i);
+ if (GT_ModHandler.sSpecialRecipeClasses.contains(tRecipe.getClass().getName())) continue;
+ if (GT_Utility.areStacksEqual(GT_OreDictUnificator.get(tRecipe.getRecipeOutput()), aResult, true)) {
+ tList.remove(i--); tList_sS=tList.size();
+ tThereWasARecipe = true;
+ }
+ }
+ }
+
+ if (Items.feather.getDamage(aResult) == W || Items.feather.getDamage(aResult) < 0)
+ Items.feather.setDamage(aResult, 0);
+
+ GT_Utility.updateItemStack(aResult);
+
+ return new GT_Shaped_Recipe(GT_Utility.copy(aResult), aDismantleable, aRemovable, aKeepNBT, aEnchantmentsAdded, aEnchantmentLevelsAdded, aRecipe).setMirrored(aMirrored);
+ }
+
}