Search in sources :

Example 1 with PacketAmadronOrderUpdate

use of pneumaticCraft.common.network.PacketAmadronOrderUpdate in project PneumaticCraft by MineMaarten.

the class GuiAmadron method updateVisibleOffers.

public void updateVisibleOffers() {
    needsRefreshing = false;
    final ContainerAmadron container = (ContainerAmadron) inventorySlots;
    int invSize = ContainerAmadron.ROWS * 2;
    container.clearStacks();
    List<AmadronOffer> offers = container.offers;
    List<AmadronOffer> visibleOffers = new ArrayList<AmadronOffer>();
    int skippedOffers = 0;
    int applicableOffers = 0;
    for (AmadronOffer offer : offers) {
        if (offer.passesQuery(searchBar.getText())) {
            applicableOffers++;
            if (skippedOffers < page * invSize) {
                skippedOffers++;
            } else if (visibleOffers.size() < invSize) {
                visibleOffers.add(offer);
            }
        }
    }
    scrollbar.setStates(Math.max(1, (applicableOffers + invSize - 1) / invSize - 1));
    widgets.removeAll(widgetOffers);
    for (int i = 0; i < visibleOffers.size(); i++) {
        AmadronOffer offer = visibleOffers.get(i);
        if (offer.getInput() instanceof ItemStack)
            container.setStack(i * 2, (ItemStack) offer.getInput());
        if (offer.getOutput() instanceof ItemStack)
            container.setStack(i * 2 + 1, (ItemStack) offer.getOutput());
        WidgetAmadronOffer widget = new WidgetAmadronOffer(i, guiLeft + 6 + 73 * (i % 2), guiTop + 55 + 35 * (i / 2), offer) {

            @Override
            public void onMouseClicked(int mouseX, int mouseY, int button) {
                NetworkHandler.sendToServer(new PacketAmadronOrderUpdate(container.offers.indexOf(getOffer()), button, PneumaticCraft.proxy.isSneakingInGui()));
            }
        };
        addWidget(widget);
        widgetOffers.add(widget);
    }
}
Also used : WidgetAmadronOffer(pneumaticCraft.client.gui.widget.WidgetAmadronOffer) AmadronOffer(pneumaticCraft.common.recipes.AmadronOffer) ArrayList(java.util.ArrayList) ContainerAmadron(pneumaticCraft.common.inventory.ContainerAmadron) WidgetAmadronOffer(pneumaticCraft.client.gui.widget.WidgetAmadronOffer) ItemStack(net.minecraft.item.ItemStack) PacketAmadronOrderUpdate(pneumaticCraft.common.network.PacketAmadronOrderUpdate) Point(java.awt.Point)

Aggregations

Point (java.awt.Point)1 ArrayList (java.util.ArrayList)1 ItemStack (net.minecraft.item.ItemStack)1 WidgetAmadronOffer (pneumaticCraft.client.gui.widget.WidgetAmadronOffer)1 ContainerAmadron (pneumaticCraft.common.inventory.ContainerAmadron)1 PacketAmadronOrderUpdate (pneumaticCraft.common.network.PacketAmadronOrderUpdate)1 AmadronOffer (pneumaticCraft.common.recipes.AmadronOffer)1