InventoryLargeChest .java

net.minecraft.inventory.InventoryLargeChest (class): members: isPartOfLargeChest, lowerChest, upperChest, getLockCode, setLockCode, isLocked, markDirty.

net.minecraft.inventoryclass221 linescommon6.3 KB

Implements

API Surface (24)

int getSizeInventory()
boolean isPartOfLargeChest(IInventory inventoryIn)
String getName()
boolean hasCustomName()
IChatComponent getDisplayName()
ItemStack getStackInSlot(int index)
ItemStack decrStackSize(int index, int count)
ItemStack removeStackFromSlot(int index)
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()
boolean isLocked()
void setLockCode(LockCode code)
LockCode getLockCode()
String getGuiID()
Container createContainer(InventoryPlayer playerInventory, EntityPlayer playerIn)
void clear()

Fields & Constants (3)

name
upperChest
lowerChest

Full Source

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

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