use of network.rs485.logisticspipes.world.DoubleCoordinates in project LogisticsPipes by RS485.
the class TDDuctInformationProvider method acceptItem.
@Override
public boolean acceptItem(LPTravelingItem item, TileEntity from) {
if (item instanceof LPTravelingItemServer) {
LPTravelingItemServer serverItem = (LPTravelingItemServer) item;
int id = serverItem.getInfo().destinationint;
if (id == -1) {
id = SimpleServiceLocator.routerManager.getIDforUUID(serverItem.getInfo().destinationUUID);
}
IRouter destination = SimpleServiceLocator.routerManager.getRouter(id);
if (destination == null) {
return false;
}
RouteCache routes = duct.getCache(true);
Iterable<Route> paramIterable = routes.outputRoutes;
Route route = null;
Object cache = null;
Triplet<Integer, ItemIdentifier, Boolean> key = new Triplet<>(id, item.getItemIdentifierStack().getItem(), serverItem.getInfo()._transportMode == TransportMode.Active);
if (duct instanceof ILPTEInformation && ((ILPTEInformation) duct).getObject() != null) {
cache = ((ILPTEInformation) duct).getObject().getCacheHolder().getCacheFor(CacheTypes.Routing, key);
}
if (cache instanceof Route) {
route = (Route) cache;
if (!routes.outputRoutes.contains(route)) {
route = null;
}
}
if (route == null) {
Pair<Double, Route> closesedConnection = null;
List<DoubleCoordinates> visited = new ArrayList<>();
visited.add(new DoubleCoordinates(from));
for (Route localRoute1 : paramIterable) {
if (localRoute1.endPoint instanceof LPItemDuct) {
LPItemDuct lpDuct = (LPItemDuct) localRoute1.endPoint;
double max = Integer.MAX_VALUE;
if (closesedConnection != null) {
max = closesedConnection.getValue1();
}
DoubleCoordinates pos = new DoubleCoordinates((TileEntity) lpDuct.pipe);
if (visited.contains(pos)) {
continue;
}
visited.add(pos);
double distance = lpDuct.pipe.getDistanceTo(id, ForgeDirection.getOrientation(localRoute1.pathDirections.get(localRoute1.pathDirections.size() - 1)).getOpposite(), item.getItemIdentifierStack().getItem(), serverItem.getInfo()._transportMode == TransportMode.Active, localRoute1.pathWeight, max, visited);
visited.remove(pos);
if (distance != Integer.MAX_VALUE && (closesedConnection == null || distance + localRoute1.pathDirections.size() < closesedConnection.getValue1())) {
closesedConnection = new Pair<>(distance + localRoute1.pathWeight, localRoute1);
}
}
}
if (closesedConnection != null) {
route = closesedConnection.getValue2();
}
}
if (route != null) {
if (duct instanceof ILPTEInformation && ((ILPTEInformation) duct).getObject() != null) {
((ILPTEInformation) duct).getObject().getCacheHolder().setCache(CacheTypes.Routing, key, route);
}
TravelingItem travelItem = new TravelingItem(item.getItemIdentifierStack().makeNormalStack(), duct, route.copy(), (byte) serverItem.output.ordinal(), (byte) 1);
travelItem.lpRoutingInformation = serverItem.getInfo();
duct.insertNewItem(travelItem);
return true;
}
} else {
return true;
}
return false;
}
use of network.rs485.logisticspipes.world.DoubleCoordinates in project LogisticsPipes by RS485.
the class LogisticsRoutingBoardRobot method findTarget.
private Pair<Double, LogisticsRoutingBoardRobot> findTarget() {
Pair<Double, LogisticsRoutingBoardRobot> result = null;
DoubleCoordinates robotPos = new DoubleCoordinates(robot);
for (Pair<DoubleCoordinates, ForgeDirection> canidatePos : connectionDetails.localConnectedRobots) {
if (robot.getLinkedStation() == null) {
continue;
}
if (canidatePos.getValue1().equals(new DoubleCoordinates(robot.getLinkedStation().x(), robot.getLinkedStation().y(), robot.getLinkedStation().z()))) {
continue;
}
double distance = CoordinateUtils.add(new DoubleCoordinates(canidatePos.getValue1()).center(), canidatePos.getValue2(), 0.5).distanceTo(robotPos);
if (result == null || result.getValue1() > distance) {
TileEntity connectedPipeTile = canidatePos.getValue1().getTileEntity(robot.worldObj);
if (!(connectedPipeTile instanceof LogisticsTileGenericPipe)) {
continue;
}
LogisticsTileGenericPipe connectedPipe = (LogisticsTileGenericPipe) connectedPipeTile;
if (!connectedPipe.isRoutingPipe()) {
continue;
}
PipePluggable connectedPluggable = ((TileGenericPipe) connectedPipe.tilePart.getOriginal()).getPipePluggable(canidatePos.getValue2());
if (!(connectedPluggable instanceof RobotStationPluggable)) {
continue;
}
DockingStation connectedStation = ((RobotStationPluggable) connectedPluggable).getStation();
if (!connectedStation.isTaken()) {
continue;
}
EntityRobotBase connectedRobot = connectedStation.robotTaking();
if (connectedRobot == null) {
continue;
}
if (!(connectedRobot.getBoard() instanceof LogisticsRoutingBoardRobot)) {
continue;
}
if (connectedRobot.isDead) {
continue;
}
if (connectedRobot.getZoneToWork() != null && !connectedRobot.getZoneToWork().contains(robotPos.getXCoord(), robotPos.getYCoord(), robotPos.getZCoord())) {
continue;
}
if (!((LogisticsRoutingBoardRobot) connectedRobot.getBoard()).isAcceptsItems()) {
continue;
}
if (((LogisticsRoutingBoardRobot) connectedRobot.getBoard()).getCurrentTarget() != null && ((LogisticsRoutingBoardRobot) connectedRobot.getBoard()).getCurrentTarget().getValue2() != robot.getBoard()) {
continue;
}
DoubleCoordinates connectedRobotPos = new DoubleCoordinates(connectedRobot);
if (CoordinateUtils.add(new DoubleCoordinates(canidatePos.getValue1()).center(), canidatePos.getValue2(), 0.5).distanceTo(connectedRobotPos) > 0.05) {
// Not at station
continue;
}
Double mindis = Double.NaN;
for (LPTravelingItemServer item : items) {
item.checkIDFromUUID();
if (item.getInfo().destinationint < 0) {
continue;
}
ExitRoute route = connectedPipe.getRoutingPipe().getRouter().getExitFor(item.getInfo().destinationint, item.getInfo()._transportMode == TransportMode.Active, item.getItemIdentifierStack().getItem());
if (route == null) {
continue;
}
if (mindis.isNaN()) {
mindis = route.distanceToDestination;
}
mindis = Math.min(mindis, route.distanceToDestination);
}
if (mindis.isNaN()) {
continue;
}
double distanceToItem = ((distance * 3) + 21) + mindis;
if (result == null || result.getValue1() > distanceToItem) {
result = new Pair<>(distanceToItem, (LogisticsRoutingBoardRobot) connectedRobot.getBoard());
}
}
}
return result;
}
use of network.rs485.logisticspipes.world.DoubleCoordinates in project LogisticsPipes by RS485.
the class LogisticsRoutingBoardRobot method startTransport.
private void startTransport(LogisticsRoutingBoardRobot target, DockingStation station) {
acceptsItems = false;
targetStationPos = new DoubleCoordinates(station.x(), station.y(), station.z());
targetStationSide = station.side();
startDelegateAI(new AIRobotGotoBlock(robot, station.x() + station.side().offsetX, station.y() + station.side().offsetY, station.z() + station.side().offsetZ));
}
use of network.rs485.logisticspipes.world.DoubleCoordinates in project LogisticsPipes by RS485.
the class TesseractConnection method getConnections.
@Override
public List<TileEntity> getConnections(TileEntity tile) {
boolean onlyOnePipe = false;
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
DoubleCoordinates p = CoordinateUtils.add(new DoubleCoordinates(tile), direction);
TileEntity canidate = p.getTileEntity(tile.getWorldObj());
if (canidate instanceof LogisticsTileGenericPipe && MainProxy.checkPipesConnections(tile, canidate, direction)) {
if (onlyOnePipe) {
onlyOnePipe = false;
break;
} else {
onlyOnePipe = true;
}
}
}
if (!onlyOnePipe) {
return new ArrayList<>(0);
}
List<? extends TileEntity> connections = SimpleServiceLocator.thermalExpansionProxy.getConnectedTesseracts(tile);
connections.remove(tile);
List<TileEntity> list = new ArrayList<>();
for (TileEntity connected : connections) {
LogisticsTileGenericPipe pipe = null;
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
DoubleCoordinates p = CoordinateUtils.add(new DoubleCoordinates(connected), direction);
TileEntity canidate = p.getTileEntity(connected.getWorldObj());
if (canidate instanceof LogisticsTileGenericPipe && MainProxy.checkPipesConnections(connected, canidate, direction)) {
if (pipe != null) {
pipe = null;
break;
} else {
pipe = (LogisticsTileGenericPipe) canidate;
}
}
}
if (pipe != null && pipe.pipe instanceof CoreRoutedPipe) {
list.add(pipe);
}
}
if (list.size() == 1) {
return list;
} else {
return new ArrayList<>(0);
}
}
use of network.rs485.logisticspipes.world.DoubleCoordinates in project LogisticsPipes by RS485.
the class TDPart method getInternalDuctForSide.
@Override
public TileEntity getInternalDuctForSide(ForgeDirection opposite) {
if (opposite.ordinal() < 6) {
LPItemDuct duct = thermalDynamicsDucts[opposite.ordinal()];
if (duct == null) {
duct = thermalDynamicsDucts[opposite.ordinal()] = new LPItemDuct(pipe, opposite);
if (MainProxy.isServer(pipe.getWorldObj())) {
TickHandler.addMultiBlockToCalculate(duct);
}
duct.setWorldObj(pipe.getWorldObj());
duct.xCoord = pipe.xCoord;
duct.yCoord = pipe.yCoord;
duct.zCoord = pipe.zCoord;
duct.validate();
DoubleCoordinates pos = CoordinateUtils.add(new DoubleCoordinates((TileEntity) pipe), opposite);
duct.onNeighborTileChange(pos.getXInt(), pos.getYInt(), pos.getZInt());
}
return duct;
}
return null;
}
Aggregations