use of network.rs485.logisticspipes.connection.SingleAdjacent in project LogisticsPipes by RS485.
the class PipeLogisticsChassis method nextOrientation.
@Override
public void nextOrientation() {
final SingleAdjacent pointedAdjacent = this.pointedAdjacent;
Pair<NeighborTileEntity<TileEntity>, ConnectionType> newNeighbor;
if (pointedAdjacent == null) {
newNeighbor = nextPointedOrientation(null);
} else {
newNeighbor = nextPointedOrientation(pointedAdjacent.getDir());
}
final ChassisOrientationPacket packet = PacketHandler.getPacket(ChassisOrientationPacket.class);
if (newNeighbor == null) {
this.pointedAdjacent = null;
packet.setDir(null);
} else {
this.pointedAdjacent = new SingleAdjacent(this, newNeighbor.getValue1().getDirection(), newNeighbor.getValue2());
packet.setDir(newNeighbor.getValue1().getDirection());
}
MainProxy.sendPacketToAllWatchingChunk(_module, packet.setTilePos(container));
refreshRender(true);
}
use of network.rs485.logisticspipes.connection.SingleAdjacent in project LogisticsPipes by RS485.
the class PipeLogisticsChassis method updateAdjacentCache.
/**
* Updates pointedAdjacent on {@link CoreRoutedPipe}.
*/
@Override
protected void updateAdjacentCache() {
super.updateAdjacentCache();
final Adjacent adjacent = getAdjacent();
if (adjacent instanceof SingleAdjacent) {
pointedAdjacent = ((SingleAdjacent) adjacent);
} else {
final SingleAdjacent oldPointedAdjacent = pointedAdjacent;
SingleAdjacent newPointedAdjacent = null;
if (oldPointedAdjacent != null) {
// update pointed adjacent with connection type or reset it
newPointedAdjacent = adjacent.optionalGet(oldPointedAdjacent.getDir()).map(connectionType -> new SingleAdjacent(this, oldPointedAdjacent.getDir(), connectionType)).orElse(null);
}
if (newPointedAdjacent == null) {
newPointedAdjacent = adjacent.neighbors().entrySet().stream().findAny().map(connectedNeighbor -> new SingleAdjacent(this, connectedNeighbor.getKey().getDirection(), connectedNeighbor.getValue())).orElse(null);
}
pointedAdjacent = newPointedAdjacent;
}
}
Aggregations