use of buildcraft.api.core.IInvSlot in project BuildCraft by BuildCraft.
the class TransactorSimple method inject.
@Override
public int inject(ItemStack stack, boolean doAdd) {
List<IInvSlot> filledSlots = new ArrayList<>(inventory.getSizeInventory());
List<IInvSlot> emptySlots = new ArrayList<>(inventory.getSizeInventory());
for (IInvSlot slot : InventoryIterator.getIterable(inventory, orientation)) {
if (slot.canPutStackInSlot(stack)) {
if (slot.getStackInSlot() == null) {
emptySlots.add(slot);
} else {
filledSlots.add(slot);
}
}
}
int injected = 0;
injected = tryPut(stack, filledSlots, injected, doAdd);
injected = tryPut(stack, emptySlots, injected, doAdd);
if (injected > 0 && doAdd) {
inventory.markDirty();
}
return injected;
}
use of buildcraft.api.core.IInvSlot in project BuildCraft by BuildCraft.
the class BptBuilderBlueprint method useRequirements.
@Override
public void useRequirements(IInventory inv, BuildingSlot slot) {
if (slot instanceof BuildingSlotBlock && ((BuildingSlotBlock) slot).mode == Mode.ClearIfInvalid) {
return;
}
LinkedList<ItemStack> tmpReq = new LinkedList<>();
try {
for (ItemStack stk : slot.getRequirements(context)) {
if (stk != null) {
tmpReq.add(stk.copy());
}
}
} catch (Throwable t) {
// Defensive code against errors in implementers
t.printStackTrace();
BCLog.logger.throwing(t);
}
if (context.world().getWorldInfo().getGameType() == GameType.CREATIVE) {
for (ItemStack s : tmpReq) {
slot.addStackConsumed(s);
}
return;
}
ListIterator<ItemStack> itr = tmpReq.listIterator();
while (itr.hasNext()) {
ItemStack reqStk = itr.next();
boolean smallStack = reqStk.stackSize == 1;
ItemStack usedStack = reqStk;
boolean itemBlock = reqStk.getItem() instanceof ItemBlock;
Fluid fluid = itemBlock ? FluidRegistry.lookupFluidForBlock(((ItemBlock) reqStk.getItem()).block) : null;
if (fluid != null && inv instanceof TileAbstractBuilder && ((TileAbstractBuilder) inv).drainBuild(new FluidStack(fluid, FluidContainerRegistry.BUCKET_VOLUME), true)) {
continue;
}
for (IInvSlot slotInv : InventoryIterator.getIterable(inv)) {
if (inv instanceof TileAbstractBuilder && !((TileAbstractBuilder) inv).isBuildingMaterialSlot(slotInv.getIndex())) {
continue;
}
ItemStack invStk = slotInv.getStackInSlot();
if (invStk == null || invStk.stackSize == 0) {
continue;
}
FluidStack fluidStack = fluid != null ? FluidContainerRegistry.getFluidForFilledItem(invStk) : null;
boolean fluidFound = fluidStack != null && fluidStack.getFluid() == fluid && fluidStack.amount >= FluidContainerRegistry.BUCKET_VOLUME;
if (fluidFound || slot.getSchematic().isItemMatchingRequirement(invStk, reqStk)) {
try {
usedStack = slot.getSchematic().useItem(context, reqStk, slotInv);
slot.addStackConsumed(usedStack);
} catch (Throwable t) {
// Defensive code against errors in implementers
t.printStackTrace();
BCLog.logger.throwing(t);
}
if (reqStk.stackSize == 0) {
break;
}
}
}
if (reqStk.stackSize != 0) {
return;
}
if (smallStack) {
// set to the actual item used.
itr.set(usedStack);
}
}
}
use of buildcraft.api.core.IInvSlot in project BuildCraft by BuildCraft.
the class SchematicAutoWorkbench method storeRequirements.
@Override
public void storeRequirements(IBuilderContext context, BlockPos pos) {
TileAutoWorkbench autoWb = getTile(context, pos);
if (autoWb != null) {
ArrayList<ItemStack> rqs = new ArrayList<>();
rqs.add(new ItemStack(BuildCraftFactory.autoWorkbenchBlock));
for (IInvSlot slot : InventoryIterator.getIterable(autoWb.craftMatrix, EnumFacing.UP)) {
ItemStack stack = slot.getStackInSlot();
if (stack != null) {
stack = stack.copy();
stack.stackSize = 1;
rqs.add(stack);
}
}
storedRequirements = JavaTools.concat(storedRequirements, rqs.toArray(new ItemStack[rqs.size()]));
}
}
use of buildcraft.api.core.IInvSlot in project BuildCraft by BuildCraft.
the class AIRobotDisposeItems method delegateAIEnded.
@Override
public void delegateAIEnded(AIRobot ai) {
if (ai instanceof AIRobotGotoStationAndUnload) {
if (ai.success()) {
if (robot.containsItems()) {
startDelegateAI(new AIRobotGotoStationAndUnload(robot));
} else {
terminate();
}
} else {
for (IInvSlot slot : InventoryIterator.getIterable(robot)) {
if (slot.getStackInSlot() != null) {
final EntityItem entity = new EntityItem(robot.worldObj, robot.posX, robot.posY, robot.posZ, slot.getStackInSlot());
robot.worldObj.spawnEntityInWorld(entity);
slot.setStackInSlot(null);
}
}
terminate();
}
}
}
use of buildcraft.api.core.IInvSlot in project BuildCraft by BuildCraft.
the class AIRobotLoad method load.
public static boolean load(EntityRobotBase robot, DockingStation station, IStackFilter filter, int quantity, boolean doLoad) {
if (station == null) {
return false;
}
int loaded = 0;
IInventory tileInventory = station.getItemInput();
if (tileInventory == null) {
return false;
}
for (IInvSlot slot : InventoryIterator.getIterable(tileInventory, station.getItemInputSide().face)) {
ItemStack stack = slot.getStackInSlot();
if (//
stack == null || //
!slot.canTakeStackFromSlot(stack) || //
!filter.matches(stack) || //
!ActionStationProvideItems.canExtractItem(station, stack) || !ActionRobotFilter.canInteractWithItem(station, filter, ActionStationProvideItems.class)) {
continue;
}
ITransactor robotTransactor = Transactor.getTransactorFor(robot, null);
if (quantity == ANY_QUANTITY) {
ItemStack added = robotTransactor.addNew(slot.getStackInSlot(), doLoad);
if (doLoad) {
slot.decreaseStackInSlot(added.stackSize);
}
return added.stackSize > 0;
} else {
ItemStack toAdd = slot.getStackInSlot().copy();
if (toAdd.stackSize > quantity - loaded) {
toAdd.stackSize = quantity - loaded;
}
ItemStack added = robotTransactor.addNew(toAdd, doLoad);
if (doLoad) {
slot.decreaseStackInSlot(added.stackSize);
}
loaded += added.stackSize;
if (quantity - loaded <= 0) {
return true;
}
}
}
return false;
}
Aggregations