-
Notifications
You must be signed in to change notification settings - Fork 497
/
InventoryMapper.java
122 lines (102 loc) · 3.13 KB
/
InventoryMapper.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/**
* Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team
* 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 net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
/**
* Wrapper class used to specify part of an existing inventory to be treated as
* a complete inventory. Used primarily to map a side of an ISidedInventory, but
* it is also helpful for complex inventories such as the Tunnel Bore.
*/
public class InventoryMapper implements IInventory {
private final IInventory inv;
private final int start;
private final int size;
private int stackSizeLimit = -1;
private boolean checkItems = true;
/**
* Creates a new InventoryMapper
*
* @param inv The backing inventory
* @param start The starting index
* @param size The size of the new inventory, take care not to exceed the
* end of the backing inventory
*/
public InventoryMapper(IInventory inv, int start, int size) {
this(inv, start, size, true);
}
public InventoryMapper(IInventory inv, int start, int size, boolean checkItems) {
this.inv = inv;
this.start = start;
this.size = size;
this.checkItems = checkItems;
}
public IInventory getBaseInventory() {
return inv;
}
@Override
public int getSizeInventory() {
return size;
}
@Override
public ItemStack getStackInSlot(int slot) {
return inv.getStackInSlot(start + slot);
}
@Override
public ItemStack decrStackSize(int slot, int amount) {
return inv.decrStackSize(start + slot, amount);
}
@Override
public void setInventorySlotContents(int slot, ItemStack itemstack) {
inv.setInventorySlotContents(start + slot, itemstack);
}
@Override
public String getInventoryName() {
return inv.getInventoryName();
}
public void setStackSizeLimit(int limit) {
stackSizeLimit = limit;
}
@Override
public int getInventoryStackLimit() {
return stackSizeLimit > 0 ? stackSizeLimit : inv.getInventoryStackLimit();
}
@Override
public boolean isUseableByPlayer(EntityPlayer entityplayer) {
return inv.isUseableByPlayer(entityplayer);
}
@Override
public void openInventory() {
inv.openInventory();
}
@Override
public void closeInventory() {
inv.closeInventory();
}
@Override
public ItemStack getStackInSlotOnClosing(int slot) {
return inv.getStackInSlotOnClosing(start + slot);
}
@Override
public boolean isItemValidForSlot(int slot, ItemStack stack) {
if (checkItems) {
return inv.isItemValidForSlot(start + slot, stack);
}
return true;
}
@Override
public boolean hasCustomInventoryName() {
return inv.hasCustomInventoryName();
}
@Override
public void markDirty() {
inv.markDirty();
}
}