Guest User

quarry

a guest
Mar 30th, 2015
3,505
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.99 KB | None | 0 0
  1. --Ore mining quarry with enderchest
  2. --Made by: Cing
  3. --also blocks off lava
  4. --and sucks up items out of a chest
  5.  
  6.  
  7. local turns = 0
  8. local size = 0
  9. local layers = 0
  10. local y = 0
  11. local place = 0
  12. local eNeeded = 0
  13. local home = 0
  14.  
  15. local notItems = {
  16.   "minecraft:dirt",
  17.   "minecraft:stone",
  18.   "minecraft:gravel",
  19.   "minecraft:chest",
  20.   "minecraft:flowing_lava"
  21.     }
  22.  
  23. function compDown()
  24. local succes, data = turtle.inspectDown()
  25.  if succes then
  26.   if data.name == notItems[1] then
  27.     elseif data.name == notItems[2] then
  28.       elseif data.name == notItems[3] then  
  29.         elseif data.name == notItems[4] then
  30.           for i = 1, 27 do
  31.             turtle.suckDown()
  32.           end
  33.           turtle.digDown()
  34.             elseif data.name == notItems[5] then
  35.               turtle.select(15)
  36.               turtle.placeDown()
  37.             else
  38.           turtle.digDown()      
  39.       end
  40.    end
  41. end
  42.  
  43. function compUp()
  44. local succes, data = turtle.inspectUp()
  45.   if succes then
  46.     if data.name == notItems[1] then
  47.       elseif data.name == notItems[2] then
  48.         elseif data.name == notItems[3] then
  49.           elseif data.name == notItems[4] then
  50.             for i = 1, 27 do
  51.               turtle.suckUp()
  52.             end
  53.             turtle.digUp()
  54.             elseif data.name== notItems[5] then
  55.               turtle.select(15)
  56.               turtle.placeUp()
  57.           else
  58.           turtle.digUp()    
  59.        end    
  60.     end
  61. end
  62.  
  63. function compare()
  64.   compDown()
  65.   compUp()  
  66. end
  67.  
  68. function moveForward()
  69. local succes, data = turtle.inspect()
  70.   while not turtle.forward() do
  71.     if succes then
  72.       if data.name == notItems[4] then
  73.         for i = 1, 27 do
  74.           turtle.suck()
  75.         end
  76.         turtle.dig()
  77.         else  
  78.           turtle.dig()
  79.        end
  80.     end  
  81.   end
  82. end
  83.  
  84. function moveDown()
  85.   while not turtle.down() do
  86.     turtle.digDown()
  87.   end
  88.  y = y-1
  89. end
  90.  
  91. function moveUp()
  92.   while not turtle.up() do
  93.     turtle.digUp()
  94.   end
  95.  y = y+1
  96. end
  97.  
  98. function goHome()
  99.   if layers == 1 and place == 0 then
  100.   else
  101.     repeat
  102.       moveUp()
  103.     until y == home
  104.   end
  105.   if layers == 0 then
  106.     if size%2 == 1 then
  107.       if turns == 0 then
  108.         for i = 1, 2 do
  109.           turtle.turnLeft()
  110.           for i = 1, size-1 do
  111.             moveForward()
  112.           end
  113.         end
  114.       end
  115.     else
  116.       if turns == 1 then
  117.         turtle.turnRight()
  118.         for i = 1, size-1 do
  119.           moveForward()
  120.         end
  121.       end
  122.     end
  123.   elseif layers%2 == 1 then
  124.     if size%2 == 1 then
  125.       for i = 1, 2 do
  126.         turtle.turnLeft()
  127.         for i = 1, size-1 do
  128.           moveForward()
  129.         end    
  130.       end
  131.     else
  132.       turtle.turnRight()
  133.       for i = 1, size-1 do
  134.         moveForward()
  135.       end
  136.     end
  137.   else
  138.     turtle.turnLeft()
  139.   end
  140. end
  141.  
  142. function fuel()
  143.   turtle.select(1)
  144.   if turtle.getFuelLevel() < 50 then
  145.     turtle.refuel()
  146.   end
  147. end
  148.  
  149. function dropItems()
  150. turtle.turnRight()
  151. turtle.turnRight()
  152. local number = 2
  153.   fuel()
  154.   turtle.select(16)
  155.   while not turtle.place() do
  156.     turtle.dig()
  157.   end  
  158.   for i = 1, 13 do
  159.     turtle.select(number)
  160.     turtle.drop()
  161.     number = number+1
  162.   end
  163.   turtle.select(16)
  164.   turtle.dig()
  165.   turtle.select(1)
  166.   turtle.turnRight()
  167.   turtle.turnRight()
  168. end
  169.  
  170. function checkItems()
  171.   if turtle.getItemDetail(11) == false then
  172.   else
  173.     dropItems()
  174.   end
  175. end
  176.  
  177. function dig()
  178.   fuel()  
  179.   compare()  
  180.   for i = 1, size-1 do
  181.     moveForward()
  182.     compare()
  183.   end
  184. end
  185.  
  186. function turnright()
  187.   turtle.turnRight()
  188.   moveForward()
  189.   turtle.turnRight()
  190. end
  191.  
  192. function turnleft()
  193.   turtle.turnLeft()
  194.   moveForward()
  195.   turtle.turnLeft()
  196. end
  197.  
  198. function nextLayer()
  199.   for i = 1,3 do
  200.     moveDown()
  201.   end
  202.   turtle.turnRight()
  203.   turtle.turnRight()
  204. end
  205.  
  206. function square()
  207. local count = 1
  208.   for i = 1, size do
  209.     dig()
  210.     if count ~= size then
  211.       if turns == 0 then
  212.         turnright()
  213.         turns = 1
  214.       else
  215.         turnleft()
  216.         turns = 0
  217.       end
  218.       count = count+1
  219.     end
  220.   end
  221.   if turns == 0 then
  222.     checkItems()
  223.   end
  224. end
  225.  
  226. function Layers()
  227.   square()
  228.   if layers > 1 then
  229.     for i = 1, layers-1 do
  230.       nextLayer()
  231.       square()
  232.     end
  233.   end
  234. end
  235.  
  236. function Bedrock()
  237.   square()
  238.   repeat
  239.     if y == 3 then
  240.       moveDown()
  241.       turtle.turnRight()
  242.       turtle.turnRight()
  243.       square()
  244.     else
  245.       nextLayer()
  246.       square()
  247.     end
  248.   until y < 3
  249. end  
  250.  
  251. function getInPlace()
  252.   if place == 1 then
  253.     for i = 1, 3 do
  254.       moveDown()
  255.     end
  256.   elseif place == 0 then
  257.     moveForward()
  258.   else
  259.     print("Place must be 1 or 0")
  260.     print("Please try again")
  261.     sleep(3)
  262.     os.reboot()
  263.   end
  264. end
  265.  
  266. function calcEnergy()
  267.   if layers == 0 then
  268.     eNeeded = ((size*size*(y/3))+50)
  269.   else
  270.     eNeeded = ((size*size*layers)+50)
  271.   end
  272. end
  273.  
  274. print("---------------------------------------")
  275. print("Advanced ore mining quarry")
  276. print("Made by: Cing")
  277. print("---------------------------------------")
  278.  
  279. print("Please put first coal in slot 1...")
  280. print("some filling blocks in slot 15...")
  281. print("and a enderchest in slot 16.")
  282. print("And don't forget to chunkload the area.")
  283. os.pullEvent()
  284.  
  285. write("What is the YLevel: ")
  286. y = tonumber(read())
  287.  
  288. write("What home level do you want: ")
  289. home = tonumber(read())
  290.  
  291. print("Are you above or under ground?")
  292. write("Type 1 for above and 0 for under: ")
  293. place = tonumber(read())
  294.  
  295. write("What size do you want: ")
  296. size = tonumber(read())
  297.  
  298. print("How many layers do you want?")
  299. write("Or type 0 to go to bedrock: ")
  300. layers = tonumber(read())
  301.  
  302. print(y)
  303. calcEnergy()
  304. repeat
  305.   if eNeeded < turtle.getFuelLevel() then
  306.   else
  307.     turtle.refuel()
  308.     print("Please put more coal in slot 1")
  309.     os.pullEvent()
  310.   end
  311. until eNeeded < turtle.getFuelLevel()
  312.  
  313. getInPlace()
  314. term.clear()
  315. term.setCursorPos(1, 1)
  316. print("Digging")
  317.  
  318. if layers == 0 then
  319.   Bedrock()
  320.   else
  321.   Layers()
  322. end
  323.  
  324. print("Done!!!")
  325. goHome()
  326. dropItems()
Advertisement
Add Comment
Please, Sign In to add comment