use of logisticspipes.transport.LPTravelingItem.LPTravelingItemServer in project LogisticsPipes by RS485.
the class LPItemDuct method transferItem.
@Override
public void transferItem(TravelingItem item) {
ItemRoutingInformation info = (ItemRoutingInformation) item.lpRoutingInformation;
if (info != null) {
info.setItem(ItemIdentifierStack.getFromStack(item.stack));
LPTravelingItemServer lpItem = new LPTravelingItemServer(info);
lpItem.setSpeed(info._transportMode == TransportMode.Active ? 0.3F : 0.2F);
pipe.pipe.transport.injectItem(lpItem, ForgeDirection.getOrientation(item.direction));
} else if (item.stack != null) {
int consumed = pipe.injectItem(item.stack, true, dir);
item.stack.stackSize -= consumed;
if (item.stack.stackSize > 0) {
pipe.pipe.transport._itemBuffer.add(new Triplet<>(ItemIdentifierStack.getFromStack(item.stack), new Pair<>(20 * 2, 0), null));
}
}
}
use of logisticspipes.transport.LPTravelingItem.LPTravelingItemServer 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 logisticspipes.transport.LPTravelingItem.LPTravelingItemServer 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 logisticspipes.transport.LPTravelingItem.LPTravelingItemServer in project LogisticsPipes by RS485.
the class LPBCTileGenericPipe method getBCPipePluggable.
@Override
public IBCPipePluggable getBCPipePluggable(final ForgeDirection sideHit) {
final PipePluggable plug = getPipePluggable(sideHit);
if (plug == null) {
return null;
}
return new IBCPipePluggable() {
@Override
public ItemStack[] getDropItems(LogisticsTileGenericPipe container) {
return plug.getDropItems(container);
}
@Override
public boolean isBlocking() {
return plug.isBlocking(pipe.container, sideHit);
}
@Override
public Object getOriginal() {
return plug;
}
@Override
@SideOnly(Side.CLIENT)
public void renderPluggable(RenderBlocks renderblocks, ForgeDirection dir, int renderPass, int x, int y, int z) {
if (plug.getRenderer() == null) {
return;
}
plug.getRenderer().renderPluggable(renderblocks, bcPipe, dir, plug, FakeBlock.INSTANCE, renderPass, x, y, z);
}
@Override
public boolean isAcceptingItems(LPTravelingItemServer arrivingItem) {
if (plug instanceof RobotStationPluggable) {
return true;
}
return false;
}
@Override
public LPTravelingItemServer handleItem(LPTravelingItemServer arrivingItem) {
DockingStation station = ((RobotStationPluggable) plug).getStation();
if (!station.isTaken()) {
return arrivingItem;
}
EntityRobotBase robot = station.robotTaking();
if (!(robot.getBoard() instanceof LogisticsRoutingBoardRobot)) {
return arrivingItem;
}
if (!((LogisticsRoutingBoardRobot) robot.getBoard()).isAcceptsItems()) {
return arrivingItem;
}
DoubleCoordinates robotPos = new DoubleCoordinates(robot);
if (CoordinateUtils.add(new DoubleCoordinates(LPBCTileGenericPipe.this).center(), sideHit, 0.5).distanceTo(robotPos) > 0.05) {
// Not at station
return arrivingItem;
}
return ((LogisticsRoutingBoardRobot) robot.getBoard()).handleItem(arrivingItem);
}
};
}
use of logisticspipes.transport.LPTravelingItem.LPTravelingItemServer in project LogisticsPipes by RS485.
the class PipeTransportLogistics method injectItem.
/**
* Accept items from BC
*/
@ModDependentMethod(modId = "BuildCraft|Transport")
public void injectItem(TravelingItem item, ForgeDirection inputOrientation) {
if (MainProxy.isServer(getWorld())) {
if (item instanceof LPRoutedBCTravelingItem) {
ItemRoutingInformation info = ((LPRoutedBCTravelingItem) item).getRoutingInformation();
info.setItem(ItemIdentifierStack.getFromStack(item.getItemStack()));
LPTravelingItemServer lpItem = new LPTravelingItemServer(info);
lpItem.setSpeed(item.getSpeed());
this.injectItem(lpItem, inputOrientation);
} else {
ItemRoutingInformation info = LPRoutedBCTravelingItem.restoreFromExtraNBTData(item);
if (info != null) {
info.setItem(ItemIdentifierStack.getFromStack(item.getItemStack()));
LPTravelingItemServer lpItem = new LPTravelingItemServer(info);
lpItem.setSpeed(item.getSpeed());
this.injectItem(lpItem, inputOrientation);
} else {
LPTravelingItemServer lpItem = SimpleServiceLocator.routedItemHelper.createNewTravelItem(item.getItemStack());
lpItem.setSpeed(item.getSpeed());
this.injectItem(lpItem, inputOrientation);
}
}
}
}
Aggregations