Search in sources :

Example 1 with Rectangle2d

use of net.minecraft.client.renderer.Rectangle2d in project minecolonies by Minecolonies.

the class AbstractTeachingGuiHandler method getTargets.

@NotNull
@Override
public <I> List<Target<I>> getTargets(@NotNull final W gui, @NotNull final I ingredient, final boolean doStart) {
    final List<Target<I>> targets = new ArrayList<>();
    if (ingredient instanceof ItemStack) {
        for (final Slot slot : gui.getMenu().slots) {
            if (!slot.isActive() || !isSupportedSlot(slot))
                continue;
            final Rectangle2d bounds = new Rectangle2d(gui.getGuiLeft() + slot.x, gui.getGuiTop() + slot.y, 17, 17);
            targets.add(new Target<I>() {

                @NotNull
                @Override
                public Rectangle2d getArea() {
                    return bounds;
                }

                @Override
                public void accept(@NotNull I ingredient) {
                    slot.set((ItemStack) ingredient);
                    updateServer(gui);
                }
            });
        }
    }
    return targets;
}
Also used : ArrayList(java.util.ArrayList) Rectangle2d(net.minecraft.client.renderer.Rectangle2d) Slot(net.minecraft.inventory.container.Slot) ItemStack(net.minecraft.item.ItemStack) NotNull(org.jetbrains.annotations.NotNull) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with Rectangle2d

use of net.minecraft.client.renderer.Rectangle2d in project Mekanism by mekanism.

the class GhostIngredientHandler method addVisibleAreas.

private static void addVisibleAreas(List<Rectangle2d> visible, Rectangle2d area, List<Rectangle2d> coveredArea) {
    boolean intersected = false;
    int x = area.getX();
    int x2 = x + area.getWidth();
    int y = area.getY();
    int y2 = y + area.getHeight();
    int size = coveredArea.size();
    for (int i = 0; i < size; i++) {
        Rectangle2d covered = coveredArea.get(i);
        int cx = covered.getX();
        int cx2 = cx + covered.getWidth();
        int cy = covered.getY();
        int cy2 = cy + covered.getHeight();
        // Check if the covered area intersects the area we are checking against
        if (x < cx2 && x2 > cx && y < cy2 && y2 > cy) {
            intersected = true;
            if (x < cx || y < cy || x2 > cx2 || y2 > cy2) {
                // If the area is not fully covered then get the parts of it that are not covered
                List<Rectangle2d> uncoveredArea = getVisibleArea(area, covered);
                if (i + 1 == size) {
                    // If there are no more elements left, just add all the remaining visible parts
                    visible.addAll(uncoveredArea);
                } else {
                    // Otherwise, grab the remaining unchecked elements from the covering layer
                    List<Rectangle2d> coveredAreas = coveredArea.subList(i + 1, size);
                    // And check each of our sub visible areas
                    for (Rectangle2d visibleArea : uncoveredArea) {
                        addVisibleAreas(visible, visibleArea, coveredAreas);
                    }
                }
            }
            // If it is covered at all exit, we either added the uncovered parts or it is fully covered
            break;
        }
    }
    if (!intersected) {
        // If we didn't intersect it at all, just add the area itself
        visible.add(area);
    }
}
Also used : Rectangle2d(net.minecraft.client.renderer.Rectangle2d)

Example 3 with Rectangle2d

use of net.minecraft.client.renderer.Rectangle2d 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 4 with Rectangle2d

use of net.minecraft.client.renderer.Rectangle2d in project minecolonies by ldtteam.

the class JobBasedRecipeCategory method calculateInfoBlocks.

@NotNull
private List<InfoBlock> calculateInfoBlocks(@NotNull T recipe) {
    final List<ITextComponent> lines = generateInfoBlocks(recipe);
    final Minecraft mc = Minecraft.getInstance();
    final List<InfoBlock> result = new ArrayList<>();
    int y = CITIZEN_Y;
    for (final ITextComponent line : lines) {
        final String text = line.getString();
        final int width = (int) mc.font.getSplitter().stringWidth(text);
        final int height = mc.font.lineHeight;
        final int x = WIDTH - width;
        String tip = null;
        if (line instanceof TranslationTextComponent) {
            final String key = ((TranslationTextComponent) line).getKey() + ".tip";
            if (I18n.exists(key)) {
                tip = (new TranslationTextComponent(key, ((TranslationTextComponent) line).getArgs())).getString();
            }
        }
        result.add(new InfoBlock(text, tip, new Rectangle2d(x, y, width, height)));
        y += height + 2;
    }
    return result;
}
Also used : Rectangle2d(net.minecraft.client.renderer.Rectangle2d) Minecraft(net.minecraft.client.Minecraft) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with Rectangle2d

use of net.minecraft.client.renderer.Rectangle2d in project minecolonies by ldtteam.

the class AbstractTeachingGuiHandler method getTargets.

@NotNull
@Override
public <I> List<Target<I>> getTargets(@NotNull final W gui, @NotNull final I ingredient, final boolean doStart) {
    final List<Target<I>> targets = new ArrayList<>();
    if (ingredient instanceof ItemStack) {
        for (final Slot slot : gui.getMenu().slots) {
            if (!slot.isActive() || !isSupportedSlot(slot))
                continue;
            final Rectangle2d bounds = new Rectangle2d(gui.getGuiLeft() + slot.x, gui.getGuiTop() + slot.y, 17, 17);
            targets.add(new Target<I>() {

                @NotNull
                @Override
                public Rectangle2d getArea() {
                    return bounds;
                }

                @Override
                public void accept(@NotNull I ingredient) {
                    slot.set((ItemStack) ingredient);
                    updateServer(gui);
                }
            });
        }
    }
    return targets;
}
Also used : ArrayList(java.util.ArrayList) Rectangle2d(net.minecraft.client.renderer.Rectangle2d) Slot(net.minecraft.inventory.container.Slot) ItemStack(net.minecraft.item.ItemStack) NotNull(org.jetbrains.annotations.NotNull) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Rectangle2d (net.minecraft.client.renderer.Rectangle2d)8 ArrayList (java.util.ArrayList)5 NotNull (org.jetbrains.annotations.NotNull)4 ItemStack (net.minecraft.item.ItemStack)3 List (java.util.List)2 Minecraft (net.minecraft.client.Minecraft)2 Slot (net.minecraft.inventory.container.Slot)2 Int2ObjectLinkedOpenHashMap (it.unimi.dsi.fastutil.ints.Int2ObjectLinkedOpenHashMap)1 Entry (it.unimi.dsi.fastutil.ints.Int2ObjectMap.Entry)1 Int2ObjectOpenHashMap (it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap)1 GuiWindow (mekanism.client.gui.element.window.GuiWindow)1 IJEIGhostTarget (mekanism.client.jei.interfaces.IJEIGhostTarget)1 LRU (mekanism.common.lib.collection.LRU)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