use of logisticspipes.utils.tuples.Pair in project LogisticsPipes by RS485.
the class PipeTransportLogistics method writeToNBT.
public void writeToNBT(NBTTagCompound nbt) {
{
NBTTagList nbttaglist = new NBTTagList();
for (LPTravelingItem item : items) {
if (item instanceof LPTravelingItemServer) {
NBTTagCompound dataTag = new NBTTagCompound();
nbttaglist.appendTag(dataTag);
((LPTravelingItemServer) item).writeToNBT(dataTag);
}
}
nbt.setTag("travelingEntities", nbttaglist);
}
NBTTagList nbttaglist2 = new NBTTagList();
for (Pair<ItemIdentifierStack, Pair<Integer, Integer>> stack : _itemBuffer) {
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
stack.getValue1().makeNormalStack().writeToNBT(nbttagcompound1);
nbttaglist2.appendTag(nbttagcompound1);
}
nbt.setTag("buffercontents", nbttaglist2);
}
use of logisticspipes.utils.tuples.Pair in project LogisticsPipes by RS485.
the class PipeTransportLogistics method readFromNBT.
public void readFromNBT(NBTTagCompound nbt) {
NBTTagList nbttaglist = nbt.getTagList("travelingEntities", 10);
for (int j = 0; j < nbttaglist.tagCount(); ++j) {
try {
NBTTagCompound dataTag = nbttaglist.getCompoundTagAt(j);
LPTravelingItem item = new LPTravelingItemServer(dataTag);
if (item.isCorrupted()) {
continue;
}
items.scheduleLoad(item);
} catch (Throwable t) {
// It may be the case that entities cannot be reloaded between
// two versions - ignore these errors.
}
}
_itemBuffer.clear();
NBTTagList nbttaglist2 = nbt.getTagList("buffercontents", 10);
for (int i = 0; i < nbttaglist2.tagCount(); i++) {
NBTTagCompound nbttagcompound1 = nbttaglist2.getCompoundTagAt(i);
_itemBuffer.add(new Triplet<>(ItemIdentifierStack.getFromStack(ItemStackLoader.loadAndFixItemStackFromNBT(nbttagcompound1)), new Pair<>(_bufferTimeOut, 0), null));
}
}
use of logisticspipes.utils.tuples.Pair in project LogisticsPipes by RS485.
the class ReflectionHelper method getField.
private static Field getField(Class<?> clazz, String name, String srgName) throws NoSuchFieldException {
Pair<Class<?>, String> key = new Pair<>(clazz, name);
Field field = ReflectionHelper.fieldCache.get(key);
if (field == null) {
try {
field = clazz.getDeclaredField(name);
} catch (NoSuchFieldException e1) {
try {
field = clazz.getField(name);
} catch (NoSuchFieldException e2) {
try {
field = clazz.getDeclaredField(srgName);
} catch (NoSuchFieldException e3) {
try {
field = clazz.getField(srgName);
} catch (NoSuchFieldException e4) {
field = clazz.getDeclaredField(name);
}
}
}
}
field.setAccessible(true);
ReflectionHelper.fieldCache.put(key, field);
}
return field;
}
use of logisticspipes.utils.tuples.Pair in project LogisticsPipes by RS485.
the class LogisticsPowerProviderTileEntity method update.
@Override
public void update() {
super.update();
pauseRequesting = false;
if (!init) {
if (MainProxy.isClient(getWorld())) {
LogisticsHUDRenderer.instance().add(this);
}
init = true;
}
double globalRequest = orders.values().stream().reduce(Double::sum).orElse(0.0);
if (globalRequest > 0) {
final double fullfillRatio = Math.min(1, Math.min(internalStorage, getMaxProvidePerTick()) / globalRequest);
if (fullfillRatio > 0) {
final Function<NeighborTileEntity<LogisticsTileGenericPipe>, CoreRoutedPipe> getPipe = (NeighborTileEntity<LogisticsTileGenericPipe> neighbor) -> (CoreRoutedPipe) neighbor.getTileEntity().pipe;
orders.entrySet().stream().map(routerIdToOrderCount -> new Pair<>(SimpleServiceLocator.routerManager.getRouter(routerIdToOrderCount.getKey()), Math.min(internalStorage, routerIdToOrderCount.getValue() * fullfillRatio))).filter(destinationToPower -> destinationToPower.getValue1() != null && destinationToPower.getValue1().getPipe() != null).forEach(destinationToPower -> new WorldCoordinatesWrapper(this).allNeighborTileEntities().stream().flatMap(neighbor -> LPNeighborTileEntityKt.optionalIs(neighbor, LogisticsTileGenericPipe.class).map(Stream::of).orElseGet(Stream::empty)).filter(neighbor -> neighbor.getTileEntity().pipe instanceof CoreRoutedPipe && !getPipe.apply(neighbor).stillNeedReplace()).flatMap(neighbor -> getPipe.apply(neighbor).getRouter().getDistanceTo(destinationToPower.getValue1()).stream().map(exitRoute -> new Pair<>(neighbor, exitRoute))).filter(neighborToExit -> neighborToExit.getValue2().containsFlag(PipeRoutingConnectionType.canPowerSubSystemFrom) && neighborToExit.getValue2().filters.stream().noneMatch(IFilter::blockPower)).findFirst().ifPresent(neighborToSource -> {
CoreRoutedPipe sourcePipe = getPipe.apply(neighborToSource.getValue1());
if (sourcePipe.isInitialized()) {
sourcePipe.container.addLaser(neighborToSource.getValue1().getOurDirection(), 1, getLaserColor(), true, true);
}
sendPowerLaserPackets(sourcePipe.getRouter(), destinationToPower.getValue1(), neighborToSource.getValue2().exitOrientation, neighborToSource.getValue2().exitOrientation != neighborToSource.getValue1().getDirection());
internalStorage -= destinationToPower.getValue2();
// because calculations with floats
if (internalStorage <= 0)
internalStorage = 0;
handlePower(destinationToPower.getValue1().getPipe(), destinationToPower.getValue2());
}));
}
}
orders.clear();
if (MainProxy.isServer(world)) {
if (internalStorage != lastUpdateStorage) {
updateClients();
lastUpdateStorage = internalStorage;
}
}
}
use of logisticspipes.utils.tuples.Pair in project LogisticsPipes by RS485.
the class ModuleProvider method getAllItems.
@Override
public void getAllItems(Map<ItemIdentifier, Integer> items, List<IFilter> filters) {
final IPipeServiceProvider service = _service;
if (service == null)
return;
items.putAll(inventoriesWithMode().map(IInventoryUtil::getItemsAndCount).flatMap(inventory -> inventory.entrySet().stream()).filter(item -> {
if (items.containsKey(item.getKey()))
// already provided by any previous module. No comparison of the amount
return false;
// skip provider-filtered items
if (filterBlocksItem(item.getKey()))
return false;
final boolean blockedInFilters = filters.stream().anyMatch(filter -> filter.isBlocked() == filter.isFilteredItem(item.getKey().getUndamaged()) || filter.blockProvider());
// skip filters-parameter-filtered items
return !blockedInFilters;
}).map(item -> new Pair<>(item.getKey(), item.getValue() - service.getItemOrderManager().totalItemsCountInOrders(item.getKey()))).filter(itemIdentAndRemaining -> itemIdentAndRemaining.getValue2() > // reduce what has been reserved
0).collect(// sum up the provided amount by the inventories
Pair.toMap(Integer::sum)));
}
Aggregations