Search in sources :

Example 6 with Ingredient

use of net.minecraft.item.crafting.Ingredient in project Charset by CharsetMC.

the class BarrelUpgradeOutputSupplier method getCraftingResult.

@Override
public ItemStack getCraftingResult(RecipeCharset recipe, IngredientMatcher matcher, InventoryCrafting inv) {
    for (Ingredient i : matcher.getMatchedIngredients()) {
        ItemStack is = matcher.getStack(i);
        if (is.getItem() instanceof ItemDayBarrel || is.getItem() instanceof ItemMinecartDayBarrel) {
            is = is.copy();
            is.setCount(1);
            return TileEntityDayBarrel.addUpgrade(is, upgradeType);
        }
    }
    return null;
}
Also used : Ingredient(net.minecraft.item.crafting.Ingredient) ItemStack(net.minecraft.item.ItemStack)

Example 7 with Ingredient

use of net.minecraft.item.crafting.Ingredient in project Charset by CharsetMC.

the class LockOutputSupplier method getCraftingResult.

@Override
public ItemStack getCraftingResult(RecipeCharset recipe, IngredientMatcher matcher, InventoryCrafting inv) {
    for (Ingredient i : matcher.getMatchedIngredients()) {
        ItemStack key = matcher.getStack(i);
        if (!key.isEmpty() && key.getItem() instanceof ItemKey) {
            ItemStack result = output.copy();
            result.setTagCompound(new NBTTagCompound());
            if (key.hasTagCompound() && key.getTagCompound().hasKey("color")) {
                result.getTagCompound().setTag("color", key.getTagCompound().getTag("color"));
            }
            result.getTagCompound().setString("key", ((ItemKey) key.getItem()).getKey(key));
            return result;
        }
    }
    return null;
}
Also used : Ingredient(net.minecraft.item.crafting.Ingredient) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack)

Example 8 with Ingredient

use of net.minecraft.item.crafting.Ingredient in project Charset by CharsetMC.

the class InventoryCraftingIterator method next.

@Override
public InventoryCrafting next() {
    int permPos = i;
    Map<Ingredient, Object> stackMap = new HashMap<>();
    for (Map.Entry<Ingredient, Object> entry : permutatingIngredients.entrySet()) {
        Object stacks = entry.getValue();
        if (stacks instanceof ItemStack[][]) {
            int length = ((ItemStack[][]) stacks).length;
            ItemStack[] stackSet = ((ItemStack[][]) stacks)[permPos % length];
            if (stackSet.length == 1) {
                stackMap.put(entry.getKey(), stackSet[0]);
            } else {
                stackMap.put(entry.getKey(), stackSet);
            }
            permPos /= length;
        } else if (stacks instanceof ItemStack[]) {
            stackMap.put(entry.getKey(), ((ItemStack[]) stacks)[permPos % ((ItemStack[]) stacks).length]);
            permPos /= ((ItemStack[]) stacks).length;
        } else {
            throw new RuntimeException("Unknown stacks type in InventoryCraftingIterator.next(): " + stacks.getClass().getName());
        }
    }
    for (int i = 0; i < recipe.input.size(); i++) {
        Ingredient ing = recipe.input.get(i);
        if (permutatingIngredients.containsKey(ing)) {
            Object o = stackMap.get(ing);
            if (o instanceof ItemStack[]) {
                ItemStack[] stacks = (ItemStack[]) o;
                setInventorySlotContents(i, stacks.length > 0 ? stacks[0] : ItemStack.EMPTY);
                inputReal[i] = Arrays.asList(stacks);
            } else if (o instanceof ItemStack) {
                setInventorySlotContents(i, (ItemStack) o);
                inputReal[i] = stackMap.get(ing);
            } else {
                throw new RuntimeException("Unknown stacks type in InventoryCraftingIterator.next(): " + o.getClass().getName());
            }
        } else {
            ItemStack[] stacks = ing.getMatchingStacks();
            setInventorySlotContents(i, stacks.length > 0 ? stacks[0] : ItemStack.EMPTY);
            inputReal[i] = ing;
        }
    }
    i++;
    return this;
}
Also used : Ingredient(net.minecraft.item.crafting.Ingredient) OreIngredient(net.minecraftforge.oredict.OreIngredient) ItemStack(net.minecraft.item.ItemStack)

Example 9 with Ingredient

use of net.minecraft.item.crafting.Ingredient in project Charset by CharsetMC.

the class RecipeCharset method matchedOrNull.

protected IngredientMatcher matchedOrNull(InventoryCrafting inv) {
    if (shapeless) {
        Set<Ingredient> objectSet = new HashSet<>();
        objectSet.addAll(input);
        IngredientMatcher matcher = new IngredientMatcher(this);
        for (int y = 0; y < inv.getHeight(); y++) {
            for (int x = 0; x < inv.getWidth(); x++) {
                ItemStack stack = inv.getStackInRowAndColumn(x, y);
                if (!stack.isEmpty()) {
                    boolean matches = false;
                    for (Ingredient o : objectSet) {
                        if (o.apply(stack)) {
                            matches = true;
                            matcher.add(stack, o);
                            objectSet.remove(o);
                            break;
                        }
                    }
                    if (!matches) {
                        return null;
                    }
                }
            }
        }
        return objectSet.size() == 0 ? matcher : null;
    } else {
        for (int yo = 0; yo <= inv.getHeight() - height; yo++) {
            for (int xo = 0; xo <= inv.getWidth() - width; xo++) {
                IngredientMatcher matcher = new IngredientMatcher(this);
                boolean matches = false;
                for (int iIdx = 0; iIdx < input.size(); iIdx++) {
                    int i = (shapedOrdering != null ? shapedOrdering[iIdx] : iIdx);
                    int x = i % width + xo;
                    int y = i / width + yo;
                    matches = matcher.add(inv.getStackInRowAndColumn(x, y), input.get(i));
                    if (!matches)
                        break;
                }
                if (!matches && mirrored) {
                    matcher = new IngredientMatcher(this);
                    matches = false;
                    for (int iIdx = 0; iIdx < input.size(); iIdx++) {
                        int i = (shapedOrdering != null ? shapedOrdering[iIdx] : iIdx);
                        int x = ((width - 1) - (i % width)) + xo;
                        int y = i / width + yo;
                        matches = matcher.add(inv.getStackInRowAndColumn(x, y), input.get(i));
                        if (!matches)
                            break;
                    }
                }
                if (matches)
                    return matcher;
            }
        }
        return null;
    }
}
Also used : Ingredient(net.minecraft.item.crafting.Ingredient) ItemStack(net.minecraft.item.ItemStack) TIntHashSet(gnu.trove.set.hash.TIntHashSet) ItemStackHashSet(pl.asie.charset.lib.utils.ItemStackHashSet)

Example 10 with Ingredient

use of net.minecraft.item.crafting.Ingredient in project Charset by CharsetMC.

the class RecipeReplacement method replaceIngredient.

@Nullable
private Ingredient replaceIngredient(Ingredient ing) {
    if (ing.getClass() == Ingredient.class || ing.getClass() == IngredientNBT.class) {
        boolean checkNBT = ing.getClass() == IngredientNBT.class;
        ItemStack[] matchingStacks = ing.getMatchingStacks();
        ItemStack[] matchingStacksNew = null;
        int replacementOreMatches = 0;
        String replacementOre = null;
        boolean dirty = false;
        for (int j = 0; j < matchingStacks.length; j++) {
            ItemStack stack = matchingStacks[j];
            if (stack.isEmpty())
                continue;
            ItemStack newStack = null;
            Object replacement = null;
            for (int i : OreDictionary.getOreIDs(stack)) {
                if (replaceableOres.containsKey(i)) {
                    replacement = replaceableOres.get(i);
                    break;
                }
            }
            if (replacement == null) {
                if (replacements.containsKey(stack)) {
                    replacement = replacements.get(stack);
                } else if (!checkNBT && replaceableItems.containsKey(stack.getItem())) {
                    replacement = replaceableItems.get(stack.getItem());
                }
            }
            if (replacement instanceof Item) {
                newStack = new ItemStack((Item) replacement, stack.getCount(), stack.getItemDamage());
                newStack.setTagCompound(stack.getTagCompound());
            } else if (replacement instanceof ItemStack) {
                newStack = ((ItemStack) replacements.get(stack)).copy();
                newStack.setCount(stack.getCount());
            } else if (replacement instanceof String) {
                replacementOreMatches++;
                replacementOre = (String) replacement;
            }
            if (newStack != null) {
                if (!dirty) {
                    matchingStacksNew = new ItemStack[matchingStacks.length];
                    System.arraycopy(matchingStacks, 0, matchingStacksNew, 0, matchingStacks.length);
                    dirty = true;
                }
                matchingStacksNew[j] = newStack;
            }
        }
        if (replacementOre != null && replacementOreMatches == matchingStacks.length) {
            return new OreIngredient(replacementOre);
        } else {
            if (matchingStacksNew != null) {
                return Ingredient.fromStacks(matchingStacksNew);
            }
        }
    } else if (ing.getClass() == OreIngredient.class) {
        try {
            NonNullList<ItemStack> list = (NonNullList<ItemStack>) ORES_GETTER.invokeExact((OreIngredient) ing);
            if (list.isEmpty()) {
                return null;
            }
            TIntIterator it = replaceableOres.keySet().iterator();
            while (it.hasNext()) {
                int oreId = it.next();
                NonNullList<ItemStack> oreList = OreDictionary.getOres(OreDictionary.getOreName(oreId));
                if (!oreList.isEmpty() && list == oreList) {
                    Object replacement = replaceableOres.get(oreId);
                    if (replacement instanceof Item) {
                        return Ingredient.fromItem((Item) replacement);
                    } else if (replacement instanceof ItemStack) {
                        return Ingredient.fromStacks((ItemStack) replacement);
                    } else if (replacement instanceof String) {
                        return new OreIngredient((String) replacement);
                    }
                }
            }
        } catch (Throwable t) {
            t.printStackTrace();
        }
    }
    return null;
}
Also used : TIntIterator(gnu.trove.iterator.TIntIterator) IngredientNBT(net.minecraftforge.common.crafting.IngredientNBT) Item(net.minecraft.item.Item) Ingredient(net.minecraft.item.crafting.Ingredient) OreIngredient(net.minecraftforge.oredict.OreIngredient) NonNullList(net.minecraft.util.NonNullList) OreIngredient(net.minecraftforge.oredict.OreIngredient) ItemStack(net.minecraft.item.ItemStack) Nullable(javax.annotation.Nullable)

Aggregations

Ingredient (net.minecraft.item.crafting.Ingredient)57 ItemStack (net.minecraft.item.ItemStack)49 ResourceLocation (net.minecraft.util.ResourceLocation)12 ArrayList (java.util.ArrayList)10 JsonElement (com.google.gson.JsonElement)8 JsonObject (com.google.gson.JsonObject)7 List (java.util.List)7 IRecipe (net.minecraft.item.crafting.IRecipe)7 JsonArray (com.google.gson.JsonArray)6 Block (net.minecraft.block.Block)6 Item (net.minecraft.item.Item)6 HashMap (java.util.HashMap)5 IBlockState (net.minecraft.block.state.IBlockState)5 ShapelessRecipes (net.minecraft.item.crafting.ShapelessRecipes)5 FluidStack (net.minecraftforge.fluids.FluidStack)5 JsonParser (com.google.gson.JsonParser)4 File (java.io.File)4 FileNotFoundException (java.io.FileNotFoundException)4 FileReader (java.io.FileReader)4 EntityItem (net.minecraft.entity.item.EntityItem)4