diff options
author | Jordan Byrne <draknyte1@hotmail.com> | 2018-04-20 00:14:08 +1000 |
---|---|---|
committer | Jordan Byrne <draknyte1@hotmail.com> | 2018-04-20 00:14:08 +1000 |
commit | 50db10656a85c8b4e64b5bcdaa497b933b4e6196 (patch) | |
tree | b11c9b7f0f30b8f7ba95df726aa73b98dc99d667 /src/Java/gtPlusPlus/xmod/gregtech/api/util | |
parent | ada14a51bd79b68ad37ff69ef0ad69610b7c73a6 (diff) | |
download | GT5-Unofficial-50db10656a85c8b4e64b5bcdaa497b933b4e6196.tar.gz GT5-Unofficial-50db10656a85c8b4e64b5bcdaa497b933b4e6196.tar.bz2 GT5-Unofficial-50db10656a85c8b4e64b5bcdaa497b933b4e6196.zip |
^ Version bump to 1.7.0-pre11-final.
$ Fixed many .08 compat issues stemming from use of newer NEI handler features in .09.
$ Redid a lot of GT_Recipe and Recipe_GT handling.
$ Fix to Adv. Vacuum Freezer recipe handling.
$ Fixed NEI not loading Multiblock Handler.
$ Fixed various crashed from NEI.
Diffstat (limited to 'src/Java/gtPlusPlus/xmod/gregtech/api/util')
-rw-r--r-- | src/Java/gtPlusPlus/xmod/gregtech/api/util/GregtechOreDictUnificator.java | 846 | ||||
-rw-r--r-- | src/Java/gtPlusPlus/xmod/gregtech/api/util/GregtechRecipeRegistrator.java | 371 |
2 files changed, 389 insertions, 828 deletions
diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/util/GregtechOreDictUnificator.java b/src/Java/gtPlusPlus/xmod/gregtech/api/util/GregtechOreDictUnificator.java index 28249ebfb5..69c95bc1ff 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/api/util/GregtechOreDictUnificator.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/api/util/GregtechOreDictUnificator.java @@ -1,473 +1,405 @@ package gtPlusPlus.xmod.gregtech.api.util; -import static gregtech.api.enums.GT_Values.*; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map.Entry; - -import net.minecraft.init.Items; -import net.minecraft.item.ItemStack; - import gregtech.api.GregTech_API; import gregtech.api.enums.Dyes; +import gregtech.api.enums.Materials; import gregtech.api.enums.OrePrefixes; import gregtech.api.enums.SubTag; import gregtech.api.objects.GT_HashSet; import gregtech.api.objects.GT_ItemStack; -import gregtech.api.util.GT_Log; -import gregtech.api.util.GT_ModHandler; -import gregtech.api.util.GT_Utility; -import gregtech.common.GT_Proxy.OreDictEventContainer; - -import gtPlusPlus.xmod.gregtech.api.enums.GregtechOrePrefixes; -import gtPlusPlus.xmod.gregtech.api.enums.GregtechOrePrefixes.GT_Materials; -import gtPlusPlus.xmod.gregtech.api.objects.GregtechItemData; -import gtPlusPlus.xmod.gregtech.api.objects.GregtechMaterialStack; -import net.minecraftforge.oredict.OreDictionary; - -/** - * NEVER INCLUDE THIS FILE IN YOUR MOD!!! - * <p/> - * This is the Core of my OreDict Unification Code - * <p/> - * If you just want to use this to unificate your Items, then use the Function in the GregTech_API File - * <p/> - * P.S. It is intended to be named "Unificator" and not "Unifier", because that sounds more awesome. - */ -public class GregtechOreDictUnificator { - private static final HashMap<String, ItemStack> sName2StackMap = new HashMap<>(); - private static final HashMap<GT_ItemStack, GregtechItemData> sItemStack2DataMap = new HashMap<>(); - private static final GT_HashSet<GT_ItemStack> sNoUnificationList = new GT_HashSet<>(); - public static volatile int VERSION = 508; - private static int isRegisteringOre = 0, isAddingOre = 0; - private static boolean mRunThroughTheList = true; - - static { - GregTech_API.sItemStackMappings.add(sItemStack2DataMap); - } - - /** - * The Blacklist just prevents the Item from being unificated into something else. - * Useful if you have things like the Industrial Diamond, which is better than regular Diamond, but also usable in absolutely all Diamond Recipes. - */ - public static void addToBlacklist(final ItemStack aStack) { - if (GT_Utility.isStackValid(aStack) && !GT_Utility.isStackInList(aStack, sNoUnificationList)) { - sNoUnificationList.add(aStack); - } - } - - public static boolean isBlacklisted(final ItemStack aStack) { - return GT_Utility.isStackInList(aStack, sNoUnificationList); - } - - public static void add(final GregtechOrePrefixes aPrefix, final GT_Materials aMaterial, final ItemStack aStack) { - set(aPrefix, aMaterial, aStack, false, false); - } - - public static void set(final GregtechOrePrefixes aPrefix, final GT_Materials aMaterial, final ItemStack aStack) { - set(aPrefix, aMaterial, aStack, true, false); - } - - public static void set(final GregtechOrePrefixes aPrefix, final GT_Materials aMaterial, ItemStack aStack, final boolean aOverwrite, final boolean aAlreadyRegistered) { - if ((aMaterial == null) || (aPrefix == null) || GT_Utility.isStackInvalid(aStack) || (Items.feather.getDamage(aStack) == W)) { - return; - } - isAddingOre++; - aStack = GT_Utility.copyAmount(1, aStack); - if (!aAlreadyRegistered) { - registerOre(aPrefix.get(aMaterial), aStack); - } - addAssociation(aPrefix, aMaterial, aStack, isBlacklisted(aStack)); - if (aOverwrite || GT_Utility.isStackInvalid(sName2StackMap.get(aPrefix.get(aMaterial).toString()))) { - sName2StackMap.put(aPrefix.get(aMaterial).toString(), aStack); - } - isAddingOre--; - } - - public static ItemStack getFirstOre(final Object aName, final long aAmount) { - if (GT_Utility.isStringInvalid(aName)) { - return null; - } - final ItemStack tStack = sName2StackMap.get(aName.toString()); - if (GT_Utility.isStackValid(tStack)) { - return GT_Utility.copyAmount(aAmount, tStack); - } - return GT_Utility.copyAmount(aAmount, getOres(aName).toArray()); - } - - public static ItemStack get(final Object aName, final long aAmount) { - return get(aName, null, aAmount, true, true); - } - - public static ItemStack get(final Object aName, final ItemStack aReplacement, final long aAmount) { - return get(aName, aReplacement, aAmount, true, true); - } - - public static ItemStack get(final GregtechOrePrefixes aPrefix, final Object aMaterial, final long aAmount) { - return get(aPrefix, aMaterial, null, aAmount); - } - - public static ItemStack get(final GregtechOrePrefixes aPrefix, final Object aMaterial, final ItemStack aReplacement, final long aAmount) { - return get(aPrefix.get(aMaterial), aReplacement, aAmount, false, true); - } - - public static ItemStack get(final Object aName, final ItemStack aReplacement, final long aAmount, final boolean aMentionPossibleTypos, final boolean aNoInvalidAmounts) { - if (aNoInvalidAmounts && (aAmount < 1)) { - return null; - } - if (!sName2StackMap.containsKey(aName.toString()) && aMentionPossibleTypos) { - GT_Log.err.println("Unknown Key for Unification, Typo? " + aName); - } - return GT_Utility.copyAmount(aAmount, sName2StackMap.get(aName.toString()), getFirstOre(aName, aAmount), aReplacement); - } - - public static ItemStack[] setStackArray(final boolean aUseBlackList, final ItemStack... aStacks) { - for (int i = 0; i < aStacks.length; i++) { - aStacks[i] = get(aUseBlackList, GT_Utility.copy(aStacks[i])); - } - return aStacks; - } - - public static ItemStack[] getStackArray(final boolean aUseBlackList, final Object... aStacks) { - final ItemStack[] rStacks = new ItemStack[aStacks.length]; - for (int i = 0; i < aStacks.length; i++) { - rStacks[i] = get(aUseBlackList, GT_Utility.copy(aStacks[i])); - } - return rStacks; - } - - public static ItemStack setStack(final ItemStack aStack) { - return setStack(true, aStack); - } - - public static ItemStack setStack(final boolean aUseBlackList, final ItemStack aStack) { - if (GT_Utility.isStackInvalid(aStack)) { - return aStack; - } - final ItemStack tStack = get(aUseBlackList, aStack); - if (GT_Utility.areStacksEqual(aStack, tStack)) { - return aStack; - } - aStack.func_150996_a(tStack.getItem()); - Items.feather.setDamage(aStack, Items.feather.getDamage(tStack)); - return aStack; - } - - public static ItemStack get(final ItemStack aStack) { - return get(true, aStack); - } - - public static ItemStack get(final boolean aUseBlackList, final ItemStack aStack) { - if (GT_Utility.isStackInvalid(aStack)) { - return null; - } - final GregtechItemData tPrefixMaterial = getAssociation(aStack); - ItemStack rStack = null; - if ((tPrefixMaterial == null) || !tPrefixMaterial.hasValidPrefixMaterialData() || (aUseBlackList && tPrefixMaterial.mBlackListed)) { - return GT_Utility.copy(aStack); - } - if (aUseBlackList && !GregTech_API.sUnificationEntriesRegistered && isBlacklisted(aStack)) { - tPrefixMaterial.mBlackListed = true; - return GT_Utility.copy(aStack); - } - if (tPrefixMaterial.mUnificationTarget == null) { - tPrefixMaterial.mUnificationTarget = sName2StackMap.get(tPrefixMaterial.toString()); - } - rStack = tPrefixMaterial.mUnificationTarget; - if (GT_Utility.isStackInvalid(rStack)) { - return GT_Utility.copy(aStack); - } - assert rStack != null; - rStack.setTagCompound(aStack.getTagCompound()); - return GT_Utility.copyAmount(aStack.stackSize, rStack); - } - - public static void addItemData(final ItemStack aStack, final GregtechItemData aData) { - if (GT_Utility.isStackValid(aStack) && (getItemData(aStack) == null) && (aData != null)) { - setItemData(aStack, aData); - } - } - - public static void setItemData(ItemStack aStack, final GregtechItemData aData) { - if (GT_Utility.isStackInvalid(aStack) || (aData == null)) { - return; - } - final GregtechItemData tData = getItemData(aStack); - if ((tData == null) || !tData.hasValidPrefixMaterialData()) { - if (tData != null) { - for (final Object tObject : tData.mExtraData) { - if (!aData.mExtraData.contains(tObject)) { - aData.mExtraData.add(tObject); - } - } - } - if (aStack.stackSize > 1) { - if (aData.mMaterial != null) { - aData.mMaterial.mAmount /= aStack.stackSize; - } - for (final GregtechMaterialStack tMaterial : aData.mByProducts) { - tMaterial.mAmount /= aStack.stackSize; - } - aStack = GT_Utility.copyAmount(1, aStack); - } - sItemStack2DataMap.put(new GT_ItemStack(aStack), aData); - if (aData.hasValidMaterialData()) { - long tValidMaterialAmount = aData.mMaterial.mMaterial.contains(SubTag.NO_RECYCLING) ? 0 : aData.mMaterial.mAmount >= 0 ? aData.mMaterial.mAmount : M; - for (final GregtechMaterialStack tMaterial : aData.mByProducts) { - tValidMaterialAmount += tMaterial.mMaterial.contains(SubTag.NO_RECYCLING) ? 0 : tMaterial.mAmount >= 0 ? tMaterial.mAmount : M; - } - if (tValidMaterialAmount < M) { - GT_ModHandler.addToRecyclerBlackList(aStack); - } - } - if (mRunThroughTheList) { - if (GregTech_API.sLoadStarted) { - mRunThroughTheList = false; - for (final Entry<GT_ItemStack, GregtechItemData> tEntry : sItemStack2DataMap.entrySet()) { - if (!tEntry.getValue().hasValidPrefixData() || tEntry.getValue().mPrefix.mAllowNormalRecycling) { - GregtechRecipeRegistrator.registerMaterialRecycling(tEntry.getKey().toStack(), tEntry.getValue()); - } - } - } - } else { - if (!aData.hasValidPrefixData() || aData.mPrefix.mAllowNormalRecycling) { - GregtechRecipeRegistrator.registerMaterialRecycling(aStack, aData); - } - } - } else { - for (final Object tObject : aData.mExtraData) { - if (!tData.mExtraData.contains(tObject)) { - tData.mExtraData.add(tObject); - } - } - } - } - - public static void addAssociation(final GregtechOrePrefixes aPrefix, final GT_Materials aMaterial, final ItemStack aStack, final boolean aBlackListed) { - if ((aPrefix == null) || (aMaterial == null) || GT_Utility.isStackInvalid(aStack)) { - return; - } - if (Items.feather.getDamage(aStack) == W) { - for (byte i = 0; i < 16; i++) { - setItemData(GT_Utility.copyAmountAndMetaData(1, i, aStack), new GregtechItemData(aPrefix, aMaterial, aBlackListed)); - } - } - setItemData(aStack, new GregtechItemData(aPrefix, aMaterial, aBlackListed)); - } - - public static GregtechItemData getItemData(final ItemStack aStack) { - if (GT_Utility.isStackInvalid(aStack)) { - return null; - } - GregtechItemData rData = sItemStack2DataMap.get(new GT_ItemStack(aStack)); - if (rData == null) { - rData = sItemStack2DataMap.get(new GT_ItemStack(GT_Utility.copyMetaData(W, aStack))); - } - return rData; - } +import gregtech.api.objects.ItemData; +import gregtech.api.objects.MaterialStack; +import gregtech.api.util.*; - public static GregtechItemData getAssociation(final ItemStack aStack) { - final GregtechItemData rData = getItemData(aStack); - return (rData != null) && rData.hasValidPrefixMaterialData() ? rData : null; - } +import gtPlusPlus.core.util.reflect.ReflectionUtils; - public static boolean isItemStackInstanceOf(final ItemStack aStack, final Object aName) { - if (GT_Utility.isStringInvalid(aName) || GT_Utility.isStackInvalid(aStack)) { - return false; - } - for (final ItemStack tOreStack : getOres(aName.toString())) { - if (GT_Utility.areStacksEqual(tOreStack, aStack, true)) { - return true; - } - } - return false; - } +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; +import net.minecraftforge.oredict.OreDictionary; - public static boolean isItemStackDye(final ItemStack aStack) { - if (GT_Utility.isStackInvalid(aStack)) { - return false; - } - for (final Dyes tDye : Dyes.VALUES) { - if (isItemStackInstanceOf(aStack, tDye.toString())) { - return true; - } - } - return false; - } +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; - public static boolean registerOre(final GregtechOrePrefixes aPrefix, final Object aMaterial, final ItemStack aStack) { - return registerOre(aPrefix.get(aMaterial), aStack); - } +import static gregtech.api.enums.GT_Values.*; - public static boolean registerOre(final Object aName, final ItemStack aStack) { - if ((aName == null) || GT_Utility.isStackInvalid(aStack)) { - return false; - } - final String tName = aName.toString(); - if (GT_Utility.isStringInvalid(tName)) { - return false; - } - final ArrayList<ItemStack> tList = getOres(tName); - for (int i = 0; i < tList.size(); i++) { - if (GT_Utility.areStacksEqual(tList.get(i), aStack, true)) { - return false; +public class GregtechOreDictUnificator { + + + private static final Map<String, ItemStack> sName2StackMap = new HashMap<String, ItemStack>(); + private static final Map<GT_ItemStack, ItemData> sItemStack2DataMap = new HashMap<GT_ItemStack, ItemData>(); + private static final Map<GT_ItemStack, List<ItemStack>> sUnificationTable = new HashMap<GT_ItemStack, List<ItemStack>>(); + private static final GT_HashSet<GT_ItemStack> sNoUnificationList = new GT_HashSet<GT_ItemStack>(); + + + private static int isRegisteringOre = 0, isAddingOre = 0; + private static boolean mRunThroughTheList = true; + + static { + try { + if (ReflectionUtils.getField(GT_OreDictUnificator.class, "sUnificationTable") == null) { + GregTech_API.sItemStackMappings.add(sUnificationTable); } } - isRegisteringOre++; - OreDictionary.registerOre(tName, GT_Utility.copyAmount(1, aStack)); - isRegisteringOre--; - return true; - } - - public static boolean isRegisteringOres() { - return isRegisteringOre > 0; - } - - public static boolean isAddingOres() { - return isAddingOre > 0; - } - - public static void resetUnificationEntries() { - for (final GregtechItemData tPrefixMaterial : sItemStack2DataMap.values()) { - tPrefixMaterial.mUnificationTarget = null; - } - } - - public static ItemStack getGem(final GregtechMaterialStack aMaterial) { - return aMaterial == null ? null : getGem(aMaterial.mMaterial, aMaterial.mAmount); - } - - public static ItemStack getGem(final GT_Materials aMaterial, final OrePrefixes aPrefix) { - return aMaterial == null ? null : getGem(aMaterial, aPrefix.mMaterialAmount); - } - - public static ItemStack getGem(final GT_Materials aMaterial, final long aMaterialAmount) { - ItemStack rStack = null; - if (((aMaterialAmount >= M) || (aMaterialAmount >= (M * 32)))) { - rStack = get(GregtechOrePrefixes.gem, aMaterial, aMaterialAmount / M); - } - if ((rStack == null) && ((((aMaterialAmount * 2) % M) == 0) || (aMaterialAmount >= (M * 16)))) { - rStack = get(GregtechOrePrefixes.gemFlawed, aMaterial, (aMaterialAmount * 2) / M); - } - if ((rStack == null) && (((aMaterialAmount * 4) >= M))) { - rStack = get(GregtechOrePrefixes.gemChipped, aMaterial, (aMaterialAmount * 4) / M); - } - return rStack; - } - - public static ItemStack getDust(final GregtechMaterialStack aMaterial) { - return aMaterial == null ? null : getDust(aMaterial.mMaterial, aMaterial.mAmount); - } - - public static ItemStack getDust(final GT_Materials aMaterial, final OrePrefixes aPrefix) { - return aMaterial == null ? null : getDust(aMaterial, aPrefix.mMaterialAmount); - } - - public static ItemStack getDust(final GT_Materials aMaterial, final long aMaterialAmount) { - if (aMaterialAmount <= 0) { - return null; - } - ItemStack rStack = null; - if ((((aMaterialAmount % M) == 0) || (aMaterialAmount >= (M * 16)))) { - rStack = get(GregtechOrePrefixes.dust, aMaterial, aMaterialAmount / M); - } - if ((rStack == null) && ((((aMaterialAmount * 4) % M) == 0) || (aMaterialAmount >= (M * 8)))) { - rStack = get(GregtechOrePrefixes.dustSmall, aMaterial, (aMaterialAmount * 4) / M); - } - if ((rStack == null) && (((aMaterialAmount * 9) >= M))) { - rStack = get(GregtechOrePrefixes.dustTiny, aMaterial, (aMaterialAmount * 9) / M); - } - return rStack; - } - - public static ItemStack getIngot(final GregtechMaterialStack aMaterial) { - return aMaterial == null ? null : getIngot(aMaterial.mMaterial, aMaterial.mAmount); - } - - public static ItemStack getIngot(final GT_Materials aMaterial, final OrePrefixes aPrefix) { - return aMaterial == null ? null : getIngot(aMaterial, aPrefix.mMaterialAmount); - } - - public static ItemStack getIngot(final GT_Materials aMaterial, final long aMaterialAmount) { - if (aMaterialAmount <= 0) { - return null; - } - ItemStack rStack = null; - if (((((aMaterialAmount % (M * 9)) == 0) && ((aMaterialAmount / (M * 9)) > 1)) || (aMaterialAmount >= (M * 72)))) { - rStack = get(GregtechOrePrefixes.block, aMaterial, aMaterialAmount / (M * 9)); - } - if ((rStack == null) && (((aMaterialAmount % M) == 0) || (aMaterialAmount >= (M * 8)))) { - rStack = get(GregtechOrePrefixes.ingot, aMaterial, aMaterialAmount / M); - } - if ((rStack == null) && (((aMaterialAmount * 9) >= M))) { - rStack = get(GregtechOrePrefixes.nugget, aMaterial, (aMaterialAmount * 9) / M); - } - return rStack; - } - - public static ItemStack getIngotOrDust(final GT_Materials aMaterial, final long aMaterialAmount) { - if (aMaterialAmount <= 0) { - return null; - } - ItemStack rStack = getIngot(aMaterial, aMaterialAmount); - if (rStack == null) { - rStack = getDust(aMaterial, aMaterialAmount); - } - return rStack; - } - - public static ItemStack getIngotOrDust(final GregtechMaterialStack aMaterial) { - ItemStack rStack = getIngot(aMaterial); - if((aMaterial!=null)&&(aMaterial.mMaterial!=null)) { - rStack = getDust(aMaterial); - } - if (rStack == null) { - rStack = getDust(aMaterial); - } - return rStack; - } - - public static ItemStack getDustOrIngot(final GT_Materials aMaterial, final long aMaterialAmount) { - if (aMaterialAmount <= 0) { - return null; - } - ItemStack rStack = getDust(aMaterial, aMaterialAmount); - if (rStack == null) { - rStack = getIngot(aMaterial, aMaterialAmount); - } - return rStack; - } - - public static ItemStack getDustOrIngot(final GregtechMaterialStack aMaterial) { - ItemStack rStack = getDust(aMaterial); - if (rStack == null) { - rStack = getIngot(aMaterial); - } - return rStack; - } - - /** - * @return a Copy of the OreDictionary.getOres() List - */ - public static ArrayList<ItemStack> getOres(final OrePrefixes aPrefix, final Object aMaterial) { - return getOres(aPrefix.get(aMaterial)); - } - - /** - * @return a Copy of the OreDictionary.getOres() List - */ - public static ArrayList<ItemStack> getOres(final Object aOreName) { - final String aName = aOreName == null ? E : aOreName.toString(); - final ArrayList<ItemStack> rList = new ArrayList<>(); - if (GT_Utility.isStringValid(aName)) { - rList.addAll(OreDictionary.getOres(aName)); - } - return rList; - } - - public static void registerRecipes(final OreDictEventContainer tOre) { - // TODO Auto-generated method stub - - } + catch (NoSuchFieldException e) {} + } + + /** + * The Blacklist just prevents the Item from being unificated into something else. + * Useful if you have things like the Industrial Diamond, which is better than regular Diamond, but also usable in absolutely all Diamond Recipes. + */ + public static void addToBlacklist(ItemStack aStack) { + if (GT_Utility.isStackValid(aStack) && !GT_Utility.isStackInList(aStack, sNoUnificationList)) + sNoUnificationList.add(aStack); + } + + public static boolean isBlacklisted(ItemStack aStack) { + return GT_Utility.isStackInList(aStack, sNoUnificationList); + } + + public static void add(OrePrefixes aPrefix, Materials aMaterial, ItemStack aStack) { + set(aPrefix, aMaterial, aStack, false, false); + } + + public static void set(OrePrefixes aPrefix, Materials aMaterial, ItemStack aStack) { + set(aPrefix, aMaterial, aStack, true, false); + } + + public static void set(OrePrefixes aPrefix, Materials aMaterial, ItemStack aStack, boolean aOverwrite, boolean aAlreadyRegistered) { + if (aMaterial == null || aPrefix == null || GT_Utility.isStackInvalid(aStack) || Items.feather.getDamage(aStack) == W) + return; + isAddingOre++; + aStack = GT_Utility.copyAmount(1, aStack); + if (!aAlreadyRegistered) registerOre(aPrefix.get(aMaterial), aStack); + addAssociation(aPrefix, aMaterial, aStack, isBlacklisted(aStack)); + if (aOverwrite || GT_Utility.isStackInvalid(sName2StackMap.get(aPrefix.get(aMaterial).toString()))) + sName2StackMap.put(aPrefix.get(aMaterial).toString(), aStack); + isAddingOre--; + } + + public static ItemStack getFirstOre(Object aName, long aAmount) { + if (GT_Utility.isStringInvalid(aName)) return null; + ItemStack tStack = sName2StackMap.get(aName.toString()); + if (GT_Utility.isStackValid(tStack)) return GT_Utility.copyAmount(aAmount, tStack); + return GT_Utility.copyAmount(aAmount, getOres(aName).toArray()); + } + + public static ItemStack get(Object aName, long aAmount) { + return get(aName, null, aAmount, true, true); + } + + public static ItemStack get(Object aName, ItemStack aReplacement, long aAmount) { + return get(aName, aReplacement, aAmount, true, true); + } + + public static ItemStack get(OrePrefixes aPrefix, Object aMaterial, long aAmount) { + return get(aPrefix, aMaterial, null, aAmount); + } + + public static ItemStack get(OrePrefixes aPrefix, Object aMaterial, ItemStack aReplacement, long aAmount) { + //if (Materials.mDefaultComponents.contains(aPrefix) && !aPrefix.mDynamicItems.contains((Materials)aMaterial)) aPrefix.mDynamicItems.add((Materials) aMaterial); + if (OrePrefixes.mPreventableComponents.contains(aPrefix) && aPrefix.mDisabledItems.contains(aMaterial)) return aReplacement; + return get(aPrefix.get(aMaterial), aReplacement, aAmount, false, true); + } + + public static ItemStack get(Object aName, ItemStack aReplacement, long aAmount, boolean aMentionPossibleTypos, boolean aNoInvalidAmounts) { + if (aNoInvalidAmounts && aAmount < 1) return null; + if (!sName2StackMap.containsKey(aName.toString()) && aMentionPossibleTypos) + GT_Log.err.println("Unknown Key for Unification, Typo? " + aName); + return GT_Utility.copyAmount(aAmount, sName2StackMap.get(aName.toString()), getFirstOre(aName, aAmount), aReplacement); + } + + public static ItemStack[] setStackArray(boolean aUseBlackList, ItemStack... aStacks) { + for (int i = 0; i < aStacks.length; i++) aStacks[i] = get(aUseBlackList, GT_Utility.copy(aStacks[i])); + return aStacks; + } + + public static ItemStack[] getStackArray(boolean aUseBlackList, Object... aStacks) { + ItemStack[] rStacks = new ItemStack[aStacks.length]; + for (int i = 0; i < aStacks.length; i++) rStacks[i] = get(aUseBlackList, GT_Utility.copy(aStacks[i])); + return rStacks; + } + + public static ItemStack setStack(ItemStack aStack) { + return setStack(true, aStack); + } + + public static ItemStack setStack(boolean aUseBlackList, ItemStack aStack) { + if (GT_Utility.isStackInvalid(aStack)) return aStack; + ItemStack tStack = get(aUseBlackList, aStack); + if (GT_Utility.areStacksEqual(aStack, tStack)) return aStack; + aStack.func_150996_a(tStack.getItem()); + Items.feather.setDamage(aStack, Items.feather.getDamage(tStack)); + return aStack; + } + + public static ItemStack get(ItemStack aStack) { + return get(true, aStack); + } + + public static ItemStack get(boolean aUseBlackList, ItemStack aStack) { + return get(aUseBlackList, aStack, false); + } + + public static ItemStack get(boolean aUseBlackList, ItemStack aStack, boolean aOnUnificationTableCreation) { + if (GT_Utility.isStackInvalid(aStack)) return null; + ItemData tPrefixMaterial = getAssociation(aStack); + ItemStack rStack = null; + if (tPrefixMaterial == null || !tPrefixMaterial.hasValidPrefixMaterialData() || (aUseBlackList && tPrefixMaterial.mBlackListed)) + return GT_Utility.copy(aStack); + if (aUseBlackList && !GregTech_API.sUnificationEntriesRegistered && isBlacklisted(aStack)) { + tPrefixMaterial.mBlackListed = true; + return GT_Utility.copy(aStack); + } + if (tPrefixMaterial.mUnificationTarget == null) { + tPrefixMaterial.mUnificationTarget = sName2StackMap.get(tPrefixMaterial.toString()); + if (!aOnUnificationTableCreation) sUnificationTable.clear(); + } + rStack = tPrefixMaterial.mUnificationTarget; + if (GT_Utility.isStackInvalid(rStack)) return GT_Utility.copy(aStack); + assert rStack != null; + rStack.setTagCompound(aStack.getTagCompound()); + return GT_Utility.copyAmount(aStack.stackSize, rStack); + } + + public static List<ItemStack> getNonUnifiedStacks(Object obj) { + synchronized (sUnificationTable) { + if (sUnificationTable.isEmpty() && !sItemStack2DataMap.isEmpty()) { + for (GT_ItemStack tGTStack0 : sItemStack2DataMap.keySet()) { + ItemStack tStack0 = tGTStack0.toStack(); + ItemStack tStack1 = get(false, tStack0, true); + if (tStack0 != null && tStack1 != null && !GT_Utility.areStacksEqual(tStack0, tStack1)) { + GT_ItemStack tGTStack1 = new GT_ItemStack(tStack1); + List<ItemStack> list = sUnificationTable.get(tGTStack1); + if (list == null) sUnificationTable.put(tGTStack1, list = new ArrayList<ItemStack>()); + if (!list.contains(tStack0)) list.add(tStack0); + } + } + } + } + ItemStack[] aStacks = {}; + if (obj instanceof ItemStack) aStacks = new ItemStack[]{(ItemStack) obj}; + else if (obj instanceof ItemStack[]) aStacks = (ItemStack[]) obj; + else if (obj instanceof List) aStacks = (ItemStack[]) ((List)obj).toArray(new ItemStack[0]); + List<ItemStack> rList = new ArrayList<ItemStack>(); + for (ItemStack aStack : aStacks) { + rList.add(aStack); + List<ItemStack> tList = sUnificationTable.get(new GT_ItemStack(aStack)); + if (tList != null) { + for (ItemStack tStack : tList) { + ItemStack tStack1 = GT_Utility.copyAmount(aStack.stackSize, tStack); + tStack1.setTagCompound(aStack.getTagCompound()); + rList.add(tStack1); + } + } + } + return rList; + } + + public static void addItemData(ItemStack aStack, ItemData aData) { + if (GT_Utility.isStackValid(aStack) && getItemData(aStack) == null && aData != null) setItemData(aStack, aData); + } + + public static void setItemData(ItemStack aStack, ItemData aData) { + if (GT_Utility.isStackInvalid(aStack) || aData == null) return; + ItemData tData = getItemData(aStack); + if (tData == null || !tData.hasValidPrefixMaterialData()) { + if (tData != null) for (Object tObject : tData.mExtraData) + if (!aData.mExtraData.contains(tObject)) aData.mExtraData.add(tObject); + if (aStack.stackSize > 1) { + if (aData.mMaterial != null) aData.mMaterial.mAmount /= aStack.stackSize; + for (MaterialStack tMaterial : aData.mByProducts) tMaterial.mAmount /= aStack.stackSize; + aStack = GT_Utility.copyAmount(1, aStack); + } + sItemStack2DataMap.put(new GT_ItemStack(aStack), aData); + if (aData.hasValidMaterialData()) { + long tValidMaterialAmount = aData.mMaterial.mMaterial.contains(SubTag.NO_RECYCLING) ? 0 : aData.mMaterial.mAmount >= 0 ? aData.mMaterial.mAmount : M; + for (MaterialStack tMaterial : aData.mByProducts) + tValidMaterialAmount += tMaterial.mMaterial.contains(SubTag.NO_RECYCLING) ? 0 : tMaterial.mAmount >= 0 ? tMaterial.mAmount : M; + if (tValidMaterialAmount < M) GT_ModHandler.addToRecyclerBlackList(aStack); + } + if (mRunThroughTheList) { + if (GregTech_API.sLoadStarted) { + mRunThroughTheList = false; + for (Entry<GT_ItemStack, ItemData> tEntry : sItemStack2DataMap.entrySet()) + if (!tEntry.getValue().hasValidPrefixData() || tEntry.getValue().mPrefix.mAllowNormalRecycling) + GT_RecipeRegistrator.registerMaterialRecycling(tEntry.getKey().toStack(), tEntry.getValue()); + } + } else { + if (!aData.hasValidPrefixData() || aData.mPrefix.mAllowNormalRecycling) + GT_RecipeRegistrator.registerMaterialRecycling(aStack, aData); + } + } else { + for (Object tObject : aData.mExtraData) + if (!tData.mExtraData.contains(tObject)) tData.mExtraData.add(tObject); + } + } + + public static void addAssociation(OrePrefixes aPrefix, Materials aMaterial, ItemStack aStack, boolean aBlackListed) { + if (aPrefix == null || aMaterial == null || GT_Utility.isStackInvalid(aStack)) return; + if (Items.feather.getDamage(aStack) == W) for (byte i = 0; i < 16; i++) + setItemData(GT_Utility.copyAmountAndMetaData(1, i, aStack), new ItemData(aPrefix, aMaterial, aBlackListed)); + setItemData(aStack, new ItemData(aPrefix, aMaterial, aBlackListed)); + } + + public static ItemData getItemData(ItemStack aStack) { + if (GT_Utility.isStackInvalid(aStack)) return null; + ItemData rData = sItemStack2DataMap.get(new GT_ItemStack(aStack)); + if (rData == null) rData = sItemStack2DataMap.get(new GT_ItemStack(GT_Utility.copyMetaData(W, aStack))); + return rData; + } + + public static ItemData getAssociation(ItemStack aStack) { + ItemData rData = getItemData(aStack); + return rData != null && rData.hasValidPrefixMaterialData() ? rData : null; + } + + public static boolean isItemStackInstanceOf(ItemStack aStack, Object aName) { + if (GT_Utility.isStringInvalid(aName) || GT_Utility.isStackInvalid(aStack)) return false; + for (ItemStack tOreStack : getOres(aName.toString())) + if (GT_Utility.areStacksEqual(tOreStack, aStack, true)) return true; + return false; + } + + public static boolean isItemStackDye(ItemStack aStack) { + if (GT_Utility.isStackInvalid(aStack)) return false; + for (Dyes tDye : Dyes.VALUES) if (isItemStackInstanceOf(aStack, tDye.toString())) return true; + return false; + } + + public static boolean registerOre(OrePrefixes aPrefix, Object aMaterial, ItemStack aStack) { + return registerOre(aPrefix.get(aMaterial), aStack); + } + + public static boolean registerOre(Object aName, ItemStack aStack) { + if (aName == null || GT_Utility.isStackInvalid(aStack)) return false; + String tName = aName.toString(); + if (GT_Utility.isStringInvalid(tName)) return false; + ArrayList<ItemStack> tList = getOres(tName); + for (int i = 0; i < tList.size(); i++) if (GT_Utility.areStacksEqual(tList.get(i), aStack, true)) return false; + isRegisteringOre++; + OreDictionary.registerOre(tName, GT_Utility.copyAmount(1, aStack)); + isRegisteringOre--; + return true; + } + + public static boolean isRegisteringOres() { + return isRegisteringOre > 0; + } + + public static boolean isAddingOres() { + return isAddingOre > 0; + } + + public static void resetUnificationEntries() { + for (ItemData tPrefixMaterial : sItemStack2DataMap.values()) tPrefixMaterial.mUnificationTarget = null; + sUnificationTable.clear(); + } + + public static ItemStack getGem(MaterialStack aMaterial) { + return aMaterial == null ? null : getGem(aMaterial.mMaterial, aMaterial.mAmount); + } + + public static ItemStack getGem(Materials aMaterial, OrePrefixes aPrefix) { + return aMaterial == null ? null : getGem(aMaterial, aPrefix.mMaterialAmount); + } + + public static ItemStack getGem(Materials aMaterial, long aMaterialAmount) { + ItemStack rStack = null; + if (((aMaterialAmount >= M))) + rStack = get(OrePrefixes.gem, aMaterial, aMaterialAmount / M); + if (rStack == null) { + if ((((aMaterialAmount * 2) % M == 0) || aMaterialAmount >= M * 16)) + rStack = get(OrePrefixes.gemFlawed, aMaterial, (aMaterialAmount * 2) / M); + if ((((aMaterialAmount * 4) >= M))) + rStack = get(OrePrefixes.gemChipped, aMaterial, (aMaterialAmount * 4) / M); + } + return rStack; + } + + public static ItemStack getDust(MaterialStack aMaterial) { + return aMaterial == null ? null : getDust(aMaterial.mMaterial, aMaterial.mAmount); + } + + public static ItemStack getDust(Materials aMaterial, OrePrefixes aPrefix) { + return aMaterial == null ? null : getDust(aMaterial, aPrefix.mMaterialAmount); + } + + public static ItemStack getDust(Materials aMaterial, long aMaterialAmount) { + if (aMaterialAmount <= 0) return null; + ItemStack rStack = null; + if (((aMaterialAmount % M == 0) || aMaterialAmount >= M * 16)) + rStack = get(OrePrefixes.dust, aMaterial, aMaterialAmount / M); + if (rStack == null && (((aMaterialAmount * 4) % M == 0) || aMaterialAmount >= M * 8)) + rStack = get(OrePrefixes.dustSmall, aMaterial, (aMaterialAmount * 4) / M); + if (rStack == null && (((aMaterialAmount * 9) >= M))) + rStack = get(OrePrefixes.dustTiny, aMaterial, (aMaterialAmount * 9) / M); + return rStack; + } + + public static ItemStack getIngot(MaterialStack aMaterial) { + return aMaterial == null ? null : getIngot(aMaterial.mMaterial, aMaterial.mAmount); + } + + public static ItemStack getIngot(Materials aMaterial, OrePrefixes aPrefix) { + return aMaterial == null ? null : getIngot(aMaterial, aPrefix.mMaterialAmount); + } + + public static ItemStack getIngot(Materials aMaterial, long aMaterialAmount) { + if (aMaterialAmount <= 0) return null; + ItemStack rStack = null; + if (((aMaterialAmount % (M * 9) == 0 && aMaterialAmount / (M * 9) > 1) || aMaterialAmount >= M * 72)) + rStack = get(OrePrefixes.block, aMaterial, aMaterialAmount / (M * 9)); + if (rStack == null && ((aMaterialAmount % M == 0) || aMaterialAmount >= M * 8)) + rStack = get(OrePrefixes.ingot, aMaterial, aMaterialAmount / M); + if (rStack == null && (((aMaterialAmount * 9) >= M))) + rStack = get(OrePrefixes.nugget, aMaterial, (aMaterialAmount * 9) / M); + return rStack; + } + + public static ItemStack getIngotOrDust(Materials aMaterial, long aMaterialAmount) { + if (aMaterialAmount <= 0) return null; + ItemStack rStack = getIngot(aMaterial, aMaterialAmount); + if (rStack == null) rStack = getDust(aMaterial, aMaterialAmount); + return rStack; + } + + public static ItemStack getIngotOrDust(MaterialStack aMaterial) { + ItemStack rStack = getIngot(aMaterial); + if(aMaterial!=null&&aMaterial.mMaterial!=null&&(aMaterial.mMaterial==Materials.Naquadah||aMaterial.mMaterial==Materials.NaquadahEnriched))rStack = getDust(aMaterial); + if (rStack == null) rStack = getDust(aMaterial); + return rStack; + } + + public static ItemStack getDustOrIngot(Materials aMaterial, long aMaterialAmount) { + if (aMaterialAmount <= 0) return null; + ItemStack rStack = getDust(aMaterial, aMaterialAmount); + if (rStack == null) rStack = getIngot(aMaterial, aMaterialAmount); + return rStack; + } + + public static ItemStack getDustOrIngot(MaterialStack aMaterial) { + ItemStack rStack = getDust(aMaterial); + if (rStack == null) rStack = getIngot(aMaterial); + return rStack; + } + + /** + * @return a Copy of the OreDictionary.getOres() List + */ + public static ArrayList<ItemStack> getOres(OrePrefixes aPrefix, Object aMaterial) { + return getOres(aPrefix.get(aMaterial)); + } + + /** + * @return a Copy of the OreDictionary.getOres() List + */ + public static ArrayList<ItemStack> getOres(Object aOreName) { + String aName = aOreName == null ? E : aOreName.toString(); + ArrayList<ItemStack> rList = new ArrayList<ItemStack>(); + if (GT_Utility.isStringValid(aName)) rList.addAll(OreDictionary.getOres(aName)); + return rList; + } } diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/util/GregtechRecipeRegistrator.java b/src/Java/gtPlusPlus/xmod/gregtech/api/util/GregtechRecipeRegistrator.java deleted file mode 100644 index be718974d9..0000000000 --- a/src/Java/gtPlusPlus/xmod/gregtech/api/util/GregtechRecipeRegistrator.java +++ /dev/null @@ -1,371 +0,0 @@ -package gtPlusPlus.xmod.gregtech.api.util; - -import static gregtech.api.enums.GT_Values.*; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import net.minecraft.init.Blocks; -import net.minecraft.init.Items; -import net.minecraft.item.ItemStack; - -import gregtech.api.GregTech_API; -import gregtech.api.enums.*; -import gregtech.api.enums.TC_Aspects.TC_AspectStack; -import gregtech.api.interfaces.internal.IThaumcraftCompat; -import gregtech.api.util.GT_ModHandler; -import gregtech.api.util.GT_Utility; - -import gtPlusPlus.core.lib.CORE; -import gtPlusPlus.xmod.gregtech.api.enums.GregtechOrePrefixes; -import gtPlusPlus.xmod.gregtech.api.enums.GregtechOrePrefixes.GT_Materials; -import gtPlusPlus.xmod.gregtech.api.objects.GregtechItemData; -import gtPlusPlus.xmod.gregtech.api.objects.GregtechMaterialStack; - -/** - * Class for Automatic Recipe registering. - */ -public class GregtechRecipeRegistrator { - /** - * List of GT_Materials, which are used in the Creation of Sticks. All Rod GT_Materials are automatically added to this List. - */ - public static final List<GT_Materials> sRodMaterialList = new ArrayList<>(); - private static final ItemStack sMt1 = new ItemStack(Blocks.dirt, 1, 0), sMt2 = new ItemStack(Blocks.dirt, 1, 0); - private static final String s_H = "h", s_F = "f", s_I = "I", s_P = "P", s_R = "R"; - private static final ItemStack[][] - sShapes1 = new ItemStack[][]{ - {sMt1, null, sMt1, sMt1, sMt1, sMt1, null, sMt1, null}, - {sMt1, null, sMt1, sMt1, null, sMt1, sMt1, sMt1, sMt1}, - {null, sMt1, null, sMt1, sMt1, sMt1, sMt1, null, sMt1}, - {sMt1, sMt1, sMt1, sMt1, null, sMt1, null, null, null}, - {sMt1, null, sMt1, sMt1, sMt1, sMt1, sMt1, sMt1, sMt1}, - {sMt1, sMt1, sMt1, sMt1, null, sMt1, sMt1, null, sMt1}, - {null, null, null, sMt1, null, sMt1, sMt1, null, sMt1}, - {null, sMt1, null, null, sMt1, null, null, sMt2, null}, - {sMt1, sMt1, sMt1, null, sMt2, null, null, sMt2, null}, - {null, sMt1, null, null, sMt2, null, null, sMt2, null}, - {sMt1, sMt1, null, sMt1, sMt2, null, null, sMt2, null}, - {null, sMt1, sMt1, null, sMt2, sMt1, null, sMt2, null}, - {sMt1, sMt1, null, null, sMt2, null, null, sMt2, null}, - {null, sMt1, sMt1, null, sMt2, null, null, sMt2, null}, - {null, sMt1, null, sMt1, null, null, null, sMt1, sMt2}, - {null, sMt1, null, null, null, sMt1, sMt2, sMt1, null}, - {null, sMt1, null, sMt1, null, sMt1, null, null, sMt2}, - {null, sMt1, null, sMt1, null, sMt1, sMt2, null, null}, - {null, sMt2, null, null, sMt1, null, null, sMt1, null}, - {null, sMt2, null, null, sMt2, null, sMt1, sMt1, sMt1}, - {null, sMt2, null, null, sMt2, null, null, sMt1, null}, - {null, sMt2, null, sMt1, sMt2, null, sMt1, sMt1, null}, - {null, sMt2, null, null, sMt2, sMt1, null, sMt1, sMt1}, - {null, sMt2, null, null, sMt2, null, sMt1, sMt1, null}, - {sMt1, null, null, null, sMt2, null, null, null, sMt2}, - {null, null, sMt1, null, sMt2, null, sMt2, null, null}, - {sMt1, null, null, null, sMt2, null, null, null, null}, - {null, null, sMt1, null, sMt2, null, null, null, null}, - {sMt1, sMt2, null, null, null, null, null, null, null}, - {sMt2, sMt1, null, null, null, null, null, null, null}, - {sMt1, null, null, sMt2, null, null, null, null, null}, - {sMt2, null, null, sMt1, null, null, null, null, null}, - {sMt1, sMt1, sMt1, sMt1, sMt1, sMt1, null, sMt2, null}, - {sMt1, sMt1, null, sMt1, sMt1, sMt2, sMt1, sMt1, null}, - {null, sMt1, sMt1, sMt2, sMt1, sMt1, null, sMt1, sMt1}, - {null, sMt2, null, sMt1, sMt1, sMt1, sMt1, sMt1, sMt1}, - {sMt1, sMt1, sMt1, sMt1, sMt2, sMt1, null, sMt2, null}, - {sMt1, sMt1, null, sMt1, sMt2, sMt2, sMt1, sMt1, null}, - {null, sMt1, sMt1, sMt2, sMt2, sMt1, null, sMt1, sMt1}, - {null, sMt2, null, sMt1, sMt2, sMt1, sMt1, sMt1, sMt1}, - {sMt1, null, null, null, sMt1, null, null, null, null}, - {null, sMt1, null, sMt1, null, null, null, null, null}, - {sMt1, sMt1, null, sMt2, null, sMt1, sMt2, null, null}, - {null, sMt1, sMt1, sMt1, null, sMt2, null, null, sMt2} - }; - private static final String[][] sShapesA = new String[][]{ - null, - null, - null, - {"Helmet", s_P + s_P + s_P, s_P + s_H + s_P}, - {"ChestPlate", s_P + s_H + s_P, s_P + s_P + s_P, s_P + s_P + s_P}, - {"Pants", s_P + s_P + s_P, s_P + s_H + s_P, s_P + " " + s_P}, - {"Boots", s_P + " " + s_P, s_P + s_H + s_P}, - {"Sword", " " + s_P + " ", s_F + s_P + s_H, " " + s_R + " "}, - {"Pickaxe", s_P + s_I + s_I, s_F + s_R + s_H, " " + s_R + " "}, - {"Shovel", s_F + s_P + s_H, " " + s_R + " ", " " + s_R + " "}, - {"Axe", s_P + s_I + s_H, s_P + s_R + " ", s_F + s_R + " "}, - {"Axe", s_P + s_I + s_H, s_P + s_R + " ", s_F + s_R + " "}, - {"Hoe", s_P + s_I + s_H, s_F + s_R + " ", " " + s_R + " "}, - {"Hoe", s_P + s_I + s_H, s_F + s_R + " ", " " + s_R + " "}, - {"Sickle", " " + s_P + " ", s_P + s_F + " ", s_H + s_P + s_R}, - {"Sickle", " " + s_P + " ", s_P + s_F + " ", s_H + s_P + s_R}, - {"Sickle", " " + s_P + " ", s_P + s_F + " ", s_H + s_P + s_R}, - {"Sickle", " " + s_P + " ", s_P + s_F + " ", s_H + s_P + s_R}, - {"Sword", " " + s_R + " ", s_F + s_P + s_H, " " + s_P + " "}, - {"Pickaxe", " " + s_R + " ", s_F + s_R + s_H, s_P + s_I + s_I}, - {"Shovel", " " + s_R + " ", " " + s_R + " ", s_F + s_P + s_H}, - {"Axe", s_F + s_R + " ", s_P + s_R + " ", s_P + s_I + s_H}, - {"Axe", s_F + s_R + " ", s_P + s_R + " ", s_P + s_I + s_H}, - {"Hoe", " " + s_R + " ", s_F + s_R + " ", s_P + s_I + s_H}, - {"Hoe", " " + s_R + " ", s_F + s_R + " ", s_P + s_I + s_H}, - {"Spear", s_P + s_H + " ", s_F + s_R + " ", " " + " " + s_R}, - {"Spear", s_P + s_H + " ", s_F + s_R + " ", " " + " " + s_R}, - {"Knive", s_H + s_P, s_R + s_F}, - {"Knive", s_F + s_H, s_P + s_R}, - {"Knive", s_F + s_H, s_P + s_R}, - {"Knive", s_P + s_F, s_R + s_H}, - {"Knive", s_P + s_F, s_R + s_H}, - null, - null, - null, - null, - {"WarAxe", s_P + s_P + s_P, s_P + s_R + s_P, s_F + s_R + s_H}, - null, - null, - null, - {"Shears", s_H + s_P, s_P + s_F}, - {"Shears", s_H + s_P, s_P + s_F}, - {"Scythe", s_I + s_P + s_H, s_R + s_F + s_P, s_R + " " + " "}, - {"Scythe", s_H + s_P + s_I, s_P + s_F + s_R, " " + " " + s_R} - }; - public static volatile int VERSION = 508; - - public static void registerMaterialRecycling(final ItemStack aStack, final GT_Materials aMaterial, final long aMaterialAmount, GregtechMaterialStack aByproduct) { - if (GT_Utility.isStackInvalid(aStack)) { - return; - } - if (aByproduct != null) { - aByproduct = aByproduct.clone(); - aByproduct.mAmount /= aStack.stackSize; - } - GregtechOreDictUnificator.addItemData(GT_Utility.copyAmount(1, aStack), new GregtechItemData(aMaterial, aMaterialAmount / aStack.stackSize, aByproduct)); - } - - public static void registerMaterialRecycling(final ItemStack aStack, final GregtechItemData aData) { - if (GT_Utility.isStackInvalid(aStack) || GT_Utility.areStacksEqual(new ItemStack(Items.blaze_rod), aStack) || (aData == null) || !aData.hasValidMaterialData() || (aData.mMaterial.mAmount <= 0) || (GT_Utility.getFluidForFilledItem(aStack, false) != null)) { - return; - } - registerReverseMacerating(GT_Utility.copyAmount(1, aStack), aData, aData.mPrefix == null); - registerReverseSmelting(GT_Utility.copyAmount(1, aStack), aData.mMaterial.mMaterial, aData.mMaterial.mAmount, true); - registerReverseFluidSmelting(GT_Utility.copyAmount(1, aStack), aData.mMaterial.mMaterial, aData.mMaterial.mAmount, aData.getByProduct(0)); - registerReverseArcSmelting(GT_Utility.copyAmount(1, aStack), aData); - } - - /** - * @param aStack the stack to be recycled. - * @param aMaterial the Material. - * @param aMaterialAmount the amount of it in Material Units. - */ - public static void registerReverseFluidSmelting(final ItemStack aStack, final GT_Materials aMaterial, final long aMaterialAmount, final GregtechMaterialStack aByproduct) { - if ((aStack == null) || (aMaterial == null) || (aMaterial.mSmeltInto.mStandardMoltenFluid == null) || !aMaterial.contains(SubTag.SMELTING_TO_FLUID) || (((L * aMaterialAmount) / (M * aStack.stackSize)) <= 0)) { - return; - } - RA.addFluidSmelterRecipe(GT_Utility.copyAmount(1, aStack), aByproduct == null ? null : aByproduct.mMaterial.contains(SubTag.NO_SMELTING) || !aByproduct.mMaterial.contains(SubTag.METAL) ? aByproduct.mMaterial.contains(SubTag.FLAMMABLE) ? GregtechOreDictUnificator.getDust(GT_Materials._NULL, aByproduct.mAmount / 2) : aByproduct.mMaterial.contains(SubTag.UNBURNABLE) ? GregtechOreDictUnificator.getDustOrIngot(aByproduct.mMaterial.mSmeltInto, aByproduct.mAmount) : null : GregtechOreDictUnificator.getIngotOrDust(aByproduct.mMaterial.mSmeltInto, aByproduct.mAmount), aMaterial.mSmeltInto.getMolten((L * aMaterialAmount) / (M * aStack.stackSize)), 10000, (int) Math.max(1, (24 * aMaterialAmount) / M), Math.max(8, (int) Math.sqrt(2 * aMaterial.mSmeltInto.mStandardMoltenFluid.getTemperature()))); - } - - /** - * @param aStack the stack to be recycled. - * @param aMaterial the Material. - * @param aMaterialAmount the amount of it in Material Units. - * @param aAllowAlloySmelter if it is allowed to be recycled inside the Alloy Smelter. - */ - public static void registerReverseSmelting(final ItemStack aStack, final GT_Materials aMaterial, long aMaterialAmount, final boolean aAllowAlloySmelter) { - if ((aStack == null) || (aMaterial == null) || (aMaterialAmount <= 0) || aMaterial.contains(SubTag.NO_SMELTING) || ((aMaterialAmount > M) && aMaterial.contains(SubTag.METAL))) { - return; - } - aMaterialAmount /= aStack.stackSize; - - if (aAllowAlloySmelter) { - CORE.GT_Recipe.addSmeltingAndAlloySmeltingRecipe(GT_Utility.copyAmount(1, aStack), GregtechOreDictUnificator.getIngot(aMaterial.mSmeltInto, aMaterialAmount)); - } else { - GT_ModHandler.addSmeltingRecipe(GT_Utility.copyAmount(1, aStack), GregtechOreDictUnificator.getIngot(aMaterial.mSmeltInto, aMaterialAmount)); - } - } - - public static void registerReverseArcSmelting(final ItemStack aStack, GregtechItemData aData) { - if ((aStack == null) || (aData == null)) { - return; - } - aData = new GregtechItemData(aData); - - if (!aData.hasValidMaterialData()) { - return; - } - - for (final GregtechMaterialStack tMaterial : aData.getAllGT_MaterialStacks()) { - if (tMaterial.mMaterial.contains(SubTag.UNBURNABLE)) { - tMaterial.mMaterial = tMaterial.mMaterial.mSmeltInto.mArcSmeltInto; - continue; - } - if (tMaterial.mMaterial.contains(SubTag.EXPLOSIVE)) { - tMaterial.mAmount /= 4; - continue; - } - if (tMaterial.mMaterial.contains(SubTag.FLAMMABLE)) { - tMaterial.mAmount /= 2; - continue; - } - if (tMaterial.mMaterial.contains(SubTag.NO_SMELTING)) { - tMaterial.mAmount = 0; - continue; - } - if (tMaterial.mMaterial.contains(SubTag.METAL)) { - tMaterial.mMaterial = tMaterial.mMaterial.mSmeltInto.mArcSmeltInto; - continue; - } - tMaterial.mAmount = 0; - } - - aData = new GregtechItemData(aData); - - if (aData.mByProducts.length > 3) { - for (final GregtechMaterialStack tMaterial : aData.getAllGT_MaterialStacks()) { - aData = new GregtechItemData(aData); - } - } - - if (!aData.hasValidMaterialData()) { - return; - } - - long tAmount = 0; - for (final GregtechMaterialStack tMaterial : aData.getAllGT_MaterialStacks()) { - tAmount += tMaterial.mAmount * tMaterial.mMaterial.getMass(); - } - - RA.addArcFurnaceRecipe(aStack, new ItemStack[]{GregtechOreDictUnificator.getIngotOrDust(aData.mMaterial), GregtechOreDictUnificator.getIngotOrDust(aData.getByProduct(0)), GregtechOreDictUnificator.getIngotOrDust(aData.getByProduct(1)), GregtechOreDictUnificator.getIngotOrDust(aData.getByProduct(2))}, null, (int) Math.max(16, tAmount / M), 96); - } - - public static void registerReverseMacerating(final ItemStack aStack, GregtechItemData aData, final boolean aAllowHammer) { - if ((aStack == null) || (aData == null)) { - return; - } - aData = new GregtechItemData(aData); - - if (!aData.hasValidMaterialData()) { - return; - } - - for (final GregtechMaterialStack tMaterial : aData.getAllGT_MaterialStacks()) { - tMaterial.mMaterial = tMaterial.mMaterial.mMacerateInto; - } - - aData = new GregtechItemData(aData); - - if (!aData.hasValidMaterialData()) { - return; - } - - long tAmount = 0; - for (final GregtechMaterialStack tMaterial : aData.getAllGT_MaterialStacks()) { - tAmount += tMaterial.mAmount * tMaterial.mMaterial.getMass(); - } - - RA.addPulveriserRecipe(aStack, new ItemStack[]{GregtechOreDictUnificator.getDust(aData.mMaterial), GregtechOreDictUnificator.getDust(aData.getByProduct(0)), GregtechOreDictUnificator.getDust(aData.getByProduct(1)), GregtechOreDictUnificator.getDust(aData.getByProduct(2))}, null, (int) Math.max(16, tAmount / M), 4); - - if (aAllowHammer) { - for (final GregtechMaterialStack tMaterial : aData.getAllGT_MaterialStacks()) { - if (tMaterial.mMaterial.contains(SubTag.CRYSTAL) && !tMaterial.mMaterial.contains(SubTag.METAL)) { - if (RA.addForgeHammerRecipe(GT_Utility.copyAmount(1, aStack), GregtechOreDictUnificator.getDust(aData.mMaterial), 200, 32)) { - break; - } - } - } - } - final ItemStack tDust = GregtechOreDictUnificator.getDust(aData.mMaterial); - if ((tDust != null) && GT_ModHandler.addPulverisationRecipe(GT_Utility.copyAmount(1, aStack), tDust, GregtechOreDictUnificator.getDust(aData.getByProduct(0)), 100, GregtechOreDictUnificator.getDust(aData.getByProduct(1)), 100, true)) { - if (GregTech_API.sThaumcraftCompat != null) { - GregTech_API.sThaumcraftCompat.addCrucibleRecipe(IThaumcraftCompat.ADVANCEDENTROPICPROCESSING, aStack, tDust, Arrays.asList(new TC_AspectStack(TC_Aspects.PERDITIO, Math.max(1, (aData.mMaterial.mAmount * 2) / M)))); - } - } - } - - /** - * You give this Function a Material and it will scan almost everything for adding recycling Recipes - * - * @param aMat a Material, for example an Ingot or a Gem. - * @param aOutput the Dust you usually get from macerating aMat - * @param aRecipeReplacing allows to replace the Recipe with a Plate variant - */ - public static synchronized void registerUsagesForGT_Materials(ItemStack aMat, String aPlate, final boolean aRecipeReplacing) { - if (aMat == null) { - return; - } - aMat = GT_Utility.copy(aMat); - ItemStack tStack; - final GregtechItemData aItemData = GregtechOreDictUnificator.getItemData(aMat); - if ((aItemData == null) || (aItemData.mPrefix != GregtechOrePrefixes.ingot)) { - aPlate = null; - } - if ((aPlate != null) && (GregtechOreDictUnificator.getFirstOre(aPlate, 1) == null)) { - aPlate = null; - } - - sMt1.func_150996_a(aMat.getItem()); - sMt1.stackSize = 1; - Items.feather.setDamage(sMt1, Items.feather.getDamage(aMat)); - - sMt2.func_150996_a(new ItemStack(Blocks.dirt).getItem()); - sMt2.stackSize = 1; - Items.feather.setDamage(sMt2, 0); - - for (final ItemStack[] tRecipe : sShapes1) { - int tAmount1 = 0; - for (final ItemStack tMat : tRecipe) { - if (tMat == sMt1) { - tAmount1++; - } - } - if ((aItemData != null) && aItemData.hasValidPrefixMaterialData()) { - for (final ItemStack tCrafted : GT_ModHandler.getRecipeOutputs(tRecipe)) { - GregtechOreDictUnificator.addItemData(tCrafted, new GregtechItemData(aItemData.mMaterial.mMaterial, aItemData.mMaterial.mAmount * tAmount1)); - } - } - } - - for (final GT_Materials tMaterial : sRodMaterialList) { - final ItemStack tMt2 = GregtechOreDictUnificator.get(GregtechOrePrefixes.stick, tMaterial, 1); - if (tMt2 != null) { - sMt2.func_150996_a(tMt2.getItem()); - sMt2.stackSize = 1; - Items.feather.setDamage(sMt2, Items.feather.getDamage(tMt2)); - - for (int i = 0; i < sShapes1.length; i++) { - final ItemStack[] tRecipe = sShapes1[i]; - - int tAmount1 = 0, tAmount2 = 0; - for (final ItemStack tMat : tRecipe) { - if (tMat == sMt1) { - tAmount1++; - } - if (tMat == sMt2) { - tAmount2++; - } - } - for (final ItemStack tCrafted : GT_ModHandler.getVanillyToolRecipeOutputs(tRecipe)) { - if ((aItemData != null) && aItemData.hasValidPrefixMaterialData()) { - GregtechOreDictUnificator.addItemData(tCrafted, new GregtechItemData(aItemData.mMaterial.mMaterial, aItemData.mMaterial.mAmount * tAmount1, new GregtechMaterialStack(tMaterial, OrePrefixes.stick.mMaterialAmount * tAmount2))); - } - - if (aRecipeReplacing && (aPlate != null) && (sShapesA[i] != null) && (sShapesA[i].length > 1)) { - assert aItemData != null; - if (GregTech_API.sRecipeFile.get(ConfigCategories.Recipes.recipereplacements, aItemData.mMaterial.mMaterial + "." + sShapesA[i][0], true)) { - if (null != (tStack = GT_ModHandler.removeRecipe(tRecipe))) { - switch (sShapesA[i].length) { - case 2: - GT_ModHandler.addCraftingRecipe(tStack, GT_ModHandler.RecipeBits.BUFFERED, new Object[]{sShapesA[i][1], s_P.charAt(0), aPlate, s_R.charAt(0), OrePrefixes.stick.get(tMaterial), s_I.charAt(0), aItemData}); - break; - case 3: - GT_ModHandler.addCraftingRecipe(tStack, GT_ModHandler.RecipeBits.BUFFERED, new Object[]{sShapesA[i][1], sShapesA[i][2], s_P.charAt(0), aPlate, s_R.charAt(0), OrePrefixes.stick.get(tMaterial), s_I.charAt(0), aItemData}); - break; - default: - GT_ModHandler.addCraftingRecipe(tStack, GT_ModHandler.RecipeBits.BUFFERED, new Object[]{sShapesA[i][1], sShapesA[i][2], sShapesA[i][3], s_P.charAt(0), aPlate, s_R.charAt(0), OrePrefixes.stick.get(tMaterial), s_I.charAt(0), aItemData}); - break; - } - } - } - } - } - } - } - } - } -} |