use of logisticspipes.interfaces.IPipeServiceProvider in project LogisticsPipes by RS485.
the class ModuleCrafter method importFromCraftingTable.
public void importFromCraftingTable(@Nullable EntityPlayer player) {
if (MainProxy.isClient(getWorld())) {
// Send packet asking for import
final CoordinatesPacket packet = PacketHandler.getPacket(CPipeSatelliteImport.class).setModulePos(this);
MainProxy.sendPacketToServer(packet);
} else {
final IPipeServiceProvider service = _service;
if (service == null)
return;
service.getAvailableAdjacent().neighbors().keySet().stream().flatMap(neighbor -> SimpleServiceLocator.craftingRecipeProviders.stream().filter(provider -> provider.importRecipe(neighbor.getTileEntity(), dummyInventory)).map(provider1 -> new Pair<>(neighbor, provider1))).findFirst().ifPresent(neighborProviderPair -> {
if (neighborProviderPair.getValue2() instanceof IFuzzyRecipeProvider) {
((IFuzzyRecipeProvider) neighborProviderPair.getValue2()).importFuzzyFlags(neighborProviderPair.getValue1().getTileEntity(), dummyInventory.getSlotAccess(), fuzzyFlags);
}
});
// Send inventory as packet
final CoordinatesPacket packet = PacketHandler.getPacket(CPipeSatelliteImportBack.class).setInventory(dummyInventory).setModulePos(this);
if (player != null) {
MainProxy.sendPacketToPlayer(packet, player);
}
MainProxy.sendPacketToAllWatchingChunk(this, packet);
}
}
use of logisticspipes.interfaces.IPipeServiceProvider in project LogisticsPipes by RS485.
the class ModuleCrafter method extractFromInventoryFiltered.
@Nonnull
private ItemStack extractFromInventoryFiltered(@Nonnull IInventoryUtil invUtil, IItemIdentifierInventory filter, boolean isExcluded, int filterInvLimit) {
final IPipeServiceProvider service = _service;
if (service == null)
return ItemStack.EMPTY;
ItemIdentifier wanteditem = null;
boolean found = false;
for (ItemIdentifier item : invUtil.getItemsAndCount().keySet()) {
found = isFiltered(filter, filterInvLimit, item, found);
if (isExcluded != found) {
wanteditem = item;
break;
}
}
if (wanteditem == null) {
return ItemStack.EMPTY;
}
int available = invUtil.itemCount(wanteditem);
if (available == 0 || !service.canUseEnergy(neededEnergy() * Math.min(64, available))) {
return ItemStack.EMPTY;
}
ItemStack extracted = invUtil.getMultipleItems(wanteditem, Math.min(64, available));
service.useEnergy(neededEnergy() * extracted.getCount());
return extracted;
}
use of logisticspipes.interfaces.IPipeServiceProvider in project LogisticsPipes by RS485.
the class ModuleSatellite method spaceFor.
private int spaceFor(@Nonnull ItemStack stack, ItemIdentifier item, boolean includeInTransit) {
final IPipeServiceProvider service = Objects.requireNonNull(_service);
int count = service.getAvailableAdjacent().inventories().stream().map(neighbor -> LPNeighborTileEntityKt.sneakyInsertion(neighbor).from(getUpgradeManager())).map(LPNeighborTileEntityKt::getInventoryUtil).filter(Objects::nonNull).map(util -> util.roomForItem(stack)).reduce(Integer::sum).orElse(0);
if (includeInTransit) {
count -= service.countOnRoute(item);
}
return count;
}
use of logisticspipes.interfaces.IPipeServiceProvider in project LogisticsPipes by RS485.
the class ModuleActiveSupplier method itemArrived.
@Override
public void itemArrived(ItemIdentifierStack item, IAdditionalTargetInformation info) {
final IPipeServiceProvider service = Objects.requireNonNull(_service);
service.getDebug().log("Supplier: Registered Item Arrived: " + item);
decreaseRequested(item);
}
use of logisticspipes.interfaces.IPipeServiceProvider in project LogisticsPipes by RS485.
the class ModuleActiveSupplier method tick.
@Override
public void tick() {
final IPipeServiceProvider service = Objects.requireNonNull(_service);
if (!service.isNthTick(100)) {
return;
}
_requestedItems.values().stream().filter(amount -> amount > 0).forEach(amount -> service.spawnParticle(Particles.VioletParticle, 2));
AdjacentUtilKt.sneakyInventoryUtils(service.getAvailableAdjacent(), getUpgradeManager()).stream().filter(invUtil -> invUtil != null && invUtil.getSizeInventory() > 0).forEach(invUtil -> {
if (getUpgradeManager().hasPatternUpgrade()) {
createPatternRequest(invUtil);
} else {
createSupplyRequest(invUtil);
}
});
}
Aggregations