aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/common/tileentities/TE_ItemProxySource.java
blob: 31403f5352a4d3c6f80ffe5e5d3d8b32a2d98136 (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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package common.tileentities;

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

public class TE_ItemProxySource extends TileEntity implements IInventory {

    private final ItemStack[] slots = new ItemStack[16];
    private String idCache = null;

    /**
     * Builds a simple unique identifier for this TileEntity by appending the x, y, and z coordinates in a string.
     *
     * @return unique identifier for this TileEntity
     */
    public String getIdentifier() {
        if (idCache == null) {
            idCache = "" + super.xCoord + super.yCoord + super.zCoord;
            return idCache;
        } else {
            return idCache;
        }
    }

    @Override
    public int getSizeInventory() {
        return slots.length;
    }

    @Override
    public ItemStack getStackInSlot(int slot) {
        return slots[slot];
    }

    @Override
    public ItemStack decrStackSize(int slot, int amount) {
        if (slots[slot] != null) {

            ItemStack copy;

            if (slots[slot].stackSize == amount) {
                copy = slots[slot];
                slots[slot] = null;
                super.markDirty();
                return copy;
            } else {
                copy = slots[slot].splitStack(amount);
                if (slots[slot].stackSize == 0) {
                    slots[slot] = null;
                }
                return copy;
            }

        } else {
            return null;
        }
    }

    @Override
    public ItemStack getStackInSlotOnClosing(int slot) {
        return null;
    }

    @Override
    public void setInventorySlotContents(int slot, ItemStack itemStack) {
        slots[slot] = itemStack;
        if (itemStack != null && itemStack.stackSize > getInventoryStackLimit()) {
            itemStack.stackSize = getInventoryStackLimit();
        }
        super.markDirty();
    }

    @Override
    public String getInventoryName() {
        return "Item Proxy Source";
    }

    @Override
    public boolean hasCustomInventoryName() {
        return true;
    }

    @Override
    public int getInventoryStackLimit() {
        return 64;
    }

    @Override
    public boolean isUseableByPlayer(EntityPlayer p_70300_1_) {
        return true;
    }

    @Override
    public void openInventory() {}

    @Override
    public void closeInventory() {}

    @Override
    public boolean isItemValidForSlot(int slot, ItemStack itemStack) {
        return true;
    }
}