}
iterator.startIteration();
while (iterator.hasNext()) {
BuildingSlotBlock slot = iterator.next();
if (slot.buildStage > buildList.getFirst().buildStage) {
iterator.reset();
return null;
}
if (slot.built) {
iterator.remove();
if (slot.mode == Mode.ClearIfInvalid) {
clearedLocations.add(new BlockIndex(slot.x,
slot.y, slot.z));
} else {
builtLocations.add(new BlockIndex(slot.x,
slot.y, slot.z));
}
postProcessing.add(slot);
continue;
}
if (slot.reserved) {
continue;
}
try {
if (BlockUtil.isUnbreakableBlock(world, slot.x, slot.y, slot.z)) {
// if the block can't be broken, just forget this iterator
iterator.remove();
if (slot.mode == Mode.ClearIfInvalid) {
clearedLocations.add(new BlockIndex(slot.x,
slot.y, slot.z));
} else {
builtLocations.add(new BlockIndex(slot.x,
slot.y, slot.z));
}
} else if (!slot.isAlreadyBuilt(context)) {
if (slot.mode == Mode.ClearIfInvalid) {
if (BuildCraftAPI.isSoftBlock(world, slot.x, slot.y,
slot.z)) {
iterator.remove();
clearedLocations.add(new BlockIndex(slot.x,
slot.y, slot.z));
} else {
if (builder == null) {
createDestroyItems(slot);
return slot;
} else if (canDestroy(builder, context, slot)) {
consumeEnergyToDestroy(builder, slot);
createDestroyItems(slot);
iterator.remove();
clearedLocations.add(new BlockIndex(slot.x,
slot.y, slot.z));
return slot;
}
}
} else if (!slot.schematic.doNotBuild()) {
if (builder == null) {
return slot;
} else if (checkRequirements(builder, slot.schematic)) {
// At this stage, regardless of the fact that the
// block can actually be built or not, we'll try.
// When the item reaches the actual block, we'll
// verify that the location is indeed clear, and
// avoid building otherwise.
builder.consumeEnergy(slot.getEnergyRequirement());
useRequirements(builder, slot);
iterator.remove();
postProcessing.add(slot);
builtLocations.add(new BlockIndex(slot.x,