From 2db36cb988b58ace9d91d6f7b636a6059507c873 Mon Sep 17 00:00:00 2001 From: bartimaeusnek <33183715+bartimaeusnek@users.noreply.github.com> Date: Mon, 21 Sep 2020 23:08:22 +0200 Subject: Disassembler rework Signed-off-by: bartimaeusnek <33183715+bartimaeusnek@users.noreply.github.com> --- .../java/gregtech/api/util/GT_Shaped_Recipe.java | 63 +++++++++++++++------- 1 file changed, 45 insertions(+), 18 deletions(-) (limited to 'src/main/java/gregtech/api/util/GT_Shaped_Recipe.java') 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 e51c490519..ea4182a16e 100644 --- a/src/main/java/gregtech/api/util/GT_Shaped_Recipe.java +++ b/src/main/java/gregtech/api/util/GT_Shaped_Recipe.java @@ -1,17 +1,20 @@ package gregtech.api.util; import gregtech.api.interfaces.internal.IGT_CraftingRecipe; -import gregtech.api.items.GT_MetaGenerated_Tool; +import net.minecraft.block.Block; 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 /*mDismantleable,*/ mRemovableByGT, mKeepingNBT; private final Enchantment[] mEnchantmentsAdded; private final int[] mEnchantmentLevelsAdded; @@ -21,7 +24,31 @@ public class GT_Shaped_Recipe extends ShapedOreRecipe implements IGT_CraftingRec mEnchantmentLevelsAdded = aEnchantmentLevelsAdded; mRemovableByGT = aRemovableByGT; mKeepingNBT = aKeepingNBT; - mDismantleable = aDismantleAble; +// 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) o)); + toPrint += " List"; + } 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); + } + } + //TODO: Register Dissassembler "Recipe" } @Override @@ -66,21 +93,21 @@ public class GT_Shaped_Recipe extends ShapedOreRecipe implements IGT_CraftingRec } // 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); - } +// 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++) -- cgit From 939441f7b24e5f6abb0b5534dfea715b4be6e5ed Mon Sep 17 00:00:00 2001 From: bartimaeusnek <33183715+bartimaeusnek@users.noreply.github.com> Date: Wed, 30 Dec 2020 23:30:33 +0100 Subject: Implemented ReverseRecipes --- .../java/gregtech/api/util/GT_Shaped_Recipe.java | 50 ++-------------------- 1 file changed, 4 insertions(+), 46 deletions(-) (limited to 'src/main/java/gregtech/api/util/GT_Shaped_Recipe.java') 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) o)); - toPrint += " List"; - } 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]); -- cgit