Search in sources :

Example 1 with IGhostIngredientHandler

use of mezz.jei.api.gui.handlers.IGhostIngredientHandler in project SophisticatedBackpacks by P3pp3rF1y.

the class SBPPlugin method registerGuiHandlers.

@Override
public void registerGuiHandlers(IGuiHandlerRegistration registration) {
    registration.addGuiContainerHandler(BackpackScreen.class, new IGuiContainerHandler<BackpackScreen>() {

        @Override
        public List<Rectangle2d> getGuiExtraAreas(BackpackScreen gui) {
            List<Rectangle2d> ret = new ArrayList<>();
            gui.getUpgradeSlotsRectangle().ifPresent(ret::add);
            ret.addAll(gui.getUpgradeSettingsControl().getTabRectangles());
            gui.getSortButtonsRectangle().ifPresent(ret::add);
            return ret;
        }
    });
    registration.addGuiContainerHandler(SettingsScreen.class, new IGuiContainerHandler<SettingsScreen>() {

        @Override
        public List<Rectangle2d> getGuiExtraAreas(SettingsScreen gui) {
            return new ArrayList<>(gui.getSettingsTabControl().getTabRectangles());
        }
    });
    registration.addGhostIngredientHandler(BackpackScreen.class, new IGhostIngredientHandler<BackpackScreen>() {

        @Override
        public <I> List<Target<I>> getTargets(BackpackScreen screen, I i, boolean b) {
            List<Target<I>> targets = new ArrayList<>();
            if (!(i instanceof ItemStack)) {
                return targets;
            }
            ItemStack ghostStack = (ItemStack) i;
            BackpackContainer container = screen.getMenu();
            container.getOpenContainer().ifPresent(c -> c.getSlots().forEach(s -> {
                if (s instanceof IFilterSlot && s.mayPlace(ghostStack)) {
                    targets.add(new Target<I>() {

                        @Override
                        public Rectangle2d getArea() {
                            return new Rectangle2d(screen.getGuiLeft() + s.x, screen.getGuiTop() + s.y, 17, 17);
                        }

                        @Override
                        public void accept(I i) {
                            PacketHandler.sendToServer(new SetGhostSlotMessage(ghostStack, s.index));
                        }
                    });
                }
            }));
            return targets;
        }

        @Override
        public void onComplete() {
        // noop
        }
    });
}
Also used : IRecipeCatalystRegistration(mezz.jei.api.registration.IRecipeCatalystRegistration) SophisticatedBackpacks(net.p3pp3rf1y.sophisticatedbackpacks.SophisticatedBackpacks) IStackHelper(mezz.jei.api.helpers.IStackHelper) BackpackScreen(net.p3pp3rf1y.sophisticatedbackpacks.client.gui.BackpackScreen) ArrayList(java.util.ArrayList) IModPlugin(mezz.jei.api.IModPlugin) ItemStack(net.minecraft.item.ItemStack) JeiPlugin(mezz.jei.api.JeiPlugin) IGhostIngredientHandler(mezz.jei.api.gui.handlers.IGhostIngredientHandler) IRecipeTransferRegistration(mezz.jei.api.registration.IRecipeTransferRegistration) IRecipeRegistration(mezz.jei.api.registration.IRecipeRegistration) IRecipeTransferHandlerHelper(mezz.jei.api.recipe.transfer.IRecipeTransferHandlerHelper) SettingsScreen(net.p3pp3rf1y.sophisticatedbackpacks.client.gui.SettingsScreen) PacketHandler(net.p3pp3rf1y.sophisticatedbackpacks.network.PacketHandler) BackpackContainer(net.p3pp3rf1y.sophisticatedbackpacks.common.gui.BackpackContainer) VanillaRecipeCategoryUid(mezz.jei.api.constants.VanillaRecipeCategoryUid) Rectangle2d(net.minecraft.client.renderer.Rectangle2d) CapabilityBackpackWrapper(net.p3pp3rf1y.sophisticatedbackpacks.api.CapabilityBackpackWrapper) IGuiHandlerRegistration(mezz.jei.api.registration.IGuiHandlerRegistration) IGuiContainerHandler(mezz.jei.api.gui.handlers.IGuiContainerHandler) ModItems(net.p3pp3rf1y.sophisticatedbackpacks.init.ModItems) ISubtypeInterpreter(mezz.jei.api.ingredients.subtypes.ISubtypeInterpreter) List(java.util.List) IFilterSlot(net.p3pp3rf1y.sophisticatedbackpacks.common.gui.IFilterSlot) ISubtypeRegistration(mezz.jei.api.registration.ISubtypeRegistration) ResourceLocation(net.minecraft.util.ResourceLocation) Rectangle2d(net.minecraft.client.renderer.Rectangle2d) IFilterSlot(net.p3pp3rf1y.sophisticatedbackpacks.common.gui.IFilterSlot) BackpackScreen(net.p3pp3rf1y.sophisticatedbackpacks.client.gui.BackpackScreen) BackpackContainer(net.p3pp3rf1y.sophisticatedbackpacks.common.gui.BackpackContainer) ArrayList(java.util.ArrayList) List(java.util.List) ItemStack(net.minecraft.item.ItemStack) SettingsScreen(net.p3pp3rf1y.sophisticatedbackpacks.client.gui.SettingsScreen)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 IModPlugin (mezz.jei.api.IModPlugin)1 JeiPlugin (mezz.jei.api.JeiPlugin)1 VanillaRecipeCategoryUid (mezz.jei.api.constants.VanillaRecipeCategoryUid)1 IGhostIngredientHandler (mezz.jei.api.gui.handlers.IGhostIngredientHandler)1 IGuiContainerHandler (mezz.jei.api.gui.handlers.IGuiContainerHandler)1 IStackHelper (mezz.jei.api.helpers.IStackHelper)1 ISubtypeInterpreter (mezz.jei.api.ingredients.subtypes.ISubtypeInterpreter)1 IRecipeTransferHandlerHelper (mezz.jei.api.recipe.transfer.IRecipeTransferHandlerHelper)1 IGuiHandlerRegistration (mezz.jei.api.registration.IGuiHandlerRegistration)1 IRecipeCatalystRegistration (mezz.jei.api.registration.IRecipeCatalystRegistration)1 IRecipeRegistration (mezz.jei.api.registration.IRecipeRegistration)1 IRecipeTransferRegistration (mezz.jei.api.registration.IRecipeTransferRegistration)1 ISubtypeRegistration (mezz.jei.api.registration.ISubtypeRegistration)1 Rectangle2d (net.minecraft.client.renderer.Rectangle2d)1 ItemStack (net.minecraft.item.ItemStack)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 SophisticatedBackpacks (net.p3pp3rf1y.sophisticatedbackpacks.SophisticatedBackpacks)1 CapabilityBackpackWrapper (net.p3pp3rf1y.sophisticatedbackpacks.api.CapabilityBackpackWrapper)1