Search in sources :

Example 1 with QIOFrequency

use of mekanism.common.content.qio.QIOFrequency in project Mekanism by mekanism.

the class GuiQIOFilterHandler method addGuiElements.

@Override
protected void addGuiElements() {
    super.addGuiElements();
    addButton(new GuiQIOFrequencyTab(this, tile));
    addButton(new GuiInnerScreen(this, 9, 16, imageWidth - 18, 12, () -> {
        List<ITextComponent> list = new ArrayList<>();
        QIOFrequency freq = tile.getQIOFrequency();
        if (freq == null) {
            list.add(MekanismLang.NO_FREQUENCY.translate());
        } else {
            list.add(MekanismLang.FREQUENCY.translate(freq.getKey()));
        }
        return list;
    }).tooltip(() -> {
        List<ITextComponent> list = new ArrayList<>();
        QIOFrequency freq = tile.getQIOFrequency();
        if (freq != null) {
            list.add(MekanismLang.QIO_ITEMS_DETAIL.translateColored(EnumColor.GRAY, EnumColor.INDIGO, TextUtils.format(freq.getTotalItemCount()), TextUtils.format(freq.getTotalItemCountCapacity())));
            list.add(MekanismLang.QIO_TYPES_DETAIL.translateColored(EnumColor.GRAY, EnumColor.INDIGO, TextUtils.format(freq.getTotalItemTypes(true)), TextUtils.format(freq.getTotalItemTypeCapacity())));
        }
        return list;
    }));
    // Filter holder
    addButton(new GuiElementHolder(this, 9, 30, 144, 68));
    // new filter button border
    addButton(new GuiElementHolder(this, 9, 98, 144, 22));
    addButton(new TranslationButton(this, 10, 99, 142, 20, MekanismLang.BUTTON_NEW_FILTER, () -> addWindow(new GuiQIOFilerSelect(this, tile))));
    scrollBar = addButton(new GuiScrollBar(this, 153, 30, 90, () -> tile.getFilters().size(), () -> FILTER_COUNT));
    // Add each of the buttons and then just change visibility state to match filter info
    for (int i = 0; i < FILTER_COUNT; i++) {
        addButton(new MovableFilterButton(this, 10, 31 + i * 22, 142, 22, i, scrollBar::getCurrentSelection, tile::getFilters, index -> {
            if (index > 0) {
                Mekanism.packetHandler.sendToServer(new PacketGuiInteract(GuiInteraction.MOVE_FILTER_UP, tile, index));
            }
        }, index -> {
            if (index < tile.getFilters().size() - 1) {
                Mekanism.packetHandler.sendToServer(new PacketGuiInteract(GuiInteraction.MOVE_FILTER_DOWN, tile, index));
            }
        }, this::onClick, filter -> {
            List<ItemStack> list = new ArrayList<>();
            if (filter != null) {
                if (filter instanceof IItemStackFilter) {
                    list.add(((IItemStackFilter<?>) filter).getItemStack());
                } else if (filter instanceof ITagFilter) {
                    String name = ((ITagFilter<?>) filter).getTagName();
                    if (name != null && !name.isEmpty()) {
                        list.addAll(TagCache.getItemTagStacks(((ITagFilter<?>) filter).getTagName()));
                    }
                } else if (filter instanceof IModIDFilter) {
                    list.addAll(TagCache.getModIDStacks(((IModIDFilter<?>) filter).getModID(), false));
                }
            }
            return list;
        }));
    }
}
Also used : EnumColor(mekanism.api.text.EnumColor) TextUtils(mekanism.common.util.text.TextUtils) GuiElementHolder(mekanism.client.gui.element.GuiElementHolder) PacketGuiInteract(mekanism.common.network.to_server.PacketGuiInteract) QIOTagFilter(mekanism.common.content.qio.filter.QIOTagFilter) GuiQIOTagFilter(mekanism.client.gui.element.window.filter.qio.GuiQIOTagFilter) ArrayList(java.util.ArrayList) QIOItemStackFilter(mekanism.common.content.qio.filter.QIOItemStackFilter) ITextComponent(net.minecraft.util.text.ITextComponent) ItemStack(net.minecraft.item.ItemStack) GuiQIOFrequencyTab(mekanism.client.gui.element.tab.GuiQIOFrequencyTab) QIOFrequency(mekanism.common.content.qio.QIOFrequency) GuiScrollBar(mekanism.client.gui.element.scroll.GuiScrollBar) Nonnull(javax.annotation.Nonnull) MovableFilterButton(mekanism.client.gui.element.button.MovableFilterButton) MatrixStack(com.mojang.blaze3d.matrix.MatrixStack) TileEntityQIOFilterHandler(mekanism.common.tile.qio.TileEntityQIOFilterHandler) TranslationButton(mekanism.client.gui.element.button.TranslationButton) Mekanism(mekanism.common.Mekanism) PlayerInventory(net.minecraft.entity.player.PlayerInventory) GuiQIOItemStackFilter(mekanism.client.gui.element.window.filter.qio.GuiQIOItemStackFilter) ITagFilter(mekanism.common.content.filter.ITagFilter) GuiInnerScreen(mekanism.client.gui.element.GuiInnerScreen) List(java.util.List) IItemStackFilter(mekanism.common.content.filter.IItemStackFilter) IModIDFilter(mekanism.common.content.filter.IModIDFilter) MekanismTileContainer(mekanism.common.inventory.container.tile.MekanismTileContainer) GuiInteraction(mekanism.common.network.to_server.PacketGuiInteract.GuiInteraction) QIOModIDFilter(mekanism.common.content.qio.filter.QIOModIDFilter) MekanismLang(mekanism.common.MekanismLang) IFilter(mekanism.common.content.filter.IFilter) GuiQIOModIDFilter(mekanism.client.gui.element.window.filter.qio.GuiQIOModIDFilter) GuiMekanismTile(mekanism.client.gui.GuiMekanismTile) TagCache(mekanism.common.base.TagCache) TranslationButton(mekanism.client.gui.element.button.TranslationButton) ITextComponent(net.minecraft.util.text.ITextComponent) ArrayList(java.util.ArrayList) GuiScrollBar(mekanism.client.gui.element.scroll.GuiScrollBar) GuiQIOFrequencyTab(mekanism.client.gui.element.tab.GuiQIOFrequencyTab) PacketGuiInteract(mekanism.common.network.to_server.PacketGuiInteract) MovableFilterButton(mekanism.client.gui.element.button.MovableFilterButton) ITagFilter(mekanism.common.content.filter.ITagFilter) GuiInnerScreen(mekanism.client.gui.element.GuiInnerScreen) IItemStackFilter(mekanism.common.content.filter.IItemStackFilter) GuiElementHolder(mekanism.client.gui.element.GuiElementHolder) ArrayList(java.util.ArrayList) List(java.util.List) IModIDFilter(mekanism.common.content.filter.IModIDFilter) QIOFrequency(mekanism.common.content.qio.QIOFrequency)

Example 2 with QIOFrequency

use of mekanism.common.content.qio.QIOFrequency in project Mekanism by mekanism.

the class PacketGuiItemDataRequest method handle.

@Override
public void handle(NetworkEvent.Context context) {
    ServerPlayerEntity player = context.getSender();
    if (player != null) {
        if (type == Type.QIO_ITEM_VIEWER) {
            if (player.containerMenu instanceof QIOItemViewerContainer) {
                QIOItemViewerContainer container = (QIOItemViewerContainer) player.containerMenu;
                QIOFrequency freq = container.getFrequency();
                if (!player.level.isClientSide() && freq != null) {
                    freq.openItemViewer(player);
                }
            }
        }
    }
}
Also used : QIOItemViewerContainer(mekanism.common.inventory.container.QIOItemViewerContainer) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) QIOFrequency(mekanism.common.content.qio.QIOFrequency)

Example 3 with QIOFrequency

use of mekanism.common.content.qio.QIOFrequency in project Mekanism by mekanism.

the class QIOItemViewerContainer method quickMoveStack.

@Nonnull
@Override
public ItemStack quickMoveStack(@Nonnull PlayerEntity player, int slotID) {
    Slot currentSlot = slots.get(slotID);
    if (currentSlot == null) {
        return ItemStack.EMPTY;
    }
    if (currentSlot instanceof VirtualCraftingOutputSlot) {
        // If we are clicking an output crafting slot, allow the slot itself to handle the transferring
        return ((VirtualCraftingOutputSlot) currentSlot).shiftClickSlot(player, hotBarSlots, mainInventorySlots);
    } else if (currentSlot instanceof InventoryContainerSlot) {
        // use our normal handling to attempt and transfer the contents to the player's inventory
        return super.quickMoveStack(player, slotID);
    }
    // special handling for shift-clicking into GUI
    if (!player.level.isClientSide()) {
        ItemStack slotStack = currentSlot.getItem();
        byte selectedCraftingGrid = getSelectedCraftingGrid(player.getUUID());
        if (selectedCraftingGrid != -1) {
            // If the player has a crafting window open
            QIOCraftingWindow craftingWindow = getCraftingWindow(selectedCraftingGrid);
            if (!craftingWindow.isOutput(slotStack)) {
                // and the stack we are trying to transfer was not the output from the crafting window
                // as then shift clicking should be sending it into the QIO, then try transferring it
                // into the crafting window before transferring into the frequency
                ItemStack stackToInsert = slotStack;
                List<InventoryContainerSlot> craftingGridSlots = getCraftingGridSlots(selectedCraftingGrid);
                SelectedWindowData windowData = craftingWindow.getWindowData();
                // Start by trying to stack it with other things and if that fails try to insert it into empty slots
                stackToInsert = insertItem(craftingGridSlots, stackToInsert, windowData);
                if (stackToInsert.getCount() != slotStack.getCount()) {
                    // and return it as a new stack for what is now in the slot
                    return transferSuccess(currentSlot, player, slotStack, stackToInsert);
                }
            // Otherwise, if nothing changed, try to transfer into the QIO Frequency
            }
        }
        QIOFrequency frequency = getFrequency();
        if (frequency != null) {
            if (currentSlot.hasItem()) {
                // Make sure that we copy it so that we aren't just pointing to the reference of it
                slotStack = slotStack.copy();
                ItemStack ret = frequency.addItem(slotStack);
                if (slotStack.getCount() == ret.getCount()) {
                    return ItemStack.EMPTY;
                }
                setTransferTracker(slotStack, slotID);
                return updateSlot(player, currentSlot, ret);
            } else {
                if (slotID == lastSlot && !lastStack.isEmpty()) {
                    doDoubleClickTransfer(player);
                }
                resetTransferTracker();
                return ItemStack.EMPTY;
            }
        }
    }
    return ItemStack.EMPTY;
}
Also used : QIOCraftingWindow(mekanism.common.content.qio.QIOCraftingWindow) Slot(net.minecraft.inventory.container.Slot) InventoryContainerSlot(mekanism.common.inventory.container.slot.InventoryContainerSlot) VirtualInventoryContainerSlot(mekanism.common.inventory.container.slot.VirtualInventoryContainerSlot) CraftingWindowInventorySlot(mekanism.common.inventory.slot.CraftingWindowInventorySlot) VirtualCraftingOutputSlot(mekanism.common.inventory.container.slot.VirtualCraftingOutputSlot) VirtualCraftingOutputSlot(mekanism.common.inventory.container.slot.VirtualCraftingOutputSlot) InventoryContainerSlot(mekanism.common.inventory.container.slot.InventoryContainerSlot) VirtualInventoryContainerSlot(mekanism.common.inventory.container.slot.VirtualInventoryContainerSlot) ItemStack(net.minecraft.item.ItemStack) QIOFrequency(mekanism.common.content.qio.QIOFrequency) Nonnull(javax.annotation.Nonnull)

Example 4 with QIOFrequency

use of mekanism.common.content.qio.QIOFrequency in project Mekanism by mekanism.

the class QIOItemViewerContainer method doDoubleClickTransfer.

private void doDoubleClickTransfer(PlayerEntity player) {
    QIOFrequency freq = getFrequency();
    mainInventorySlots.forEach(slot -> {
        if (freq != null && slot.hasItem() && slot.mayPickup(player) && InventoryUtils.areItemsStackable(lastStack, slot.getItem())) {
            updateSlot(player, slot, freq.addItem(slot.getItem()));
        }
    });
    hotBarSlots.forEach(slot -> {
        if (freq != null && slot.hasItem() && slot.mayPickup(player) && InventoryUtils.areItemsStackable(lastStack, slot.getItem())) {
            updateSlot(player, slot, freq.addItem(slot.getItem()));
        }
    });
}
Also used : QIOFrequency(mekanism.common.content.qio.QIOFrequency)

Example 5 with QIOFrequency

use of mekanism.common.content.qio.QIOFrequency in project Mekanism by mekanism.

the class TileEntityQIOComponent method decrementFrequencyColor.

@ComputerMethod
private void decrementFrequencyColor() throws ComputerException {
    validateSecurityIsPublic();
    QIOFrequency frequency = computerGetFrequency();
    frequency.setColor(frequency.getColor().getPrevious());
}
Also used : QIOFrequency(mekanism.common.content.qio.QIOFrequency) ComputerMethod(mekanism.common.integration.computer.annotation.ComputerMethod)

Aggregations

QIOFrequency (mekanism.common.content.qio.QIOFrequency)17 ItemStack (net.minecraft.item.ItemStack)6 Nonnull (javax.annotation.Nonnull)5 ComputerMethod (mekanism.common.integration.computer.annotation.ComputerMethod)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 EnumColor (mekanism.api.text.EnumColor)3 Mekanism (mekanism.common.Mekanism)3 MekanismLang (mekanism.common.MekanismLang)3 QIOItemViewerContainer (mekanism.common.inventory.container.QIOItemViewerContainer)3 HashedItem (mekanism.common.lib.inventory.HashedItem)3 MatrixStack (com.mojang.blaze3d.matrix.MatrixStack)2 GuiMekanismTile (mekanism.client.gui.GuiMekanismTile)2 GuiInnerScreen (mekanism.client.gui.element.GuiInnerScreen)2 GuiQIOFrequencyTab (mekanism.client.gui.element.tab.GuiQIOFrequencyTab)2 ComputerException (mekanism.common.integration.computer.ComputerException)2 StackUtils (mekanism.common.util.StackUtils)2 TileEntity (net.minecraft.tileentity.TileEntity)2 Direction (net.minecraft.util.Direction)2 Byte2ObjectArrayMap (it.unimi.dsi.fastutil.bytes.Byte2ObjectArrayMap)1