use of buildcraft.api.core.IStackFilter in project BuildCraft by BuildCraft.
the class ItemTransactorHelper method move.
/**
* Attempts to move up to maxItems from the source {@link IItemTransactor} to the destination.
*
* @param filter The stack filter to use - only items that match this filter will be moved.
* @param maxItems The maximum number of items to move.
* @return The number of items moved.
*/
public static int move(IItemTransactor src, IItemTransactor dst, IStackFilter filter, int maxItems) {
int moved = 0;
IStackFilter rFilter = dst::canPartiallyAccept;
if (filter != null) {
rFilter = rFilter.and(filter);
}
while (true) {
int m = moveSingle0(src, dst, rFilter, maxItems - moved, false, false);
if (m == 0) {
break;
} else {
moved += m;
}
}
return moved;
}
use of buildcraft.api.core.IStackFilter in project BuildCraft by BuildCraft.
the class ItemTransactorHelper method moveSingle0.
private static int moveSingle0(IItemTransactor src, IItemTransactor dst, IStackFilter filter, int maxItems, boolean simulateSrc, boolean simulateDst) {
ItemStack potential = src.extract(filter, 1, maxItems, true);
if (potential.isEmpty())
return 0;
ItemStack leftOver = dst.insert(potential, false, simulateDst);
int toTake = potential.getCount() - leftOver.getCount();
IStackFilter exactFilter = (stack) -> StackUtil.canMerge(stack, potential);
ItemStack taken = src.extract(exactFilter, toTake, toTake, simulateSrc);
if (taken.getCount() != toTake) {
String msg = "One of the two transactors (either src = ";
msg += src.getClass() + " or dst = " + dst.getClass() + ")";
msg += " didn't respect the movement flags! ( potential = " + potential;
msg += ", leftOver = " + leftOver + ", taken = " + taken;
msg += ", count = " + toTake + " )";
throw new IllegalStateException(msg);
}
return toTake;
}
use of buildcraft.api.core.IStackFilter in project BuildCraft by BuildCraft.
the class FlexibleRecipe method craft.
@Override
public CraftingResult<T> craft(IFlexibleCrafter baseCrafter, boolean preview) {
if (output == null) {
return null;
}
IFlexibleCrafter crafter = baseCrafter;
if (preview) {
crafter = new FakeFlexibleCrafter(baseCrafter);
}
CraftingResult<T> result = new CraftingResult<>();
result.recipe = this;
result.powerCost = powerCost;
result.craftingTime = craftingTime;
for (ItemStack requirement : inputItems) {
IStackFilter filter = new ArrayStackFilter(requirement);
int amount = requirement.stackSize;
if (consumeItems(crafter, result, filter, amount) != 0) {
return null;
}
}
for (List<ItemStack> requirements : inputItemsWithAlternatives) {
IStackFilter filter = new ArrayStackFilter(requirements.toArray(new ItemStack[requirements.size()]));
int amount = requirements.get(0).stackSize;
if (consumeItems(crafter, result, filter, amount) != 0) {
return null;
}
}
for (FluidStack requirement : inputFluids) {
int amount = requirement.amount;
for (int tankid = 0; tankid < crafter.getCraftingFluidStackSize(); tankid++) {
FluidStack fluid = crafter.getCraftingFluidStack(tankid);
if (fluid != null && fluid.isFluidEqual(requirement)) {
int amountUsed;
if (fluid.amount > amount) {
amountUsed = amount;
if (!preview) {
crafter.decrCraftingFluidStack(tankid, amount);
}
amount = 0;
} else {
amountUsed = fluid.amount;
if (!preview) {
crafter.decrCraftingFluidStack(tankid, fluid.amount);
}
amount -= fluid.amount;
}
result.usedFluids.add(new FluidStack(requirement.getFluid(), amountUsed));
}
if (amount == 0) {
break;
}
}
if (amount != 0) {
return null;
}
}
// Output generation
result.crafted = output;
return result;
}
use of buildcraft.api.core.IStackFilter in project BuildCraft by BuildCraft.
the class BoardRobotCarrier method update.
@Override
public void update() {
if (!robot.containsItems()) {
IStackFilter filter = ActionRobotFilter.getGateFilter(robot.getLinkedStation());
startDelegateAI(new AIRobotGotoStationAndLoad(robot, filter, AIRobotLoad.ANY_QUANTITY));
} else {
startDelegateAI(new AIRobotGotoStationAndUnload(robot));
}
}
use of buildcraft.api.core.IStackFilter in project BuildCraft by BuildCraft.
the class TileAdvancedCraftingTable method searchNeighborsForIngredients.
private void searchNeighborsForIngredients() {
for (IInvSlot slot : InventoryIterator.getIterable(craftingSlots, EnumFacing.UP)) {
ItemStack ingred = slot.getStackInSlot();
if (ingred == null) {
continue;
}
IStackFilter filter = new CraftingFilter(ingred);
if (InvUtils.countItems(invInput, EnumFacing.UP, filter) < InvUtils.countItems(craftingSlots, EnumFacing.UP, filter)) {
for (EnumFacing side : SEARCH_SIDES) {
TileEntity tile = getTile(side);
if (tile instanceof IInventory) {
IInventory inv = InvUtils.getInventory((IInventory) tile);
ItemStack result = InvUtils.moveOneItem(inv, side.getOpposite(), invInput, side, filter);
if (result != null) {
return;
}
}
}
}
}
}
Aggregations