use of logisticspipes.request.resources.FluidResource 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.request.resources.FluidResource in project LogisticsPipes by RS485.
the class ServerRouter method getRoutersInterestedIn.
public static BitSet getRoutersInterestedIn(IResource item) {
if (item instanceof ItemResource) {
return ServerRouter.getRoutersInterestedIn(((ItemResource) item).getItem());
} else if (item instanceof FluidResource) {
return ServerRouter.getRoutersInterestedIn(((FluidResource) item).getFluid().getItemIdentifier());
} else if (item instanceof DictResource) {
DictResource dict = (DictResource) item;
BitSet s = new BitSet(ServerRouter.getBiggestSimpleID() + 1);
for (IRouter r : ServerRouter.genericInterests) {
s.set(r.getSimpleID());
}
ServerRouter.globalSpecificInterests.entrySet().stream().filter(entry -> dict.matches(entry.getKey(), IResource.MatchSettings.NORMAL)).flatMap(entry -> entry.getValue().stream()).forEach(router -> s.set(router.simpleID));
return s;
}
return new BitSet(ServerRouter.getBiggestSimpleID() + 1);
}
use of logisticspipes.request.resources.FluidResource in project LogisticsPipes by RS485.
the class RequestTree method requestFluid.
private static int requestFluid(FluidIdentifier liquid, int amount, IRequestFluid pipe, RequestLog log, boolean acceptPartial) {
FluidResource req = new FluidResource(liquid, amount, pipe);
RequestTree request = new RequestTree(req, null, RequestTree.defaultRequestFlags, null);
if (request.isDone() || acceptPartial) {
request.fullFill();
if (log != null) {
log.handleSucessfullRequestOf(req.copyForDisplayWith(req.getRequestedAmount()), null);
}
return request.getPromiseAmount();
} else {
if (log != null) {
request.sendMissingMessage(log);
}
return request.getPromiseAmount();
}
}
use of logisticspipes.request.resources.FluidResource in project LogisticsPipes by RS485.
the class PipeFluidProvider method canProvide.
@Override
public void canProvide(RequestTreeNode tree, RequestTree root, List<IFilter> filter) {
if (tree.isDone()) {
return;
}
if (!(tree.getRequestType() instanceof FluidResource)) {
return;
}
FluidIdentifier fluid = ((FluidResource) tree.getRequestType()).getFluid();
AtomicInteger containedAmount = new AtomicInteger(0);
for (Pair<NeighborTileEntity<TileEntity>, ITankUtil> pair : PipeFluidUtil.INSTANCE.getAdjacentTanks(this, false)) {
boolean fallback = true;
if (pair.getValue2() instanceof ISpecialTankUtil) {
final ISpecialTankUtil util = (ISpecialTankUtil) pair.getValue2();
fallback = false;
ISpecialTankAccessHandler handler = util.getSpecialHandler();
TileEntity tile = util.getTileEntity();
Map<FluidIdentifier, Long> map = handler.getAvailableLiquid(tile);
if (map.containsKey(fluid)) {
long addition = (containedAmount.get()) + map.get(fluid);
containedAmount.set(addition > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) addition);
}
}
if (fallback) {
if (pair.getValue2().containsTanks()) {
pair.getValue2().tanks().map(tank -> FluidIdentifierStack.getFromStack(tank.getContents())).forEach(liquid -> {
if (liquid != null && liquid.getFluid() != null) {
if (fluid.equals(liquid.getFluid())) {
if (pair.getValue2().canDrain(liquid.getFluid())) {
if (pair.getValue2().drain(liquid.getFluid().makeFluidIdentifierStack(1), false) != null) {
long addition = ((long) containedAmount.get()) + liquid.getAmount();
containedAmount.set(addition > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) addition);
}
}
}
}
});
}
}
}
FluidLogisticsPromise promise = new FluidLogisticsPromise();
promise.liquid = fluid;
promise.amount = Math.min(tree.getMissingAmount(), containedAmount.get() - root.getAllPromissesFor(this, fluid.getItemIdentifier()));
promise.sender = this;
promise.type = ResourceType.PROVIDER;
if (promise.amount > 0) {
tree.addPromise(promise);
}
}
Aggregations