use of pneumaticCraft.common.semiblock.SemiBlockLogistics.FluidStackWrapper 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)));
}
}
}
}
}
use of pneumaticCraft.common.semiblock.SemiBlockLogistics.FluidStackWrapper in project PneumaticCraft by MineMaarten.
the class LogisticsManager method getTasks.
public PriorityQueue<LogisticsTask> getTasks(Object holdingStack) {
ItemStack item = holdingStack instanceof ItemStack ? (ItemStack) holdingStack : null;
FluidStack fluid = holdingStack instanceof FluidStack ? (FluidStack) holdingStack : null;
PriorityQueue<LogisticsTask> tasks = new PriorityQueue<LogisticsTask>();
for (int priority = logistics.length - 1; priority >= 0; priority--) {
for (SemiBlockLogistics requester : logistics[priority]) {
for (int i = 0; i < priority; i++) {
for (SemiBlockLogistics provider : logistics[i]) {
if (provider.shouldProvideTo(priority)) {
if (item != null) {
int requestedAmount = getRequestedAmount(requester, item);
if (requestedAmount > 0) {
ItemStack stack = item.copy();
stack.stackSize = requestedAmount;
tasks.add(new LogisticsTask(provider, requester, stack));
return tasks;
}
} else if (fluid != null) {
int requestedAmount = getRequestedAmount(requester, fluid);
if (requestedAmount > 0) {
fluid = fluid.copy();
fluid.amount = requestedAmount;
tasks.add(new LogisticsTask(provider, requester, new FluidStackWrapper(fluid)));
return tasks;
}
} else {
tryProvide(provider, requester, tasks);
}
}
}
}
}
}
return tasks;
}
Aggregations