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
|
package gregtech.api.logic.interfaces;
import java.util.HashSet;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
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.enums.InventoryType;
import gregtech.api.logic.ItemInventoryLogic;
public interface ItemInventoryLogicHost extends ISidedInventory {
/**
* To be used for single blocks or when directly interacting with the controller
*
* @param side The side from where items are being inputted or extracted from
* @param type The type of inventory being accessed. For inputting its Input, For outputting its Output.
* @return The Item Logic responsible for said type. Will return null if the side is not valid
*/
@Nullable
ItemInventoryLogic getItemLogic(@Nonnull ForgeDirection side, @Nonnull InventoryType type);
/**
* Only to be used by MultiBlockPart for accessing the Controller Inventory
*
* @param type Type of inventory, is it Input or Output
* @param id ID of the locked inventory. A null id is all inventories of said controller of said type
* @return The Item Logic responsible for everything that should be done with said inventory
*/
@Nonnull
default ItemInventoryLogic getItemLogic(@Nonnull InventoryType type, @Nullable UUID id) {
return Objects.requireNonNull(getItemLogic(ForgeDirection.UNKNOWN, type));
}
/**
* Only to be used for MultiBlockPart
*
* @return
*/
@Nullable
default InventoryType getItemInventoryType() {
return null;
}
/**
* Returns an empty set if the type is {@link InventoryType#Both} or this is used when the machine isn't a
* controller
*/
@Nonnull
default Set<Entry<UUID, ItemInventoryLogic>> getAllItemInventoryLogics(@Nonnull InventoryType type) {
return new HashSet<>();
}
@Override
@Nullable
default ItemStack decrStackSize(int slot, int count) {
InventoryType type = getItemInventoryType();
if (type == InventoryType.Both) return null;
ItemInventoryLogic logic = getItemLogic(ForgeDirection.UNKNOWN, type == null ? InventoryType.Output : type);
if (logic == null) return null;
return logic.extractItem(slot, count);
}
@Override
default int getSizeInventory() {
InventoryType type = getItemInventoryType();
if (type == InventoryType.Both) return 0;
ItemInventoryLogic logic = getItemLogic(ForgeDirection.UNKNOWN, type == null ? InventoryType.Output : type);
if (logic == null) return 0;
return logic.getSlots();
}
@Override
@Nullable
default ItemStack getStackInSlot(int slot) {
InventoryType type = getItemInventoryType();
if (type == InventoryType.Both) return null;
ItemInventoryLogic logic = getItemLogic(ForgeDirection.UNKNOWN, type == null ? InventoryType.Output : type);
if (logic == null) return null;
return logic.getInventory()
.getStackInSlot(slot);
}
@Override
default boolean isItemValidForSlot(int slot, @Nullable ItemStack stack) {
InventoryType type = getItemInventoryType();
if (type == InventoryType.Both) return false;
ItemInventoryLogic logic = getItemLogic(ForgeDirection.UNKNOWN, type == null ? InventoryType.Output : type);
if (logic == null) return false;
return logic.getInventory()
.isItemValid(slot, stack);
}
@Override
default void setInventorySlotContents(int slot, @Nullable ItemStack stack) {
InventoryType type = getItemInventoryType();
if (type == InventoryType.Both) return;
ItemInventoryLogic logic = getItemLogic(ForgeDirection.UNKNOWN, type == null ? InventoryType.Output : type);
if (logic == null) return;
logic.getInventory()
.setStackInSlot(slot, stack);
}
@Override
default boolean canExtractItem(int ignoredSlot, ItemStack ignoredItem, int side) {
InventoryType type = getItemInventoryType();
if (type == null) return false;
return getItemLogic(ForgeDirection.getOrientation(side), type) != null;
}
@Override
default boolean canInsertItem(int ignoredSlot, ItemStack ignoredItem, int side) {
InventoryType type = getItemInventoryType();
if (type == null) return false;
return getItemInventoryType() != InventoryType.Output
&& getItemLogic(ForgeDirection.getOrientation(side), type) != null;
}
@Override
default int[] getAccessibleSlotsFromSide(int side) {
InventoryType type = getItemInventoryType();
if (type == null) return new int[0];
ItemInventoryLogic logic = getItemLogic(ForgeDirection.UNKNOWN, type == null ? InventoryType.Output : type);
if (logic == null) return new int[0];
int[] indexes = new int[logic.getSlots()];
for (int i = 0; i < logic.getSlots(); i++) {
indexes[i] = i;
}
return indexes;
}
@Override
default void closeInventory() {}
@Override
default String getInventoryName() {
return "";
}
@Override
default int getInventoryStackLimit() {
return 64;
}
@Override
default ItemStack getStackInSlotOnClosing(int index) {
return null;
}
@Override
default boolean hasCustomInventoryName() {
return false;
}
@Override
default boolean isUseableByPlayer(@Nonnull EntityPlayer player) {
return false;
}
@Override
default void openInventory() {}
}
|