use of pneumaticCraft.common.semiblock.ISpecificRequester in project PneumaticCraft by MineMaarten.
the class LogisticsManager method getRequestedAmount.
public static int getRequestedAmount(SemiBlockLogistics requester, ItemStack providingStack) {
TileEntity te = requester.getTileEntity();
if (!(te instanceof IInventory))
return 0;
int requestedAmount = requester instanceof ISpecificRequester ? ((ISpecificRequester) requester).amountRequested(providingStack) : providingStack.stackSize;
if (requestedAmount == 0)
return 0;
providingStack = providingStack.copy();
providingStack.stackSize = requestedAmount;
ItemStack remainder = providingStack.copy();
remainder.stackSize += requester.getIncomingItems(providingStack);
for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
remainder = IOHelper.insert(te, remainder, d, true);
if (remainder == null)
break;
}
if (remainder != null)
providingStack.stackSize -= remainder.stackSize;
if (providingStack.stackSize <= 0)
return 0;
return providingStack.stackSize;
}
use of pneumaticCraft.common.semiblock.ISpecificRequester in project PneumaticCraft by MineMaarten.
the class LogisticsManager method getRequestedAmount.
public static int getRequestedAmount(SemiBlockLogistics requester, FluidStack providingStack) {
int requestedAmount = requester instanceof ISpecificRequester ? ((ISpecificRequester) requester).amountRequested(providingStack) : providingStack.amount;
if (requestedAmount == 0)
return 0;
providingStack = providingStack.copy();
providingStack.amount = requestedAmount;
FluidStack remainder = providingStack.copy();
remainder.amount += requester.getIncomingFluid(remainder.getFluid());
TileEntity te = requester.getTileEntity();
if (te instanceof IFluidHandler) {
IFluidHandler fluidHandler = (IFluidHandler) te;
for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
int fluidFilled = fluidHandler.fill(d, remainder, false);
if (fluidFilled > 0) {
remainder.amount -= fluidFilled;
break;
}
}
}
providingStack.amount -= remainder.amount;
if (providingStack.amount <= 0)
return 0;
return providingStack.amount;
}
Aggregations