Search in sources :

Example 1 with IRequestWatcher

use of logisticspipes.interfaces.IRequestWatcher in project LogisticsPipes by RS485.

the class RequestHandler method requestMacrolist.

public static void requestMacrolist(NBTTagCompound itemlist, final CoreRoutedPipe requester, final EntityPlayer player) {
    if (!requester.useEnergy(5)) {
        player.sendMessage(new TextComponentTranslation("lp.misc.noenergy"));
        return;
    }
    NBTTagList list = itemlist.getTagList("inventar", 10);
    final List<ItemIdentifierStack> transaction = new ArrayList<>(list.tagCount());
    for (int i = 0; i < list.tagCount(); i++) {
        NBTTagCompound itemnbt = list.getCompoundTagAt(i);
        NBTTagCompound itemNBTContent = itemnbt.getCompoundTag("nbt");
        if (!itemnbt.hasKey("nbt")) {
            itemNBTContent = null;
        }
        ItemIdentifierStack stack = ItemIdentifier.get(Item.getItemById(itemnbt.getInteger("id")), itemnbt.getInteger("data"), itemNBTContent).makeStack(itemnbt.getInteger("amount"));
        transaction.add(stack);
    }
    RequestTree.request(transaction, requester, new RequestLog() {

        @Override
        public void handleMissingItems(List<IResource> resources) {
            MainProxy.sendPacketToPlayer(PacketHandler.getPacket(MissingItems.class).setItems(resources).setFlag(true), player);
        }

        @Override
        public void handleSucessfullRequestOf(IResource item, LinkedLogisticsOrderList parts) {
        }

        @Override
        public void handleSucessfullRequestOfList(List<IResource> resources, LinkedLogisticsOrderList parts) {
            MainProxy.sendPacketToPlayer(PacketHandler.getPacket(MissingItems.class).setItems(resources).setFlag(false), player);
            if (requester instanceof IRequestWatcher) {
                ((IRequestWatcher) requester).handleOrderList(null, parts);
            }
        }
    }, RequestTree.defaultRequestFlags, null);
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) IRequestWatcher(logisticspipes.interfaces.IRequestWatcher) ArrayList(java.util.ArrayList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) NBTTagList(net.minecraft.nbt.NBTTagList) LinkedLogisticsOrderList(logisticspipes.routing.order.LinkedLogisticsOrderList) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) IResource(logisticspipes.request.resources.IResource)

Aggregations

ArrayList (java.util.ArrayList)1 IRequestWatcher (logisticspipes.interfaces.IRequestWatcher)1 IResource (logisticspipes.request.resources.IResource)1 LinkedLogisticsOrderList (logisticspipes.routing.order.LinkedLogisticsOrderList)1 ItemIdentifierStack (logisticspipes.utils.item.ItemIdentifierStack)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 NBTTagList (net.minecraft.nbt.NBTTagList)1 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)1