Search in sources :

Example 6 with AmadronOffer

use of me.desht.pneumaticcraft.common.recipes.AmadronOffer in project pnc-repressurized by TeamPneumatic.

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(me.desht.pneumaticcraft.common.recipes.AmadronOffer)

Example 7 with AmadronOffer

use of me.desht.pneumaticcraft.common.recipes.AmadronOffer in project pnc-repressurized by TeamPneumatic.

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(me.desht.pneumaticcraft.common.recipes.AmadronOffer) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 8 with AmadronOffer

use of me.desht.pneumaticcraft.common.recipes.AmadronOffer in project pnc-repressurized by TeamPneumatic.

the class PacketSyncAmadronOffers method toBytes.

@Override
public void toBytes(ByteBuf buf) {
    buf.writeInt(offers.size());
    for (AmadronOffer offer : offers) {
        buf.writeBoolean(offer instanceof AmadronOfferCustom);
        writeFluidOrItemStack(offer.getInput(), buf);
        writeFluidOrItemStack(offer.getOutput(), buf);
        if (offer instanceof AmadronOfferCustom) {
            ((AmadronOfferCustom) offer).writeToBuf(buf);
        }
    }
}
Also used : AmadronOffer(me.desht.pneumaticcraft.common.recipes.AmadronOffer) AmadronOfferCustom(me.desht.pneumaticcraft.common.recipes.AmadronOfferCustom)

Example 9 with AmadronOffer

use of me.desht.pneumaticcraft.common.recipes.AmadronOffer in project pnc-repressurized by TeamPneumatic.

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()).getCount() * times;
                for (int i = 0; i < drone.getInv().getSlots(); i++) {
                    requiredCount -= drone.getInv().getStackInSlot(i).getCount();
                }
                if (requiredCount <= 0) {
                    for (int i = 0; i < drone.getInv().getSlots(); i++) {
                        drone.getInv().setStackInSlot(i, ItemStack.EMPTY);
                    }
                    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(me.desht.pneumaticcraft.common.entity.living.EntityDrone) AmadronRetrievalEvent(me.desht.pneumaticcraft.api.drone.AmadronRetrievalEvent) AmadronOffer(me.desht.pneumaticcraft.common.recipes.AmadronOffer) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 10 with AmadronOffer

use of me.desht.pneumaticcraft.common.recipes.AmadronOffer in project pnc-repressurized by TeamPneumatic.

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.inventorySlots.get(i * 2).putStack((ItemStack) offer.getInput());
        }
        if (offer.getOutput() instanceof ItemStack) {
            container.inventorySlots.get(i * 2 + 1).putStack((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, PneumaticCraftRepressurized.proxy.isSneakingInGui()));
            }
        };
        addWidget(widget);
        widgetOffers.add(widget);
    }
    // the server also needs to know what's in the tablet, or the next
    // "window items" packet will empty all the client-side slots
    NetworkHandler.sendToServer(new PacketAmadronInvSync(container.getInventory()));
}
Also used : AmadronOffer(me.desht.pneumaticcraft.common.recipes.AmadronOffer) WidgetAmadronOffer(me.desht.pneumaticcraft.client.gui.widget.WidgetAmadronOffer) ArrayList(java.util.ArrayList) ContainerAmadron(me.desht.pneumaticcraft.common.inventory.ContainerAmadron) WidgetAmadronOffer(me.desht.pneumaticcraft.client.gui.widget.WidgetAmadronOffer) PacketAmadronInvSync(me.desht.pneumaticcraft.common.network.PacketAmadronInvSync) ItemStack(net.minecraft.item.ItemStack) PacketAmadronOrderUpdate(me.desht.pneumaticcraft.common.network.PacketAmadronOrderUpdate)

Aggregations

AmadronOffer (me.desht.pneumaticcraft.common.recipes.AmadronOffer)10 EntityDrone (me.desht.pneumaticcraft.common.entity.living.EntityDrone)3 AmadronOfferCustom (me.desht.pneumaticcraft.common.recipes.AmadronOfferCustom)3 ItemStack (net.minecraft.item.ItemStack)3 JsonArray (com.google.gson.JsonArray)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 NBTTagList (net.minecraft.nbt.NBTTagList)2 BlockPos (net.minecraft.util.math.BlockPos)2 World (net.minecraft.world.World)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 IOException (java.io.IOException)1 Map (java.util.Map)1 AmadronRetrievalEvent (me.desht.pneumaticcraft.api.drone.AmadronRetrievalEvent)1 WidgetAmadronOffer (me.desht.pneumaticcraft.client.gui.widget.WidgetAmadronOffer)1 ContainerAmadron (me.desht.pneumaticcraft.common.inventory.ContainerAmadron)1 PacketAmadronInvSync (me.desht.pneumaticcraft.common.network.PacketAmadronInvSync)1