document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. -- #############################
  2. -- seichi
  3. -- version 0.2b
  4. -- http://hevohevo.hatenablog.com/
  5.  
  6. -- #############################
  7. -- config (default parameters)
  8. DEPTH = 4 -- okuyuki
  9. WIDTH =4 -- haba
  10. HEIGHT = 4 -- takasa
  11.  
  12. -- #############################
  13. -- functions
  14. function surelyDigUp()
  15.   while turtle.digUp() do
  16.     os.sleep(0.4)
  17.   end
  18. end
  19.  
  20. function surelyUp()
  21.   surelyDigUp()
  22.   return turtle.up()
  23. end
  24.  
  25. function surelyDig()
  26.   while turtle.dig() do end
  27. end
  28.  
  29. function surelyFwd()
  30.   for i=1,4 do
  31.     local status, err = turtle.forward()
  32.     if status then
  33.       return true  -- success!
  34.     elseif err=="Out of fuel" then
  35.       return status, err
  36.     end
  37.  
  38.     surelyDig() -- face to a normal block or a sand(gravel) hill
  39.  
  40.     if turtle.detect() and not turtle.dig() then
  41.       return false, "bedrock!"
  42.     end
  43.  
  44.     if turtle.forward() then return true end -- success!
  45.  
  46.     if turtle.attack() then
  47.       -- face to monster-mob
  48.       while turtle.attack() do end
  49.     else
  50.       -- face to sand-blocks which is dropping long time
  51.       os.sleep(5) -- probably, adjustment is required
  52.     end
  53.   end
  54.   return turtle.forward()
  55. end
  56.  
  57. function seichiThreeStep()
  58.   for i=1,HEIGHT-1 do
  59.     surelyUp()
  60.   end
  61.   surelyFwd()  
  62.   for i=1,HEIGHT-1 do
  63.     surelyDig()
  64.     turtle.digDown()
  65.     turtle.down()
  66.   end
  67.   surelyFwd()
  68. end
  69.  
  70. function seichiTwoStep()
  71.   for i=1,HEIGHT-1 do
  72.     surelyUp()
  73.   end
  74.   surelyFwd()  
  75.   for i=1,HEIGHT-1 do
  76.     turtle.digDown()
  77.     turtle.down()
  78.   end
  79. end
  80.  
  81. function seichiOneStep()
  82.   for i=1,HEIGHT-1 do
  83.     surelyUp()
  84.   end
  85.   for i=1,HEIGHT-1 do
  86.     turtle.down()
  87.   end
  88. end
  89.  
  90. function seichiOneLine(d)
  91.   local d = d or DEPTH
  92.   for i=1, d/3 do
  93.     seichiThreeStep()
  94.     if i<(d/3) then surelyFwd() end
  95.   end
  96.   if d%3==1 then
  97.     seichiOneStep()
  98.   elseif d%3==2 then
  99.     seichiTwoStep()
  100.   end
  101. end
  102.  
  103. function countAllItems()
  104.   local count = 0
  105.   for i=1,16 do
  106.     count = count+turtle.getItemCount(i)
  107.   end
  108.   return count
  109. end
  110.  
  111. -- #############################
  112. -- main
  113.  
  114. -- arguments setting
  115. local args = {...}
  116. if #args ~= 3 and #args ~=0 then error(\'seichi <DEPTH> <WIDTH> <HEIGHT>\') end
  117. DEPTH = tonumber(args[1]) or DEPTH
  118. WIDTH = tonumber(args[2]) or WIDTH
  119. HEIGHT = tonumber(args[3]) or HEIGHT
  120. print(string.format("D/W/H = %d/%d/%d", DEPTH, WIDTH, HEIGHT))
  121.  
  122. -- fuel check
  123. local requiredFuelLevel = DEPTH*WIDTH*HEIGHT -- a rough estimate
  124. if requiredFuelLevel > turtle.getFuelLevel() then
  125.   error(\'Not enough Fuel: \',turtle.getFuelLevel(),\'/\',requiredFUelLevel)
  126. else
  127.   print(\'currnet/required = \',turtle.getFuelLevel(),\'/\',requiredFuelLevel)
  128. end
  129.  
  130. -- start
  131. local num_item = countAllItems() -- store qty of items
  132. surelyFwd()
  133.  
  134. for w= 1,WIDTH do
  135.   seichiOneLine()
  136.  
  137.   if WIDTH>w and w%2 == 1 then -- current width pos is odd number
  138.     turtle.turnRight()
  139.     surelyFwd()
  140.     turtle.turnRight()
  141.   elseif WIDTH>w and w%2 == 0 then -- current width pos is even number
  142.     turtle.turnLeft()
  143.     surelyFwd()
  144.     turtle.turnLeft()
  145.   end
  146. end
  147. print("current fuel: ",turtle.getFuelLevel())
  148. print("acquired items: ", countAllItems()-num_item) -- calc qty of acquired items
');