Advertisement
Guest User

chunkMiner.lua

a guest
Aug 20th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.25 KB | None | 0 0
  1. local trt_name = "chunki"
  2. local updateCh = 42
  3.  
  4. local height = 64
  5. local stopAt = 16
  6. local chunkSize = 16
  7.  
  8. local w, h = term.getSize()
  9.  
  10.  
  11. -- Modem functions
  12. local modem = nil
  13. local modAvl = false
  14.  
  15. function wrapModem( side )
  16.     if peripheral.getType(side) == "modem" then
  17.         modem = peripheral.wrap(side)
  18.         modAvl = true
  19.  
  20.         term.write("Found Modem")
  21.     end
  22. end
  23.  
  24. function sendUpdate(update)
  25.     if modAvl then
  26.         modem.transmit(updateCh, updateCh+1, update)    
  27.     end
  28. end
  29.  
  30. term.clear()
  31.  
  32. term.setCursorPos(w-11, 1)
  33. if peripheral.getType("left") ~= nil then
  34.     wrapModem("left")
  35. else if peripheral.getType("right") ~= nil then
  36.     wrapModem("right")
  37.     end
  38. end
  39. term.setCursorPos(1,1)
  40.  
  41.  
  42. --
  43. term.write("ChunkMiner")
  44. term.setCursorPos(1,2)
  45.  
  46. function percentage(input, max)
  47.     return input/max*100
  48. end
  49.  
  50. function printBar(perc)
  51.     local tens = perc/10
  52.     term.write("|")
  53.     for i=0,10 do
  54.         if i < tens then
  55.             term.write("#")
  56.         else
  57.             term.write(" ")
  58.         end
  59.     end
  60.     term.write("| ")
  61. end
  62.  
  63.  
  64. function progress( name, cursorPos, input, max, sendUpd )
  65.     term.setCursorPos(1,cursorPos)
  66.     term.clearLine()
  67.     term.write(name)
  68.     printBar(percentage(input, max))
  69.  
  70.     if sendUpd then
  71.         local update = {
  72.             name = trt_name,
  73.             progress = percentage(input, max),
  74.             fuel = percentage(turtle.getFuelLevel(), turtle.getFuelLimit())  
  75.         }
  76.  
  77.         sendUpdate(update)
  78.     end
  79. end
  80.  
  81. --inv functions
  82. function invFull()
  83.     if turtle.getItemCount(9) > 0 then
  84.         turtle.select(1)
  85.         return true
  86.     end
  87.     turtle.select(1)
  88.     return false
  89. end
  90.  
  91. function emptyInv()
  92.     for i=1,16 do
  93.         turtle.select(i)
  94.         turtle.drop(turtle.getItemCount(i))
  95.     end
  96.     turtle.select(1)
  97. end
  98.  
  99. --mining functions
  100. function digForward()
  101.     while turtle.forward() == false do
  102.         turtle.dig()
  103.         turtle.attack()
  104.     end
  105. end
  106.  
  107. function line()
  108.     for i=1,chunkSize-1 do
  109.  
  110.         progress("Line  ", 2, i, chunkSize-1)
  111.  
  112.         digForward()
  113.     end
  114. end
  115.  
  116.  
  117. function slice()
  118.     for i=1,chunkSize/2 do
  119.         progress("Slice ", 3, i, chunkSize/2)
  120.  
  121.         line()
  122.         turtle.turnRight()
  123.         digForward()
  124.         turtle.turnRight()
  125.         line()
  126.         if i ~= chunkSize/2 then
  127.             turtle.turnLeft()
  128.             digForward()
  129.             turtle.turnLeft()
  130.         end
  131.  
  132.     end
  133. end
  134.  
  135. function down(height)
  136.     for i=1,height-stopAt do
  137.         progress("Heigth", 4, i, height-stopAt, true)
  138.  
  139.         slice()
  140.         turtle.digDown()
  141.         turtle.down()
  142.         turtle.turnRight()
  143.         line()
  144.        
  145.         if invFull() then
  146.             local success, data = turtle.inspect()
  147.             if success then
  148.                 while data.name ~= "minecraft:chest" do
  149.                     success, data = turtle.inspect()
  150.                     turtle.up()
  151.                 end
  152.             end
  153.             turtle.down()
  154.             emptyInv()
  155.             while turtle.detectDown() == false do
  156.                 turtle.down()
  157.             end
  158.             turtle.turnRight()
  159.         else
  160.             turtle.turnRight()
  161.         end
  162.     end
  163. end
  164. digForward()
  165. down(height)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement