Advertisement
Heirteir

Untitled

Dec 9th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.07 KB | None | 0 0
  1. Direction = {
  2. new = function (self, dir_name, ex, ze)
  3. local new = {}
  4. setmetatable(new, {__index = self})
  5. self.vector = {x = ex, z = ze}
  6. self.dir_name = dir_name
  7. return new
  8. end
  9. }
  10.  
  11. Directions = {
  12. Direction:new("n", 0, -1), -- n
  13. Direction:new("e", 1, 0), -- e
  14. Direction:new("s", 0, 1), -- s
  15. Direction:new("w", -1, 0) -- w
  16. }
  17.  
  18. -- Config = textutils.unserialize(fs.open("/heirteir/drone/config/config.data", "r").readAll())
  19.  
  20. Command = {
  21. new = function (self, func)
  22. local new = {}
  23. setmetatable(new, {__index = self})
  24. self.command = func
  25. return new
  26. end,
  27. getCommand = function (self)
  28. return self.command
  29. end
  30. }
  31.  
  32. CommandBuffer = {
  33. commands = {},
  34. running_command = false,
  35. new = function (self)
  36. local new = {}
  37. setmetatable(new, {__index = self})
  38. return new
  39. end,
  40. finishQueue = function (self)
  41. for val = 1,
  42. #self.commands,
  43. +1 do
  44. self:runNextCommand()
  45. end
  46. end,
  47. runNextCommand = function (self)
  48. if self.running_command then return end
  49.  
  50. self.running_command = true
  51.  
  52. if self.commands[0].getCommand() then table.remove(self.commands, 0) end
  53.  
  54. self.running_command = false
  55. end,
  56. addCommand = function (self, func)
  57. table.insert(self.commands, Command:new(func))
  58. end
  59. }
  60.  
  61. MiningDrone = {
  62. new = function (self, dir)
  63. local new = {}
  64. setmetatable(new, {__index = self})
  65. self.command_buffer = CommandBuffer:new()
  66. self.origin = {value = {0, 0, 0}, direction = dir}
  67. self.current_pos = {value = {0, 0, 0}, direction = dir}
  68. return new
  69. end,
  70. queryDirection = function(self)
  71. print("Please enter the facing direction: ")
  72. local input = read()
  73. local dir = 0
  74.  
  75. for val = 1, #Directions, +1 do
  76. if Directions[val].dir_name == input then dir = val break end
  77. end
  78.  
  79. self.current_pos.direction = dir
  80. end,
  81. stripMine = function (self)
  82. self:queryDirection()
  83.  
  84. local up = true
  85.  
  86. for val = 1, 20, +1 do
  87. if up then
  88. self:up(2)
  89. self:forward(1)
  90. else then
  91. self:down(2)
  92. self:forward(1)
  93. end
  94.  
  95. up = not up
  96. end
  97. end,
  98. dig = function (self)
  99. while (turtle.detect()) do
  100. turtle.dig()
  101. sleep(0.4)
  102. end
  103. return true
  104. end,
  105. digUp = function (self)
  106. while (turtle.detectUp()) do
  107. turtle.DigUp()
  108. sleep(0.4)
  109. end
  110. end,
  111. digDown = function (self)
  112. while (turtle.detectDown()) do
  113. turtle.DigDown()
  114. sleep(0.4)
  115. end
  116. end,
  117. forward = function (self, amt)
  118. for val = 1, amt, +1 do
  119. self:dig()
  120.  
  121. while not turtle.forward() do sleep(0.4) end
  122. end
  123. return true
  124. end,
  125. up = function (self, amt)
  126. for val = 1, amt, +1 do
  127. self:digUp()
  128.  
  129. while not turtle.up() do sleep(0.4) end
  130. end
  131. end,
  132. down = function(self, amt)
  133. for val = 1, amt, +1 do
  134. self:digDown()
  135.  
  136. while not turtle.down() do sleep(0.4) end
  137. end
  138. end,
  139. turn = function (self, amt)
  140. if amt < 0 then
  141. amt = math.abs(amt)
  142. for val = 1, amt, +1 do
  143. self::turnLeft()
  144. end
  145. elseif amt > 0 then
  146. amt = math.abs(amt)
  147. for val = 1, amt, +1 do
  148. self::turnRight()
  149. end
  150. end
  151. end,
  152. turnRight = function(self)
  153. turtle.turnRight()
  154. self.current_pos.direction = (self.current_pos.direction + 1) % 4
  155. return true
  156. end,
  157. turnLeft = function(self)
  158. turtle.turnLeft()
  159. self.current_pos.direction = (self.current_pos.direction - 1) % 4
  160. return true
  161. end
  162. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement