Advertisement
Heirteir

Untitled

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