aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/common/container/Container_ItemProxySource.java
blob: 23af97e5bb1cd608c86c5479d92e933134007b11 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package common.container;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;

public class Container_ItemProxySource extends Container {

    private final IInventory teInventory;

    private int slotID = 0;

    public Container_ItemProxySource(TileEntity te, EntityPlayer player) {
        this.teInventory = (IInventory) te;

        // Source Slots
        addSlotToContainer(new Slot(teInventory, slotID++, 53, 8));
        addSlotToContainer(new Slot(teInventory, slotID++, 71, 8));
        addSlotToContainer(new Slot(teInventory, slotID++, 89, 8));
        addSlotToContainer(new Slot(teInventory, slotID++, 107, 8));
        addSlotToContainer(new Slot(teInventory, slotID++, 53, 26));
        addSlotToContainer(new Slot(teInventory, slotID++, 71, 26));
        addSlotToContainer(new Slot(teInventory, slotID++, 89, 26));
        addSlotToContainer(new Slot(teInventory, slotID++, 107, 26));
        addSlotToContainer(new Slot(teInventory, slotID++, 53, 44));
        addSlotToContainer(new Slot(teInventory, slotID++, 71, 44));
        addSlotToContainer(new Slot(teInventory, slotID++, 89, 44));
        addSlotToContainer(new Slot(teInventory, slotID++, 107, 44));
        addSlotToContainer(new Slot(teInventory, slotID++, 53, 62));
        addSlotToContainer(new Slot(teInventory, slotID++, 71, 62));
        addSlotToContainer(new Slot(teInventory, slotID++, 89, 62));
        addSlotToContainer(new Slot(teInventory, slotID++, 107, 62));

        // Inventory
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 9; j++) {
                addSlotToContainer(new Slot(player.inventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
            }
        }
        // Hotbar
        for (int i = 0; i < 9; i++) {
            addSlotToContainer(new Slot(player.inventory, i, 8 + i * 18, 142));
        }
    }

    @Override
    public ItemStack transferStackInSlot(EntityPlayer player, int slotRaw) {
        ItemStack stack = null;
        final Slot slot = (Slot) inventorySlots.get(slotRaw);

        if (slot != null && slot.getHasStack()) {
            final ItemStack stackInSlot = slot.getStack();
            stack = stackInSlot.copy();

            if (slotRaw < 3 * 9) {
                if (!mergeItemStack(stackInSlot, 3 * 9, inventorySlots.size(), true)) {
                    return null;
                }
            } else if (!mergeItemStack(stackInSlot, 0, 3 * 9, false)) {
                return null;
            }

            if (stackInSlot.stackSize == 0) {
                slot.putStack((ItemStack) null);
            } else {
                slot.onSlotChanged();
            }
        }
        return stack;
    }

    @Override
    public boolean canInteractWith(EntityPlayer player) {
        return teInventory.isUseableByPlayer(player);
    }
}