2014-04-29 10:54:20 +10:00
|
|
|
package codechicken.nei.api;
|
|
|
|
|
|
2024-08-17 23:24:27 +03:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Optional;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
2023-09-25 00:34:42 +02:00
|
|
|
import net.minecraft.client.gui.inventory.GuiContainer;
|
2024-08-17 23:24:27 +03:00
|
|
|
import net.minecraft.inventory.Slot;
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
2023-01-28 17:55:51 -08:00
|
|
|
|
2024-08-17 23:24:27 +03:00
|
|
|
import codechicken.nei.PositionedStack;
|
2023-09-25 00:35:24 +02:00
|
|
|
import codechicken.nei.recipe.IRecipeHandler;
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
public interface IOverlayHandler {
|
2023-01-28 17:55:51 -08:00
|
|
|
|
2023-02-09 19:21:30 +09:00
|
|
|
void overlayRecipe(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex, boolean shift);
|
2024-08-17 23:24:27 +03:00
|
|
|
|
|
|
|
|
default List<Boolean> presenceOverlay(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex) {
|
|
|
|
|
final List<Boolean> itemPresenceSlots = new ArrayList<>();
|
|
|
|
|
final List<PositionedStack> ingredients = recipe.getIngredientStacks(recipeIndex);
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
|
final List<ItemStack> invStacks = ((List<Slot>) firstGui.inventorySlots.inventorySlots).stream()
|
|
|
|
|
.filter(
|
|
|
|
|
s -> s != null && s.getStack() != null
|
|
|
|
|
&& s.getStack().stackSize > 0
|
|
|
|
|
&& s.isItemValid(s.getStack())
|
|
|
|
|
&& s.canTakeStack(firstGui.mc.thePlayer))
|
|
|
|
|
.map(s -> s.getStack().copy()).collect(Collectors.toCollection(ArrayList::new));
|
|
|
|
|
|
|
|
|
|
for (PositionedStack stack : ingredients) {
|
|
|
|
|
Optional<ItemStack> used = invStacks.stream().filter(is -> is.stackSize > 0 && stack.contains(is))
|
|
|
|
|
.findFirst();
|
|
|
|
|
|
|
|
|
|
itemPresenceSlots.add(used.isPresent());
|
|
|
|
|
|
|
|
|
|
if (used.isPresent()) {
|
|
|
|
|
ItemStack is = used.get();
|
|
|
|
|
is.stackSize -= 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return itemPresenceSlots;
|
|
|
|
|
}
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|