Advertisement
Guest User

miner.lua

a guest
Apr 25th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.42 KB | None | 0 0
  1. hilbert = "a"
  2. for i=1,7,1 do
  3. new_seq = " "
  4. for j=0,string.len(hilbert),1 do
  5.  char = string.sub(hilbert, j, j)
  6.  if char == "a" then
  7.    new_seq = new_seq.."-bF+aFa+Fb-"
  8.  elseif char == "b" then
  9.    new_seq = new_seq.."+aF-bFb-Fa+"
  10.  else
  11.    print(char)
  12.    new_seq = new_seq..char
  13.  end
  14. end
  15. hilbert = new_seq
  16. end
  17. print(hilbert)
  18.  
  19. int place = 0;
  20. while(place < string.len(hilbert)) do
  21.  if turtle.getFuelLevel() <= place then
  22.   slot = findFuel()
  23.   if slot == nil then
  24.    returnHome(place)
  25.    break
  26.   else
  27.    turtle.select(slot)
  28.    turtle.refuel()
  29.   end
  30.  else
  31.  instr = string.sub(hilbert,place,place)
  32.  if instr == "F" then
  33.    turtle.dig()
  34.    turtle.forward()
  35.    turtle.digDown()
  36.  elseif instr == "+" then
  37.    turtle.turnRight()
  38.  elseif instr == "-" then
  39.    turtle.turnLeft()
  40.  end
  41.  
  42.  place = place+1
  43.  
  44.  if invFull() then
  45.  returnHome(place)
  46.  emptyInv()
  47.  place=0
  48.  end
  49. end
  50.  
  51. function returnHome(plc)
  52. turtle.turnLeft()
  53. turtle.turnLeft()
  54. while plc > 0 do
  55.  findFuel()
  56.  chr = string.sub(hilbert,plc,plc)
  57.  if chr = "F" then
  58.   turtle.forward()
  59.  elseif chr = "+" then
  60.   turtle.turnRight()
  61.  elseif chr = "-" then
  62.   turtle.turnLeft()
  63.  end
  64.  plc = plc-1
  65. end
  66.    
  67. function findFuel()  
  68.  for slot=0,16,1 do
  69.   turtle.select(slot)
  70.   if turtle.refuel() then
  71.   return slot
  72.   end
  73.  end
  74. return nil
  75. end
  76.  
  77. function emptyInv()
  78.  findFuel()
  79.  for i=0,16,1 do
  80.   turtle.select(i)
  81.   turtle.dropDown(64)
  82.  end
  83. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement