Advertisement
Guest User

updateTest

a guest
Jan 22nd, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.73 KB | None | 0 0
  1. function checkSupply()
  2.         local b_sup = False
  3.         for i=9,16,1 do
  4.                 if turtle.getItemCount(i) > 0 then
  5.     -- print(i)
  6.                         return i
  7.                 end
  8.         end
  9. end
  10.  
  11. function dropTrash()
  12.         for i=1,8,1 do
  13.                 turtle.select(i)
  14.                 turtle.drop()
  15.         end
  16. end
  17.  
  18. function hangAleft()
  19.     turtle.turnLeft()
  20.     turtle.forward()
  21.     turtle.turnRight()
  22. end
  23.  
  24. function snake(bool)
  25.     if bool == true then
  26.         turtle.turnLeft()
  27.         turtle.forward()
  28.         turtle.turnLeft()
  29.     else
  30.         turtle.turnRight()
  31.         turtle.forward()
  32.         turtle.turnRight()
  33.     end
  34. end
  35.  
  36. function replaceBlock(type)
  37.     local hasBlocks = checkSupply()
  38.     --print(hasBlocks)
  39.     if hasBlocks ~= false then
  40.  
  41.         if type == 1 then
  42.         --Wall
  43.  
  44.             if turtle.detect() then
  45.                 turtle.dig()
  46.                 checkSupply()
  47.                 turtle.select(hasBlocks)
  48.                 turtle.place()
  49.             else
  50.                 return false
  51.             end
  52.         elseif type == 2 then
  53.         --Floor
  54.             if turtle.detectDown() then
  55.                 turtle.digDown()
  56.                 checkSupply()
  57.                 turtle.select(hasBlocks)
  58.                 turtle.placeDown()
  59.             else
  60.                 return false
  61.             end      
  62.      
  63.         elseif type == 3 then
  64.         --Ceiling
  65.             if turtle.detectUp() then
  66.                 turtle.digUp()
  67.                 checkSupply()
  68.                 turtle.select(hasBlocks)
  69.                 turtle.placeDown()
  70.             else
  71.                 return false
  72.             end    
  73.         end  
  74.     end
  75. end
  76.  
  77. function moveType(type,max,count,alt)
  78.  
  79.  local counter = count
  80.  local maxy = max
  81.  local booly = alt
  82.  
  83.     if type == 1 then
  84.         if booly == true then
  85.             turtle.up()
  86.             counter = counter + 1
  87.             if counter == maxy + 1 then
  88.                 replaceBlock(type)
  89.                 hangAleft()
  90.              booly = false
  91.             end
  92.         else
  93.             turtle.down()
  94.             counter = counter - 1
  95.             if counter == 1 then
  96.                 replaceBlock(type)
  97.                 hangAleft()
  98.                 booly = true
  99.             end
  100.         end
  101.         return counter,booly
  102.      --print(count .. " / " .. reset)
  103.     else
  104.         turtle.forward()
  105.   counter = counter + 1
  106.   print(counter)
  107.         if counter == maxy + 1 then
  108.    replaceBlock(type)
  109.             snake(booly)
  110.             if booly == true then
  111.                 booly = false
  112.             else
  113.                 booly = true
  114.             end
  115.             counter = 1
  116.         end
  117.         return counter, booly
  118.  
  119.     end
  120. end
  121.  
  122. function mineMove(x,y,type)
  123.  
  124.  local num = tonumber(type)
  125.  
  126.  local reset = tonumber(x)
  127.  local bull = true
  128.  
  129.     local count = 1
  130.  
  131.  
  132.         for i=1,y,1 do
  133.             for a=1,x,1 do
  134.  
  135.             --  print(i .. " | " .. a)
  136.      
  137.                 replaceBlock(num)  
  138.      print(">>>" .. count .. " , " .. tostring(bull))
  139.                 local a,b = moveType(num,reset,count,bull)
  140.              print(a .. " | " .. tostring(b))
  141.      count = a
  142.      bull = b
  143.      print("<<<" .. count .. " , " .. tostring(bull))
  144.    end
  145.         end
  146. end
  147.  
  148.  
  149.  
  150. function main()
  151.         print("enter y:")
  152.         local x = read()
  153.  
  154.         print("enter x:")
  155.         local y = read()
  156.        
  157.         print("1=wall | 2=floor | 3=ceiling")
  158.         print("enter type:")
  159.         local type = read()
  160.  
  161.  
  162.         mineMove(x,y,type)
  163. end
  164.  
  165. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement