use of mezz.jei.api.recipe.transfer.IRecipeTransferError in project LogisticsPipes by RS485.
the class RecipeTransferHandler method transferRecipe.
@Nullable
@Override
public IRecipeTransferError transferRecipe(@Nonnull DummyContainer container, @Nonnull IRecipeLayout recipeLayout, @Nonnull EntityPlayer player, boolean maxTransfer, boolean doTransfer) {
LogisticsBaseGuiScreen gui = container.guiHolderForJEI;
if (gui instanceof GuiLogisticsCraftingTable || gui instanceof GuiRequestTable) {
TileEntity tile;
if (gui instanceof GuiLogisticsCraftingTable) {
tile = ((GuiLogisticsCraftingTable) gui)._crafter;
} else {
tile = ((GuiRequestTable) gui)._table.container;
}
if (tile == null) {
return recipeTransferHandlerHelper.createInternalError();
}
if (!recipeLayout.getRecipeCategory().getUid().equals(VanillaRecipeCategoryUid.CRAFTING)) {
return recipeTransferHandlerHelper.createInternalError();
}
NEISetCraftingRecipe packet = PacketHandler.getPacket(NEISetCraftingRecipe.class);
NonNullList<ItemStack> stackList = packet.getStackList();
ItemStack[][] stacks = new ItemStack[9][];
boolean hasCanidates = false;
IGuiItemStackGroup guiItemStackGroup = recipeLayout.getItemStacks();
Map<Integer, ? extends IGuiIngredient<ItemStack>> guiIngredients = guiItemStackGroup.getGuiIngredients();
if (doTransfer) {
for (Map.Entry<Integer, ? extends IGuiIngredient<ItemStack>> ps : guiIngredients.entrySet()) {
if (!ps.getValue().isInput())
continue;
int slot = ps.getKey() - 1;
if (slot < 9) {
final ItemStack displayedIngredient = ps.getValue().getDisplayedIngredient();
stackList.set(slot, displayedIngredient == null ? ItemStack.EMPTY : displayedIngredient);
NonNullList<ItemStack> itemCandidateList = NonNullList.create();
// add all non-null non-empty ingredients to the itemCandidateList
ps.getValue().getAllIngredients().stream().filter(itemStack -> Objects.nonNull(itemStack) && !itemStack.isEmpty()).forEach(itemCandidateList::add);
if (!itemCandidateList.isEmpty()) {
Iterator<ItemStack> iter = itemCandidateList.iterator();
while (iter.hasNext()) {
ItemStack wildCardCheckStack = iter.next();
if (wildCardCheckStack.getItemDamage() == OreDictionary.WILDCARD_VALUE) {
iter.remove();
final CreativeTabs creativeTab = wildCardCheckStack.getItem().getCreativeTab();
if (creativeTab != null) {
NonNullList<ItemStack> secondList = NonNullList.create();
wildCardCheckStack.getItem().getSubItems(creativeTab, secondList);
itemCandidateList.addAll(secondList);
}
iter = itemCandidateList.iterator();
}
}
stacks[slot] = itemCandidateList.toArray(new ItemStack[0]);
if (stacks[slot].length > 1) {
hasCanidates = true;
} else if (stacks[slot].length == 1) {
stackList.set(slot, stacks[slot][0]);
}
}
}
}
if (hasCanidates) {
gui.setSubGui(new GuiRecipeImport(tile, stacks));
} else {
MainProxy.sendPacketToServer(packet.setTilePos(tile));
}
}
return null;
}
return recipeTransferHandlerHelper.createInternalError();
}
Aggregations