ravneravn

endermine startup

Aug 8th, 2013
103
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local function goUp()
  2. while not turtle.up() do turtle.digUp() end
  3. end
  4.  
  5. local function goDown()
  6. while not turtle.down() do turtle.digDown() end
  7. end
  8.  
  9. rednet.open("right")
  10.  
  11. turtleId = os.getComputerLabel()
  12.  
  13. function loadPos()
  14. handle = fs.open("enderMine/savedPosition", "r")
  15. readFile = handle.readLine()
  16. if readFile ~= nil then
  17. position = textutils.unserialize(readFile)
  18. end
  19. handle.close()
  20. end
  21.  
  22. local function moveForward()
  23. while not turtle.forward() do turtle.dig()
  24. end
  25. end
  26.  
  27.  
  28. function sendBroadcast(message)
  29. rednet.open("right")
  30. rednet.broadcast("["..turtleId.."] "..message)
  31. end
  32.  
  33. -------
  34. print("finding pos")
  35. loadPos()
  36. print("pos found")
  37.  
  38.  
  39. if position["status"] == "on" then
  40. print("status: on")
  41. if position["enderchest"] == "no" then
  42. wait = 1
  43. shell.run("mine", position["currY"], "on", "manual")
  44. else
  45. shell.run("mine", position["currY"], "on")
  46. end
  47. end
  48.  
  49.  
  50.  
  51. sendBroadcast("Standing by")
  52. print("enderMiner "..turtleId..", standing by")
  53. print("")
  54. print("Usage:")
  55. print("mine [current y] [-] [manual(optional)]")
  56. print("")
  57. print("Noice blocks: slot 1-3, put 1 cobble in slot 4")
  58. print("Enderchest in slot 16")
  59.  
  60.  
  61. while true do
  62. event, sid, mes, dis = os.pullEvent()
  63. wait = 0
  64. if mes == "new" then
  65. turtle.select(5)
  66. turtle.digUp()
  67. for i = 1, 16 do moveForward() end
  68. turtle.placeUp()
  69. wait = 1
  70. shell.run("mine", position["currY"])
  71.  
  72. elseif mes == "download" then
  73. wait = 1
  74. sendBroadcast("Updating")
  75. shell.run("download")
  76.  
  77. elseif mes == "pastebin" then
  78. event, sid, file, dis = os.pullEvent("rednet_message")
  79. dl = textutils.unserialize(file)
  80. wait = 1
  81. sendBroadcast("Downloading "..dl["placement"])
  82. shell.run("pastebin", "get", dl["fileName"], dl["placement"])
  83.  
  84. elseif mes == "go up" then
  85. event, sid, surface, dis = os.pullEvent("rednet_message")
  86. wait = 1
  87. sendBroadcast("Going to y level "..surface)
  88. while position["currY"] < tonumber(surface) do goUp() end
  89. while position["currY"] > tonumber(surface) do goDown() end
  90.  
  91. elseif event == "key" and sid == 28 then
  92. turtle.select(5)
  93. turtle.digUp()
  94. for i = 1, 16 do moveForward() end
  95. turtle.placeUp()
  96. wait = 1
  97. shell.run("mine", position["currY"])
  98. end
  99. end
  100.  
  101.  
  102. print("done")
RAW Paste Data