}
private BuildingSlotBlock internalGetNextBlock(World world, TileAbstractBuilder builder) {
BuildingSlotBlock result = null;
IInvSlot firstSlotToConsume = null;
for (IInvSlot invSlot : InventoryIterator.getIterable(builder, ForgeDirection.UNKNOWN)) {
if (!builder.isBuildingMaterialSlot(invSlot.getIndex())) {
continue;
}
ItemStack stack = invSlot.getStackInSlot();
if (stack != null && stack.stackSize > 0) {
firstSlotToConsume = invSlot;
break;
}
}
iterator.startIteration();
while (iterator.hasNext()) {
BuildingSlotBlock slot = iterator.next();
if (slot.buildStage > buildList.getFirst().buildStage) {
iterator.reset ();
return null;
}
if (BlockUtil.isUnbreakableBlock(world, slot.x, slot.y, slot.z)) {
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.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 (canDestroy(builder, context, slot)) {
consumeEnergyToDestroy(builder, slot);
createDestroyItems(slot);
result = slot;
iterator.remove();
clearedLocations.add(new BlockIndex(slot.x, slot.y, slot.z));
break;
}
}
} else if (slot.mode == Mode.Build) {
if (!BuildCraftAPI.isSoftBlock(world, slot.x, slot.y, slot.z)) {
iterator.remove();
builtLocations.add(new BlockIndex(slot.x, slot.y, slot.z));
} else {
if (builder.consumeEnergy(BuilderAPI.BUILD_ENERGY) && firstSlotToConsume != null) {
slot.addStackConsumed(firstSlotToConsume.decreaseStackInSlot(1));
result = slot;
iterator.remove();
builtLocations.add(new BlockIndex(slot.x, slot.y, slot.z));
break;