ShapelessRecipes .java

net.minecraft.item.crafting.ShapelessRecipes (class): members: recipeOutput, recipeItems, getRemainingItems, getRecipeOutput, getRecipeSize, matches.

net.minecraft.item.craftingclass97 linescommon2.6 KB

Implements

API Surface (5)

ItemStack getRecipeOutput()
ItemStack[] getRemainingItems(InventoryCrafting inv)
boolean matches(InventoryCrafting inv, World worldIn)
ItemStack getCraftingResult(InventoryCrafting inv)
int getRecipeSize()

Fields & Constants (2)

recipeOutput
recipeItems

Code Graph: Dependencies (4)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

ShapelessRecipes.java97 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.item.crafting;
2
3
import com.google.common.collect.Lists;
4
import java.util.List;
5
import net.minecraft.inventory.InventoryCrafting;
6
import net.minecraft.item.ItemStack;
7
import net.minecraft.world.World;
8
9
public class ShapelessRecipes implements IRecipe
10
{
11
    /** Is the ItemStack that you get when craft the recipe. */
12
    private final ItemStack recipeOutput;
13
    private final List<ItemStack> recipeItems;
14
15
    public ShapelessRecipes(ItemStack output, List<ItemStack> inputList)
16
    {
17
        this.recipeOutput = output;
18
        this.recipeItems = inputList;
19
    }
20
21
    public ItemStack getRecipeOutput()
22
    {
23
        return this.recipeOutput;
24
    }
25
26
    public ItemStack[] getRemainingItems(InventoryCrafting inv)
27
    {
28
        ItemStack[] aitemstack = new ItemStack[inv.getSizeInventory()];
29
30
        for (int i = 0; i < aitemstack.length; ++i)
31
        {
32
            ItemStack itemstack = inv.getStackInSlot(i);
33
34
            if (itemstack != null && itemstack.getItem().hasContainerItem())
35
            {
36
                aitemstack[i] = new ItemStack(itemstack.getItem().getContainerItem());
37
            }
38
        }
39
40
        return aitemstack;
41
    }
42
43
    /**
44
     * Used to check if a recipe matches current crafting inventory
45
     */
46
    public boolean matches(InventoryCrafting inv, World worldIn)
47
    {
48
        List<ItemStack> list = Lists.newArrayList(this.recipeItems);
49
50
        for (int i = 0; i < inv.getHeight(); ++i)
51
        {
52
            for (int j = 0; j < inv.getWidth(); ++j)
53
            {
54
                ItemStack itemstack = inv.getStackInRowAndColumn(j, i);
55
56
                if (itemstack != null)
57
                {
58
                    boolean flag = false;
59
60
                    for (ItemStack itemstack1 : list)
61
                    {
62
                        if (itemstack.getItem() == itemstack1.getItem() && (itemstack1.getMetadata() == 32767 || itemstack.getMetadata() == itemstack1.getMetadata()))
63
                        {
64
                            flag = true;
65
                            list.remove(itemstack1);
66
                            break;
67
                        }
68
                    }
69
70
                    if (!flag)
71
                    {
72
                        return false;
73
                    }
74
                }
75
            }
76
        }
77
78
        return list.isEmpty();
79
    }
80
81
    /**
82
     * Returns an Item that is the result of this recipe
83
     */
84
    public ItemStack getCraftingResult(InventoryCrafting inv)
85
    {
86
        return this.recipeOutput.copy();
87
    }
88
89
    /**
90
     * Returns the size of the recipe area
91
     */
92
    public int getRecipeSize()
93
    {
94
        return this.recipeItems.size();
95
    }
96
}
97

Deobfuscated MCP 1.8.9 source of ShapelessRecipes from Marcelektro/MavenMCP-1.8.9 (net/minecraft/item/crafting/ShapelessRecipes.java), stored verbatim.