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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
|
package gtPlusPlus.api.objects.minecraft;
import java.util.ArrayList;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.util.ForgeDirection;
import gregtech.api.util.GTUtility;
import gregtech.common.covers.CoverInfo;
import gtPlusPlus.core.tileentities.base.TileEntityBase;
import gtPlusPlus.core.util.data.ArrayUtils;
public class BTF_Inventory implements ISidedInventory {
public final ItemStack[] mInventory;
public final TileEntityBase mTile;
public BTF_Inventory(int aSlots, TileEntityBase tile) {
this.mInventory = new ItemStack[aSlots];
this.mTile = tile;
}
public ItemStack[] getRealInventory() {
purgeNulls();
return this.mInventory;
}
@Override
public int getSizeInventory() {
return this.mInventory.length;
}
@Override
public ItemStack getStackInSlot(int aIndex) {
return aIndex >= 0 && aIndex < this.mInventory.length ? this.mInventory[aIndex] : null;
}
@Override
public void setInventorySlotContents(int aIndex, ItemStack aStack) {
if (aIndex >= 0 && aIndex < this.mInventory.length) {
this.mInventory[aIndex] = aStack;
}
}
public boolean isAccessAllowed(EntityPlayer aPlayer) {
return true;
}
public boolean isValidSlot(int aIndex) {
return true;
}
@Override
public int getInventoryStackLimit() {
return 64;
}
public boolean setStackToZeroInsteadOfNull(int aIndex) {
return false;
}
@Override
public boolean isItemValidForSlot(int aIndex, ItemStack aStack) {
return isValidSlot(aIndex);
}
@Override
public ItemStack decrStackSize(int aIndex, int aAmount) {
ItemStack tStack = this.getStackInSlot(aIndex);
ItemStack rStack = GTUtility.copy(new Object[] { tStack });
if (tStack != null) {
if (tStack.stackSize <= aAmount) {
if (this.setStackToZeroInsteadOfNull(aIndex)) {
tStack.stackSize = 0;
} else {
this.setInventorySlotContents(aIndex, null);
}
} else {
rStack = tStack.splitStack(aAmount);
if (tStack.stackSize == 0 && !this.setStackToZeroInsteadOfNull(aIndex)) {
this.setInventorySlotContents(aIndex, null);
}
}
}
return rStack;
}
@Override
public int[] getAccessibleSlotsFromSide(int ordinalSide) {
final ForgeDirection side = ForgeDirection.getOrientation(ordinalSide);
ArrayList<Integer> tList = new ArrayList<>();
CoverInfo coverInfo = this.mTile.getCoverInfoAtSide(side);
boolean tSkip = coverInfo.letsItemsIn(-2) || coverInfo.letsItemsIn(-2);
for (int rArray = 0; rArray < this.getSizeInventory(); ++rArray) {
if (this.isValidSlot(rArray)
&& (tSkip || coverInfo.letsItemsOut(rArray) || coverInfo.letsItemsIn(rArray))) {
tList.add(rArray);
}
}
int[] arg6 = new int[tList.size()];
for (int i = 0; i < arg6.length; ++i) {
arg6[i] = tList.get(i);
}
return arg6;
}
@Override
public boolean canInsertItem(int aIndex, ItemStack aStack, int ordinalSide) {
return this.isValidSlot(aIndex) && aStack != null
&& aIndex < this.mInventory.length
&& (this.mInventory[aIndex] == null || GTUtility.areStacksEqual(aStack, this.mInventory[aIndex]))
&& this.allowPutStack(this.mTile, aIndex, ForgeDirection.getOrientation(ordinalSide), aStack);
}
@Override
public boolean canExtractItem(int aIndex, ItemStack aStack, int ordinalSide) {
return this.isValidSlot(aIndex) && aStack != null
&& aIndex < this.mInventory.length
&& this.allowPullStack(this.mTile, aIndex, ForgeDirection.getOrientation(ordinalSide), aStack);
}
public boolean allowPullStack(TileEntityBase mTile2, int aIndex, ForgeDirection side, ItemStack aStack) {
return aIndex >= 0 && aIndex < this.getSizeInventory();
}
public boolean allowPutStack(TileEntityBase aBaseMetaTileEntity, int aIndex, ForgeDirection side,
ItemStack aStack) {
return (aIndex >= 0 && aIndex < this.getSizeInventory())
&& (this.mInventory[aIndex] == null || GTUtility.areStacksEqual(this.mInventory[aIndex], aStack));
}
@Override
public ItemStack getStackInSlotOnClosing(int i) {
return null;
}
@Override
public final boolean hasCustomInventoryName() {
return mTile != null && mTile.hasCustomInventoryName();
}
@Override
public void markDirty() {
if (mTile != null) {
purgeNulls();
mTile.markDirty();
}
}
@Override
public boolean isUseableByPlayer(EntityPlayer entityplayer) {
return true;
}
@Override
public void openInventory() {}
@Override
public void closeInventory() {}
@Override
public final String getInventoryName() {
return this.mTile != null ? mTile.getInventoryName() : "";
}
public boolean isFull() {
for (int s = 0; s < this.getSizeInventory(); s++) {
ItemStack slot = mInventory[s];
if (slot == null || slot.stackSize != slot.getMaxStackSize()) {
return false;
}
}
return true;
}
public boolean isEmpty() {
for (int s = 0; s < this.getSizeInventory(); s++) {
ItemStack slot = mInventory[s];
if (slot != null) return false;
}
return true;
}
public boolean addItemStack(ItemStack aInput) {
if (aInput != null & (isEmpty() || !isFull())) {
for (int s = 0; s < this.getSizeInventory(); s++) {
if (mInventory != null && mInventory[s] != null) {
ItemStack slot = mInventory[s];
if (slot == null || (slot != null && GTUtility.areStacksEqual(aInput, slot)
&& slot.stackSize != slot.getItem()
.getItemStackLimit(slot))) {
if (slot == null) {
slot = aInput.copy();
} else {
slot.stackSize++;
}
this.setInventorySlotContents(s, slot);
return true;
}
}
}
}
return false;
}
public final void purgeNulls() {
ItemStack[] aTemp = ArrayUtils.removeNulls(this.mInventory);
for (int g = 0; g < this.getSizeInventory(); g++) {
if (aTemp.length < this.getSizeInventory()) {
if (g <= aTemp.length - 1) {
this.mInventory[g] = aTemp[g];
} else {
this.mInventory[g] = null;
}
} else {
this.mInventory[g] = aTemp[g];
}
}
}
}
|