use of logisticspipes.utils.StackTraceUtil.Info 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 (LogisticsPipes.isDEBUG()) {
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<EnumFacing, List<CoreRoutedPipe>> pipeDirections = new HashMap<>();
for (Entry<CoreRoutedPipe, ExitRoute> entry : adjacent.entrySet()) {
List<CoreRoutedPipe> list = pipeDirections.computeIfAbsent(entry.getValue().exitOrientation, k -> new ArrayList<>());
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().markAndNotifyBlock(pipe.getPos(), pipe.getWorld().getChunkFromBlockCoords(pipe.getPos()), pipe.getWorld().getBlockState(pipe.getPos()), pipe.getWorld().getBlockState(pipe.getPos()), 3);
pipe.refreshConnectionAndRender(false);
}
adjacentChanged = true;
}
if (_adjacent.size() != adjacent.size()) {
adjacentChanged = true;
}
for (CoreRoutedPipe pipe : _adjacent.keySet()) {
if (!adjacent.containsKey(pipe)) {
adjacentChanged = true;
break;
}
}
if (_powerAdjacent != null) {
if (power == null) {
adjacentChanged = true;
} else {
for (Pair<ILogisticsPowerProvider, List<IFilter>> provider : _powerAdjacent) {
if (!power.contains(provider)) {
adjacentChanged = true;
break;
}
}
}
}
if (power != null) {
if (_powerAdjacent == null) {
adjacentChanged = true;
} else {
for (Pair<ILogisticsPowerProvider, List<IFilter>> provider : power) {
if (!_powerAdjacent.contains(provider)) {
adjacentChanged = true;
break;
}
}
}
}
if (_subSystemPowerAdjacent != null) {
if (subSystemPower == null) {
adjacentChanged = true;
} else {
for (Pair<ISubSystemPowerProvider, List<IFilter>> provider : _subSystemPowerAdjacent) {
if (!subSystemPower.contains(provider)) {
adjacentChanged = true;
break;
}
}
}
}
if (subSystemPower != null) {
if (_subSystemPowerAdjacent == null) {
adjacentChanged = true;
} else {
for (Pair<ISubSystemPowerProvider, List<IFilter>> provider : subSystemPower) {
if (!_subSystemPowerAdjacent.contains(provider)) {
adjacentChanged = true;
break;
}
}
}
}
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<ServerRouter, ExitRoute> adjacentRouter = new HashMap<>();
EnumSet<EnumFacing> routedexits = EnumSet.noneOf(EnumFacing.class);
EnumMap<EnumFacing, Integer> subpowerexits = new EnumMap<>(EnumFacing.class);
for (Entry<CoreRoutedPipe, ExitRoute> pipe : adjacent.entrySet()) {
adjacentRouter.put((ServerRouter) 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.utils.StackTraceUtil.Info in project LogisticsPipes by RS485.
the class LogisticsTileGenericPipe method updateEntity.
@Override
public void updateEntity() {
Info superDebug = StackTraceUtil.addSuperTraceInformation("Time: " + getWorld().getWorldTime());
Info debug = StackTraceUtil.addTraceInformation("(" + getX() + ", " + getY() + ", " + getZ() + ")", superDebug);
if (sendInitPacket && MainProxy.isServer(getWorldObj())) {
sendInitPacket = false;
getRenderController().sendInit();
}
if (!worldObj.isRemote) {
if (deletePipe) {
worldObj.setBlockToAir(xCoord, yCoord, zCoord);
}
if (pipe == null) {
debug.end();
return;
}
if (!initialized) {
initialize(pipe);
}
}
if (!LogisticsBlockGenericPipe.isValid(pipe)) {
debug.end();
return;
}
pipe.updateEntity();
if (worldObj.isRemote) {
debug.end();
return;
}
if (blockNeighborChange) {
computeConnections();
pipe.onNeighborBlockChange(0);
blockNeighborChange = false;
refreshRenderState = true;
}
//Sideblocks need to be checked before this
tilePart.updateEntity_LP();
if (refreshRenderState) {
// Pipe connections;
for (ForgeDirection o : ForgeDirection.VALID_DIRECTIONS) {
renderState.pipeConnectionMatrix.setConnected(o, pipeConnectionsBuffer[o.ordinal()]);
renderState.pipeConnectionMatrix.setBCConnected(o, pipeBCConnectionsBuffer[o.ordinal()]);
renderState.pipeConnectionMatrix.setTDConnected(o, pipeTDConnectionsBuffer[o.ordinal()]);
}
// Pipe Textures
for (int i = 0; i < 7; i++) {
ForgeDirection o = ForgeDirection.getOrientation(i);
renderState.textureMatrix.setIconIndex(o, pipe.getIconIndex(o));
}
//New Pipe Texture States
renderState.textureMatrix.refreshStates(pipe);
if (renderState.isDirty()) {
renderState.clean();
sendUpdateToClient();
}
refreshRenderState = false;
}
if (bcPlugableState.isDirty(true)) {
sendUpdateToClient();
}
if (sendClientUpdate) {
sendClientUpdate = false;
MainProxy.sendPacketToAllWatchingChunk(xCoord, zCoord, MainProxy.getDimensionForWorld(worldObj), getLPDescriptionPacket());
}
getRenderController().onUpdate();
if (!addedToNetwork) {
addedToNetwork = true;
SimpleServiceLocator.openComputersProxy.addToNetwork(this);
}
debug.end();
}
use of logisticspipes.utils.StackTraceUtil.Info in project LogisticsPipes by RS485.
the class ServerRouter method update.
@Override
public void update(boolean doFullRefresh, CoreRoutedPipe pipe) {
if (connectionNeedsChecking == 2) {
ensureChangeListenerAttachedToPipe(pipe);
final Info info = StackTraceUtil.addTraceInformation(causedBy::toString);
boolean blockNeedsUpdate = checkAdjacentUpdate();
if (blockNeedsUpdate) {
updateLsa();
}
info.end();
ensureChangeListenerAttachedToPipe(pipe);
}
if (connectionNeedsChecking == 1) {
connectionNeedsChecking = 2;
}
handleQueuedTasks(pipe);
updateInterests();
if (doFullRefresh) {
ensureChangeListenerAttachedToPipe(pipe);
boolean blockNeedsUpdate = checkAdjacentUpdate();
if (blockNeedsUpdate) {
// updateAdjacentAndLsa();
updateLsa();
}
ensureChangeListenerAttachedToPipe(pipe);
lazyUpdateRoutingTable();
} else if (Configs.MULTI_THREAD_NUMBER > 0) {
lazyUpdateRoutingTable();
}
}
use of logisticspipes.utils.StackTraceUtil.Info in project LogisticsPipes by RS485.
the class LogisticsTileGenericPipe method update.
@Override
public void update() {
imcmpltgpCompanion.update();
final Info superDebug = StackTraceUtil.addSuperTraceInformation(() -> "Time: " + getWorld().getWorldTime());
final Info debug = StackTraceUtil.addTraceInformation(() -> "(" + getX() + ", " + getY() + ", " + getZ() + ")", superDebug);
if (sendInitPacket && MainProxy.isServer(getWorld())) {
sendInitPacket = false;
getRenderController().sendInit();
}
if (!world.isRemote) {
if (deletePipe) {
world.setBlockToAir(getPos());
}
if (pipe == null) {
debug.end();
return;
}
if (!initialized) {
initialize(pipe);
}
}
if (!LogisticsBlockGenericPipe.isValid(pipe)) {
debug.end();
return;
}
pipe.updateEntity();
if (world.isRemote) {
debug.end();
return;
}
if (blockNeighborChange) {
computeConnections();
pipe.onNeighborBlockChange();
blockNeighborChange = false;
refreshRenderState = true;
if (MainProxy.isServer(world)) {
MainProxy.sendPacketToAllWatchingChunk(this, PacketHandler.getPacket(PipeSolidSideCheck.class).setTilePos(this));
}
}
if (refreshRenderState) {
refreshRenderState();
if (renderState.isDirty()) {
renderState.clean();
sendUpdateToClient();
}
refreshRenderState = false;
}
if (sendClientUpdate) {
sendClientUpdate = false;
MainProxy.sendPacketToAllWatchingChunk(this, getLPDescriptionPacket());
}
getRenderController().onUpdate();
if (!addedToNetwork) {
addedToNetwork = true;
SimpleServiceLocator.openComputersProxy.addToNetwork(this);
}
debug.end();
}
Aggregations