Advertisement
Lanzr

clent

Oct 28th, 2023 (edited)
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  1. local swflag = false
  2. local initFlag = false
  3. local bkslot = 2
  4. local placerOrient = "NULL"
  5. local placeLock = false
  6. local moveLock = false
  7. local moveOrient = "NULL"
  8. local nowKey = nil
  9.  
  10. -- local mModule = peripheral.find("")
  11. local mModule = peripheral.wrap("right")
  12.  
  13. local ID = os.getComputerID()
  14. local procPlacer = "placer_proc"..ID
  15. local hostName = "placer_host_"..ID
  16.  
  17. rednet.open("left")
  18. print("my Proc is:\n ",procPlacer)
  19. rednet.host(procPlacer,hostName)
  20.  
  21. local moveLockMap = {
  22. ['up']=(function () turtle.up() end),
  23. ['down']=(function () turtle.down() end),
  24. ['font']=(function () turtle.forward() end),
  25. ['back']=(function () turtle.back() end),
  26. ['NULL']=(function () end)
  27. }
  28.  
  29.  
  30. local keyMap = {
  31. ["w"]=(function ()
  32. moveOrient = "font"
  33. turtle.forward() end),
  34. ["s"]=(function ()
  35. moveOrient = "back"
  36. turtle.back() end),
  37. ["a"]=(function () turtle.turnLeft() end),
  38. ["d"]=(function () turtle.turnRight() end),
  39. ["space"]=(function ()
  40. moveOrient = "up"
  41. turtle.up() end),
  42. ["leftShift"]=(function ()
  43. moveOrient = "down"
  44. turtle.down() end),
  45. ["q"]=(function () turtle.digUp() end),
  46. ["e"]=(function () turtle.digDown() end),
  47. ["f"]=(function () turtle.dig() end),
  48. ["c"]=(function ()
  49. moveOrient = "NULL"
  50. placerOrient = "null" end),
  51. ["x"]=(function () placerOrient = "font" end),
  52. ["l"]=(function () os.shutdown() end),
  53. ["g"]=(function () mModule.savePoint("back") end),
  54. ["t"]=(function () mModule.warpToPoint("back") end),
  55. ["h"]=(function () moveLock = not moveLock end),
  56. }
  57.  
  58.  
  59. local function mainloop()
  60. while(not initFlag) do
  61. os.sleep(2)
  62. end
  63.  
  64. while 1 do
  65. turtle.select(bkslot)
  66. if(nowKey ~= nil) then
  67. if(keyMap[nowKey]~= nil) then keyMap[nowKey]() end
  68. nowKey = nil
  69. else
  70. --cruise
  71. if(moveLock) then
  72. moveLockMap[moveOrient]()
  73. end
  74. end
  75.  
  76. -- check space
  77. while (turtle.getItemCount() == 0) do
  78. bkslot = bkslot + 1
  79. if(turtle.getItemCount(2) ~= 0) then
  80. bkslot = 2
  81. break
  82. end
  83. if(bkslot > 16) then
  84. os.shutdown()
  85. end
  86. turtle.select(bkslot)
  87. end
  88.  
  89.  
  90.  
  91. -- place
  92.  
  93. -- if(placeLock == true) then
  94. -- placeMap(placerOrient)
  95. -- end
  96. -- turn if block
  97.  
  98. -- check fuel
  99. if(turtle.getFuelLevel() < 100) then
  100. turtle.select(1)
  101. turtle.refuel(1)
  102. end
  103. end
  104. end
  105.  
  106. local function netCheck()
  107. while 1 do
  108. local event, sender, message, protocol = os.pullEvent("rednet_message")
  109. initFlag = true
  110. if(protocol == procPlacer) then
  111. print(nowKey)
  112. nowKey = message
  113. end
  114. end
  115. end
  116.  
  117.  
  118. -- local function shutdownCheck()
  119. -- os.pullEvent("redstone")
  120. -- print("shutdown !")
  121. -- end
  122.  
  123. -- parallel.waitForAny(main_frame,netCheck)
  124. parallel.waitForAll(mainloop,netCheck)
  125.  
  126. return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement