use of logisticspipes.pipes.basic.CoreRoutedPipe in project LogisticsPipes by RS485.
the class ModuleCoordinatesPacket method getLogisticsModule.
@SuppressWarnings("unchecked")
public <T> T getLogisticsModule(EntityPlayer player, Class<T> clazz) {
LogisticsModule module = null;
if (type == ModulePositionType.IN_PIPE) {
moduleBased = true;
LogisticsTileGenericPipe pipe = this.getPipe(player.getEntityWorld());
moduleBased = false;
if (pipe == null || !(pipe.pipe instanceof CoreRoutedPipe)) {
targetNotFound("Couldn't find " + clazz.getName() + ", pipe didn't exsist");
return null;
}
module = ((CoreRoutedPipe) pipe.pipe).getLogisticsModule();
} else if (type == ModulePositionType.IN_HAND) {
if (MainProxy.isServer(player.getEntityWorld())) {
if (player.openContainer instanceof DummyModuleContainer) {
DummyModuleContainer dummy = (DummyModuleContainer) player.openContainer;
module = dummy.getModule();
} else {
targetNotFound("Couldn't find " + clazz.getName() + ", container wasn't a DummyModule Container");
return null;
}
} else {
module = MainProxy.proxy.getModuleFromGui();
if (module == null) {
targetNotFound("Couldn't find " + clazz.getName() + ", GUI didn't provide the module");
return null;
}
}
} else {
moduleBased = true;
LogisticsTileGenericPipe pipe = this.getPipe(player.getEntityWorld());
moduleBased = false;
if (pipe == null || !(pipe.pipe instanceof CoreRoutedPipe)) {
targetNotFound("Couldn't find " + clazz.getName() + ", pipe didn't exsist");
return null;
} else if (!pipe.isInitialized()) {
return null;
}
if (!(pipe.pipe instanceof PipeLogisticsChassi)) {
targetNotFound("Couldn't find " + clazz.getName() + ", pipe wasn't a chassi pipe");
return null;
}
module = ((PipeLogisticsChassi) pipe.pipe).getLogisticsModule().getSubModule(positionInt);
}
if (module != null) {
if (!(clazz.isAssignableFrom(module.getClass()))) {
targetNotFound("Couldn't find " + clazz.getName() + ", found " + module.getClass());
return null;
}
} else {
targetNotFound("Couldn't find " + clazz.getName());
}
return (T) module;
}
use of logisticspipes.pipes.basic.CoreRoutedPipe in project LogisticsPipes by RS485.
the class ModuleCoordinatesGuiProvider method getLogisticsModule.
@SuppressWarnings("unchecked")
public <T> T getLogisticsModule(World world, Class<T> clazz) {
LogisticsTileGenericPipe pipe = getPipe(world);
if (pipe == null || !(pipe.pipe instanceof CoreRoutedPipe)) {
if (LPConstants.DEBUG && (pipe == null || pipe.isInitialized())) {
LogisticsPipes.log.fatal(toString());
new RuntimeException("Couldn't find " + clazz.getName() + ", pipe didn't exsist").printStackTrace();
}
return null;
}
LogisticsModule module = null;
if (slot == ModulePositionType.IN_PIPE) {
module = ((CoreRoutedPipe) pipe.pipe).getLogisticsModule();
} else if (slot == ModulePositionType.IN_HAND) {
throw new UnsupportedOperationException("NO IN_HAND FOR THIS PACKET TYPE");
} else {
if (!(pipe.pipe instanceof PipeLogisticsChassi)) {
if (LPConstants.DEBUG) {
LogisticsPipes.log.fatal(toString());
new RuntimeException("Couldn't find " + clazz.getName() + ", pipe wasn't a chassi pipe").printStackTrace();
}
return null;
}
module = ((PipeLogisticsChassi) pipe.pipe).getLogisticsModule().getSubModule(positionInt);
}
if (module != null) {
if (!(clazz.isAssignableFrom(module.getClass()))) {
if (LPConstants.DEBUG) {
LogisticsPipes.log.fatal(toString());
new RuntimeException("Couldn't find " + clazz.getName() + ", found " + module.getClass()).printStackTrace();
}
return null;
}
} else {
if (LPConstants.DEBUG) {
LogisticsPipes.log.fatal(toString());
new RuntimeException("Couldn't find " + clazz.getName()).printStackTrace();
}
}
return (T) module;
}
use of logisticspipes.pipes.basic.CoreRoutedPipe in project LogisticsPipes by RS485.
the class RequestRunningCraftingTasks method processPacket.
@Override
public void processPacket(EntityPlayer player) {
LogisticsStatisticsTileEntity tile = this.getTile(player.getEntityWorld(), LogisticsStatisticsTileEntity.class);
CoreRoutedPipe pipe = tile.getConnectedPipe();
if (pipe == null) {
return;
}
List<ItemIdentifierStack> items = new ArrayList<>();
for (ExitRoute r : pipe.getRouter().getIRoutersByCost()) {
if (r == null) {
continue;
}
if (r.destination.getPipe() instanceof PipeItemsCraftingLogistics) {
PipeItemsCraftingLogistics crafting = (PipeItemsCraftingLogistics) r.destination.getPipe();
List<ItemIdentifierStack> content = crafting.getItemOrderManager().getContentList(player.getEntityWorld());
items.addAll(content);
}
}
MainProxy.sendPacketToPlayer(PacketHandler.getPacket(RunningCraftingTasks.class).setIdentList(items), player);
}
use of logisticspipes.pipes.basic.CoreRoutedPipe in project LogisticsPipes by RS485.
the class RequestRoutingLasersPacket method handleRouteInDirection.
private void handleRouteInDirection(final LogisticsTileGenericPipe pipeIn, ForgeDirection dirIn, ArrayList<ExitRoute> connectedRoutersIn, final List<LaserData> lasersIn, EnumSet<PipeRoutingConnectionType> connectionTypeIn, final Log logIn) {
List<DataEntry> worklist = new LinkedList<>();
worklist.add(new DataEntry(pipeIn, dirIn, connectedRoutersIn, lasersIn, connectionTypeIn, logIn));
while (!worklist.isEmpty()) {
final DataEntry entry = worklist.remove(0);
final LogisticsTileGenericPipe pipe = entry.pipe;
final ForgeDirection dir = entry.dir;
final ArrayList<ExitRoute> connectedRouters = entry.connectedRouters;
final List<LaserData> lasers = entry.lasers;
final EnumSet<PipeRoutingConnectionType> connectionType = entry.connectionType;
final Log log = entry.log;
if (LPConstants.DEBUG) {
log.log("Size: " + connectedRouters.size());
}
lasers.add(new LaserData(pipe.xCoord, pipe.yCoord, pipe.zCoord, dir, connectionType).setStartPipe(firstPipe));
firstPipe = false;
HashMap<CoreRoutedPipe, ExitRoute> map = PathFinder.paintAndgetConnectedRoutingPipes(pipe, dir, Configs.LOGISTICS_DETECTION_COUNT, Configs.LOGISTICS_DETECTION_LENGTH, (worldObj, laser) -> {
if (pipe.getWorld() == worldObj) {
lasers.add(laser);
}
}, connectionType);
for (CoreRoutedPipe connectedPipe : map.keySet()) {
IRouter newRouter = connectedPipe.getRouter();
Iterator<ExitRoute> iRoutes = connectedRouters.iterator();
while (iRoutes.hasNext()) {
ExitRoute route = iRoutes.next();
if (route.destination == newRouter) {
iRoutes.remove();
}
}
}
Map<CoreRoutedPipe, ArrayList<ExitRoute>> sort = new HashMap<>();
for (ExitRoute routeTo : connectedRouters) {
ExitRoute result = null;
CoreRoutedPipe resultPipe = null;
for (Entry<CoreRoutedPipe, ExitRoute> routeCanidate : map.entrySet()) {
List<ExitRoute> distances = routeCanidate.getValue().destination.getDistanceTo(routeTo.destination);
for (ExitRoute distance : distances) {
if (distance.isSameWay(routeTo)) {
if (result == null || result.distanceToDestination > distance.distanceToDestination) {
result = distance;
resultPipe = routeCanidate.getKey();
}
}
}
}
if (result == null) {
continue;
}
if (!sort.containsKey(resultPipe)) {
sort.put(resultPipe, new ArrayList<>());
}
if (!sort.get(resultPipe).contains(result)) {
sort.get(resultPipe).add(result);
}
}
for (Entry<CoreRoutedPipe, ArrayList<ExitRoute>> connectedPipe : sort.entrySet()) {
HashMap<ForgeDirection, ArrayList<ExitRoute>> routers = new HashMap<>();
for (ExitRoute exit : connectedPipe.getValue()) {
if (!routers.containsKey(exit.exitOrientation)) {
routers.put(exit.exitOrientation, new ArrayList<>());
}
if (!routers.get(exit.exitOrientation).contains(exit)) {
routers.get(exit.exitOrientation).add(exit);
}
}
for (final ForgeDirection exitDir : routers.keySet()) {
if (exitDir == ForgeDirection.UNKNOWN) {
continue;
}
worklist.add(new DataEntry(connectedPipe.getKey().container, exitDir, routers.get(exitDir), lasers, map.get(connectedPipe.getKey()).connectionDetails, new Log() {
@Override
void log(String logString) {
if (LPConstants.DEBUG) {
log.log(exitDir.name() + ": " + logString);
}
}
}));
}
}
}
}
use of logisticspipes.pipes.basic.CoreRoutedPipe in project LogisticsPipes by RS485.
the class StatUpdate method processPacket.
@Override
public void processPacket(EntityPlayer player) {
final LogisticsTileGenericPipe pipe = this.getPipe(player.worldObj);
if (pipe == null) {
return;
}
if (!(pipe.pipe instanceof CoreRoutedPipe)) {
return;
}
CoreRoutedPipe cPipe = (CoreRoutedPipe) pipe.pipe;
cPipe.stat_session_sent = stat_session_sent;
cPipe.stat_session_recieved = stat_session_recieved;
cPipe.stat_session_relayed = stat_session_relayed;
cPipe.stat_lifetime_sent = stat_lifetime_sent;
cPipe.stat_lifetime_recieved = stat_lifetime_recieved;
cPipe.stat_lifetime_relayed = stat_lifetime_relayed;
cPipe.server_routing_table_size = server_routing_table_size;
}
Aggregations