Search in sources :

Example 6 with LogisticsBaseGuiScreen

use of logisticspipes.utils.gui.LogisticsBaseGuiScreen in project LogisticsPipes by RS485.

the class GhostIngredientHandler method getTargets.

@Nonnull
@Override
public <I> List<Target<I>> getTargets(@Nonnull LogisticsBaseGuiScreen gui, @Nonnull I ingredient, boolean doStart) {
    if (ingredient instanceof ItemStack) {
        Stream<Target<I>> slotStream = gui.inventorySlots.inventorySlots.stream().filter(it -> it instanceof DummySlot).map(it -> (DummySlot) it).map(it -> new Target<I>() {

            @Nonnull
            @Override
            public Rectangle getArea() {
                return new Rectangle(gui.getGuiLeft() + it.xPos, gui.getGuiTop() + it.yPos, 17, 17);
            }

            @Override
            public void accept(@Nonnull I ingredient) {
                it.putStack((ItemStack) ingredient);
                MainProxy.sendPacketToServer(PacketHandler.getPacket(SetGhostItemPacket.class).setInteger(it.slotNumber).setStack((ItemStack) ingredient));
            }
        });
        if (FluidIdentifier.get((ItemStack) ingredient) != null) {
            Stream<Target<I>> fluidStream = gui.inventorySlots.inventorySlots.stream().filter(it -> it instanceof FluidSlot).map(it -> (FluidSlot) it).map(it -> new Target<I>() {

                @Nonnull
                @Override
                public Rectangle getArea() {
                    return new Rectangle(gui.getGuiLeft() + it.xPos, gui.getGuiTop() + it.yPos, 17, 17);
                }

                @Override
                public void accept(@Nonnull I ingredient) {
                    FluidIdentifier ident = FluidIdentifier.get((ItemStack) ingredient);
                    if (ident != null) {
                        ItemStack stack = ident.getItemIdentifier().unsafeMakeNormalStack(1);
                        it.putStack(stack);
                        MainProxy.sendPacketToServer(PacketHandler.getPacket(SetGhostItemPacket.class).setInteger(it.slotNumber).setStack(stack));
                    }
                }
            });
            slotStream = Stream.concat(slotStream, fluidStream);
        }
        return slotStream.collect(Collectors.toList());
    } else if (ingredient instanceof FluidStack) {
        return gui.inventorySlots.inventorySlots.stream().filter(it -> it instanceof FluidSlot).map(it -> (FluidSlot) it).map(it -> new Target<I>() {

            @Nonnull
            @Override
            public Rectangle getArea() {
                return new Rectangle(gui.getGuiLeft() + it.xPos, gui.getGuiTop() + it.yPos, 17, 17);
            }

            @Override
            public void accept(@Nonnull I ingredient) {
                FluidIdentifier ident = FluidIdentifier.get((FluidStack) ingredient);
                if (ident != null) {
                    ItemStack stack = ident.getItemIdentifier().unsafeMakeNormalStack(1);
                    it.putStack(stack);
                    MainProxy.sendPacketToServer(PacketHandler.getPacket(SetGhostItemPacket.class).setInteger(it.slotNumber).setStack(stack));
                }
            }
        }).collect(Collectors.toList());
    }
    return Collections.emptyList();
}
Also used : Rectangle(java.awt.Rectangle) FluidSlot(logisticspipes.utils.gui.FluidSlot) PacketHandler(logisticspipes.network.PacketHandler) MainProxy(logisticspipes.proxy.MainProxy) Collectors(java.util.stream.Collectors) LogisticsBaseGuiScreen(logisticspipes.utils.gui.LogisticsBaseGuiScreen) ItemStack(net.minecraft.item.ItemStack) List(java.util.List) SetGhostItemPacket(logisticspipes.network.packets.SetGhostItemPacket) FluidIdentifier(logisticspipes.utils.FluidIdentifier) Stream(java.util.stream.Stream) FluidStack(net.minecraftforge.fluids.FluidStack) IGhostIngredientHandler(mezz.jei.api.gui.IGhostIngredientHandler) Collections(java.util.Collections) Nonnull(javax.annotation.Nonnull) DummySlot(logisticspipes.utils.gui.DummySlot) Nonnull(javax.annotation.Nonnull) FluidStack(net.minecraftforge.fluids.FluidStack) DummySlot(logisticspipes.utils.gui.DummySlot) Rectangle(java.awt.Rectangle) FluidSlot(logisticspipes.utils.gui.FluidSlot) FluidIdentifier(logisticspipes.utils.FluidIdentifier) ItemStack(net.minecraft.item.ItemStack) Nonnull(javax.annotation.Nonnull)

Example 7 with LogisticsBaseGuiScreen

use of logisticspipes.utils.gui.LogisticsBaseGuiScreen 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();
}
Also used : DummyContainer(logisticspipes.utils.gui.DummyContainer) NEISetCraftingRecipe(logisticspipes.network.packets.NEISetCraftingRecipe) GuiRecipeImport(logisticspipes.gui.popup.GuiRecipeImport) MainProxy(logisticspipes.proxy.MainProxy) LogisticsBaseGuiScreen(logisticspipes.utils.gui.LogisticsBaseGuiScreen) ItemStack(net.minecraft.item.ItemStack) OreDictionary(net.minecraftforge.oredict.OreDictionary) Map(java.util.Map) IGuiIngredient(mezz.jei.api.gui.IGuiIngredient) CreativeTabs(net.minecraft.creativetab.CreativeTabs) NonNullList(net.minecraft.util.NonNullList) IRecipeTransferHandlerHelper(mezz.jei.api.recipe.transfer.IRecipeTransferHandlerHelper) Nonnull(javax.annotation.Nonnull) IRecipeLayout(mezz.jei.api.gui.IRecipeLayout) Nullable(javax.annotation.Nullable) IRecipeTransferError(mezz.jei.api.recipe.transfer.IRecipeTransferError) Iterator(java.util.Iterator) GuiRequestTable(logisticspipes.gui.orderer.GuiRequestTable) PacketHandler(logisticspipes.network.PacketHandler) IGuiItemStackGroup(mezz.jei.api.gui.IGuiItemStackGroup) GuiLogisticsCraftingTable(logisticspipes.gui.GuiLogisticsCraftingTable) Objects(java.util.Objects) Stream(java.util.stream.Stream) VanillaRecipeCategoryUid(mezz.jei.api.recipe.VanillaRecipeCategoryUid) EntityPlayer(net.minecraft.entity.player.EntityPlayer) TileEntity(net.minecraft.tileentity.TileEntity) IRecipeTransferHandler(mezz.jei.api.recipe.transfer.IRecipeTransferHandler) GuiRecipeImport(logisticspipes.gui.popup.GuiRecipeImport) GuiLogisticsCraftingTable(logisticspipes.gui.GuiLogisticsCraftingTable) LogisticsBaseGuiScreen(logisticspipes.utils.gui.LogisticsBaseGuiScreen) IGuiItemStackGroup(mezz.jei.api.gui.IGuiItemStackGroup) CreativeTabs(net.minecraft.creativetab.CreativeTabs) TileEntity(net.minecraft.tileentity.TileEntity) GuiRequestTable(logisticspipes.gui.orderer.GuiRequestTable) NEISetCraftingRecipe(logisticspipes.network.packets.NEISetCraftingRecipe) ItemStack(net.minecraft.item.ItemStack) Map(java.util.Map) Nullable(javax.annotation.Nullable)

Example 8 with LogisticsBaseGuiScreen

use of logisticspipes.utils.gui.LogisticsBaseGuiScreen in project LogisticsPipes by RS485.

the class ClientProxy method openFluidSelectGui.

@Override
public void openFluidSelectGui(final int slotId) {
    if (Minecraft.getMinecraft().currentScreen instanceof LogisticsBaseGuiScreen) {
        final List<ItemIdentifierStack> list = new ArrayList<>();
        for (FluidIdentifier fluid : FluidIdentifier.all()) {
            if (fluid == null) {
                continue;
            }
            list.add(fluid.getItemIdentifier().makeStack(1));
        }
        SelectItemOutOfList subGui = new SelectItemOutOfList(list, slot -> {
            if (slot == -1)
                return;
            MainProxy.sendPacketToServer(PacketHandler.getPacket(DummyContainerSlotClick.class).setSlotId(slotId).setStack(list.get(slot).makeNormalStack()).setButton(0));
        });
        LogisticsBaseGuiScreen gui = (LogisticsBaseGuiScreen) Minecraft.getMinecraft().currentScreen;
        if (!gui.hasSubGui()) {
            gui.setSubGui(subGui);
        } else {
            SubGuiScreen nextGui = gui.getSubGui();
            while (nextGui.hasSubGui()) {
                nextGui = nextGui.getSubGui();
            }
            nextGui.setSubGui(subGui);
        }
    } else {
        throw new UnsupportedOperationException(String.valueOf(Minecraft.getMinecraft().currentScreen));
    }
}
Also used : LogisticsBaseGuiScreen(logisticspipes.utils.gui.LogisticsBaseGuiScreen) SelectItemOutOfList(logisticspipes.gui.popup.SelectItemOutOfList) ArrayList(java.util.ArrayList) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) FluidIdentifier(logisticspipes.utils.FluidIdentifier) SubGuiScreen(logisticspipes.utils.gui.SubGuiScreen)

Aggregations

LogisticsBaseGuiScreen (logisticspipes.utils.gui.LogisticsBaseGuiScreen)8 SubGuiScreen (logisticspipes.utils.gui.SubGuiScreen)5 GuiLogisticsCraftingTable (logisticspipes.gui.GuiLogisticsCraftingTable)3 GuiRequestTable (logisticspipes.gui.orderer.GuiRequestTable)3 GuiRecipeImport (logisticspipes.gui.popup.GuiRecipeImport)3 ItemStack (net.minecraft.item.ItemStack)3 ArrayList (java.util.ArrayList)2 Stream (java.util.stream.Stream)2 Nonnull (javax.annotation.Nonnull)2 PacketHandler (logisticspipes.network.PacketHandler)2 GuiProvider (logisticspipes.network.abstractguis.GuiProvider)2 PopupGuiProvider (logisticspipes.network.abstractguis.PopupGuiProvider)2 TargetNotFoundException (logisticspipes.network.exception.TargetNotFoundException)2 NEISetCraftingRecipe (logisticspipes.network.packets.NEISetCraftingRecipe)2 MainProxy (logisticspipes.proxy.MainProxy)2 FluidIdentifier (logisticspipes.utils.FluidIdentifier)2 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)2 PositionedStack (codechicken.nei.PositionedStack)1 SideOnly (cpw.mods.fml.relauncher.SideOnly)1 Rectangle (java.awt.Rectangle)1