use of logisticspipes.routing.IRouter in project LogisticsPipes by RS485.
the class ModuleCrafter method addCrafting.
@Override
public ICraftingTemplate addCrafting(IResource toCraft) {
List<ItemIdentifierStack> stack = getCraftedItems();
if (stack == null) {
return null;
}
IReqCraftingTemplate template = null;
if (getUpgradeManager().isFuzzyUpgrade() && outputFuzzy().nextSetBit(0) != -1) {
for (ItemIdentifierStack craftable : stack) {
DictResource dict = new DictResource(craftable, null);
dict.loadFromBitSet(outputFuzzy().copyValue());
if (toCraft.matches(dict, IResource.MatchSettings.NORMAL)) {
template = new DictCraftingTemplate(dict, this, priority.getValue());
break;
}
}
} else {
for (ItemIdentifierStack craftable : stack) {
if (toCraft.matches(craftable.getItem(), IResource.MatchSettings.NORMAL)) {
template = new ItemCraftingTemplate(craftable, this, priority.getValue());
break;
}
}
}
if (template == null) {
return null;
}
IRequestItems[] target = new IRequestItems[9];
for (int i = 0; i < 9; i++) {
target[i] = this;
}
if (!isSatelliteConnected()) {
// has a satellite configured and that one is unreachable
return null;
}
if (!getUpgradeManager().isAdvancedSatelliteCrafter()) {
IRouter r = getSatelliteRouter(-1);
if (r != null) {
IRequestItems sat = r.getPipe();
for (int i = 6; i < 9; i++) {
target[i] = sat;
}
}
} else {
for (int i = 0; i < 9; i++) {
IRouter r = getSatelliteRouter(i);
if (r != null) {
target[i] = r.getPipe();
}
}
}
// Check all materials
for (int i = 0; i < 9; i++) {
ItemIdentifierStack resourceStack = dummyInventory.getIDStackInSlot(i);
if (resourceStack == null || resourceStack.getStackSize() == 0) {
continue;
}
IResource req;
if (getUpgradeManager().isFuzzyUpgrade() && inputFuzzy(i).nextSetBit(0) != -1) {
DictResource dict;
req = dict = new DictResource(resourceStack, target[i]);
dict.loadFromBitSet(inputFuzzy(i).copyValue());
} else {
req = new ItemResource(resourceStack, target[i]);
}
template.addRequirement(req, new CraftingChassisInformation(i, getPositionInt()));
}
int liquidCrafter = getUpgradeManager().getFluidCrafter();
IRequestFluid[] liquidTarget = new IRequestFluid[liquidCrafter];
if (!getUpgradeManager().isAdvancedSatelliteCrafter()) {
IRouter r = getFluidSatelliteRouter(-1);
if (r != null) {
IRequestFluid sat = (IRequestFluid) r.getPipe();
for (int i = 0; i < liquidCrafter; i++) {
liquidTarget[i] = sat;
}
}
} else {
for (int i = 0; i < liquidCrafter; i++) {
IRouter r = getFluidSatelliteRouter(i);
if (r != null) {
liquidTarget[i] = (IRequestFluid) r.getPipe();
}
}
}
for (int i = 0; i < liquidCrafter; i++) {
FluidIdentifier liquid = getFluidMaterial(i);
int amount = liquidAmounts.get(i);
if (liquid == null || amount <= 0 || liquidTarget[i] == null) {
continue;
}
template.addRequirement(new FluidResource(liquid, amount, liquidTarget[i]), null);
}
if (getUpgradeManager().hasByproductExtractor() && getByproductItem() != null) {
template.addByproduct(getByproductItem());
}
return template;
}
use of logisticspipes.routing.IRouter in project LogisticsPipes by RS485.
the class CoreRoutedPipe method sendRoutedItem.
private void sendRoutedItem(IRoutedItem routedItem, EnumFacing from) {
if (from == null) {
throw new NullPointerException();
}
transport.injectItem(routedItem, from.getOpposite());
IRouter r = SimpleServiceLocator.routerManager.getServerRouter(routedItem.getDestination());
if (r != null) {
CoreRoutedPipe pipe = r.getCachedPipe();
if (pipe != null) {
pipe.notifyOfSend(routedItem.getInfo());
}
// else TODO: handle sending items to known chunk-unloaded destination?
}
// should not be able to send to a non-existing router
// router.startTrackingRoutedItem((RoutedEntityItem) routedItem.getTravelingItem());
spawnParticle(Particles.OrangeParticle, 2);
stat_lifetime_sent++;
stat_session_sent++;
updateStats();
}
use of logisticspipes.routing.IRouter in project LogisticsPipes by RS485.
the class ItemAmountPipeSign method spread.
private void spread(Map<ItemIdentifier, Integer> availableItems, BitSet set) {
// Improve performance by updating a wall of Amount pipe signs all at once
IRouter router = pipe.getRouter();
if (set.get(router.getSimpleID()))
return;
set.set(router.getSimpleID());
for (ExitRoute exit : router.getIRoutersByCost()) {
// Only when the signs are in one wall. To not spread to far.
if (exit.distanceToDestination > 2)
break;
if (!exit.filters.isEmpty())
continue;
if (set.get(exit.destination.getSimpleID()))
continue;
if (exit.connectionDetails.contains(PipeRoutingConnectionType.canRequestFrom) && exit.connectionDetails.contains(PipeRoutingConnectionType.canRouteTo)) {
CoreRoutedPipe cachedPipe = exit.destination.getCachedPipe();
if (cachedPipe != null) {
List<Pair<EnumFacing, IPipeSign>> pipeSigns = cachedPipe.getPipeSigns();
pipeSigns.stream().filter(signPair -> signPair != null && signPair.getValue2() instanceof ItemAmountPipeSign).forEach(signPair -> ((ItemAmountPipeSign) signPair.getValue2()).updateStats(availableItems, set));
}
}
}
}
use of logisticspipes.routing.IRouter in project LogisticsPipes by RS485.
the class LogisticsPowerProviderTileEntity method sendPowerLaserPackets.
private void sendPowerLaserPackets(IRouter sourceRouter, IRouter destinationRouter, EnumFacing exitOrientation, boolean addBall) {
if (sourceRouter == destinationRouter) {
return;
}
LinkedList<Triplet<IRouter, EnumFacing, Boolean>> todo = new LinkedList<>();
todo.add(new Triplet<>(sourceRouter, exitOrientation, addBall));
while (!todo.isEmpty()) {
Triplet<IRouter, EnumFacing, Boolean> part = todo.pollFirst();
List<ExitRoute> exits = part.getValue1().getRoutersOnSide(part.getValue2());
for (ExitRoute exit : exits) {
if (exit.containsFlag(PipeRoutingConnectionType.canPowerSubSystemFrom)) {
// Find only result (caused by only straight connections)
int distance = part.getValue1().getDistanceToNextPowerPipe(exit.exitOrientation);
CoreRoutedPipe pipe = part.getValue1().getPipe();
if (pipe != null && pipe.isInitialized()) {
pipe.container.addLaser(exit.exitOrientation, distance, getLaserColor(), false, part.getValue3());
}
// Use new sourceRouter
IRouter nextRouter = exit.destination;
if (nextRouter == destinationRouter) {
return;
}
outerRouters: for (ExitRoute newExit : nextRouter.getDistanceTo(destinationRouter)) {
if (newExit.containsFlag(PipeRoutingConnectionType.canPowerSubSystemFrom)) {
for (IFilter filter : newExit.filters) {
if (filter.blockPower()) {
continue outerRouters;
}
}
todo.addLast(new Triplet<>(nextRouter, newExit.exitOrientation, newExit.exitOrientation != exit.exitOrientation));
}
}
}
}
}
}
use of logisticspipes.routing.IRouter in project LogisticsPipes by RS485.
the class LogisticsHUDRenderer method refreshList.
private void refreshList(double x, double y, double z) {
ArrayList<Pair<Double, IHeadUpDisplayRendererProvider>> newList = new ArrayList<>();
for (IRouter router : SimpleServiceLocator.routerManager.getRouters()) {
if (router == null) {
continue;
}
CoreRoutedPipe pipe = router.getPipe();
if (!(pipe instanceof IHeadUpDisplayRendererProvider)) {
continue;
}
if (pipe.getWorld().provider.getDimension() == FMLClientHandler.instance().getClient().world.provider.getDimension()) {
double dis = Math.hypot(pipe.getX() - x + 0.5, Math.hypot(pipe.getY() - y + 0.5, pipe.getZ() - z + 0.5));
if (dis < Configs.LOGISTICS_HUD_RENDER_DISTANCE && dis > 0.75) {
newList.add(new Pair<>(dis, (IHeadUpDisplayRendererProvider) pipe));
if (!list.contains(pipe)) {
((IHeadUpDisplayRendererProvider) pipe).startWatching();
}
}
}
}
List<IHeadUpDisplayBlockRendererProvider> remove = new ArrayList<>();
providers.stream().filter(provider -> provider.getWorldForHUD().provider.getDimension() == FMLClientHandler.instance().getClient().world.provider.getDimension()).forEach(provider -> {
double dis = Math.hypot(provider.getX() - x + 0.5, Math.hypot(provider.getY() - y + 0.5, provider.getZ() - z + 0.5));
if (dis < Configs.LOGISTICS_HUD_RENDER_DISTANCE && dis > 0.75 && !provider.isHUDInvalid() && provider.isHUDExistent()) {
newList.add(new Pair<>(dis, provider));
if (!list.contains(provider)) {
provider.startWatching();
}
} else if (provider.isHUDInvalid() || !provider.isHUDExistent()) {
remove.add(provider);
}
});
for (IHeadUpDisplayBlockRendererProvider provider : remove) {
providers.remove(provider);
}
if (newList.size() < 1) {
clearList(true);
return;
}
newList.sort(Comparator.comparing(Pair::getValue1));
for (IHeadUpDisplayRendererProvider part : list) {
boolean contains = false;
for (Pair<Double, IHeadUpDisplayRendererProvider> inpart : newList) {
if (inpart.getValue2().equals(part)) {
contains = true;
break;
}
}
if (!contains) {
part.stopWatching();
}
}
clearList(false);
for (Pair<Double, IHeadUpDisplayRendererProvider> part : newList) {
list.addLast(part.getValue2());
}
}
Aggregations