99import net .minecraftforge .items .ItemHandlerHelper ;
1010
1111import it .unimi .dsi .fastutil .objects .Object2ObjectOpenHashMap ;
12- import org .apache .commons .lang3 .tuple .Pair ;
1312
1413import java .util .Collection ;
1514import 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}
0 commit comments