use of network.rs485.logisticspipes.connection.Adjacent in project LogisticsPipes by RS485.
the class LogisticsPowerProviderTileEntity method updateEntity.
@Override
public void updateEntity() {
super.updateEntity();
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) {
double fullfillRatio = Math.min(1, Math.min(internalStorage, getMaxProvidePerTick()) / globalRequest);
if (fullfillRatio > 0) {
for (Entry<Integer, Double> order : orders.entrySet()) {
double toSend = order.getValue() * fullfillRatio;
if (toSend > internalStorage) {
toSend = internalStorage;
}
IRouter destinationRouter = SimpleServiceLocator.routerManager.getRouter(order.getKey());
if (destinationRouter != null && destinationRouter.getPipe() != null) {
WorldCoordinatesWrapper worldCoordinates = new WorldCoordinatesWrapper(this);
outerTiles: for (AdjacentTileEntity adjacent : worldCoordinates.getAdjacentTileEntities().collect(Collectors.toList())) {
if (adjacent.tileEntity instanceof LogisticsTileGenericPipe) {
if (((LogisticsTileGenericPipe) adjacent.tileEntity).pipe instanceof CoreRoutedPipe) {
if (((CoreRoutedPipe) ((LogisticsTileGenericPipe) adjacent.tileEntity).pipe).stillNeedReplace()) {
continue;
}
IRouter sourceRouter = ((CoreRoutedPipe) ((LogisticsTileGenericPipe) adjacent.tileEntity).pipe).getRouter();
if (sourceRouter != null) {
outerRouters: for (ExitRoute exit : sourceRouter.getDistanceTo(destinationRouter)) {
if (exit.containsFlag(PipeRoutingConnectionType.canPowerSubSystemFrom)) {
for (IFilter filter : exit.filters) {
if (filter.blockPower()) {
continue outerRouters;
}
}
CoreRoutedPipe pipe = sourceRouter.getPipe();
if (pipe != null && pipe.isInitialized()) {
pipe.container.addLaser(adjacent.direction.getOpposite(), 1, getLaserColor(), true, true);
}
sendPowerLaserPackets(sourceRouter, destinationRouter, exit.exitOrientation, exit.exitOrientation != adjacent.direction);
internalStorage -= toSend;
handlePower(destinationRouter.getPipe(), toSend);
break outerTiles;
}
}
}
}
}
}
}
}
}
}
orders.clear();
if (MainProxy.isServer(worldObj)) {
if (internalStorage != lastUpdateStorage) {
updateClients();
lastUpdateStorage = internalStorage;
}
}
}
use of network.rs485.logisticspipes.connection.Adjacent 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 network.rs485.logisticspipes.connection.Adjacent in project LogisticsPipes by RS485.
the class PipeTransportLayer method itemArrived.
@Override
public ForgeDirection itemArrived(IRoutedItem item, ForgeDirection denyed) {
if (item.getItemIdentifierStack() != null) {
_trackStatistics.recievedItem(item.getItemIdentifierStack().getStackSize());
}
List<AdjacentTileEntity> adjacentEntities = new WorldCoordinatesWrapper(routedPipe.container).getConnectedAdjacentTileEntities(IPipeInformationProvider.ConnectionPipeType.ITEM).collect(Collectors.toList());
LinkedList<ForgeDirection> possibleForgeDirection = new LinkedList<>();
for (AdjacentTileEntity adjacent : adjacentEntities) {
if (SimpleServiceLocator.pipeInformationManager.isItemPipe(adjacent.tileEntity)) {
continue;
}
if (_router.isRoutedExit(adjacent.direction)) {
continue;
}
if (denyed != null && denyed.equals(adjacent.direction)) {
continue;
}
CoreRoutedPipe pipe = _router.getPipe();
if (pipe != null) {
if (pipe.isLockedExit(adjacent.direction)) {
continue;
}
}
possibleForgeDirection.add(adjacent.direction);
}
if (possibleForgeDirection.size() != 0) {
return possibleForgeDirection.get(routedPipe.getWorld().rand.nextInt(possibleForgeDirection.size()));
}
// 2nd prio, deliver to non-routed exit
for (AdjacentTileEntity adjacent : adjacentEntities) {
if (_router.isRoutedExit(adjacent.direction)) {
continue;
}
CoreRoutedPipe pipe = _router.getPipe();
if (pipe != null) {
if (pipe.isLockedExit(adjacent.direction)) {
continue;
}
}
possibleForgeDirection.add(adjacent.direction);
}
if (possibleForgeDirection.size() == 0) {
return null;
}
return possibleForgeDirection.get(routedPipe.getWorld().rand.nextInt(possibleForgeDirection.size()));
}
use of network.rs485.logisticspipes.connection.Adjacent in project LogisticsPipes by RS485.
the class ModuleSatellite method spaceFor.
private int spaceFor(ItemIdentifier item, boolean includeInTransit) {
WorldCoordinatesWrapper worldCoordinates = new WorldCoordinatesWrapper(pipe.container);
//@formatter:off
int count = worldCoordinates.getConnectedAdjacentTileEntities(ConnectionPipeType.ITEM).filter(adjacent -> adjacent.tileEntity instanceof IInventory).map(adjacent -> {
IInventory inv = (IInventory) adjacent.tileEntity;
if (inv instanceof net.minecraft.inventory.ISidedInventory) {
inv = new SidedInventoryMinecraftAdapter((net.minecraft.inventory.ISidedInventory) inv, adjacent.direction.getOpposite(), false);
}
IInventoryUtil util = SimpleServiceLocator.inventoryUtilFactory.getInventoryUtil(inv, adjacent.direction);
return util.roomForItem(item, 9999);
}).reduce(Integer::sum).orElse(0);
if (includeInTransit) {
count -= pipe.countOnRoute(item);
}
return count;
}
use of network.rs485.logisticspipes.connection.Adjacent in project LogisticsPipes by RS485.
the class ModuleCrafterMK3 method tick.
@Override
public void tick() {
super.tick();
if (inv.isEmpty()) {
return;
}
if (!_service.isNthTick(6)) {
return;
}
//Add from internal buffer
List<AdjacentTileEntity> crafters = locateCrafters();
boolean change = false;
for (AdjacentTileEntity adjacent : crafters) {
for (int i = inv.getSizeInventory() - 1; i >= 0; i--) {
ItemIdentifierStack slot = inv.getIDStackInSlot(i);
if (slot == null) {
continue;
}
ForgeDirection insertion = adjacent.direction.getOpposite();
if (getUpgradeManager().hasSneakyUpgrade()) {
insertion = getUpgradeManager().getSneakyOrientation();
}
ItemIdentifierStack toadd = slot.clone();
toadd.setStackSize(Math.min(toadd.getStackSize(), toadd.getItem().getMaxStackSize()));
if (_service.getItemOrderManager().hasOrders(ResourceType.CRAFTING)) {
toadd.setStackSize(Math.min(toadd.getStackSize(), ((IInventory) adjacent.tileEntity).getInventoryStackLimit()));
ItemStack added = InventoryHelper.getTransactorFor(adjacent.tileEntity, adjacent.direction.getOpposite()).add(toadd.makeNormalStack(), insertion, true);
slot.setStackSize(slot.getStackSize() - added.stackSize);
if (added.stackSize != 0) {
change = true;
}
} else {
_service.queueRoutedItem(SimpleServiceLocator.routedItemHelper.createNewTravelItem(toadd), adjacent.direction.getOpposite());
slot.setStackSize(slot.getStackSize() - toadd.getStackSize());
change = true;
}
if (slot.getStackSize() <= 0) {
inv.clearInventorySlotContents(i);
} else {
inv.setInventorySlotContents(i, slot);
}
}
}
if (change) {
inv.markDirty();
_service.getCacheHolder().trigger(CacheTypes.Inventory);
}
}
Aggregations