mirror of
https://github.com/GTNewHorizons/NotEnoughItems.git
synced 2026-11-27 15:33:19 +00:00
Extract inventory and missing ingredient helpers (#1164)
This commit is contained in:
1 parent
cdc8e22aec
commit
bdadcc37a6
8 files changed
+75
-67
No files matched your search
@@ -1,12 +1,17 @@
|
||||
package codechicken.nei;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.inventory.SlotCrafting;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
@@ -96,6 +101,16 @@ public class ItemStackAmount {
|
||||
return list;
|
||||
}
|
||||
|
||||
public Map<Item, List<ItemStack>> groupByItem() {
|
||||
final Map<Item, List<ItemStack>> groups = new HashMap<>();
|
||||
|
||||
for (ItemStack stack : values()) {
|
||||
groups.computeIfAbsent(stack.getItem(), i -> new ArrayList<>()).add(stack);
|
||||
}
|
||||
|
||||
return groups;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return this.itemMap.size();
|
||||
}
|
||||
@@ -140,4 +155,16 @@ public class ItemStackAmount {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static ItemStackAmount of(GuiContainer gui) {
|
||||
final ItemStackAmount result = new ItemStackAmount();
|
||||
|
||||
for (Slot slot : gui.inventorySlots.inventorySlots) {
|
||||
if (slot.getHasStack() && !(slot instanceof SlotCrafting) && slot.canTakeStack(gui.mc.thePlayer)) {
|
||||
result.add(slot.getStack());
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user