Advertisement
BillBodkin

dig3

Oct 17th, 2015
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.06 KB | None | 0 0
  1. --variables
  2.  
  3. atHome = true
  4. maxX = 50
  5. maxY = 50
  6. distanceDown = 90
  7. distanceUp = 15
  8.  
  9. on = true
  10. requiredFuel = 0
  11. digX = 0
  12. digY = 0
  13.  
  14. --functions
  15.  
  16. function refuel()
  17.    
  18.     requiredFuel =  (digX * 2)+(digY * 2)+200
  19.    
  20.     turtle.turnLeft()
  21.     turtle.select(16)
  22.     while turtle.getFuelLevel() < requiredFuel do
  23.         shell.run("clear")
  24.         print ("Getting Fuel")
  25.         turtle.suck(64)
  26.         turtle.refuel()
  27.         print("Fuel Level: " ..  tostring(turtle.getFuelLevel()) .. " / ".. tostring(requiredFuel))
  28.     end
  29.     shell.run("clear")
  30.     turtle.select(1)
  31.     turtle.turnRight()
  32. end
  33.  
  34. function getDigLocation()
  35.     shell.run("clear")
  36.     if atHome == true then
  37.         tmp = http.get( "http://192.168.1.2/cc/dig3/x.php" )
  38.         digX = tonumber(tmp.readAll())
  39.         tmp = http.get( "http://192.168.1.2/cc/dig3/y.php" )
  40.         digY = tonumber(tmp.readAll())
  41.     else
  42.         tmp = http.get( "http://cablepost.ddns.net/cc/dig3/x.php" )
  43.         digX = tonumber(tmp.readAll())
  44.         tmp = http.get( "http://cablepost.ddns.net/cc/dig3/y.php" )
  45.         digY = tonumber(tmp.readAll())
  46.     end
  47.    
  48.     print("Dig location is: X="..tostring(digX)..",Y="..tostring(digY))
  49. end
  50.  
  51. function increaceDigLocation()
  52.     if atHome == true then
  53.         http.get( "http://192.168.1.2/cc/dig3/y1.php" )
  54.         http.get( "http://192.168.1.2/cc/dig3/y1.php" )
  55.         if digY >= maxY then
  56.             http.get( "http://192.168.1.2/cc/dig3/resetY.php" )
  57.             http.get( "http://192.168.1.2/cc/dig3/x1.php" )
  58.         end
  59.         if digX >= maxX then
  60.             http.get( "http://192.168.1.2/cc/dig3/reset.php" )
  61.             print("digging complete")
  62.             on = false
  63.         end
  64.     else
  65.         http.get( "http://cablepost.ddns.net/cc/dig3/y1.php" )
  66.         http.get( "http://cablepost.ddns.net/cc/dig3/y1.php" )
  67.         if digY >= maxY then
  68.             http.get( "http://cablepost.ddns.net/cc/dig3/resetY.php" )
  69.             http.get( "http://cablepost.ddns.net/cc/dig3/x1.php" )
  70.         end
  71.         if digX >= maxX then
  72.             http.get( "http://cablepost.ddns.net/cc/dig3/reset.php" )
  73.             print("digging complete")
  74.             on = false
  75.         end
  76.     end
  77. end
  78.  
  79. function drop()
  80.     shell.run("clear")
  81.     turtle.turnRight()
  82.     for i = 1,16 do
  83.         turtle.select(i)
  84.         local data = turtle.getItemDetail()
  85.         if data then
  86.             print(data.name)
  87.             if data.name == "minecraft:coal" then
  88.                 turtle.turnLeft()
  89.                 turtle.turnLeft()
  90.                 turtle.drop(64)
  91.                 turtle.turnLeft()
  92.                 turtle.turnLeft()
  93.             end
  94.         end
  95.         turtle.drop(64)
  96.     end
  97.     turtle.select(1)
  98.     turtle.turnLeft()
  99. end
  100.  
  101. function dig()
  102.    
  103.     shell.run("clear")
  104.     print("Digging...")
  105.     print("Fuel Level: " ..  tostring(turtle.getFuelLevel()) .. " / ".. tostring(requiredFuel))
  106.     print("Dig location is: X="..tostring(digX)..",Y="..tostring(digY))
  107.    
  108.     turtle.select(1)
  109.    
  110.     print("Going up")
  111.     timesM = 0
  112.     while timesM <= distanceUp do
  113.         turtle.up()
  114.         timesM = timesM + 1
  115.     end
  116.    
  117.     turtle.turnRight()
  118.    
  119.     print("matching X axis")
  120.     timesM = 0
  121.     while timesM <= digX do
  122.         turtle.dig()
  123.         turtle.forward()
  124.         timesM = timesM + 1
  125.     end
  126.    
  127.     turtle.turnLeft()
  128.    
  129.     print("Matching Y axis")
  130.     timesM = 0
  131.     while timesM <= digY do
  132.         turtle.dig()
  133.         turtle.forward()
  134.         timesM = timesM + 1
  135.     end
  136.    
  137.     print("going down")
  138.     timesM = 0
  139.     while timesM <= distanceDown do
  140.         turtle.dig()
  141.         turtle.digDown()
  142.         turtle.down()
  143.         timesM = timesM + 1
  144.     end
  145.    
  146.     turtle.dig()
  147.    
  148.     print("going up")
  149.     timesM = 0
  150.     while timesM <= 80 do
  151.         while turtle.detectUp() do
  152.             print("There is a block above me.")
  153.             turtle.digUp()
  154.         end
  155.         turtle.up()
  156.         timesM = timesM + 1
  157.     end
  158.    
  159.     print("backing-up to home")
  160.     timesM = 0
  161.     while timesM <= digY do
  162.         turtle.back()
  163.         timesM = timesM + 1
  164.     end
  165.    
  166.     turtle.turnRight()
  167.    
  168.     timesM = 0
  169.     while timesM <= digX do
  170.         turtle.back()
  171.         timesM = timesM + 1
  172.     end
  173.    
  174.     turtle.turnLeft()
  175.    
  176.     print("returning to ground")
  177.     on2 = true
  178.     while on2 == true do
  179.         turtle.down()
  180.         if turtle.detectDown() then
  181.             break
  182.         end
  183.     end
  184.    
  185. end
  186.  
  187. function checkEnd()
  188.     shell.run("clear")
  189.     if turtle.detect() then
  190.         turtle.dig()
  191.         turtle.turnRight()
  192.         turtle.select(1)
  193.         turtle.drop(64)
  194.         --drop()
  195.         turtle.turnLeft()
  196.         on = false
  197.     end
  198. end
  199.  
  200. --script
  201.  
  202. while on == true do
  203.     getDigLocation()
  204.     refuel()
  205.     dig()
  206.     drop()
  207.     increaceDigLocation()
  208.     checkEnd()
  209. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement