-
Notifications
You must be signed in to change notification settings - Fork 497
/
InventoryConcatenator.java
103 lines (84 loc) · 2.28 KB
/
InventoryConcatenator.java
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
/*
* Copyright (c) SpaceToad, 2011-2012
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.core.inventory;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
/**
* Allows you to deal with multiple inventories through a single interface.
*
* @author CovertJaguar <http://www.railcraft.info/>
*/
public class InventoryConcatenator implements IInventory {
private final List<Integer> slotMap = new ArrayList<Integer>();
private final List<IInventory> invMap = new ArrayList<IInventory>();
private InventoryConcatenator() {
}
public static InventoryConcatenator make() {
return new InventoryConcatenator();
}
public InventoryConcatenator add(IInventory inv) {
for (int slot = 0; slot < inv.getSizeInventory(); slot++) {
slotMap.add(slot);
invMap.add(inv);
}
return this;
}
@Override
public int getSizeInventory() {
return slotMap.size();
}
@Override
public ItemStack getStackInSlot(int slot) {
return invMap.get(slot).getStackInSlot(slotMap.get(slot));
}
@Override
public ItemStack decrStackSize(int slot, int amount) {
return invMap.get(slot).decrStackSize(slotMap.get(slot), amount);
}
@Override
public ItemStack getStackInSlotOnClosing(int slot) {
return invMap.get(slot).getStackInSlotOnClosing(slotMap.get(slot));
}
@Override
public void setInventorySlotContents(int slot, ItemStack stack) {
invMap.get(slot).setInventorySlotContents(slotMap.get(slot), stack);
}
@Override
public String getInvName() {
return "";
}
@Override
public boolean isInvNameLocalized() {
return false;
}
@Override
public int getInventoryStackLimit() {
return 64;
}
@Override
public void onInventoryChanged() {
}
@Override
public boolean isUseableByPlayer(EntityPlayer entityplayer) {
return true;
}
@Override
public void openChest() {
}
@Override
public void closeChest() {
}
@Override
public boolean isItemValidForSlot(int slot, ItemStack stack) {
return invMap.get(slot).isItemValidForSlot(slotMap.get(slot), stack);
}
}