use of logisticspipes.request.resources.IResource in project LogisticsPipes by RS485.
the class PipeItemsRequestLogistics method performRequest.
@Override
public List<ItemStack> performRequest(ItemStack wanted) {
final List<IResource> missing = new ArrayList<>();
RequestTree.request(ItemIdentifier.get(wanted).makeStack(wanted.stackSize), this, new RequestLog() {
@Override
public void handleMissingItems(List<IResource> items) {
missing.addAll(items);
}
@Override
public void handleSucessfullRequestOf(IResource item, LinkedLogisticsOrderList parts) {
}
@Override
public void handleSucessfullRequestOfList(List<IResource> items, LinkedLogisticsOrderList parts) {
}
}, null);
List<ItemStack> missingList = new ArrayList<>(missing.size());
for (IResource e : missing) {
if (e instanceof ItemResource) {
missingList.add(((ItemResource) e).getItem().unsafeMakeNormalStack(e.getRequestedAmount()));
} else if (e instanceof DictResource) {
missingList.add(((DictResource) e).getItem().unsafeMakeNormalStack(e.getRequestedAmount()));
}
}
return missingList;
}
use of logisticspipes.request.resources.IResource in project LogisticsPipes by RS485.
the class RequestTreeNode method getProviders.
private static List<Pair<IProvide, List<IFilter>>> getProviders(IRouter destination, IResource item) {
// get all the routers
BitSet routersIndex = ServerRouter.getRoutersInterestedIn(item);
// get the routing table
List<ExitRoute> validSources = new ArrayList<>();
for (int i = routersIndex.nextSetBit(0); i >= 0; i = routersIndex.nextSetBit(i + 1)) {
IRouter r = SimpleServiceLocator.routerManager.getServerRouter(i);
if (r.isCacheInvalid()) {
// Skip Routers without a valid pipe
continue;
}
List<ExitRoute> e = destination.getDistanceTo(r);
if (e != null) {
validSources.addAll(e);
}
}
// closer providers are good
validSources.sort(new workWeightedSorter(1.0));
List<Pair<IProvide, List<IFilter>>> providers = new LinkedList<>();
validSources.stream().filter(r -> r.containsFlag(PipeRoutingConnectionType.canRequestFrom)).forEach(r -> {
CoreRoutedPipe pipe = r.destination.getPipe();
if (pipe instanceof IProvide) {
List<IFilter> list = new LinkedList<>(r.filters);
providers.add(new Pair<>((IProvide) pipe, list));
}
});
return providers;
}
use of logisticspipes.request.resources.IResource 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);
}
use of logisticspipes.request.resources.IResource in project LogisticsPipes by RS485.
the class RequestHandler method simulate.
public static void simulate(final EntityPlayer player, final ItemIdentifierStack stack, CoreRoutedPipe pipe) {
final List<IResource> usedList = new ArrayList<>();
final List<IResource> missingList = new ArrayList<>();
RequestTree.simulate(new ItemIdentifierStack(stack), pipe, new RequestLog() {
@Override
public void handleMissingItems(List<IResource> resources) {
missingList.addAll(resources);
}
@Override
public void handleSucessfullRequestOf(IResource item, LinkedLogisticsOrderList parts) {
}
@Override
public void handleSucessfullRequestOfList(List<IResource> resources, LinkedLogisticsOrderList parts) {
usedList.addAll(resources);
}
});
MainProxy.sendPacketToPlayer(PacketHandler.getPacket(ComponentList.class).setUsed(usedList).setMissing(missingList), player);
}
use of logisticspipes.request.resources.IResource in project LogisticsPipes by RS485.
the class RequestTree method sendUsedMessage.
public void sendUsedMessage(RequestLog log) {
Map<IResource, Integer> used = new HashMap<>();
Map<IResource, Integer> missing = new HashMap<>();
buildUsedMap(used, missing);
log.handleSucessfullRequestOfList(RequestTreeNode.shrinkToList(used), new LinkedLogisticsOrderList());
log.handleMissingItems(RequestTreeNode.shrinkToList(missing));
}
Aggregations