Advertisement
golfer45

Turtle code .02

Oct 23rd, 2014
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.32 KB | None | 0 0
  1. function startup() -- actully fuking works a damn miricale dont fuck with
  2.   size = {0,0,0} -- x,y,z
  3.   --print("Enter Size of area(x)")
  4.   --size[1] = io.read() + 0
  5.   --print("Enter Size of area(z)")
  6.   --size[3] = io.read() + 0
  7.   --coord = startCoord
  8.   dir = 1
  9.   justTurned = false
  10.   selectSlot = 1
  11.   row = 1
  12.   length = 20 --size[3]
  13.   maxRow = 20 --size[1]
  14.   map = {} -- map[row((z)][length(x)]
  15.   i = 1
  16.   g = 0 -- g is last i position
  17.   n = 1
  18.   map = {}          -- create the matrix
  19.     for q=1,20 do
  20.       map[q] = {}     -- create a new row
  21.       for j=1,20 do
  22.         map[q][j] = 0
  23.         --print(map[q][j])
  24.       end
  25.     end
  26.   i = 1 -- i is now x position in one row
  27.   n = 1
  28.   print("flag 1")
  29.   while row <= maxRow do -- set dig points on table
  30.     if i == 1 then-- if the first block in a row
  31.       if (row%2) ~= 0 then-- if row is odd set for dig
  32.         map[row][i] = 1
  33.         g = i
  34.         i = i+1
  35.       else -- if the row isnt odd move over two blocks and set dig point
  36.         i = i+2
  37.         map[row][i] = 1
  38.         g = i
  39.         i = i+1
  40.       end
  41.     else -- if not first block
  42.       if (i <= length) then-- if less than lenght
  43.         if (i == g+4) then -- if 4 blocks over from last dig point
  44.           map[row][i] = 1
  45.           g = i
  46.         end
  47.         i = i+1
  48.       else -- if over lenght go top next row
  49.         i = 1
  50.         row = row+1
  51.       end
  52.     end
  53.   end
  54.   for q=1,20 do
  55.       for j=1,20 do
  56.         print(map[q][j])
  57.       end
  58.       print("cut")
  59.   end
  60. end
  61.  
  62.  
  63.  
  64. function master() -- master function, should work
  65.     while coord[1] <= size[1] do
  66.         while coord[3] <= size[3] and coord[3] >= 0 do
  67.             while cheackSlot() == false do
  68.                 selectSlot = selectSlot + 1
  69.                 if selectSlot == 15
  70.                     getItems()
  71.                 end
  72.             end
  73.             if (map[coord[1]][coord[3]] == 1) then
  74.              turtle.putDown()
  75.             end
  76.             turtle.dig()
  77.             turtle.forward()
  78.             coord[3] = coord[3] + (1 * dir)
  79.             justTurned = false
  80.            
  81.         end
  82.         if coord[3] > size[3]   then
  83.             turtle.turnRight()
  84.           coord[1] = coord[1] + 1
  85.           turtle.dig()
  86.             turtle.forward()
  87.             turtle.turnRight()
  88.             turtle.dig()
  89.             turtle.forward()
  90.             justTurned = true
  91.             dir = -1
  92.         else
  93.             turtle.turnLeft()
  94.             turtle.dig()
  95.             turtle.forward()
  96.             coord[1] = coord[1] + 1
  97.             turtle.turnLeft()
  98.             turtle.dig()
  99.             turtle.forward()
  100.             justTurned = true
  101.             dir = 1
  102.         end
  103.         cheackFuel
  104.        
  105.         --if cheackInv() == false or coord[1] = size[1] then
  106.         --  getItems()
  107.         --end  
  108. end
  109.  
  110. function getItems -- todo, can only be called on surface
  111.         tempCoord = coord
  112.         if coord[1] != 0 then
  113.             if dir == -1 then
  114.                 turtle.turnRight()
  115.             else
  116.                 turtle.turnLeft()
  117.             end
  118.         end    
  119.         while coord[1] < 0 do
  120.           turtle.dig()
  121.             turtle.forward()
  122.         end
  123.         turtle.turnLeft()
  124.         while coord[3] < 0 do
  125.           turtle.dig()
  126.             turtle.forward()
  127.         end
  128.         while selectSlot < 16 do
  129.             turtle.suck()
  130.             turtle.select(selectSlot)
  131.             selectSlot = selectSlot + 1
  132.         end
  133.         while cheakFuel() == false do
  134.             print("need fuel")
  135.             turtle.select(16)
  136.             turtle.refuel(turtle.getItemCount(16))
  137.         selectSlot = 1
  138.         if tempCoord[1] >= size[1] and tempCoord[3] >= size[3] then
  139.             return true
  140.         else
  141.             return false
  142.             turtle.turnleft()
  143.             while coord[3] < tempCoord[3] do
  144.               turtle.dig()
  145.                 turtle.forward()
  146.             end
  147.             turtle.turnLeft()
  148.             while coord[1] < tempCoord[1] do
  149.               turtle.dig()
  150.                 turtle.forward()
  151.             end
  152.         end
  153. end
  154.  
  155.  
  156. function cheackInv() -- todo
  157.     selectSlot = 1
  158.     emptySlots = 0
  159.     slot = turtle.getSlot
  160.     while selectSlot < 16 do
  161.         if turtle.getItemCount(selectSlot) == 0 then
  162.             emptySlots = emptySlots + 1
  163.         end
  164.         selectSlot = selectSlot + 1
  165.     end
  166.     if emptySlots >=11 then
  167.         return true
  168.     end
  169.     return false
  170.  
  171. end    
  172.  
  173. function cheackSlot() -- cheaks if slot is empty, should work
  174.     if turtle.getItemCount(selectSlot) == 0 then
  175.         return false
  176.     else
  177.         return true
  178.     end
  179. end
  180.  
  181. function cheackFuel() -- cheakcfuel/refuels if needed, should work, can only be called on surface
  182.   refuel()
  183.     if turtle.getFuelLevel() < 2000 then
  184.         getItems()
  185.   end  
  186. end
  187.  
  188. function refuel() -- refuels turtle, should work
  189.   slot = turtle.getSlot
  190.   turtle.selct(4)
  191.   fuelNeeded = 20000 - turtle.getFuelLevel
  192.   (fuelNeeded/80) = coalToTake
  193.   if coalToTake >= turtle.getItemCount then
  194.     coalToTake = turtle.getItemCount - 1
  195.   end  
  196.   turtle.refuel(coalToTake)
  197.   turtle.select(slot)
  198. end
  199.  
  200. function dig() -- digs a vertical shaft, should work
  201.   if coord[2] = size[2] then
  202.     dirDig = -1
  203.     mine()
  204.     max = 0
  205.   else
  206.     dirDig = 1
  207.     mine()
  208.     max = size[2]
  209.   end    
  210.  
  211.   while coord[2] ~= max do
  212.     mine()
  213.     if dirDig = 1 then
  214.       turtle.digDown
  215.       turtle.down
  216.       coord[2] = coord[2] + 1
  217.     else
  218.       turtle.digUp
  219.       turtle.up
  220.       coord[2] = coord[2] - 1
  221.     end
  222.   end
  223.   mine()
  224. end        
  225.  
  226.  
  227. function compare() -- dig if not 1 of 4 ingnored blocks, should work
  228.  
  229.   if turtle.compareTo(1) == false and turtle.compareTo(2) == false and turtle.compareTo(3) == false and turtle.compareTo(4) == false then
  230.     turtle.dig
  231.   end
  232. end
  233.  
  234. function mine() -- does some digging bby, should work
  235.   turtle.compare
  236.   turtle.turnLeft
  237.   turtle.compare
  238.   turtle.turnLeft
  239.   turtle.compare
  240.   turtle.turnLeft
  241.   turtle.compare
  242.   turtle.turnleft
  243. end  
  244.  
  245.  
  246.  
  247.      
  248.    
  249. startup()
  250. print(map)
  251. --master()
  252. --getItems()
  253. print("done")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement