Search in sources :

Example 1 with BackpackScreen

use of net.p3pp3rf1y.sophisticatedbackpacks.client.gui.BackpackScreen in project SophisticatedBackpacks by P3pp3rF1y.

the class ClientProxy method tryCallSort.

private static boolean tryCallSort(Screen gui) {
    Minecraft mc = Minecraft.getInstance();
    if (mc.player != null && mc.player.containerMenu instanceof BackpackContainer && gui instanceof BackpackScreen) {
        BackpackScreen screen = (BackpackScreen) gui;
        MouseHelper mh = mc.mouseHandler;
        double mouseX = mh.xpos() * mc.getWindow().getGuiScaledWidth() / mc.getWindow().getScreenWidth();
        double mouseY = mh.ypos() * mc.getWindow().getGuiScaledHeight() / mc.getWindow().getScreenHeight();
        BackpackContainer container = (BackpackContainer) mc.player.containerMenu;
        Slot selectedSlot = screen.findSlot(mouseX, mouseY);
        if (selectedSlot != null && !container.isPlayersInventorySlot(selectedSlot.index)) {
            container.sort();
            return true;
        }
    }
    return false;
}
Also used : BackpackContainer(net.p3pp3rf1y.sophisticatedbackpacks.common.gui.BackpackContainer) MouseHelper(net.minecraft.client.MouseHelper) Slot(net.minecraft.inventory.container.Slot) BackpackScreen(net.p3pp3rf1y.sophisticatedbackpacks.client.gui.BackpackScreen) Minecraft(net.minecraft.client.Minecraft)

Example 2 with BackpackScreen

use of net.p3pp3rf1y.sophisticatedbackpacks.client.gui.BackpackScreen 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)

Example 3 with BackpackScreen

use of net.p3pp3rf1y.sophisticatedbackpacks.client.gui.BackpackScreen in project SophisticatedBackpacks by P3pp3rF1y.

the class QuarkButtonReplacer method replace.

@Override
public Button replace(BackpackScreen screen, Button button) {
    MiniInventoryButton miniInventoryButton = ((MiniInventoryButton) button);
    int type = ObfuscationReflectionHelper.getPrivateValue(MiniInventoryButton.class, miniInventoryButton, "type");
    Slot slot = screen.getMenu().getSlot(8);
    int x = screen.getGuiLeft() + slot.x + 6;
    int y = screen.getGuiTop() + slot.y - 13;
    if (isBackpackSortButton(button, type, x, y)) {
        return new MiniInventoryButton(screen, SORT_TYPE, button.x - screen.getGuiLeft(), button.y - screen.getGuiTop(), "quark.gui.button.sort_container", b -> screen.getMenu().sort());
    } else if (isInsertButton(type)) {
        return new MiniInventoryButton(screen, INSERT_TYPE, button.x - screen.getGuiLeft(), button.y - screen.getGuiTop(), "quark.gui.button.insert", b -> PacketHandler.sendToServer(new TransferMessage(false)));
    } else if (isExtractButton(type)) {
        return new MiniInventoryButton(screen, EXTRACT_TYPE, button.x - screen.getGuiLeft(), button.y - screen.getGuiTop(), "quark.gui.button.extract", b -> PacketHandler.sendToServer(new TransferMessage(true)));
    }
    return button;
}
Also used : SophisticatedBackpacks(net.p3pp3rf1y.sophisticatedbackpacks.SophisticatedBackpacks) ObfuscationReflectionHelper(net.minecraftforge.fml.common.ObfuscationReflectionHelper) Button(net.minecraft.client.gui.widget.button.Button) Slot(net.minecraft.inventory.container.Slot) MiniInventoryButton(vazkii.quark.content.management.client.gui.MiniInventoryButton) BackpackScreen(net.p3pp3rf1y.sophisticatedbackpacks.client.gui.BackpackScreen) PacketHandler(net.p3pp3rf1y.sophisticatedbackpacks.network.PacketHandler) MiniInventoryButton(vazkii.quark.content.management.client.gui.MiniInventoryButton) Slot(net.minecraft.inventory.container.Slot)

Example 4 with BackpackScreen

use of net.p3pp3rf1y.sophisticatedbackpacks.client.gui.BackpackScreen in project SophisticatedBackpacks by P3pp3rF1y.

the class ClientProxy method sendBackpackOpenOrCloseMessage.

@SuppressWarnings({ "java:S2440", "InstantiationOfUtilityClass" })
private static void sendBackpackOpenOrCloseMessage() {
    if (!GUI.isActive()) {
        PacketHandler.sendToServer(new BackpackOpenMessage());
        return;
    }
    Screen screen = Minecraft.getInstance().screen;
    if (screen instanceof BackpackScreen) {
        BackpackScreen backpackScreen = (BackpackScreen) screen;
        Slot slot = backpackScreen.getSlotUnderMouse();
        if (slot != null && slot.getItem().getItem() instanceof BackpackItem) {
            if (slot.getItem().getCount() == 1) {
                PacketHandler.sendToServer(new BackpackOpenMessage(slot.index, true));
            }
        } else {
            PacketHandler.sendToServer(new BackpackCloseMessage());
        }
    } else if (screen instanceof InventoryScreen) {
        Slot slot = ((InventoryScreen) screen).getSlotUnderMouse();
        if (slot != null && isSupportedPlayerInventorySlot(slot.index) && slot.getItem().getItem() instanceof BackpackItem) {
            PacketHandler.sendToServer(new BackpackOpenMessage(slot.getSlotIndex(), false));
        }
    }
}
Also used : BackpackOpenMessage(net.p3pp3rf1y.sophisticatedbackpacks.network.BackpackOpenMessage) BackpackScreen(net.p3pp3rf1y.sophisticatedbackpacks.client.gui.BackpackScreen) Screen(net.minecraft.client.gui.screen.Screen) ContainerScreen(net.minecraft.client.gui.screen.inventory.ContainerScreen) InventoryScreen(net.minecraft.client.gui.screen.inventory.InventoryScreen) CreativeScreen(net.minecraft.client.gui.screen.inventory.CreativeScreen) BackpackCloseMessage(net.p3pp3rf1y.sophisticatedbackpacks.network.BackpackCloseMessage) Slot(net.minecraft.inventory.container.Slot) BackpackScreen(net.p3pp3rf1y.sophisticatedbackpacks.client.gui.BackpackScreen) InventoryScreen(net.minecraft.client.gui.screen.inventory.InventoryScreen) BackpackItem(net.p3pp3rf1y.sophisticatedbackpacks.backpack.BackpackItem)

Aggregations

BackpackScreen (net.p3pp3rf1y.sophisticatedbackpacks.client.gui.BackpackScreen)4 Slot (net.minecraft.inventory.container.Slot)3 SophisticatedBackpacks (net.p3pp3rf1y.sophisticatedbackpacks.SophisticatedBackpacks)2 BackpackContainer (net.p3pp3rf1y.sophisticatedbackpacks.common.gui.BackpackContainer)2 PacketHandler (net.p3pp3rf1y.sophisticatedbackpacks.network.PacketHandler)2 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