aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech
diff options
context:
space:
mode:
authorbartimaeusnek <33183715+bartimaeusnek@users.noreply.github.com>2020-12-30 23:30:33 +0100
committerbartimaeusnek <33183715+bartimaeusnek@users.noreply.github.com>2020-12-31 02:02:58 +0100
commit939441f7b24e5f6abb0b5534dfea715b4be6e5ed (patch)
treeadf8d57b6b80b2202ce354fa5a5d83cfc9de11ce /src/main/java/gregtech
parent2db36cb988b58ace9d91d6f7b636a6059507c873 (diff)
downloadGT5-Unofficial-939441f7b24e5f6abb0b5534dfea715b4be6e5ed.tar.gz
GT5-Unofficial-939441f7b24e5f6abb0b5534dfea715b4be6e5ed.tar.bz2
GT5-Unofficial-939441f7b24e5f6abb0b5534dfea715b4be6e5ed.zip
Implemented ReverseRecipes
Diffstat (limited to 'src/main/java/gregtech')
-rw-r--r--src/main/java/gregtech/GT_Mod.java5
-rw-r--r--src/main/java/gregtech/api/objects/ReverseShapedRecipe.java43
-rw-r--r--src/main/java/gregtech/api/objects/ReverseShapelessRecipe.java43
-rw-r--r--src/main/java/gregtech/api/util/GT_Recipe.java2
-rw-r--r--src/main/java/gregtech/api/util/GT_Shaped_Recipe.java50
-rw-r--r--src/main/java/gregtech/api/util/GT_Shapeless_Recipe.java20
-rw-r--r--src/main/java/gregtech/api/util/GT_Utility.java179
-rw-r--r--src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Disassembler.java31
8 files changed, 291 insertions, 82 deletions
diff --git a/src/main/java/gregtech/GT_Mod.java b/src/main/java/gregtech/GT_Mod.java
index b0ac434c61..fe44141324 100644
--- a/src/main/java/gregtech/GT_Mod.java
+++ b/src/main/java/gregtech/GT_Mod.java
@@ -32,6 +32,8 @@ import gregtech.api.enums.SubTag;
import gregtech.api.enums.Textures;
import gregtech.api.interfaces.internal.IGT_Mod;
import gregtech.api.objects.ItemData;
+import gregtech.api.objects.ReverseShapedRecipe;
+import gregtech.api.objects.ReverseShapelessRecipe;
import gregtech.api.objects.XSTR;
import gregtech.api.threads.GT_Runnable_MachineBlockUpdate;
import gregtech.api.util.GT_Assemblyline_Server;
@@ -1077,6 +1079,9 @@ public class GT_Mod implements IGT_Mod {
achievements = new GT_Achievements();
+ ReverseShapedRecipe.runReverseRecipes();
+ ReverseShapelessRecipe.runReverseRecipes();
+
GT_Recipe.GTppRecipeHelper = true;
GT_Log.out.println("GT_Mod: Loading finished, deallocating temporary Init Variables.");
GregTech_API.sBeforeGTPreload = null;
diff --git a/src/main/java/gregtech/api/objects/ReverseShapedRecipe.java b/src/main/java/gregtech/api/objects/ReverseShapedRecipe.java
new file mode 100644
index 0000000000..cb9e7d4d83
--- /dev/null
+++ b/src/main/java/gregtech/api/objects/ReverseShapedRecipe.java
@@ -0,0 +1,43 @@
+package gregtech.api.objects;
+
+import gregtech.api.util.GT_Recipe;
+import gregtech.api.util.GT_Utility;
+import gregtech.common.tileentities.machines.basic.GT_MetaTileEntity_Disassembler;
+import net.minecraft.item.ItemStack;
+
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.Optional;
+import java.util.Queue;
+
+import static gregtech.api.util.GT_Recipe.GT_Recipe_Map.sDisassemblerRecipes;
+
+public class ReverseShapedRecipe {
+ private static Queue<ReverseShapedRecipe> reverseRecipes = new LinkedList<>();
+ private ItemStack aResult;
+ private Object[] aRecipe;
+
+ public static Queue<ReverseShapedRecipe> getReverseRecipes() {
+ return reverseRecipes;
+ }
+
+ public ReverseShapedRecipe(ItemStack output, Object[] aRecipe) {
+ this.aResult = output;
+ this.aRecipe = aRecipe;
+ reverseRecipes.add(this);
+ }
+
+ public static void runReverseRecipes() {
+ for (ReverseShapedRecipe x : reverseRecipes) {
+ Optional<GT_Recipe> recipeOptional = GT_Utility.reverseShapedRecipe(x.aResult, x.aRecipe);
+ if (!recipeOptional.isPresent())
+ continue;
+ GT_Recipe recipe = recipeOptional.get();
+ ItemStack[] replacement = new ItemStack[recipe.mOutputs.length];
+ GT_MetaTileEntity_Disassembler.handleRecipeTransformation(recipe.mOutputs, replacement, Collections.singleton(recipe.mOutputs));
+
+ recipe.mOutputs = replacement;
+ sDisassemblerRecipes.add(recipe);
+ }
+ }
+}
diff --git a/src/main/java/gregtech/api/objects/ReverseShapelessRecipe.java b/src/main/java/gregtech/api/objects/ReverseShapelessRecipe.java
new file mode 100644
index 0000000000..1c5e27d246
--- /dev/null
+++ b/src/main/java/gregtech/api/objects/ReverseShapelessRecipe.java
@@ -0,0 +1,43 @@
+package gregtech.api.objects;
+
+import gregtech.api.util.GT_Recipe;
+import gregtech.api.util.GT_Utility;
+import gregtech.common.tileentities.machines.basic.GT_MetaTileEntity_Disassembler;
+import net.minecraft.item.ItemStack;
+
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.Optional;
+import java.util.Queue;
+
+import static gregtech.api.util.GT_Recipe.GT_Recipe_Map.sDisassemblerRecipes;
+
+public class ReverseShapelessRecipe {
+ private static Queue<ReverseShapelessRecipe> reverseRecipes = new LinkedList<>();
+ private ItemStack aResult;
+ private Object[] aRecipe;
+
+ public static Queue<ReverseShapelessRecipe> getReverseRecipes() {
+ return reverseRecipes;
+ }
+
+ public ReverseShapelessRecipe(ItemStack output, Object[] aRecipe) {
+ this.aResult = output;
+ this.aRecipe = aRecipe;
+ reverseRecipes.add(this);
+ }
+
+ public static void runReverseRecipes() {
+ for (ReverseShapelessRecipe x : reverseRecipes) {
+ Optional<GT_Recipe> recipeOptional = GT_Utility.reverseShapelessRecipe(x.aResult, x.aRecipe);
+ if (!recipeOptional.isPresent())
+ continue;
+ GT_Recipe recipe = recipeOptional.get();
+ ItemStack[] replacement = new ItemStack[recipe.mOutputs.length];
+ GT_MetaTileEntity_Disassembler.handleRecipeTransformation(recipe.mOutputs, replacement, Collections.singleton(recipe.mOutputs));
+
+ recipe.mOutputs = replacement;
+ sDisassemblerRecipes.add(recipe);
+ }
+ }
+}
diff --git a/src/main/java/gregtech/api/util/GT_Recipe.java b/src/main/java/gregtech/api/util/GT_Recipe.java
index 537d92b365..9756a8199a 100644
--- a/src/main/java/gregtech/api/util/GT_Recipe.java
+++ b/src/main/java/gregtech/api/util/GT_Recipe.java
@@ -561,7 +561,7 @@ public class GT_Recipe implements Comparable<GT_Recipe> {
public static final GT_Recipe_Map sRecyclerRecipes = new GT_Recipe_Map_Recycler(new HashSet<>(0), "ic.recipe.recycler", "Recycler", "ic2.recycler", RES_PATH_GUI + "basicmachines/Recycler", 1, 1, 1, 0, 1, E, 1, E, true, false);
public static final GT_Recipe_Map sFurnaceRecipes = new GT_Recipe_Map_Furnace(new HashSet<>(0), "mc.recipe.furnace", "Furnace", "smelting", RES_PATH_GUI + "basicmachines/E_Furnace", 1, 1, 1, 0, 1, E, 1, E, true, false);
public static final GT_Recipe_Map sMicrowaveRecipes = new GT_Recipe_Map_Microwave(new HashSet<>(0), "gt.recipe.microwave", "Microwave", "smelting", RES_PATH_GUI + "basicmachines/E_Furnace", 1, 1, 1, 0, 1, E, 1, E, true, false);
-
+ public static final GT_Recipe_Map sDisassemblerRecipes = new GT_Recipe_Map(new HashSet<>(250), "gt.recipe.disassembler", "Disassembler", null, RES_PATH_GUI + "basicmachines/Disassembler", 1, 9, 1, 0, 1, E, 1, E, true, false);
public static final GT_Recipe_Map sScannerFakeRecipes = new GT_Recipe_Map(new HashSet<>(300), "gt.recipe.scanner", "Scanner", null, RES_PATH_GUI + "basicmachines/Scanner", 1, 1, 1, 0, 1, E, 1, E, true, true);
public static final GT_Recipe_Map sRockBreakerFakeRecipes = new GT_Recipe_Map(new HashSet<>(200), "gt.recipe.rockbreaker", "Rock Breaker", null, RES_PATH_GUI + "basicmachines/RockBreaker", 1, 1, 0, 0, 1, E, 1, E, true, true);
public static final GT_Recipe_Map sByProductList = new GT_Recipe_Map(new HashSet<>(1000), "gt.recipe.byproductlist", "Ore Byproduct List", null, RES_PATH_GUI + "basicmachines/Default", 1, 6, 1, 0, 1, E, 1, E, true, true);
diff --git a/src/main/java/gregtech/api/util/GT_Shaped_Recipe.java b/src/main/java/gregtech/api/util/GT_Shaped_Recipe.java
index ea4182a16e..f00fc7758e 100644
--- a/src/main/java/gregtech/api/util/GT_Shaped_Recipe.java
+++ b/src/main/java/gregtech/api/util/GT_Shaped_Recipe.java
@@ -1,20 +1,17 @@
package gregtech.api.util;
import gregtech.api.interfaces.internal.IGT_CraftingRecipe;
-import net.minecraft.block.Block;
+import gregtech.api.objects.ReverseShapedRecipe;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.inventory.InventoryCrafting;
-import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraftforge.oredict.ShapedOreRecipe;
-import java.util.List;
-
public class GT_Shaped_Recipe extends ShapedOreRecipe implements IGT_CraftingRecipe {
- public final boolean /*mDismantleable,*/ mRemovableByGT, mKeepingNBT;
+ public final boolean mRemovableByGT, mKeepingNBT;
private final Enchantment[] mEnchantmentsAdded;
private final int[] mEnchantmentLevelsAdded;
@@ -24,31 +21,9 @@ public class GT_Shaped_Recipe extends ShapedOreRecipe implements IGT_CraftingRec
mEnchantmentLevelsAdded = aEnchantmentLevelsAdded;
mRemovableByGT = aRemovableByGT;
mKeepingNBT = aKeepingNBT;
-// mDismantleable = aDismantleAble;
- if (aDismantleAble){
- for (Object o : aRecipe) {
- String toPrint = null;
- if (o instanceof String) {
- toPrint = (String) o;
- toPrint += " String";
- } else if (o instanceof ItemStack) {
- toPrint = GT_LanguageManager.getTranslation(GT_LanguageManager.getTranslateableItemStackName((ItemStack) o));
- toPrint += " ItemStack";
- } else if (o instanceof List) {
- toPrint = String.join(", ", ((List<String>) o));
- toPrint += " List<String>";
- } else if (o instanceof Item) {
- toPrint = GT_LanguageManager.getTranslation(GT_LanguageManager.getTranslateableItemStackName(new ItemStack((Item) o)));
- toPrint += " Item";
- } else if (o instanceof Block) {
- toPrint = GT_LanguageManager.getTranslation(GT_LanguageManager.getTranslateableItemStackName(new ItemStack((Block) o)));
- toPrint += " Block";
- }
- if (toPrint != null)
- System.out.println(toPrint);
- }
+ if (aDismantleAble) {
+ new ReverseShapedRecipe(aResult, aRecipe);
}
- //TODO: Register Dissassembler "Recipe"
}
@Override
@@ -92,23 +67,6 @@ public class GT_Shaped_Recipe extends ShapedOreRecipe implements IGT_CraftingRec
if (tCharge > 0) GT_ModHandler.chargeElectricItem(rStack, tCharge, Integer.MAX_VALUE, true, false);
}
- // Saving Ingredients inside the Item.
-// if (mDismantleable) {
-// NBTTagCompound rNBT = rStack.getTagCompound(), tNBT = new NBTTagCompound();
-// if (rNBT == null) rNBT = new NBTTagCompound();
-// for (int i = 0; i < 9; i++) {
-// ItemStack tStack = aGrid.getStackInSlot(i);
-// if (tStack != null && GT_Utility.getContainerItem(tStack, true) == null && !(tStack.getItem() instanceof GT_MetaGenerated_Tool)) {
-// tStack = GT_Utility.copyAmount(1, tStack);
-// if(GT_Utility.isStackValid(tStack)){
-// GT_ModHandler.dischargeElectricItem(tStack, Integer.MAX_VALUE, Integer.MAX_VALUE, true, false, true);
-// tNBT.setTag("Ingredient." + i, tStack.writeToNBT(new NBTTagCompound()));}
-// }
-// }
-// rNBT.setTag("GT.CraftingComponents", tNBT);
-// rStack.setTagCompound(rNBT);
-// }
-
// Add Enchantments
for (int i = 0; i < mEnchantmentsAdded.length; i++)
GT_Utility.ItemNBT.addEnchantment(rStack, mEnchantmentsAdded[i], EnchantmentHelper.getEnchantmentLevel(mEnchantmentsAdded[i].effectId, rStack) + mEnchantmentLevelsAdded[i]);
diff --git a/src/main/java/gregtech/api/util/GT_Shapeless_Recipe.java b/src/main/java/gregtech/api/util/GT_Shapeless_Recipe.java
index 42141f6780..fce135dfe6 100644
--- a/src/main/java/gregtech/api/util/GT_Shapeless_Recipe.java
+++ b/src/main/java/gregtech/api/util/GT_Shapeless_Recipe.java
@@ -1,18 +1,15 @@
package gregtech.api.util;
import gregtech.api.interfaces.internal.IGT_CraftingRecipe;
-import net.minecraft.block.Block;
+import gregtech.api.objects.ReverseShapelessRecipe;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.inventory.InventoryCrafting;
-import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraftforge.oredict.ShapelessOreRecipe;
-import java.util.List;
-
public class GT_Shapeless_Recipe extends ShapelessOreRecipe implements IGT_CraftingRecipe {
public final boolean /*mDismantleable,*/ mRemovableByGT, mKeepingNBT;
private final Enchantment[] mEnchantmentsAdded;
@@ -24,22 +21,9 @@ public class GT_Shapeless_Recipe extends ShapelessOreRecipe implements IGT_Craft
mEnchantmentLevelsAdded = aEnchantmentLevelsAdded;
mRemovableByGT = aRemovableByGT;
mKeepingNBT = aKeepingNBT;
-// mDismantleable = aDismantleAble;
if (aDismantleAble){
- for (Object o : aRecipe) {
- String toPrint = o.toString();
- if (o instanceof ItemStack)
- toPrint = GT_LanguageManager.getTranslation(GT_LanguageManager.getTranslateableItemStackName((ItemStack)o));
- else if (o instanceof List)
- toPrint = String.join(", ", ((List<String>) o));
- else if (o instanceof Item)
- toPrint = GT_LanguageManager.getTranslation(GT_LanguageManager.getTranslateableItemStackName(new ItemStack((Item)o)));
- else if (o instanceof Block)
- toPrint = GT_LanguageManager.getTranslation(GT_LanguageManager.getTranslateableItemStackName(new ItemStack((Block)o)));
- System.out.println(toPrint);
- }
+ new ReverseShapelessRecipe(aResult, aRecipe);
}
- //TODO: Register Dissassembler "Recipe"
}
@Override
diff --git a/src/main/java/gregtech/api/util/GT_Utility.java b/src/main/java/gregtech/api/util/GT_Utility.java
index 3530fa17c2..adc0f95881 100644
--- a/src/main/java/gregtech/api/util/GT_Utility.java
+++ b/src/main/java/gregtech/api/util/GT_Utility.java
@@ -14,6 +14,7 @@ import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.tileentity.*;
import gregtech.api.items.GT_EnergyArmor_Item;
import gregtech.api.items.GT_Generic_Item;
+import gregtech.api.items.GT_MetaGenerated_Tool;
import gregtech.api.net.GT_Packet_Sound;
import gregtech.api.objects.GT_CopiedBlockTexture;
import gregtech.api.objects.GT_ItemStack;
@@ -1022,7 +1023,7 @@ public class GT_Utility {
return copyMetaData(Items.feather.getDamage(aStack) + 1, aStack);
return null;
}
-
+
public static synchronized boolean removeIC2BottleRecipe(ItemStack aContainer, ItemStack aInput, Map<ic2.api.recipe.ICannerBottleRecipeManager.Input, RecipeOutput> aRecipeList, ItemStack aOutput){
if ((isStackInvalid(aInput) && isStackInvalid(aOutput) && isStackInvalid(aContainer)) || aRecipeList == null) return false;
boolean rReturn = false;
@@ -1742,7 +1743,7 @@ public class GT_Utility {
if(aDimensionID<=1 && aDimensionID>=-1 && !GregTech_API.sDimensionalList.contains(aDimensionID)) return true;
return !GregTech_API.sDimensionalList.contains(aDimensionID) && DimensionManager.isDimensionRegistered(aDimensionID);
}
-
+
//public static boolean isRealDimension(int aDimensionID) {
// try {
// if (DimensionManager.getProvider(aDimensionID).getClass().getName().contains("com.xcompwiz.mystcraft"))
@@ -1756,7 +1757,7 @@ public class GT_Utility {
// } catch (Throwable e) {/*Do nothing*/}
// return GregTech_API.sDimensionalList.contains(aDimensionID);
//}
-
+
public static boolean moveEntityToDimensionAtCoords(Entity entity, int aDimension, double aX, double aY, double aZ) {
//Credit goes to BrandonCore Author :!:
@@ -2040,7 +2041,7 @@ public class GT_Utility {
if (D1) e.printStackTrace(GT_Log.err);
}
}
-
+
if (aPlayer.capabilities.isCreativeMode) {
FluidStack tFluid = undergroundOilReadInformation(aWorld.getChunkFromBlockCoords(aX,aZ));//-# to only read
if (tFluid!=null)
@@ -2355,7 +2356,7 @@ public class GT_Utility {
setBookTitle(aStack, "Raw Prospection Data");
NBTTagCompound tNBT = GT_Utility.ItemNBT.getNBT(aStack);
-
+
tNBT.setByte("prospection_tier", aTier);
tNBT.setString("prospection_pos", "Dim: " + aDim + "\nX: " + aX + " Y: " + aY + " Z: " + aZ);
@@ -2369,27 +2370,27 @@ public class GT_Utility {
String[] aStats = aStr.split(",");
tOilsTransformed.add(aStats[0] + ": " + aStats[1] + "L " + aStats[2]);
}
-
+
tNBT.setString("prospection_oils", joinListToString(tOilsTransformed));
String tOilsPosStr = "X: " + Math.floorDiv(aX, 16*8)*16*8 + " Z: " + Math.floorDiv(aZ, 16*8)*16*8 + "\n";
int xOff = aX - Math.floorDiv(aX, 16*8)*16*8;
xOff = xOff/16;
int xOffRemain = 7 - xOff;
-
+
int zOff = aZ - Math.floorDiv(aZ, 16*8)*16*8;
zOff = zOff/16;
int zOffRemain = 7 - zOff;
-
+
for( ; zOff > 0; zOff-- ) {
tOilsPosStr = tOilsPosStr.concat("--------\n");
}
for( ; xOff > 0; xOff-- ) {
tOilsPosStr = tOilsPosStr.concat("-");
}
-
+
tOilsPosStr = tOilsPosStr.concat("P");
-
+
for( ; xOffRemain > 0; xOffRemain-- ) {
tOilsPosStr = tOilsPosStr.concat("-");
}
@@ -2444,11 +2445,11 @@ public class GT_Utility {
+ "Location is center of orevein\n\n"
+ "Check NEI to confirm orevein type";
tNBTList.appendTag(new NBTTagString(tPageText));
-
+
if (tOres != null)
fillBookWithList(tNBTList, "Ores Found %s\n\n", "\n", 7, tOres);
-
+
if (tOils != null)
fillBookWithList(tNBTList, "Oils%s\n\n", "\n", 9, tOils);
@@ -2466,7 +2467,7 @@ public class GT_Utility {
tOilsPosStr + "\n" +
"P - Prospector in 8x8 field";
tNBTList.appendTag(new NBTTagString(tPageText));
-
+
tNBT.setString("author", tPos.replace("\n"," "));
tNBT.setTag("pages", tNBTList);
setNBT(aStack, tNBT);
@@ -2606,11 +2607,11 @@ public class GT_Utility {
}
public static boolean isPartOfMaterials(ItemStack aStack, Materials aMaterials){
- return GT_OreDictUnificator.getAssociation(aStack) != null ? GT_OreDictUnificator.getAssociation(aStack).mMaterial.mMaterial.equals(aMaterials) : false;
+ return GT_OreDictUnificator.getAssociation(aStack) != null && GT_OreDictUnificator.getAssociation(aStack).mMaterial.mMaterial.equals(aMaterials);
}
public static boolean isPartOfOrePrefix(ItemStack aStack, OrePrefixes aPrefix){
- return GT_OreDictUnificator.getAssociation(aStack) != null ? GT_OreDictUnificator.getAssociation(aStack).mPrefix.equals(aPrefix) : false;
+ return GT_OreDictUnificator.getAssociation(aStack) != null && GT_OreDictUnificator.getAssociation(aStack).mPrefix.equals(aPrefix);
}
public static boolean isOre(ItemStack aStack) {
for (int id: OreDictionary.getOreIDs(aStack)) {
@@ -2620,4 +2621,152 @@ public class GT_Utility {
return false;
}
+ public static Optional<GT_Recipe> reverseShapelessRecipe(ItemStack output, Object... aRecipe) {
+ if (output == null) {
+ return Optional.empty();
+ }
+
+ List<ItemStack> inputs = new ArrayList<>();
+
+ for (Object o : aRecipe) {
+ if (o instanceof ItemStack) {
+ ItemStack toAdd = ((ItemStack) o).copy();
+ inputs.add(toAdd);
+ } else if (o instanceof String) {
+ ItemStack stack = GT_OreDictUnificator.get(o, 1);
+ if (stack == null) {
+ Optional<ItemStack> oStack = OreDictionary.getOres((String) o)
+ .stream()
+ .findAny();
+ if (oStack.isPresent()) {
+ ItemStack copy = oStack.get().copy();
+ inputs.add(copy);
+ }
+ } else {
+ ItemStack copy = stack.copy();
+ inputs.add(copy);
+ }
+ } else if (o instanceof Item)
+ inputs.add(new ItemStack((Item) o));
+ else if (o instanceof Block)
+ inputs.add(new ItemStack((Block) o));
+ else
+ throw new IllegalStateException("A Recipe contains an invalid input! Output: " + output);
+ }
+
+ inputs.removeIf(x -> x.getItem() instanceof GT_MetaGenerated_Tool);
+
+ return Optional.of(
+ new GT_Recipe(
+ false,
+ new ItemStack[]{output},
+ inputs.toArray(new ItemStack[0]),
+ null, null,
+ null, null,
+ 300, 30, 0
+ )
+ );
+ }
+
+
+ public static Optional<GT_Recipe> reverseShapedRecipe(ItemStack output, Object... aRecipe) {
+ if (output == null) {
+// System.out.println("Null Recipe detected!");
+ return Optional.empty();
+ }
+// System.out.println("Registering Reverse Recipe for: " + GT_LanguageManager.getTranslation(GT_LanguageManager.getTranslateableItemStackName(output) + "|" + output.getUnlocalizedName()));
+// for (Object o : aRecipe) {
+// String toPrint;
+// if (o instanceof String) {
+// toPrint = (String) o;
+// toPrint += " String";
+// } else if (o instanceof ItemStack) {
+// toPrint = GT_LanguageManager.getTranslation(GT_LanguageManager.getTranslateableItemStackName((ItemStack) o));
+// toPrint += " ItemStack";
+// } else if (o instanceof List) {
+// toPrint = String.join(", ", ((List<String>) o));
+// toPrint += " List<String>";
+// } else if (o instanceof Item) {
+// toPrint = GT_LanguageManager.getTranslation(GT_LanguageManager.getTranslateableItemStackName(new ItemStack((Item) o)));
+// toPrint += " Item";
+// } else if (o instanceof Block) {
+// toPrint = GT_LanguageManager.getTranslation(GT_LanguageManager.getTranslateableItemStackName(new ItemStack((Block) o)));
+// toPrint += " Block";
+// } else if (o != null) {
+// toPrint = o.toString();
+// toPrint += " Other";
+// } else {
+// toPrint = "NULL";
+// }
+// System.out.println(toPrint);
+// }
+ Map<Object, Integer> recipeAsMap = new HashMap<>();
+ Map<Character, Object> ingridients = new HashMap<>();
+ Map<Character, Integer> amounts = new HashMap<>();
+ boolean startFound = false;
+ for (int i = 0, aRecipeLength = aRecipe.length; i < aRecipeLength; i++) {
+ Object o = aRecipe[i];
+ if (!startFound) {
+ if (o instanceof String) {
+ for (Character c : ((String) o).toCharArray())
+ amounts.merge(c, 1, (a, b) -> ++a);
+ } else if (o instanceof Character)
+ startFound = true;
+ } else if (!(o instanceof Character))
+ ingridients.put((Character) aRecipe[i - 1], o);
+ }
+ for (Map.Entry<Character, Object> characterObjectEntry : ingridients.entrySet()) {
+ for (Map.Entry<Character, Integer> characterIntegerEntry : amounts.entrySet()) {
+ if (characterObjectEntry.getKey() != characterIntegerEntry.getKey())
+ continue;
+ recipeAsMap.put(characterObjectEntry.getValue(), characterIntegerEntry.getValue());
+ }
+ }
+ List<ItemStack> inputs = new ArrayList<>();
+
+ for (Map.Entry<Object, Integer> o : recipeAsMap.entrySet()) {
+ if (o.getKey() instanceof ItemStack) {
+ ItemStack toAdd = ((ItemStack) o.getKey()).copy();
+ toAdd.stackSize = o.getValue();
+ inputs.add(toAdd);
+ } else if (o.getKey() instanceof String) {
+// System.out.println("Found OreDictEntry: "+o.getKey());
+ ItemStack stack = GT_OreDictUnificator.get(o.getKey(), o.getValue());
+ if (stack == null) {
+ Optional<ItemStack> oStack = OreDictionary.getOres((String) o.getKey())
+ .stream()
+ .findAny();
+ if (oStack.isPresent()) {
+ ItemStack copy = oStack.get().copy();
+ copy.stackSize = o.getValue();
+ inputs.add(copy);
+ }
+// else
+// System.out.println("OreDict Entry "+o.getKey()+" couldn't be found!");
+ } else {
+ ItemStack copy = stack.copy();
+ copy.stackSize = o.getValue();
+ inputs.add(copy);
+ }
+ } else if (o.getKey() instanceof Item)
+ inputs.add(new ItemStack((Item) o.getKey(), o.getValue()));
+ else if (o.getKey() instanceof Block)
+ inputs.add(new ItemStack((Block) o.getKey(), o.getValue()));
+ else
+ throw new IllegalStateException("A Recipe contains an invalid input! Output: " + output);
+ }
+
+ inputs.removeIf(x -> x.getItem() instanceof GT_MetaGenerated_Tool);
+
+ return Optional.of(
+ new GT_Recipe(
+ false,
+ new ItemStack[]{output},
+ inputs.toArray(new ItemStack[0]),
+ null, null,
+ null, null,
+ 300, 30, 0
+ )
+ );
+ }
}
diff --git a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Disassembler.java b/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Disassembler.java
index 4589940a14..92ed054b05 100644
--- a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Disassembler.java
+++ b/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Disassembler.java
@@ -120,6 +120,13 @@ public class GT_MetaTileEntity_Disassembler
}
private boolean process(){
+
+ GT_Recipe gt_recipe = GT_Recipe.GT_Recipe_Map.sDisassemblerRecipes.findRecipe(this.getBaseMetaTileEntity(), true, this.mEUt, null, this.getAllInputs());
+ if (gt_recipe != null) {
+ gt_recipe.isRecipeInputEqual(true, null, this.getRealInventory());
+ return setOutputsAndTime(gt_recipe.mOutputs, gt_recipe.mInputs[0].stackSize);
+ }
+
Collection<DissassembleReference> recipes = this.findRecipeFromMachine();
if (recipes.isEmpty())
return false;
@@ -131,6 +138,7 @@ public class GT_MetaTileEntity_Disassembler
recipe.inputs[i] = null;
recipe.inputs = GT_Utility.getArrayListWithoutNulls(recipe.inputs).toArray(new ItemStack[0]);
+
return setOutputsAndTime(recipe.inputs, recipe.stackSize);
}
@@ -160,12 +168,12 @@ public class GT_MetaTileEntity_Disassembler
.map(x -> x.recipe)
.collect(Collectors.toList());
- handleRecipeTranceformation(inputs, output, recipesColl);
+ handleRecipeTransformation(inputs, output, recipesColl);
return new DissassembleReference(recipes.stream().mapToInt(x -> x.stackSize).min().orElseThrow(NumberFormatException::new), output, null);
}
- private static void handleRecipeTranceformation(ItemStack[] inputs, ItemStack[] output, List<GT_Recipe> recipesColl) {
+ private static void handleRecipeTransformation(ItemStack[] inputs, ItemStack[] output, List<GT_Recipe> recipesColl) {
for (int i = 0, inputsLength = inputs.length; i < inputsLength; i++) {
Set<ItemStack[]> inputsStacks = null;
if (recipesColl != null)
@@ -183,6 +191,25 @@ public class GT_MetaTileEntity_Disassembler
addOthersAndHandleAlwaysReplace(inputs, output);
}
+ /**
+ * Public Interface for ReverseRecipes, do not call inside of this class.
+ * @param inputs
+ * @param output
+ * @param inputsStacks
+ */
+ public static void handleRecipeTransformation(ItemStack[] inputs, ItemStack[] output, Set<ItemStack[]> inputsStacks) {
+ for (int i = 0, inputsLength = inputs.length; i < inputsLength; i++) {
+ ItemStack input = inputs[i];
+ ItemData data = GT_OreDictUnificator.getItemData(input);
+ if (data == null || data.mMaterial == null || data.mMaterial.mMaterial == null || data.mPrefix == null) {
+ output[i] = input;
+ continue;
+ }
+ handleReplacement(inputsStacks, data, output, input, i);
+ }
+ addOthersAndHandleAlwaysReplace(inputs, output);
+ }
+
private static void addOthersAndHandleAlwaysReplace(ItemStack[] inputs, ItemStack[] output){
for (int i = 0; i < inputs.length; i++) {
//Adds rest of Items