use of pneumaticCraft.common.semiblock.ISpecificProvider in project PneumaticCraft by MineMaarten.
the class LogisticsManager method tryProvide.
//curAI = new DroneAILiquidImport(drone, new FakeWidgetLogistics(provider.getPos(), providingStack));
// transportingFluid = new FluidStackWrapper(providingStack);
private void tryProvide(SemiBlockLogistics provider, SemiBlockLogistics requester, PriorityQueue<LogisticsTask> tasks) {
IInventory providingInventory = IOHelper.getInventoryForTE(provider.getTileEntity());
if (providingInventory != null) {
if (requester instanceof IProvidingInventoryListener)
((IProvidingInventoryListener) requester).notify(provider.getTileEntity());
for (int i = 0; i < providingInventory.getSizeInventory(); i++) {
ItemStack providingStack = providingInventory.getStackInSlot(i);
if (providingStack != null && (!(provider instanceof ISpecificProvider) || ((ISpecificProvider) provider).canProvide(providingStack)) && IOHelper.canExtractItemFromInventory(providingInventory, providingStack, i, 0)) {
int requestedAmount = getRequestedAmount(requester, providingStack);
if (requestedAmount > 0) {
ItemStack stack = providingStack.copy();
stack.stackSize = requestedAmount;
tasks.add(new LogisticsTask(provider, requester, stack));
}
}
}
}
if (provider.getTileEntity() instanceof IFluidHandler) {
IFluidHandler providingTank = (IFluidHandler) provider.getTileEntity();
for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
FluidStack providingStack = providingTank.drain(d, 16000, false);
if (providingStack != null && (!(provider instanceof ISpecificProvider) || ((ISpecificProvider) provider).canProvide(providingStack)) && providingTank.canDrain(d, providingStack.getFluid())) {
int requestedAmount = getRequestedAmount(requester, providingStack);
if (requestedAmount > 0) {
FluidStack stack = providingStack.copy();
stack.amount = requestedAmount;
tasks.add(new LogisticsTask(provider, requester, new FluidStackWrapper(stack)));
}
}
}
}
}
Aggregations