Search in sources :

Example 1 with AmadronOffer

use of pneumaticCraft.common.recipes.AmadronOffer 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)

Example 2 with AmadronOffer

use of pneumaticCraft.common.recipes.AmadronOffer in project PneumaticCraft by MineMaarten.

the class AmadronOfferConfig method writeToJson.

@Override
protected final void writeToJson(JsonObject json) {
    JsonArray array = new JsonArray();
    for (AmadronOffer offer : getOffers()) {
        array.add(offer.toJson());
    }
    json.addProperty("description", getComment());
    writeToJsonCustom(json);
    json.add("offers", array);
}
Also used : JsonArray(com.google.gson.JsonArray) AmadronOffer(pneumaticCraft.common.recipes.AmadronOffer)

Example 3 with AmadronOffer

use of pneumaticCraft.common.recipes.AmadronOffer in project PneumaticCraft by MineMaarten.

the class ContainerAmadron method clickOffer.

public void clickOffer(int offerId, int mouseButton, boolean sneaking, EntityPlayer player) {
    problemState = EnumProblemState.NO_PROBLEMS;
    int cartSlot = getCartSlot(offerId);
    if (cartSlot >= 0) {
        if (mouseButton == 2) {
            shoppingAmounts[cartSlot] = 0;
        } else if (sneaking) {
            if (mouseButton == 0)
                shoppingAmounts[cartSlot] /= 2;
            else {
                AmadronOffer offer = offers.get(offerId);
                if (offer instanceof AmadronOfferCustom) {
                    AmadronOfferCustom custom = (AmadronOfferCustom) offer;
                    if (custom.getPlayerId().equals(player.getGameProfile().getId().toString())) {
                        if (AmadronOfferManager.getInstance().removeStaticOffer(custom)) {
                            if (AmadronOfferSettings.notifyOfTradeRemoval)
                                NetworkHandler.sendToAll(new PacketAmadronTradeRemoved(custom));
                            custom.returnStock();
                            try {
                                AmadronOfferStaticConfig.INSTANCE.writeToFile();
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                            player.closeScreen();
                        }
                    }
                }
                shoppingAmounts[cartSlot] *= 2;
                if (shoppingAmounts[cartSlot] == 0)
                    shoppingAmounts[cartSlot] = 1;
            }
        } else {
            if (mouseButton == 0)
                shoppingAmounts[cartSlot]--;
            else
                shoppingAmounts[cartSlot]++;
        }
        if (shoppingAmounts[cartSlot] <= 0) {
            shoppingAmounts[cartSlot] = 0;
            shoppingItems[cartSlot] = -1;
        } else {
            shoppingAmounts[cartSlot] = capShoppingAmount(offerId, shoppingAmounts[cartSlot], player);
            if (shoppingAmounts[cartSlot] > 0)
                shoppingItems[cartSlot] = offerId;
            else
                shoppingItems[cartSlot] = -1;
        }
    }
}
Also used : AmadronOffer(pneumaticCraft.common.recipes.AmadronOffer) IOException(java.io.IOException) AmadronOfferCustom(pneumaticCraft.common.recipes.AmadronOfferCustom) PacketAmadronTradeRemoved(pneumaticCraft.common.network.PacketAmadronTradeRemoved)

Example 4 with AmadronOffer

use of pneumaticCraft.common.recipes.AmadronOffer in project PneumaticCraft by MineMaarten.

the class ItemAmadronTablet method getShoppingCart.

public static Map<AmadronOffer, Integer> getShoppingCart(ItemStack tablet) {
    Map<AmadronOffer, Integer> offers = new HashMap<AmadronOffer, Integer>();
    if (tablet.hasTagCompound() && tablet.getTagCompound().hasKey("shoppingCart")) {
        NBTTagList list = tablet.getTagCompound().getTagList("shoppingCart", 10);
        for (int i = 0; i < list.tagCount(); i++) {
            NBTTagCompound tag = list.getCompoundTagAt(i);
            offers.put(tag.hasKey("inStock") ? AmadronOfferCustom.loadFromNBT(tag) : AmadronOffer.loadFromNBT(tag), tag.getInteger("amount"));
        }
    }
    return offers;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) HashMap(java.util.HashMap) AmadronOffer(pneumaticCraft.common.recipes.AmadronOffer) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 5 with AmadronOffer

use of pneumaticCraft.common.recipes.AmadronOffer in project PneumaticCraft by MineMaarten.

the class EventHandlerPneumaticCraft method onDroneSuicide.

@SubscribeEvent
public void onDroneSuicide(DroneSuicideEvent event) {
    if (event.drone instanceof EntityDrone) {
        EntityDrone drone = (EntityDrone) event.drone;
        AmadronOffer offer = drone.getHandlingOffer();
        if (offer != null) {
            int times = drone.getOfferTimes();
            if (offer.getInput() instanceof ItemStack) {
                int requiredCount = ((ItemStack) offer.getInput()).stackSize * times;
                for (int i = 0; i < drone.getInventory().getSizeInventory(); i++) {
                    if (drone.getInventory().getStackInSlot(i) != null) {
                        requiredCount -= drone.getInventory().getStackInSlot(i).stackSize;
                    }
                }
                if (requiredCount <= 0) {
                    for (int i = 0; i < drone.getInventory().getSizeInventory(); i++) {
                        drone.getInventory().setInventorySlotContents(i, null);
                    }
                    MinecraftForge.EVENT_BUS.post(new AmadronRetrievalEvent(event.drone));
                }
            } else {
                int requiredCount = ((FluidStack) offer.getInput()).amount * times;
                if (drone.getTank().getFluidAmount() >= requiredCount) {
                    MinecraftForge.EVENT_BUS.post(new AmadronRetrievalEvent(event.drone));
                }
            }
        }
    }
}
Also used : EntityDrone(pneumaticCraft.common.entity.living.EntityDrone) AmadronRetrievalEvent(pneumaticCraft.api.drone.AmadronRetrievalEvent) AmadronOffer(pneumaticCraft.common.recipes.AmadronOffer) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Aggregations

AmadronOffer (pneumaticCraft.common.recipes.AmadronOffer)10 ItemStack (net.minecraft.item.ItemStack)3 EntityDrone (pneumaticCraft.common.entity.living.EntityDrone)3 AmadronOfferCustom (pneumaticCraft.common.recipes.AmadronOfferCustom)3 JsonArray (com.google.gson.JsonArray)2 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 NBTTagList (net.minecraft.nbt.NBTTagList)2 ChunkPosition (net.minecraft.world.ChunkPosition)2 World (net.minecraft.world.World)2 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 Point (java.awt.Point)1 IOException (java.io.IOException)1 Map (java.util.Map)1 FluidStack (net.minecraftforge.fluids.FluidStack)1 AmadronRetrievalEvent (pneumaticCraft.api.drone.AmadronRetrievalEvent)1 WidgetAmadronOffer (pneumaticCraft.client.gui.widget.WidgetAmadronOffer)1