Skip to content

Commit 5dbc628

Browse files
committed
some javadoc on new stuff & move some methods
1 parent cba4806 commit 5dbc628

File tree

5 files changed

+72
-25
lines changed

5 files changed

+72
-25
lines changed

src/main/java/com/cleanroommc/modularui/factory/inventory/Inventory.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
import net.minecraft.inventory.IInventory;
55
import net.minecraft.item.ItemStack;
66

7+
/**
8+
* A {@link InventoryType} implementation for {@link IInventory}.
9+
*/
710
public abstract class Inventory extends InventoryType {
811

912
public Inventory(String id) {

src/main/java/com/cleanroommc/modularui/factory/inventory/InventoryType.java

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import net.minecraftforge.items.ItemHandlerHelper;
1010

1111
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
12-
import org.apache.commons.lang3.tuple.Pair;
1312

1413
import java.util.Collection;
1514
import java.util.Collections;
@@ -50,6 +49,13 @@ public boolean isActive() {
5049

5150
public abstract int getSlotCount(EntityPlayer player);
5251

52+
/**
53+
* Returns the first stackable slot index for the given item
54+
*
55+
* @param player player of which inventory to visit
56+
* @param stack stack which should be checked stackability with
57+
* @return index of slot with stackable item or -1 if none found
58+
*/
5359
public int findFirstStackable(EntityPlayer player, ItemStack stack) {
5460
for (int i = 0, n = getSlotCount(player); i < n; ++i) {
5561
ItemStack stackInSlot = getStackInSlot(player, i);
@@ -66,6 +72,15 @@ public int findFirstStackable(EntityPlayer player, ItemStack stack) {
6672
return -1;
6773
}
6874

75+
/**
76+
* Visits all slots which item is stackable with the given item in the inventory with the given visitor function.
77+
* Two empty items also count as stackable.
78+
*
79+
* @param player player of which inventory to visit
80+
* @param stack stack which should be checked stackability with
81+
* @param visitor visit function
82+
* @return if the visitor function returned true on a slot
83+
*/
6984
public boolean visitAllStackable(EntityPlayer player, ItemStack stack, InventoryVisitor visitor) {
7085
for (int i = 0, n = getSlotCount(player); i < n; ++i) {
7186
ItemStack stackInSlot = getStackInSlot(player, i);
@@ -86,6 +101,13 @@ public boolean visitAllStackable(EntityPlayer player, ItemStack stack, Inventory
86101
return false;
87102
}
88103

104+
/**
105+
* Visits all slots in the inventory with the given visitor function.
106+
*
107+
* @param player player of which inventory to visit
108+
* @param visitor visit function
109+
* @return if the visitor function returned true on a slot
110+
*/
89111
public boolean visitAll(EntityPlayer player, InventoryVisitor visitor) {
90112
for (int i = 0, n = getSlotCount(player); i < n; ++i) {
91113
ItemStack stackInSlot = getStackInSlot(player, i);
@@ -111,28 +133,4 @@ public static InventoryType getFromId(String id) {
111133
public static Collection<InventoryType> getAll() {
112134
return Collections.unmodifiableCollection(inventoryTypes.values());
113135
}
114-
115-
public static Pair<InventoryType, Integer> findFirstStackableInAll(EntityPlayer player, ItemStack stack) {
116-
for (InventoryType type : getAll()) {
117-
int i = type.findFirstStackable(player, stack);
118-
if (i >= 0) return Pair.of(type, i);
119-
}
120-
return null;
121-
}
122-
123-
public static void visitAllStackableInAll(EntityPlayer player, ItemStack stack, InventoryVisitor visitor) {
124-
for (InventoryType type : getAll()) {
125-
if (type.visitAllStackable(player, stack, visitor)) {
126-
return;
127-
}
128-
}
129-
}
130-
131-
public static void visitAllInAll(EntityPlayer player, InventoryVisitor visitor) {
132-
for (InventoryType type : getAll()) {
133-
if (type.visitAll(player, visitor)) {
134-
return;
135-
}
136-
}
137-
}
138136
}

src/main/java/com/cleanroommc/modularui/factory/inventory/InventoryTypes.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@
44

55
import net.minecraft.entity.player.EntityPlayer;
66
import net.minecraft.inventory.IInventory;
7+
import net.minecraft.item.ItemStack;
78
import net.minecraftforge.items.IItemHandlerModifiable;
89

910
import baubles.api.BaublesApi;
11+
import org.apache.commons.lang3.tuple.Pair;
12+
13+
import java.util.Collection;
1014

1115
public class InventoryTypes {
1216

@@ -32,4 +36,32 @@ public IItemHandlerModifiable getInventory(EntityPlayer player) {
3236
throw new IllegalArgumentException("Tried to receive bauble item, but bauble is not loaded");
3337
}
3438
};
39+
40+
public static Collection<InventoryType> getAll() {
41+
return InventoryType.getAll();
42+
}
43+
44+
public static Pair<InventoryType, Integer> findFirstStackable(EntityPlayer player, ItemStack stack) {
45+
for (InventoryType type : getAll()) {
46+
int i = type.findFirstStackable(player, stack);
47+
if (i >= 0) return Pair.of(type, i);
48+
}
49+
return null;
50+
}
51+
52+
public static void visitAllStackable(EntityPlayer player, ItemStack stack, InventoryVisitor visitor) {
53+
for (InventoryType type : getAll()) {
54+
if (type.visitAllStackable(player, stack, visitor)) {
55+
return;
56+
}
57+
}
58+
}
59+
60+
public static void visitAll(EntityPlayer player, InventoryVisitor visitor) {
61+
for (InventoryType type : getAll()) {
62+
if (type.visitAll(player, visitor)) {
63+
return;
64+
}
65+
}
66+
}
3567
}

src/main/java/com/cleanroommc/modularui/factory/inventory/InventoryVisitor.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,18 @@
22

33
import net.minecraft.item.ItemStack;
44

5+
/**
6+
* A function to visit a slot in a player bound inventory.
7+
*/
58
public interface InventoryVisitor {
69

10+
/**
11+
* Called on visiting a slot in a player bound inventory.
12+
*
13+
* @param type type of the current inventory
14+
* @param index index of the slot
15+
* @param stack content of the slot
16+
* @return true if no further slots should be visited
17+
*/
718
boolean visit(InventoryType type, int index, ItemStack stack);
819
}

src/main/java/com/cleanroommc/modularui/factory/inventory/ItemHandler.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
import net.minecraft.item.ItemStack;
55
import net.minecraftforge.items.IItemHandlerModifiable;
66

7+
/**
8+
* A {@link InventoryType} implementation for {@link IItemHandlerModifiable}.
9+
*/
710
public abstract class ItemHandler extends InventoryType {
811

912
public ItemHandler(String id) {

0 commit comments

Comments
 (0)