-- Check if there are enough iron bars and an empty slot for the iron blocks function checkInventory() local ironBarCount = 0 local ironBlockCount = 0 for slot = 1, 16 do local item = turtle.getItemDetail(slot) if item then if item.name == "minecraft:iron_bars" then ironBarCount = ironBarCount + item.count elseif item.name == "minecraft:iron_block" then ironBlockCount = ironBlockCount + item.count end end end return ironBarCount >= 9 and ironBlockCount < 64 end -- Craft iron bars into iron blocks function craftIronBlocks() turtle.select(1) turtle.transferTo(16, 9) -- Move iron bars to slot 9 (crafting input slot) turtle.craft() while not turtle.dropUp() do sleep(1) end end -- Main program loop function main() while true do if checkInventory() then craftIronBlocks() else sleep(5) end end end -- Start the program main()