forked from neoforged/NeoForge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathItemContainerContents.java.patch
41 lines (40 loc) · 1.32 KB
/
ItemContainerContents.java.patch
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
--- a/net/minecraft/world/item/component/ItemContainerContents.java
+++ b/net/minecraft/world/item/component/ItemContainerContents.java
@@ -146,6 +_,38 @@
return this.hashCode;
}
+ // Neo Start
+
+ /**
+ * {@return the number of slots in this container}
+ */
+ public int getSlots() {
+ return this.items.size();
+ }
+
+ /**
+ * Gets a copy of the stack at a particular slot.
+ *
+ * @param slot The slot to check. Must be within [0, {@link #getSlots()}]
+ * @return A copy of the stack in that slot
+ * @throws UnsupportedOperationException if the provided slot index is out-of-bounds.
+ */
+ public ItemStack getStackInSlot(int slot) {
+ validateSlotIndex(slot);
+ return this.items.get(slot).copy();
+ }
+
+ /**
+ * Throws {@link UnsupportedOperationException} if the provided slot index is invalid.
+ */
+ private void validateSlotIndex(int slot) {
+ if (slot < 0 || slot >= getSlots()) {
+ throw new UnsupportedOperationException("Slot " + slot + " not in valid range - [0," + getSlots() + ")");
+ }
+ }
+
+ // Neo End
+
static record Slot(int index, ItemStack item) {
public static final Codec<ItemContainerContents.Slot> CODEC = RecordCodecBuilder.create(
p_331695_ -> p_331695_.group(