Advertisement
Lanzr

pp

Oct 21st, 2022 (edited)
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.81 KB | None | 0 0
  1. local nowKey
  2. local function keyCheck()
  3.     while true do
  4.         local event, key, isHeld = os.pullEvent("key")
  5.         nowKey = keys.getName(key)
  6.     end
  7. end
  8.  
  9. local function keyMap(kvalue)
  10.     if(kvalue == "w") then
  11.         turtle.forward()
  12.     elseif (kvalue == "s") then
  13.         turtle.back()
  14.     elseif (kvalue == "a") then
  15.         turtle.turnLeft()
  16.     elseif (kvalue == "d") then
  17.         turtle.turnRight()
  18.     elseif (kvalue == "leftShift") then
  19.         turtle.down()
  20.     elseif (kvalue == "space") then
  21.         turtle.up()
  22.     end
  23. end
  24.  
  25. local function moveloop()
  26. while 1 do
  27.     if(nowKey ~= nil) then
  28.         keyMap(nowKey)
  29.         nowKey = nil
  30.     end
  31.     os.sleep(1)
  32. end
  33. end
  34.  
  35. if(arg[1] == nil) then
  36.     parallel.waitForAll(moveloop,keyCheck)
  37.     return
  38. end
  39. print("start work!")
  40. local emptyFlag =false
  41. local bkslot = 2
  42.  
  43. local function turtleSelfCheck()
  44.     -- check fuel
  45.     if(turtle.getFuelLevel() < 100) then
  46.         turtle.select(1)
  47.         turtle.refuel(1)
  48.     end
  49.     -- check space
  50.     turtle.select(bkslot)
  51.     if(emptyFlag == false) then
  52.         while (turtle.getItemCount() == 0) do
  53.             bkslot = bkslot + 1
  54.             if(turtle.getItemCount(2) ~= 0) then
  55.                 bkslot = 2
  56.                 break
  57.             end
  58.             if(bkslot > 16) then
  59.                 os.shutdown()
  60.             end
  61.             turtle.select(bkslot)
  62.         end
  63.     end
  64.    
  65. end
  66.  
  67.  
  68. local count = tonumber(arg[1])
  69. local orient = arg[2]
  70. while (count > 0) do
  71.  
  72.     turtleSelfCheck()
  73.     -- place
  74.     if(orient == "u") then
  75.         turtle.up()
  76.         turtle.forward()
  77.         turtle.placeDown()
  78.     elseif (orient == "d") then
  79.         turtle.forward()
  80.         turtle.down()
  81.         turtle.placeDown()
  82.     else
  83.         break
  84.     end
  85.     count = count - 1
  86. end
  87.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement