use of network.rs485.logisticspipes.world.DoubleCoordinates in project LogisticsPipes by RS485.
the class LPRobotConnectionControl method getConnections.
@Override
public List<ConnectionInformation> getConnections(IPipeInformationProvider startPipe, EnumSet<PipeRoutingConnectionType> connection, ForgeDirection side) {
List<ConnectionInformation> list = new ArrayList<>();
LogisticsTileGenericPipe pipe = (LogisticsTileGenericPipe) startPipe;
if (pipe == null || pipe.tilePart.getOriginal() == null) {
// Proxy got disabled
return list;
}
DoubleCoordinates pos = new DoubleCoordinates(startPipe);
pos.center();
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
PipePluggable pluggable = ((TileGenericPipe) pipe.tilePart.getOriginal()).getPipePluggable(dir);
if (!(pluggable instanceof RobotStationPluggable)) {
continue;
}
DockingStation station = ((RobotStationPluggable) pluggable).getStation();
if (!station.isTaken()) {
continue;
}
EntityRobotBase robot = station.robotTaking();
if (robot == null) {
continue;
}
if (!(robot.getBoard() instanceof LogisticsRoutingBoardRobot)) {
continue;
}
if (robot.isDead) {
continue;
}
if (!((LogisticsRoutingBoardRobot) robot.getBoard()).isAcceptsItems()) {
continue;
}
DoubleCoordinates robotPos = new DoubleCoordinates(robot);
if (((LogisticsRoutingBoardRobot) robot.getBoard()).getCurrentTarget() != null) {
Pair<Double, LogisticsRoutingBoardRobot> currentTarget = ((LogisticsRoutingBoardRobot) robot.getBoard()).getCurrentTarget();
DoubleCoordinates pipePos = currentTarget.getValue2().getLinkedStationPosition();
TileEntity connectedPipeTile = pipePos.getTileEntity(pipe.getWorldObj());
if (!(connectedPipeTile instanceof LogisticsTileGenericPipe)) {
continue;
}
LogisticsTileGenericPipe connectedPipe = (LogisticsTileGenericPipe) connectedPipeTile;
if (!connectedPipe.isRoutingPipe()) {
continue;
}
IPipeInformationProvider connectedInfo = SimpleServiceLocator.pipeInformationManager.getInformationProviderFor(connectedPipe);
EntityRobotBase connectedRobot = currentTarget.getValue2().robot;
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;
}
DoubleCoordinates connectedRobotPos = new DoubleCoordinates(connectedRobot);
if (CoordinateUtils.add(new DoubleCoordinates(pipePos).center(), currentTarget.getValue2().robot.getLinkedStation().side(), 0.5).distanceTo(connectedRobotPos) > 0.05) {
// Not at station
continue;
}
EnumSet<PipeRoutingConnectionType> newCon = connection.clone();
newCon.removeAll(EnumSet.of(PipeRoutingConnectionType.canPowerFrom, PipeRoutingConnectionType.canPowerSubSystemFrom));
double distance = CoordinateUtils.add(new DoubleCoordinates(currentTarget.getValue2().getLinkedStationPosition()).center(), currentTarget.getValue2().robot.getLinkedStation().side(), 0.5).distanceTo(robotPos);
list.add(new ConnectionInformation(connectedInfo, newCon, currentTarget.getValue2().robot.getLinkedStation().side().getOpposite(), dir, (distance * 3) + 21));
} else {
if (CoordinateUtils.add(new DoubleCoordinates(pos), dir, 0.5).distanceTo(robotPos) > 0.05) {
// Not at station
continue;
}
for (Pair<DoubleCoordinates, ForgeDirection> canidatePos : ((LogisticsRoutingBoardRobot) robot.getBoard()).getConnectionDetails().localConnectedRobots) {
if (canidatePos.getValue1().equals(new DoubleCoordinates(startPipe))) {
continue;
}
double distance = CoordinateUtils.add(new DoubleCoordinates(canidatePos.getValue1()).center(), canidatePos.getValue2(), 0.5).distanceTo(robotPos);
TileEntity connectedPipeTile = canidatePos.getValue1().getTileEntity(pipe.getWorldObj());
if (!(connectedPipeTile instanceof LogisticsTileGenericPipe)) {
continue;
}
LogisticsTileGenericPipe connectedPipe = (LogisticsTileGenericPipe) connectedPipeTile;
if (!connectedPipe.isRoutingPipe()) {
continue;
}
IPipeInformationProvider connectedInfo = SimpleServiceLocator.pipeInformationManager.getInformationProviderFor(connectedPipe);
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;
}
EnumSet<PipeRoutingConnectionType> newCon = connection.clone();
newCon.removeAll(EnumSet.of(PipeRoutingConnectionType.canPowerFrom, PipeRoutingConnectionType.canPowerSubSystemFrom));
list.add(new ConnectionInformation(connectedInfo, newCon, canidatePos.getValue2().getOpposite(), dir, (distance * 3) + 21));
}
}
}
return list;
}
use of network.rs485.logisticspipes.world.DoubleCoordinates in project LogisticsPipes by RS485.
the class LogisticsBlockGenericPipe method removePipe.
public static void removePipe(CoreUnroutedPipe pipe) {
if (!LogisticsBlockGenericPipe.isValid(pipe)) {
return;
}
if (pipe.canBeDestroyed() || pipe.destroyByPlayer()) {
pipe.onBlockRemoval();
} else if (pipe.preventRemove()) {
LogisticsBlockGenericPipe.cacheTileToPreventRemoval(pipe);
}
World world = pipe.container.getWorldObj();
if (pipe.isMultiBlock()) {
if (pipe.preventRemove()) {
throw new UnsupportedOperationException("A multi block can't be protected against removal.");
}
LPPositionSet<DoubleCoordinatesType<CoreMultiBlockPipe.SubBlockTypeForShare>> list = ((CoreMultiBlockPipe) pipe).getRotatedSubBlocks();
list.stream().forEach(pos -> pos.add(new DoubleCoordinates(pipe)));
for (DoubleCoordinates pos : pipe.container.subMultiBlock) {
TileEntity tile = pos.getTileEntity(world);
if (tile instanceof LogisticsTileGenericSubMultiBlock) {
DoubleCoordinatesType<CoreMultiBlockPipe.SubBlockTypeForShare> equ = list.findClosest(pos);
if (equ != null) {
((LogisticsTileGenericSubMultiBlock) tile).removeSubType(equ.getType());
}
if (((LogisticsTileGenericSubMultiBlock) tile).removeMainPipe(new DoubleCoordinates(pipe))) {
pos.setBlockToAir(world);
} else {
MainProxy.sendPacketToAllWatchingChunk(tile, ((LogisticsTileGenericSubMultiBlock) tile).getLPDescriptionPacket());
}
}
}
}
if (world == null) {
return;
}
int x = pipe.container.xCoord;
int y = pipe.container.yCoord;
int z = pipe.container.zCoord;
if (LogisticsBlockGenericPipe.lastRemovedDate != world.getTotalWorldTime()) {
LogisticsBlockGenericPipe.lastRemovedDate = world.getTotalWorldTime();
LogisticsBlockGenericPipe.pipeRemoved.clear();
}
LogisticsBlockGenericPipe.pipeRemoved.put(new DoubleCoordinates(x, y, z), pipe);
world.removeTileEntity(x, y, z);
}
use of network.rs485.logisticspipes.world.DoubleCoordinates in project LogisticsPipes by RS485.
the class LogisticsBlockGenericPipe method getDrops.
@Override
public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune) {
if (world.isRemote) {
return null;
}
ArrayList<ItemStack> list = new ArrayList<>();
int count = quantityDropped(metadata, fortune, world.rand);
for (int i = 0; i < count; i++) {
CoreUnroutedPipe pipe = LogisticsBlockGenericPipe.getPipe(world, x, y, z);
if (pipe == null) {
pipe = LogisticsBlockGenericPipe.pipeRemoved.get(new DoubleCoordinates(x, y, z));
}
if (pipe != null) {
if (pipe.item != null && (pipe.canBeDestroyed() || pipe.destroyByPlayer())) {
list.addAll(pipe.dropContents());
list.add(new ItemStack(pipe.item, 1, damageDropped(metadata)));
} else if (pipe.item != null) {
LogisticsBlockGenericPipe.cacheTileToPreventRemoval(pipe);
}
}
}
return list;
}
use of network.rs485.logisticspipes.world.DoubleCoordinates in project LogisticsPipes by RS485.
the class LogisticsBlockGenericSubMultiBlock method addCollisionBoxesToList.
@SuppressWarnings("rawtypes")
@Override
public void addCollisionBoxesToList(World world, int x, int y, int z, AxisAlignedBB axisalignedbb, List arraylist, Entity entity) {
DoubleCoordinates pos = new DoubleCoordinates(x, y, z);
TileEntity tile = pos.getTileEntity(world);
if (tile instanceof LogisticsTileGenericSubMultiBlock) {
List<LogisticsTileGenericPipe> mainPipeList = ((LogisticsTileGenericSubMultiBlock) tile).getMainPipe();
mainPipeList.stream().filter(mainPipe -> mainPipe != null && mainPipe.pipe != null && mainPipe.pipe.isMultiBlock()).forEach(mainPipe -> LogisticsPipes.LogisticsPipeBlock.addCollisionBoxesToList(world, mainPipe.xCoord, mainPipe.yCoord, mainPipe.zCoord, axisalignedbb, arraylist, entity));
}
}
use of network.rs485.logisticspipes.world.DoubleCoordinates in project LogisticsPipes by RS485.
the class LogisticsBlockGenericSubMultiBlock method addDestroyEffects.
@Override
public boolean addDestroyEffects(World world, int x, int y, int z, int meta, EffectRenderer effectRenderer) {
DoubleCoordinates pos = new DoubleCoordinates(x, y, z);
TileEntity tile = pos.getTileEntity(world);
if (tile instanceof LogisticsTileGenericSubMultiBlock) {
List<LogisticsTileGenericPipe> mainPipeList = ((LogisticsTileGenericSubMultiBlock) tile).getMainPipe();
for (LogisticsTileGenericPipe mainPipe : mainPipeList) {
if (mainPipe != null && mainPipe.pipe != null && mainPipe.pipe.isMultiBlock()) {
if (LogisticsPipes.LogisticsPipeBlock.doRayTrace(world, mainPipe.xCoord, mainPipe.yCoord, mainPipe.zCoord, Minecraft.getMinecraft().thePlayer) != null) {
return LogisticsPipes.LogisticsPipeBlock.addDestroyEffects(world, mainPipe.xCoord, mainPipe.yCoord, mainPipe.zCoord, meta, effectRenderer);
}
}
}
}
return super.addDestroyEffects(world, x, y, z, meta, effectRenderer);
}
Aggregations