use of logisticspipes.pipes.basic.CoreRoutedPipe in project LogisticsPipes by RS485.
the class LogisticsTriggerProvider method getInternalTriggers.
@Override
public Collection<ITriggerInternal> getInternalTriggers(IStatementContainer pipe) {
if (pipe.getTile() instanceof LPBCTileGenericPipe) {
LogisticsTileGenericPipe lPipe = ((LPBCTileGenericPipe) pipe.getTile()).getLpPipe();
LinkedList<ITriggerInternal> triggers = new LinkedList<>();
if (lPipe.pipe instanceof PipeItemsSupplierLogistics || lPipe.pipe instanceof PipeItemsFluidSupplier) {
triggers.add(BuildCraftProxy.LogisticsFailedTrigger);
}
if (lPipe.pipe instanceof PipeItemsCraftingLogistics) {
triggers.add(BuildCraftProxy.LogisticsCraftingTrigger);
}
if (lPipe.pipe instanceof CoreRoutedPipe) {
//Only show this conditional on Gates that can accept parameters
triggers.add(BuildCraftProxy.LogisticsHasDestinationTrigger);
}
if (!triggers.isEmpty()) {
return triggers;
}
}
return null;
}
use of logisticspipes.pipes.basic.CoreRoutedPipe in project LogisticsPipes by RS485.
the class EnderIOTransceiverConnection method getConnections.
@Override
public Collection<TileEntity> getConnections(TileEntity tile) {
boolean onlyOnePipe = false;
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
DoubleCoordinates p = CoordinateUtils.add(new DoubleCoordinates(tile), direction);
TileEntity candidate = p.getTileEntity(tile.getWorldObj());
if (candidate instanceof LogisticsTileGenericPipe && MainProxy.checkPipesConnections(tile, candidate, direction)) {
if (onlyOnePipe) {
onlyOnePipe = false;
break;
} else {
onlyOnePipe = true;
}
}
}
if (!onlyOnePipe || !SimpleServiceLocator.enderIOProxy.isSendAndReceive(tile)) {
return new ArrayList<>(0);
}
List<? extends TileEntity> connections = SimpleServiceLocator.enderIOProxy.getConnectedTransceivers(tile);
Set<TileEntity> set = new HashSet<>();
for (TileEntity connected : connections) {
if (!SimpleServiceLocator.enderIOProxy.isSendAndReceive(connected)) {
continue;
}
LogisticsTileGenericPipe pipe = null;
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
DoubleCoordinates p = CoordinateUtils.add(new DoubleCoordinates(connected), direction);
TileEntity candidate = p.getTileEntity(tile.getWorldObj());
if (candidate instanceof LogisticsTileGenericPipe && MainProxy.checkPipesConnections(connected, candidate, direction)) {
if (pipe != null) {
pipe = null;
break;
} else {
pipe = (LogisticsTileGenericPipe) candidate;
}
}
}
if (pipe != null && pipe.pipe instanceof CoreRoutedPipe) {
set.add(pipe);
}
}
if (set.size() == 1) {
return set;
} else {
return new ArrayList<>(0);
}
}
use of logisticspipes.pipes.basic.CoreRoutedPipe in project LogisticsPipes by RS485.
the class ServerRouter method updateInterests.
@Override
public void updateInterests() {
if (--ticksUntillNextInventoryCheck > 0) {
return;
}
ticksUntillNextInventoryCheck = ServerRouter.REFRESH_TIME;
if (ServerRouter.iterated++ % simpleID == 0) {
// randomly wait 1 extra tick - just so that every router doesn't tick at the same time
ticksUntillNextInventoryCheck++;
}
if (ServerRouter.iterated >= ServerRouter.getBiggestSimpleID()) {
ServerRouter.iterated = 0;
}
CoreRoutedPipe pipe = getPipe();
if (pipe == null) {
return;
}
if (pipe.hasGenericInterests()) {
declareGenericInterest();
} else {
removeGenericInterest();
}
Set<ItemIdentifier> newInterests = pipe.getSpecificInterests();
if (newInterests == null) {
newInterests = new TreeSet<>();
}
if (!newInterests.equals(_hasInterestIn)) {
for (ItemIdentifier i : _hasInterestIn) {
if (!newInterests.contains(i)) {
removeInterest(i);
}
}
newInterests.stream().filter(i -> !_hasInterestIn.contains(i)).forEach(this::addInterest);
_hasInterestIn = newInterests;
}
}
use of logisticspipes.pipes.basic.CoreRoutedPipe in project LogisticsPipes by RS485.
the class ServerRouter method recheckAdjacent.
/**
* Rechecks the piped connection to all adjacent routers as well as discover
* new ones.
*/
private boolean recheckAdjacent() {
connectionNeedsChecking = 0;
if (LPConstants.DEBUG) {
causedBy.clear();
}
if (getPipe() != null) {
/*
if (getPipe().getDebug() != null && getPipe().getDebug().debugThisPipe) {
Info info = StackTraceUtil.addTraceInformation("(" + getPipe().getX() + ", " + getPipe().getY() + ", " + getPipe().getZ() + ")");
StackTraceUtil.printTrace();
info.end();
}
*/
getPipe().spawnParticle(Particles.LightRedParticle, 5);
}
LPTickHandler.adjChecksDone++;
boolean adjacentChanged = false;
CoreRoutedPipe thisPipe = getPipe();
if (thisPipe == null) {
return false;
}
HashMap<CoreRoutedPipe, ExitRoute> adjacent;
List<Pair<ILogisticsPowerProvider, List<IFilter>>> power;
List<Pair<ISubSystemPowerProvider, List<IFilter>>> subSystemPower;
PathFinder finder = new PathFinder(thisPipe.container, Configs.LOGISTICS_DETECTION_COUNT, Configs.LOGISTICS_DETECTION_LENGTH, localChangeListener);
power = finder.powerNodes;
subSystemPower = finder.subPowerProvider;
adjacent = finder.result;
Map<ForgeDirection, List<CoreRoutedPipe>> pipeDirections = new HashMap<>();
for (Entry<CoreRoutedPipe, ExitRoute> entry : adjacent.entrySet()) {
List<CoreRoutedPipe> list = pipeDirections.get(entry.getValue().exitOrientation);
if (list == null) {
list = new ArrayList<>();
pipeDirections.put(entry.getValue().exitOrientation, list);
}
list.add(entry.getKey());
}
pipeDirections.entrySet().stream().filter(entry -> entry.getValue().size() > Configs.MAX_UNROUTED_CONNECTIONS).forEach(entry -> entry.getValue().forEach(adjacent::remove));
listenedPipes.stream().filter(list -> !finder.listenedPipes.contains(list)).forEach(list -> list.remove(localChangeListener));
listenedPipes = finder.listenedPipes;
for (CoreRoutedPipe pipe : adjacent.keySet()) {
if (pipe.stillNeedReplace()) {
return false;
}
}
boolean[] oldSideDisconnected = sideDisconnected;
sideDisconnected = new boolean[6];
checkSecurity(adjacent);
boolean changed = false;
for (int i = 0; i < 6; i++) {
changed |= sideDisconnected[i] != oldSideDisconnected[i];
}
if (changed) {
CoreRoutedPipe pipe = getPipe();
if (pipe != null) {
pipe.getWorld().notifyBlocksOfNeighborChange(pipe.getX(), pipe.getY(), pipe.getZ(), pipe.getWorld().getBlock(pipe.getX(), pipe.getY(), pipe.getZ()));
pipe.refreshConnectionAndRender(false);
}
adjacentChanged = true;
}
if (_adjacent.size() != adjacent.size()) {
adjacentChanged = true;
}
for (CoreRoutedPipe pipe : _adjacent.keySet()) {
if (!adjacent.containsKey(pipe)) {
adjacentChanged = true;
}
}
if (_powerAdjacent != null) {
if (power == null) {
adjacentChanged = true;
} else {
for (Pair<ILogisticsPowerProvider, List<IFilter>> provider : _powerAdjacent) {
if (!power.contains(provider)) {
adjacentChanged = true;
}
}
}
}
if (power != null) {
if (_powerAdjacent == null) {
adjacentChanged = true;
} else {
for (Pair<ILogisticsPowerProvider, List<IFilter>> provider : power) {
if (!_powerAdjacent.contains(provider)) {
adjacentChanged = true;
}
}
}
}
if (_subSystemPowerAdjacent != null) {
if (subSystemPower == null) {
adjacentChanged = true;
} else {
for (Pair<ISubSystemPowerProvider, List<IFilter>> provider : _subSystemPowerAdjacent) {
if (!subSystemPower.contains(provider)) {
adjacentChanged = true;
}
}
}
}
if (subSystemPower != null) {
if (_subSystemPowerAdjacent == null) {
adjacentChanged = true;
} else {
for (Pair<ISubSystemPowerProvider, List<IFilter>> provider : subSystemPower) {
if (!_subSystemPowerAdjacent.contains(provider)) {
adjacentChanged = true;
}
}
}
}
for (Entry<CoreRoutedPipe, ExitRoute> pipe : adjacent.entrySet()) {
ExitRoute oldExit = _adjacent.get(pipe.getKey());
if (oldExit == null) {
adjacentChanged = true;
break;
}
ExitRoute newExit = pipe.getValue();
if (!newExit.equals(oldExit)) {
adjacentChanged = true;
break;
}
}
if (!oldTouchedPipes.equals(finder.touchedPipes)) {
CacheHolder.clearCache(oldTouchedPipes);
CacheHolder.clearCache(finder.touchedPipes);
oldTouchedPipes = finder.touchedPipes;
BitSet visited = new BitSet(ServerRouter.getBiggestSimpleID());
visited.set(getSimpleID());
act(visited, new floodClearCache());
}
if (adjacentChanged) {
HashMap<IRouter, ExitRoute> adjacentRouter = new HashMap<>();
EnumSet<ForgeDirection> routedexits = EnumSet.noneOf(ForgeDirection.class);
EnumMap<ForgeDirection, Integer> subpowerexits = new EnumMap<>(ForgeDirection.class);
for (Entry<CoreRoutedPipe, ExitRoute> pipe : adjacent.entrySet()) {
adjacentRouter.put(pipe.getKey().getRouter(), pipe.getValue());
if ((pipe.getValue().connectionDetails.contains(PipeRoutingConnectionType.canRouteTo) || pipe.getValue().connectionDetails.contains(PipeRoutingConnectionType.canRequestFrom) && !routedexits.contains(pipe.getValue().exitOrientation))) {
routedexits.add(pipe.getValue().exitOrientation);
}
if (!subpowerexits.containsKey(pipe.getValue().exitOrientation) && pipe.getValue().connectionDetails.contains(PipeRoutingConnectionType.canPowerSubSystemFrom)) {
subpowerexits.put(pipe.getValue().exitOrientation, PathFinder.messureDistanceToNextRoutedPipe(getLPPosition(), pipe.getValue().exitOrientation, pipe.getKey().getWorld()));
}
}
_adjacent = Collections.unmodifiableMap(adjacent);
_adjacentRouter_Old = _adjacentRouter;
_adjacentRouter = Collections.unmodifiableMap(adjacentRouter);
if (power != null) {
_powerAdjacent = Collections.unmodifiableList(power);
} else {
_powerAdjacent = null;
}
if (subSystemPower != null) {
_subSystemPowerAdjacent = Collections.unmodifiableList(subSystemPower);
} else {
_subSystemPowerAdjacent = null;
}
_routedExits = routedexits;
_subPowerExits = subpowerexits;
SendNewLSA();
}
return adjacentChanged;
}
use of logisticspipes.pipes.basic.CoreRoutedPipe in project LogisticsPipes by RS485.
the class LogisticsHUDRenderer method refreshList.
private void refreshList(double x, double y, double z) {
ArrayList<Pair<Double, IHeadUpDisplayRendererProvider>> newList = new ArrayList<>();
for (IRouter router : SimpleServiceLocator.routerManager.getRouters()) {
if (router == null) {
continue;
}
CoreRoutedPipe pipe = router.getPipe();
if (!(pipe instanceof IHeadUpDisplayRendererProvider)) {
continue;
}
if (MainProxy.getDimensionForWorld(pipe.getWorld()) == MainProxy.getDimensionForWorld(FMLClientHandler.instance().getClient().theWorld)) {
double dis = Math.hypot(pipe.getX() - x + 0.5, Math.hypot(pipe.getY() - y + 0.5, pipe.getZ() - z + 0.5));
if (dis < Configs.LOGISTICS_HUD_RENDER_DISTANCE && dis > 0.75) {
newList.add(new Pair<>(dis, (IHeadUpDisplayRendererProvider) pipe));
if (!list.contains(pipe)) {
((IHeadUpDisplayRendererProvider) pipe).startWatching();
}
}
}
}
List<IHeadUpDisplayBlockRendererProvider> remove = new ArrayList<>();
providers.stream().filter(provider -> MainProxy.getDimensionForWorld(provider.getWorld()) == MainProxy.getDimensionForWorld(FMLClientHandler.instance().getClient().theWorld)).forEach(provider -> {
double dis = Math.hypot(provider.getX() - x + 0.5, Math.hypot(provider.getY() - y + 0.5, provider.getZ() - z + 0.5));
if (dis < Configs.LOGISTICS_HUD_RENDER_DISTANCE && dis > 0.75 && !provider.isHUDInvalid() && provider.isHUDExistent()) {
newList.add(new Pair<>(dis, provider));
if (!list.contains(provider)) {
provider.startWatching();
}
} else if (provider.isHUDInvalid() || !provider.isHUDExistent()) {
remove.add(provider);
}
});
for (IHeadUpDisplayBlockRendererProvider provider : remove) {
providers.remove(provider);
}
if (newList.size() < 1) {
clearList(true);
return;
}
Collections.sort(newList, (o1, o2) -> {
if (o1.getValue1() < o2.getValue1()) {
return -1;
} else if (o1.getValue1() > o2.getValue1()) {
return 1;
} else {
return 0;
}
});
for (IHeadUpDisplayRendererProvider part : list) {
boolean contains = false;
for (Pair<Double, IHeadUpDisplayRendererProvider> inpart : newList) {
if (inpart.getValue2().equals(part)) {
contains = true;
break;
}
}
if (!contains) {
part.stopWatching();
}
}
clearList(false);
for (Pair<Double, IHeadUpDisplayRendererProvider> part : newList) {
list.addLast(part.getValue2());
}
}
Aggregations