aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/tileentities/TE_ItemDistributionNode.java
blob: 20b6500598c77c0200c87a0db93f3e31f0b9e1f3 (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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package tileentities;

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

public class TE_ItemDistributionNode extends TileEntity implements IConduit, IInventory {
	
private ItemDistributionNetworkController network;
	
	public TE_ItemDistributionNode() {
		ItemDistributionNetworkController.placeConduit(this);
	}
	
	@Override
	public void setNetwork(ItemDistributionNetworkController network) {
		this.network = network;
	}
	
	@Override
	public ItemDistributionNetworkController getNetwork() {
		return network;
	}
	
	@Override
	public int getSizeInventory() {
		return 16;
	}

	@Override
	public ItemStack getStackInSlot(int slot) {
		return network.getStackInSlot(slot);
	}

	@Override
	public ItemStack decrStackSize(int slot, int amount) {
		
		if(network.getStackInSlot(slot) != null) {
			if(network.getStackInSlot(slot).stackSize == amount) {
				final ItemStack itemStack = network.getStackInSlot(slot);
				network.setStackInSlot(slot, null);
				super.markDirty();
				return itemStack;
			} else {
				final ItemStack itemStack = network.getStackInSlot(slot).splitStack(amount);
				if(network.getStackInSlot(slot).stackSize == 0) {
					network.setStackInSlot(slot, null);
				}
				super.markDirty();
				return itemStack;
			}
		}
		
		return null;
	}

	@Override
	public ItemStack getStackInSlotOnClosing(int slot) {
		if(network.getStackInSlot(slot) != null) {
			final ItemStack itemStack = network.getStackInSlot(slot);
			network.setStackInSlot(slot, null);
			return itemStack;
		}
		return null;
	}

	@Override
	public void setInventorySlotContents(int slot, ItemStack itemStack) {
		if(itemStack == null) {
			return;
		}
		if(itemStack.stackSize > getInventoryStackLimit()) {
			itemStack.stackSize = getInventoryStackLimit();
		}
		network.setStackInSlot(slot, itemStack);
		super.markDirty();
	}

	@Override
	public String getInventoryName() {
		return network.getUUID().toString();
	}

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

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

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

	@Override
	public void openInventory() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void closeInventory() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public boolean isItemValidForSlot(int slot, ItemStack itemStack) {
		return network.isInputSlot(slot) && network.getStackInSlot(slot).isItemEqual(itemStack);
	}

}