ContainerHopper .java

net.minecraft.inventory.ContainerHopper (class): members: hopperInventory, onContainerClosed, transferStackInSlot, canInteractWith. imports: ItemStack.

net.minecraft.inventoryclass88 linescommonextends Container2.5 KB

API Surface (3)

boolean canInteractWith(EntityPlayer playerIn)
ItemStack transferStackInSlot(EntityPlayer playerIn, int index)
void onContainerClosed(EntityPlayer playerIn)

Fields & Constants (1)

hopperInventory

Code Graph: Dependencies (5)

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

Full Source

ContainerHopper.java88 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
7
public class ContainerHopper extends Container
8
{
9
    private final IInventory hopperInventory;
10
11
    public ContainerHopper(InventoryPlayer playerInventory, IInventory hopperInventoryIn, EntityPlayer player)
12
    {
13
        this.hopperInventory = hopperInventoryIn;
14
        hopperInventoryIn.openInventory(player);
15
        int i = 51;
16
17
        for (int j = 0; j < hopperInventoryIn.getSizeInventory(); ++j)
18
        {
19
            this.addSlotToContainer(new Slot(hopperInventoryIn, j, 44 + j * 18, 20));
20
        }
21
22
        for (int l = 0; l < 3; ++l)
23
        {
24
            for (int k = 0; k < 9; ++k)
25
            {
26
                this.addSlotToContainer(new Slot(playerInventory, k + l * 9 + 9, 8 + k * 18, l * 18 + i));
27
            }
28
        }
29
30
        for (int i1 = 0; i1 < 9; ++i1)
31
        {
32
            this.addSlotToContainer(new Slot(playerInventory, i1, 8 + i1 * 18, 58 + i));
33
        }
34
    }
35
36
    public boolean canInteractWith(EntityPlayer playerIn)
37
    {
38
        return this.hopperInventory.isUseableByPlayer(playerIn);
39
    }
40
41
    /**
42
     * Take a stack from the specified inventory slot.
43
     */
44
    public ItemStack transferStackInSlot(EntityPlayer playerIn, int index)
45
    {
46
        ItemStack itemstack = null;
47
        Slot slot = (Slot)this.inventorySlots.get(index);
48
49
        if (slot != null && slot.getHasStack())
50
        {
51
            ItemStack itemstack1 = slot.getStack();
52
            itemstack = itemstack1.copy();
53
54
            if (index < this.hopperInventory.getSizeInventory())
55
            {
56
                if (!this.mergeItemStack(itemstack1, this.hopperInventory.getSizeInventory(), this.inventorySlots.size(), true))
57
                {
58
                    return null;
59
                }
60
            }
61
            else if (!this.mergeItemStack(itemstack1, 0, this.hopperInventory.getSizeInventory(), false))
62
            {
63
                return null;
64
            }
65
66
            if (itemstack1.stackSize == 0)
67
            {
68
                slot.putStack((ItemStack)null);
69
            }
70
            else
71
            {
72
                slot.onSlotChanged();
73
            }
74
        }
75
76
        return itemstack;
77
    }
78
79
    /**
80
     * Called when the container is closed.
81
     */
82
    public void onContainerClosed(EntityPlayer playerIn)
83
    {
84
        super.onContainerClosed(playerIn);
85
        this.hopperInventory.closeInventory(playerIn);
86
    }
87
}
88

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