InventoryCrafting .java

net.minecraft.inventory.InventoryCrafting (class): members: getStackInRowAndColumn, inventoryHeight, inventoryWidth, eventHandler, stackList, getHeight.

net.minecraft.inventoryclass211 linescommon5.3 KB

Implements

API Surface (21)

int getSizeInventory()
ItemStack getStackInSlot(int index)
ItemStack getStackInRowAndColumn(int row, int column)
String getName()
boolean hasCustomName()
IChatComponent getDisplayName()
ItemStack removeStackFromSlot(int index)
ItemStack decrStackSize(int index, int count)
void setInventorySlotContents(int index, ItemStack stack)
int getInventoryStackLimit()
void markDirty()
boolean isUseableByPlayer(EntityPlayer player)
void openInventory(EntityPlayer player)
void closeInventory(EntityPlayer player)
boolean isItemValidForSlot(int index, ItemStack stack)
int getField(int id)
void setField(int id, int value)
int getFieldCount()
void clear()
int getHeight()
int getWidth()

Fields & Constants (4)

stackList
inventoryWidth
inventoryHeight
eventHandler

String literals (1)

"container.crafting"

Code Graph: Dependencies (7)

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

Full Source

InventoryCrafting.java211 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.inventory;
2
3
import net.minecraft.entity.player.EntityPlayer;
4
import net.minecraft.item.ItemStack;
5
import net.minecraft.util.ChatComponentText;
6
import net.minecraft.util.ChatComponentTranslation;
7
import net.minecraft.util.IChatComponent;
8
9
public class InventoryCrafting implements IInventory
10
{
11
    /** List of the stacks in the crafting matrix. */
12
    private final ItemStack[] stackList;
13
14
    /** the width of the crafting inventory */
15
    private final int inventoryWidth;
16
    private final int inventoryHeight;
17
18
    /**
19
     * Class containing the callbacks for the events on_GUIClosed and on_CraftMaxtrixChanged.
20
     */
21
    private final Container eventHandler;
22
23
    public InventoryCrafting(Container eventHandlerIn, int width, int height)
24
    {
25
        int i = width * height;
26
        this.stackList = new ItemStack[i];
27
        this.eventHandler = eventHandlerIn;
28
        this.inventoryWidth = width;
29
        this.inventoryHeight = height;
30
    }
31
32
    /**
33
     * Returns the number of slots in the inventory.
34
     */
35
    public int getSizeInventory()
36
    {
37
        return this.stackList.length;
38
    }
39
40
    /**
41
     * Returns the stack in the given slot.
42
     */
43
    public ItemStack getStackInSlot(int index)
44
    {
45
        return index >= this.getSizeInventory() ? null : this.stackList[index];
46
    }
47
48
    /**
49
     * Returns the itemstack in the slot specified (Top left is 0, 0). Args: row, column
50
     */
51
    public ItemStack getStackInRowAndColumn(int row, int column)
52
    {
53
        return row >= 0 && row < this.inventoryWidth && column >= 0 && column <= this.inventoryHeight ? this.getStackInSlot(row + column * this.inventoryWidth) : null;
54
    }
55
56
    /**
57
     * Get the name of this object. For players this returns their username
58
     */
59
    public String getName()
60
    {
61
        return "container.crafting";
62
    }
63
64
    /**
65
     * Returns true if this thing is named
66
     */
67
    public boolean hasCustomName()
68
    {
69
        return false;
70
    }
71
72
    /**
73
     * Get the formatted ChatComponent that will be used for the sender's username in chat
74
     */
75
    public IChatComponent getDisplayName()
76
    {
77
        return (IChatComponent)(this.hasCustomName() ? new ChatComponentText(this.getName()) : new ChatComponentTranslation(this.getName(), new Object[0]));
78
    }
79
80
    /**
81
     * Removes a stack from the given slot and returns it.
82
     */
83
    public ItemStack removeStackFromSlot(int index)
84
    {
85
        if (this.stackList[index] != null)
86
        {
87
            ItemStack itemstack = this.stackList[index];
88
            this.stackList[index] = null;
89
            return itemstack;
90
        }
91
        else
92
        {
93
            return null;
94
        }
95
    }
96
97
    /**
98
     * Removes up to a specified number of items from an inventory slot and returns them in a new stack.
99
     */
100
    public ItemStack decrStackSize(int index, int count)
101
    {
102
        if (this.stackList[index] != null)
103
        {
104
            if (this.stackList[index].stackSize <= count)
105
            {
106
                ItemStack itemstack1 = this.stackList[index];
107
                this.stackList[index] = null;
108
                this.eventHandler.onCraftMatrixChanged(this);
109
                return itemstack1;
110
            }
111
            else
112
            {
113
                ItemStack itemstack = this.stackList[index].splitStack(count);
114
115
                if (this.stackList[index].stackSize == 0)
116
                {
117
                    this.stackList[index] = null;
118
                }
119
120
                this.eventHandler.onCraftMatrixChanged(this);
121
                return itemstack;
122
            }
123
        }
124
        else
125
        {
126
            return null;
127
        }
128
    }
129
130
    /**
131
     * Sets the given item stack to the specified slot in the inventory (can be crafting or armor sections).
132
     */
133
    public void setInventorySlotContents(int index, ItemStack stack)
134
    {
135
        this.stackList[index] = stack;
136
        this.eventHandler.onCraftMatrixChanged(this);
137
    }
138
139
    /**
140
     * Returns the maximum stack size for a inventory slot. Seems to always be 64, possibly will be extended.
141
     */
142
    public int getInventoryStackLimit()
143
    {
144
        return 64;
145
    }
146
147
    /**
148
     * For tile entities, ensures the chunk containing the tile entity is saved to disk later - the game won't think it
149
     * hasn't changed and skip it.
150
     */
151
    public void markDirty()
152
    {
153
    }
154
155
    /**
156
     * Do not make give this method the name canInteractWith because it clashes with Container
157
     */
158
    public boolean isUseableByPlayer(EntityPlayer player)
159
    {
160
        return true;
161
    }
162
163
    public void openInventory(EntityPlayer player)
164
    {
165
    }
166
167
    public void closeInventory(EntityPlayer player)
168
    {
169
    }
170
171
    /**
172
     * Returns true if automation is allowed to insert the given stack (ignoring stack size) into the given slot.
173
     */
174
    public boolean isItemValidForSlot(int index, ItemStack stack)
175
    {
176
        return true;
177
    }
178
179
    public int getField(int id)
180
    {
181
        return 0;
182
    }
183
184
    public void setField(int id, int value)
185
    {
186
    }
187
188
    public int getFieldCount()
189
    {
190
        return 0;
191
    }
192
193
    public void clear()
194
    {
195
        for (int i = 0; i < this.stackList.length; ++i)
196
        {
197
            this.stackList[i] = null;
198
        }
199
    }
200
201
    public int getHeight()
202
    {
203
        return this.inventoryHeight;
204
    }
205
206
    public int getWidth()
207
    {
208
        return this.inventoryWidth;
209
    }
210
}
211

Deobfuscated MCP 1.8.9 source of InventoryCrafting from Marcelektro/MavenMCP-1.8.9 (net/minecraft/inventory/InventoryCrafting.java), stored verbatim.