use of network.rs485.logisticspipes.connection.Adjacent in project LogisticsPipes by RS485.
the class PowerSupplierHandler method requestRFPower.
private boolean requestRFPower() {
// Use Buffer
final List<LPNeighborTileEntity<TileEntity>> adjacentTileEntities = new WorldCoordinatesWrapper(pipe.container).allNeighborTileEntities();
double globalNeed = 0;
double[] need = new double[adjacentTileEntities.size()];
int i = 0;
for (NeighborTileEntity<TileEntity> adjacent : adjacentTileEntities) {
if (SimpleServiceLocator.powerProxy.isEnergyReceiver(adjacent.getTileEntity(), adjacent.getOurDirection())) {
if (pipe.canPipeConnect(adjacent.getTileEntity(), adjacent.getDirection())) {
ICoFHEnergyReceiver energyReceiver = SimpleServiceLocator.powerProxy.getEnergyReceiver(adjacent.getTileEntity(), adjacent.getOurDirection());
globalNeed += need[i] = (energyReceiver.getMaxEnergyStored() - energyReceiver.getEnergyStored());
}
}
++i;
}
if (globalNeed != 0 && !Double.isNaN(globalNeed)) {
double fullfillable = Math.min(1, internalBufferRF / globalNeed);
i = 0;
for (NeighborTileEntity<TileEntity> adjacent : adjacentTileEntities) {
if (SimpleServiceLocator.powerProxy.isEnergyReceiver(adjacent.getTileEntity(), adjacent.getOurDirection())) {
if (pipe.canPipeConnect(adjacent.getTileEntity(), adjacent.getDirection())) {
EnumFacing oppositeDir = adjacent.getOurDirection();
ICoFHEnergyReceiver energyReceiver = SimpleServiceLocator.powerProxy.getEnergyReceiver(adjacent.getTileEntity(), oppositeDir);
if (internalBufferRF + 1 < need[i] * fullfillable) {
return true;
}
int used = energyReceiver.receiveEnergy(oppositeDir, (int) (need[i] * fullfillable), false);
if (used > 0) {
pipe.container.addLaser(adjacent.getDirection(), 0.5F, LogisticsPowerProviderTileEntity.RF_COLOR, false, true);
internalBufferRF -= used;
}
if (internalBufferRF < 0) {
internalBufferRF = 0;
return true;
}
}
}
++i;
}
}
// Rerequest Buffer
List<Pair<ISubSystemPowerProvider, List<IFilter>>> provider = pipe.getRouter().getSubSystemPowerProvider();
double available = 0;
outer: for (Pair<ISubSystemPowerProvider, List<IFilter>> pair : provider) {
for (IFilter filter : pair.getValue2()) {
if (filter.blockPower()) {
continue outer;
}
}
if (pair.getValue1().usePaused()) {
continue;
}
if (!pair.getValue1().getBrand().equals("RF")) {
continue;
}
available += pair.getValue1().getPowerLevel();
}
if (available > 0) {
double neededPower = PowerSupplierHandler.INTERNAL_RF_BUFFER_MAX - internalBufferRF;
if (neededPower > 0) {
if (pipe.useEnergy((int) (neededPower / 100), false)) {
outer: for (Pair<ISubSystemPowerProvider, List<IFilter>> pair : provider) {
for (IFilter filter : pair.getValue2()) {
if (filter.blockPower()) {
continue outer;
}
}
if (pair.getValue1().usePaused()) {
continue;
}
if (!pair.getValue1().getBrand().equals("RF")) {
continue;
}
double requestamount = neededPower * (pair.getValue1().getPowerLevel() / available);
pair.getValue1().requestPower(pipe.getRouterId(), requestamount);
}
}
}
}
return false;
}
use of network.rs485.logisticspipes.connection.Adjacent in project LogisticsPipes by RS485.
the class FluidRoutedPipe method endReached.
public boolean endReached(LPTravelingItemServer arrivingItem, TileEntity tile) {
if (canInsertToTanks() && MainProxy.isServer(getWorld())) {
getCacheHolder().trigger(CacheTypes.Inventory);
if (arrivingItem.getItemIdentifierStack() == null || !(arrivingItem.getItemIdentifierStack().getItem().isFluidContainer())) {
return false;
}
if (getRouter().getSimpleID() != arrivingItem.getDestination()) {
return false;
}
int filled;
FluidIdentifierStack liquid = SimpleServiceLocator.logisticsFluidManager.getFluidFromContainer(arrivingItem.getItemIdentifierStack());
if (isConnectableTank(tile, arrivingItem.output, false)) {
// Try to put liquid into all adjacent tanks.
for (Pair<NeighborTileEntity<TileEntity>, ITankUtil> util : PipeFluidUtil.INSTANCE.getAdjacentTanks(this, false)) {
filled = util.getValue2().fill(liquid, true);
liquid.lowerAmount(filled);
if (liquid.getAmount() != 0) {
continue;
}
return true;
}
// Try inserting the liquid into the pipe side tank
filled = ((PipeFluidTransportLogistics) transport).sideTanks[arrivingItem.output.ordinal()].fill(liquid.makeFluidStack(), true);
if (filled == liquid.getAmount()) {
return true;
}
liquid.lowerAmount(filled);
}
// Try inserting the liquid into the pipe internal tank
filled = ((PipeFluidTransportLogistics) transport).internalTank.fill(liquid.makeFluidStack(), true);
if (filled == liquid.getAmount()) {
return true;
}
// If liquids still exist,
liquid.lowerAmount(filled);
// TODO: FIX THIS
if (this instanceof IRequireReliableFluidTransport) {
((IRequireReliableFluidTransport) this).liquidNotInserted(liquid.getFluid(), liquid.getAmount());
}
IRoutedItem routedItem = SimpleServiceLocator.routedItemHelper.createNewTravelItem(SimpleServiceLocator.logisticsFluidManager.getFluidContainer(liquid));
Pair<Integer, FluidSinkReply> replies = SimpleServiceLocator.logisticsFluidManager.getBestReply(liquid, getRouter(), routedItem.getJamList());
if (replies == null) {
// clear destination without marking item as lost
routedItem.setDestination(0);
} else {
int dest = replies.getValue1();
routedItem.setDestination(dest);
}
routedItem.setTransportMode(TransportMode.Passive);
this.queueRoutedItem(routedItem, arrivingItem.output.getOpposite());
return true;
}
return false;
}
use of network.rs485.logisticspipes.connection.Adjacent in project LogisticsPipes by RS485.
the class LogisticsEventListener method onPlayerLeftClickBlock.
@SubscribeEvent
public void onPlayerLeftClickBlock(final PlayerInteractEvent.RightClickBlock event) {
if (MainProxy.isServer(event.getEntityPlayer().world)) {
WorldCoordinatesWrapper worldCoordinates = new WorldCoordinatesWrapper(event.getEntityPlayer().world, event.getPos());
TileEntity tileEntity = worldCoordinates.getTileEntity();
if (tileEntity instanceof TileEntityChest || SimpleServiceLocator.ironChestProxy.isIronChest(tileEntity)) {
List<WeakReference<AsyncQuicksortModule>> list = worldCoordinates.allNeighborTileEntities().stream().filter(NeighborTileEntity::isLogisticsPipe).filter(adjacent -> ((LogisticsTileGenericPipe) adjacent.getTileEntity()).pipe instanceof PipeLogisticsChassis).filter(adjacent -> ((PipeLogisticsChassis) ((LogisticsTileGenericPipe) adjacent.getTileEntity()).pipe).getPointedOrientation() == adjacent.getOurDirection()).map(adjacent -> (PipeLogisticsChassis) ((LogisticsTileGenericPipe) adjacent.getTileEntity()).pipe).flatMap(chassis -> chassis.getModules().getModules()).filter(logisticsModule -> logisticsModule instanceof AsyncQuicksortModule).map(logisticsModule -> new WeakReference<>((AsyncQuicksortModule) logisticsModule)).collect(Collectors.toList());
if (!list.isEmpty()) {
LogisticsEventListener.chestQuickSortConnection.put(event.getEntityPlayer(), list);
}
}
}
}
use of network.rs485.logisticspipes.connection.Adjacent in project LogisticsPipes by RS485.
the class PipeFluidExtractor method enabledUpdateEntity.
@Override
public void enabledUpdateEntity() {
super.enabledUpdateEntity();
if (!isNthTick(10)) {
return;
}
WorldCoordinatesWrapper worldCoordinates = new WorldCoordinatesWrapper(container);
worldCoordinates.getAdjacentTileEntities().filter(adjacent -> adjacent.tileEntity instanceof IFluidHandler && SimpleServiceLocator.pipeInformationManager.isNotAPipe(adjacent.tileEntity)).forEach(adjacent -> extractFrom((IFluidHandler) adjacent.tileEntity, adjacent.direction));
}
use of network.rs485.logisticspipes.connection.Adjacent in project LogisticsPipes by RS485.
the class PipeItemsBasicLogistics method getPointedInventory.
@Override
public IInventoryUtil getPointedInventory(boolean forExtraction) {
IInventoryUtil inv = super.getPointedInventory(forExtraction);
if (inv == null) {
Optional<Pair<IInventory, ForgeDirection>> first = new WorldCoordinatesWrapper(container).getConnectedAdjacentTileEntities(ConnectionPipeType.ITEM).filter(adjacent -> adjacent.tileEntity instanceof IInventory).map(adjacentInventory -> new Pair<>(InventoryHelper.getInventory((IInventory) adjacentInventory.tileEntity), adjacentInventory.direction)).filter(inventoryDirectionPair -> inventoryDirectionPair.getValue1() != null).findFirst();
if (first.isPresent()) {
Pair<IInventory, ForgeDirection> p = first.get();
inv = SimpleServiceLocator.inventoryUtilFactory.getInventoryUtil(p.getValue1(), p.getValue2().getOpposite());
}
}
return inv;
}
Aggregations