use of logisticspipes.request.resources.ItemResource in project LogisticsPipes by RS485.
the class ServerRouter method getRoutersInterestedIn.
public static BitSet getRoutersInterestedIn(IResource item) {
if (item instanceof ItemResource) {
return ServerRouter.getRoutersInterestedIn(((ItemResource) item).getItem());
} else if (item instanceof FluidResource) {
return ServerRouter.getRoutersInterestedIn(((FluidResource) item).getFluid().getItemIdentifier());
} else if (item instanceof DictResource) {
DictResource dict = (DictResource) item;
BitSet s = new BitSet(ServerRouter.getBiggestSimpleID() + 1);
for (IRouter r : ServerRouter.genericInterests) {
s.set(r.getSimpleID());
}
ServerRouter.globalSpecificInterests.entrySet().stream().filter(entry -> dict.matches(entry.getKey(), IResource.MatchSettings.NORMAL)).flatMap(entry -> entry.getValue().stream()).forEach(router -> s.set(router.simpleID));
return s;
}
return new BitSet(ServerRouter.getBiggestSimpleID() + 1);
}
use of logisticspipes.request.resources.ItemResource in project LogisticsPipes by RS485.
the class RequestTree method request.
public static boolean request(List<ItemIdentifierStack> items, IRequestItems requester, RequestLog log, EnumSet<ActiveRequestType> requestFlags, IAdditionalTargetInformation info) {
Map<IResource, Integer> messages = new HashMap<>();
RequestTree tree = new RequestTree(new ItemResource(new ItemIdentifierStack(ItemIdentifier.get(Item.getItemFromBlock(Blocks.STONE), 0, null), 0), requester), null, requestFlags, info);
boolean isDone = true;
for (ItemIdentifierStack stack : items) {
ItemIdentifier item = stack.getItem();
Integer count = messages.get(item);
if (count == null) {
count = 0;
}
count += stack.getStackSize();
ItemResource req = new ItemResource(stack, requester);
messages.put(req, count);
RequestTree node = new RequestTree(req, tree, requestFlags, info);
isDone = isDone && node.isDone();
}
if (isDone) {
LinkedLogisticsOrderList list = tree.fullFillAll();
if (log != null) {
log.handleSucessfullRequestOfList(RequestTreeNode.shrinkToList(messages), list);
}
return true;
} else {
if (log != null) {
tree.logFailedRequestTree(log);
}
return false;
}
}
use of logisticspipes.request.resources.ItemResource in project LogisticsPipes by RS485.
the class PipeItemsProviderLogistics method canProvide.
@Override
public void canProvide(RequestTreeNode tree, RequestTree root, List<IFilter> filters) {
if (!isEnabled()) {
return;
}
if (tree.getRequestType() instanceof ItemResource) {
ItemIdentifier item = ((ItemResource) tree.getRequestType()).getItem();
for (IFilter filter : filters) {
if (filter.isBlocked() == filter.isFilteredItem(item.getUndamaged()) || filter.blockProvider()) {
return;
}
}
// Check the transaction and see if we have helped already
int canProvide = getAvailableItemCount(item);
canProvide -= root.getAllPromissesFor(this, item);
if (canProvide < 1) {
return;
}
LogisticsPromise promise = new LogisticsPromise(item, Math.min(canProvide, tree.getMissingAmount()), this, ResourceType.PROVIDER);
tree.addPromise(promise);
} else if (tree.getRequestType() instanceof DictResource) {
DictResource dict = (DictResource) tree.getRequestType();
HashMap<ItemIdentifier, Integer> available = new HashMap<>();
getAllItems(available, filters);
for (Entry<ItemIdentifier, Integer> item : available.entrySet()) {
if (!dict.matches(item.getKey(), IResource.MatchSettings.NORMAL)) {
continue;
}
int canProvide = getAvailableItemCount(item.getKey());
canProvide -= root.getAllPromissesFor(this, item.getKey());
if (canProvide < 1) {
continue;
}
LogisticsPromise promise = new LogisticsPromise(item.getKey(), Math.min(canProvide, tree.getMissingAmount()), this, ResourceType.PROVIDER);
tree.addPromise(promise);
if (tree.getMissingAmount() <= 0) {
break;
}
}
}
}
use of logisticspipes.request.resources.ItemResource 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.ItemResource in project LogisticsPipes by RS485.
the class ModuleCrafter method extractFromLogisticsCraftingTable.
private ItemStack extractFromLogisticsCraftingTable(LogisticsCraftingTableTileEntity tile, IResource wanteditem, int count, ForgeDirection dir) {
ItemStack extracted = extractFromIInventory(tile, wanteditem, count, dir);
if (extracted != null) {
return extracted;
}
ItemStack retstack = null;
while (count > 0) {
ItemStack stack = tile.getOutput(wanteditem, _service);
if (stack == null || stack.stackSize == 0) {
break;
}
if (retstack == null) {
if (!wanteditem.matches(ItemIdentifier.get(stack), wanteditem instanceof ItemResource ? IResource.MatchSettings.WITHOUT_NBT : IResource.MatchSettings.NORMAL)) {
break;
}
} else {
if (!retstack.isItemEqual(stack)) {
break;
}
if (!ItemStack.areItemStackTagsEqual(retstack, stack)) {
break;
}
}
if (!_service.useEnergy(neededEnergy() * stack.stackSize)) {
break;
}
if (retstack == null) {
retstack = stack;
} else {
retstack.stackSize += stack.stackSize;
}
count -= stack.stackSize;
if (getUpgradeManager().isFuzzyUpgrade()) {
break;
}
}
return retstack;
}
Aggregations