use of buildcraft.core.lib.inventory.InventoryCopy in project BuildCraft by BuildCraft.
the class BptBuilderBlueprint method checkRequirements.
public boolean checkRequirements(TileAbstractBuilder builder, Schematic slot) {
LinkedList<ItemStack> tmpReq = new LinkedList<>();
try {
LinkedList<ItemStack> req = new LinkedList<>();
slot.getRequirementsForPlacement(context, req);
for (ItemStack stk : req) {
if (stk != null) {
tmpReq.add(stk.copy());
}
}
} catch (Throwable t) {
// Defensive code against errors in implementers
t.printStackTrace();
BCLog.logger.throwing(t);
}
LinkedList<ItemStack> stacksUsed = new LinkedList<>();
if (context.world().getWorldInfo().getGameType() == GameType.CREATIVE) {
for (ItemStack s : tmpReq) {
stacksUsed.add(s);
}
return !(builder.energyAvailable() < slot.getEnergyRequirement(stacksUsed));
}
for (ItemStack reqStk : tmpReq) {
boolean itemBlock = reqStk.getItem() instanceof ItemBlock;
Fluid fluid = itemBlock ? FluidRegistry.lookupFluidForBlock(((ItemBlock) reqStk.getItem()).block) : null;
if (fluid != null && builder.drainBuild(new FluidStack(fluid, FluidContainerRegistry.BUCKET_VOLUME), true)) {
continue;
}
for (IInvSlot slotInv : InventoryIterator.getIterable(new InventoryCopy(builder))) {
if (!builder.isBuildingMaterialSlot(slotInv.getIndex())) {
continue;
}
ItemStack invStk = slotInv.getStackInSlot();
if (invStk == null || invStk.stackSize == 0) {
continue;
}
FluidStack fluidStack = fluid != null ? FluidContainerRegistry.getFluidForFilledItem(invStk) : null;
boolean compatibleContainer = fluidStack != null && fluidStack.getFluid() == fluid && fluidStack.amount >= FluidContainerRegistry.BUCKET_VOLUME;
if (slot.isItemMatchingRequirement(invStk, reqStk) || compatibleContainer) {
try {
stacksUsed.add(slot.useItem(context, reqStk, slotInv));
} 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 false;
}
}
return builder.energyAvailable() >= slot.getEnergyRequirement(stacksUsed);
}
Aggregations