Search in sources :

Example 1 with AdvancedCraftingShaped

use of gregapi.recipes.AdvancedCraftingShaped in project gregtech6 by GregTech6.

the class CR method shaped.

private static boolean shaped(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, boolean aDeleteOnlyIfNoDyeInvolved, boolean aNotAutoCraftable, Object[] aRecipe) {
    if (aOnlyAddIfResultIsNotNull && ST.invalid(aResult))
        return F;
    if (aRecipe == null || aRecipe.length <= 0)
        return F;
    boolean tThereWasARecipe = F;
    aResult = ST.validMeta(OM.get(aResult));
    for (byte i = 0; i < aRecipe.length; i++) if (aRecipe[i] != null) {
        if (aRecipe[i] instanceof IItemContainer) {
            aRecipe[i] = ((IItemContainer) aRecipe[i]).get(1);
            if (aRecipe[i] == null)
                return F;
        } else if (aRecipe[i] instanceof Enum) {
            aRecipe[i] = ((Enum<?>) aRecipe[i]).name();
        } else if (aRecipe[i] instanceof Item) {
            aRecipe[i] = ST.make((Item) aRecipe[i], 1, W);
        } else if (aRecipe[i] instanceof Block) {
            aRecipe[i] = ST.make((Block) aRecipe[i], 1, W);
        } else if (!(aRecipe[i] instanceof ItemStack || aRecipe[i] instanceof OreDictItemData || aRecipe[i] instanceof String || aRecipe[i] instanceof Character)) {
            aRecipe[i] = aRecipe[i].toString();
        }
    }
    try {
        String shape = "";
        int idx = 0;
        if (aRecipe[idx] instanceof Boolean)
            throw new IllegalArgumentException();
        ArrayList<Object> tRecipeList = new ArrayList<>(Arrays.asList(aRecipe));
        while (aRecipe[idx] instanceof String) {
            String s = (String) aRecipe[idx++];
            shape += s;
            while (s.length() < 3) s += " ";
            if (s.length() > 3)
                throw new IllegalArgumentException();
            for (char c : s.toCharArray()) {
                switch(c) {
                    case 'a':
                        tRecipeList.add(c);
                        tRecipeList.add(OreDictToolNames.axe);
                        break;
                    case 'b':
                        tRecipeList.add(c);
                        tRecipeList.add(OreDictToolNames.blade);
                        break;
                    case 'c':
                        tRecipeList.add(c);
                        tRecipeList.add(OreDictToolNames.crowbar);
                        break;
                    case 'd':
                        tRecipeList.add(c);
                        tRecipeList.add(OreDictToolNames.screwdriver);
                        break;
                    case 'e':
                        tRecipeList.add(c);
                        tRecipeList.add(OreDictToolNames.drill);
                        break;
                    case 'f':
                        tRecipeList.add(c);
                        tRecipeList.add(OreDictToolNames.file);
                        break;
                    case 'g':
                        tRecipeList.add(c);
                        tRecipeList.add(OreDictToolNames.handdrill);
                        break;
                    case 'h':
                        tRecipeList.add(c);
                        tRecipeList.add(OreDictToolNames.hammer);
                        break;
                    case 'i':
                        tRecipeList.add(c);
                        tRecipeList.add(OreDictToolNames.solderingiron);
                        break;
                    case 'j':
                        tRecipeList.add(c);
                        tRecipeList.add(OreDictToolNames.solderingmetal);
                        break;
                    case 'k':
                        tRecipeList.add(c);
                        tRecipeList.add(OreDictToolNames.knife);
                        break;
                    case 'l':
                        tRecipeList.add(c);
                        tRecipeList.add(OreDictToolNames.magnifyingglass);
                        break;
                    case 'n':
                        tRecipeList.add(c);
                        tRecipeList.add(OreDictToolNames.monkeywrench);
                        break;
                    case 'o':
                        tRecipeList.add(c);
                        tRecipeList.add(OreDictToolNames.bendingcylindersmall);
                        break;
                    case 'p':
                        tRecipeList.add(c);
                        tRecipeList.add(OreDictToolNames.drawplate);
                        break;
                    case 'q':
                        tRecipeList.add(c);
                        tRecipeList.add(OreDictToolNames.scissors);
                        break;
                    case 'r':
                        tRecipeList.add(c);
                        tRecipeList.add(OreDictToolNames.softhammer);
                        break;
                    case 's':
                        tRecipeList.add(c);
                        tRecipeList.add(OreDictToolNames.saw);
                        break;
                    case 'v':
                        tRecipeList.add(c);
                        tRecipeList.add(OreDictToolNames.sawaxe);
                        break;
                    case 'w':
                        tRecipeList.add(c);
                        tRecipeList.add(OreDictToolNames.wrench);
                        break;
                    case 'x':
                        tRecipeList.add(c);
                        tRecipeList.add(OreDictToolNames.wirecutter);
                        break;
                    case 'y':
                        tRecipeList.add(c);
                        tRecipeList.add(OreDictToolNames.chisel);
                        break;
                    case 'z':
                        tRecipeList.add(c);
                        tRecipeList.add(OreDictToolNames.bendingcylinder);
                        break;
                }
            }
        }
        aRecipe = tRecipeList.toArray();
        HashMap<Character, ItemStack> tItemStackMap = new HashMap<>();
        HashMap<Character, OreDictItemData> tItemDataMap = new HashMap<>();
        tItemStackMap.put(' ', null);
        boolean tRemoveRecipe = T;
        for (; idx < aRecipe.length; idx += 2) {
            if (aRecipe[idx] == null || aRecipe[idx + 1] == null) {
                ERR.println("WARNING: Missing Item for shaped Recipe: " + (aResult == null ? "null" : aResult.getDisplayName()));
                for (Object tContent : aRecipe) ERR.println(tContent);
                return F;
            }
            Character tChar = (Character) aRecipe[idx];
            Object tInput = aRecipe[idx + 1];
            if (tInput instanceof ItemStack) {
                tItemStackMap.put(tChar, ST.copy_((ItemStack) tInput));
                tItemDataMap.put(tChar, OM.data_((ItemStack) tInput));
            } else {
                String tInputString = tInput.toString();
                if (tInput instanceof OreDictItemData) {
                    tItemDataMap.put(tChar, (OreDictItemData) tInput);
                    if (UT.Code.stringInvalid(tInputString)) {
                        throw new IllegalArgumentException();
                    }
                } else if (UT.Code.stringValid(tInputString)) {
                    tItemDataMap.put(tChar, OreDictManager.INSTANCE.getAutomaticItemData(tInputString));
                } else {
                    throw new IllegalArgumentException();
                }
                ItemStack tStack = OreDictManager.INSTANCE.getFirstOre(tInputString, 1);
                if (tStack == null)
                    tRemoveRecipe = F;
                else
                    tItemStackMap.put(tChar, tStack);
                aRecipe[idx + 1] = tInputString;
            }
        }
        if (aReversible && aResult != null) {
            OreDictItemData[] tData = new OreDictItemData[9];
            int x = -1;
            for (char chr : shape.toCharArray()) tData[++x] = tItemDataMap.get(chr);
            if (UT.Code.containsSomething(tData))
                OM.data(aResult, new OreDictItemData(tData));
        }
        if (aCheckForCollisions && tRemoveRecipe) {
            ItemStack[] tRecipe = new ItemStack[9];
            int x = -1;
            for (char chr : shape.toCharArray()) {
                tRecipe[++x] = tItemStackMap.get(chr);
                if (tRecipe[x] != null && ST.meta_(tRecipe[x]) == W)
                    ST.meta_(tRecipe[x], 0);
            }
            tThereWasARecipe = remove(tRecipe) != null || tThereWasARecipe;
        }
    } catch (Throwable e) {
        e.printStackTrace(ERR);
    }
    if (aResult == null || aResult.stackSize <= 0)
        return F;
    if (aRemoveAllOthersWithSameOutput || aRemoveAllOthersWithSameOutputIfTheyHaveSameNBT || aRemoveAllOtherShapedsWithSameOutput || aRemoveAllOtherNativeRecipes)
        tThereWasARecipe = remout(aResult, !aRemoveAllOthersWithSameOutputIfTheyHaveSameNBT, aRemoveAllOtherShapedsWithSameOutput, aRemoveAllOtherNativeRecipes, aDeleteOnlyIfNoDyeInvolved) || tThereWasARecipe;
    if (aOnlyAddIfThereIsAnyRecipeOutputtingThis && !tThereWasARecipe) {
        List<IRecipe> tList = list();
        for (int i = 0; i < tList.size(); i++) {
            IRecipe tRecipe = tList.get(i);
            if (CLASSES_SPECIAL.contains(tRecipe.getClass().getName()))
                continue;
            if (ST.equal(OM.get(tRecipe.getRecipeOutput()), aResult, T)) {
                tThereWasARecipe = T;
                break;
            }
        }
    }
    aResult = ST.update_(aResult);
    if (tThereWasARecipe || !aOnlyAddIfThereIsAnyRecipeOutputtingThis) {
        if (BUFFERING && aBuffered)
            BUFFER.add(new AdvancedCraftingShaped(ST.copy_(aResult), aDismantleable, aRemovable, aKeepNBT, !aNotAutoCraftable, aEnchantmentsAdded, aEnchantmentLevelsAdded, aRecipe).setMirrored(aMirrored));
        else
            GameRegistry.addRecipe(new AdvancedCraftingShaped(ST.copy_(aResult), aDismantleable, aRemovable, aKeepNBT, !aNotAutoCraftable, aEnchantmentsAdded, aEnchantmentLevelsAdded, aRecipe).setMirrored(aMirrored));
    }
    return T;
}
Also used : HashMap(java.util.HashMap) OreDictItemData(gregapi.oredict.OreDictItemData) ArrayList(java.util.ArrayList) Item(net.minecraft.item.Item) IRecipe(net.minecraft.item.crafting.IRecipe) IItemContainer(gregapi.code.IItemContainer) AdvancedCraftingShaped(gregapi.recipes.AdvancedCraftingShaped) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack)

Aggregations

IItemContainer (gregapi.code.IItemContainer)1 OreDictItemData (gregapi.oredict.OreDictItemData)1 AdvancedCraftingShaped (gregapi.recipes.AdvancedCraftingShaped)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Block (net.minecraft.block.Block)1 Item (net.minecraft.item.Item)1 ItemStack (net.minecraft.item.ItemStack)1 IRecipe (net.minecraft.item.crafting.IRecipe)1