use of logisticspipes.utils.item.ItemIdentifier in project LogisticsPipes by RS485.
the class ModuleCrafter method extractFromIInventoryFiltered.
private ItemStack extractFromIInventoryFiltered(IInventory inv, ItemIdentifierInventory filter, boolean isExcluded, int filterInvLimit, ForgeDirection dir) {
IInventoryUtil invUtil = SimpleServiceLocator.inventoryUtilFactory.getInventoryUtil(inv, dir);
ItemIdentifier wanteditem = null;
for (ItemIdentifier item : invUtil.getItemsAndCount().keySet()) {
if (isExcluded) {
boolean found = false;
for (int i = 0; i < filter.getSizeInventory() && i < filterInvLimit; i++) {
ItemIdentifierStack identStack = filter.getIDStackInSlot(i);
if (identStack == null) {
continue;
}
if (identStack.getItem().equalsWithoutNBT(item)) {
found = true;
break;
}
}
if (!found) {
wanteditem = item;
}
} else {
boolean found = false;
for (int i = 0; i < filter.getSizeInventory() && i < filterInvLimit; i++) {
ItemIdentifierStack identStack = filter.getIDStackInSlot(i);
if (identStack == null) {
continue;
}
if (identStack.getItem().equalsWithoutNBT(item)) {
found = true;
break;
}
}
if (found) {
wanteditem = item;
}
}
}
if (wanteditem == null) {
return null;
}
int available = invUtil.itemCount(wanteditem);
if (available == 0) {
return null;
}
if (!_service.useEnergy(neededEnergy() * Math.min(64, available))) {
return null;
}
return invUtil.getMultipleItems(wanteditem, Math.min(64, available));
}
use of logisticspipes.utils.item.ItemIdentifier in project LogisticsPipes by RS485.
the class ModuleCrafter method spaceFor.
protected int spaceFor(ItemIdentifier item, boolean includeInTransit) {
Pair<String, ItemIdentifier> key = new Pair<>("spaceFor", item);
Object cache = _service.getCacheHolder().getCacheFor(CacheTypes.Inventory, key);
if (cache != null) {
int count = (Integer) cache;
if (includeInTransit) {
count -= _service.countOnRoute(item);
}
return count;
}
WorldCoordinatesWrapper worldCoordinates = new WorldCoordinatesWrapper(getWorld(), _service.getX(), _service.getY(), _service.getZ());
//@formatter:off
int count = worldCoordinates.getConnectedAdjacentTileEntities(ConnectionPipeType.ITEM).filter(adjacent -> adjacent.tileEntity instanceof IInventory).map(adjacent -> new Pair<>((IInventory) adjacent.tileEntity, adjacent.direction)).map(invDirPair -> {
if (invDirPair.getValue1() instanceof ISidedInventory) {
invDirPair.setValue1(new SidedInventoryMinecraftAdapter((ISidedInventory) invDirPair.getValue1(), invDirPair.getValue2().getOpposite(), false));
}
if (getUpgradeManager().hasSneakyUpgrade()) {
invDirPair.setValue2(getUpgradeManager().getSneakyOrientation());
}
IInventoryUtil inv = SimpleServiceLocator.inventoryUtilFactory.getInventoryUtil(invDirPair.getValue1(), invDirPair.getValue2());
return inv.roomForItem(item, 9999);
}).reduce(Integer::sum).orElse(0);
_service.getCacheHolder().setCache(CacheTypes.Inventory, key, count);
if (includeInTransit) {
count -= _service.countOnRoute(item);
}
return count;
}
use of logisticspipes.utils.item.ItemIdentifier in project LogisticsPipes by RS485.
the class LogisticsManager method getAvailableItems.
/**
* @param validDestinations
* a list of ExitRoute of valid destinations.
* @return HashMap with ItemIdentifier and Integer item count of available
* items.
*/
@Override
public HashMap<ItemIdentifier, Integer> getAvailableItems(List<ExitRoute> validDestinations) {
//TODO: Replace this entire function wiht a fetch from the pre-built arrays (path incoming later)
List<Map<ItemIdentifier, Integer>> items = new ArrayList<>(ServerRouter.getBiggestSimpleID());
for (int i = 0; i < ServerRouter.getBiggestSimpleID(); i++) {
items.add(new HashMap<>());
}
BitSet used = new BitSet(ServerRouter.getBiggestSimpleID());
outer: for (ExitRoute r : validDestinations) {
if (r == null) {
continue;
}
if (!r.containsFlag(PipeRoutingConnectionType.canRequestFrom)) {
continue;
}
if (!(r.destination.getPipe() instanceof IProvideItems)) {
continue;
}
for (IFilter filter : r.filters) {
if (filter.blockProvider()) {
continue outer;
}
}
IProvideItems provider = (IProvideItems) r.destination.getPipe();
provider.getAllItems(items.get(r.destination.getSimpleID()), r.filters);
used.set(r.destination.getSimpleID(), true);
}
//TODO: Fix this doubly nested list
HashMap<ItemIdentifier, Integer> allAvailableItems = new HashMap<>();
for (Map<ItemIdentifier, Integer> allItems : items) {
for (Entry<ItemIdentifier, Integer> item : allItems.entrySet()) {
Integer currentItem = allAvailableItems.get(item.getKey());
if (currentItem == null) {
allAvailableItems.put(item.getKey(), item.getValue());
} else {
allAvailableItems.put(item.getKey(), currentItem + item.getValue());
}
}
}
return allAvailableItems;
}
use of logisticspipes.utils.item.ItemIdentifier in project LogisticsPipes by RS485.
the class LogisticsManager method getAmountFor.
@Override
public int getAmountFor(ItemIdentifier itemType, List<ExitRoute> validDestinations) {
// TODO: Replace this entire function wiht a fetch from the pre-built arrays (path incoming later)
List<Map<ItemIdentifier, Integer>> items = new ArrayList<>(ServerRouter.getBiggestSimpleID());
for (int i = 0; i < ServerRouter.getBiggestSimpleID(); i++) {
items.add(new HashMap<>());
}
BitSet used = new BitSet(ServerRouter.getBiggestSimpleID());
outer: for (ExitRoute r : validDestinations) {
if (r == null) {
continue;
}
if (!r.containsFlag(PipeRoutingConnectionType.canRequestFrom)) {
continue;
}
if (!(r.destination.getPipe() instanceof IProvideItems)) {
continue;
}
for (IFilter filter : r.filters) {
if (filter.blockProvider()) {
continue outer;
}
}
IProvideItems provider = (IProvideItems) r.destination.getPipe();
provider.getAllItems(items.get(r.destination.getSimpleID()), r.filters);
used.set(r.destination.getSimpleID(), true);
}
// TODO: Fix this doubly nested list
int amount = 0;
for (Map<ItemIdentifier, Integer> allItems : items) {
for (Entry<ItemIdentifier, Integer> item : allItems.entrySet()) {
if (item.getKey().equals(itemType)) {
amount += item.getValue();
}
}
}
return amount;
}
use of logisticspipes.utils.item.ItemIdentifier in project LogisticsPipes by RS485.
the class ModuleActiveSupplier method addStatusInformation.
public void addStatusInformation(List<StatusEntry> status) {
StatusEntry entry = new StatusEntry();
entry.name = "Requested Items";
entry.subEntry = new ArrayList<>();
for (Entry<ItemIdentifier, Integer> part : _requestedItems.entrySet()) {
StatusEntry subEntry = new StatusEntry();
subEntry.name = part.toString();
entry.subEntry.add(subEntry);
}
status.add(entry);
}
Aggregations