Advertisement
Heirteir

Untitled

Dec 9th, 2019
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.06 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, table.getn(self.commands), +1 do
  42. self:runNextCommand()
  43. end
  44. end,
  45. runNextCommand = function (self)
  46. if self.running_command then return end
  47.  
  48. self.running_command = true
  49.  
  50. if self.commands[0].getCommand() then table.remove(self.commands, 0) end
  51.  
  52. self.running_command = false
  53. end,
  54. addCommand = function (self, func)
  55. table.insert(self.commands, Command:new(func))
  56. end
  57. }
  58.  
  59. MiningDrone = {
  60. new = function (self, dir)
  61. local new = {}
  62. setmetatable(new, {__index = self})
  63. self.command_buffer = CommandBuffer:new()
  64. self.origin = {value = {0, 0, 0}, direction = dir}
  65. self.current_pos = {value = {0, 0, 0}, direction = dir}
  66. return new
  67. end,
  68. queryDirection = function(self)
  69. print("Please enter the facing direction: ")
  70. local input = read()
  71. local dir = 0
  72.  
  73. for val = 1, #Directions, +1 do
  74. if Directions[val].dir_name == input then dir = val break end
  75. end
  76.  
  77. self.current_pos.direction = dir
  78. end,
  79. stripMine = function (self)
  80. self:queryDirection()
  81.  
  82. local up = true
  83.  
  84. for val = 1, 20, +1 do
  85. if up then
  86. self:up(2)
  87. self:forward(1)
  88. else then
  89. self:down(2)
  90. self:forward(1)
  91. end
  92.  
  93. up = not up
  94. end
  95. end,
  96. dig = function (self)
  97. while (turtle.detect()) do
  98. turtle.dig()
  99. sleep(0.4)
  100. end
  101. return true
  102. end,
  103. digUp = function (self)
  104. while (turtle.detectUp()) do
  105. turtle.DigUp()
  106. sleep(0.4)
  107. end
  108. end,
  109. digDown = function (self)
  110. while (turtle.detectDown()) do
  111. turtle.DigDown()
  112. sleep(0.4)
  113. end
  114. end,
  115. forward = function (self, amt)
  116. for val = 1, amt, +1 do
  117. self:dig()
  118.  
  119. while not turtle.forward() do sleep(0.4) end
  120. end
  121. return true
  122. end,
  123. up = function (self, amt)
  124. for val = 1, amt, +1 do
  125. self:digUp()
  126.  
  127. while not turtle.up() do sleep(0.4) end
  128. end
  129. end,
  130. down = function(self, amt)
  131. for val = 1, amt, +1 do
  132. self:digDown()
  133.  
  134. while not turtle.down() do sleep(0.4) end
  135. end
  136. end,
  137. turn = function (self, amt)
  138. if amt < 0 then
  139. amt = math.abs(amt)
  140. for val = 1, amt, +1 do
  141. self::turnLeft()
  142. end
  143. elseif amt > 0 then
  144. amt = math.abs(amt)
  145. for val = 1, amt, +1 do
  146. self::turnRight()
  147. end
  148. end
  149. end,
  150. turnRight = function(self)
  151. turtle.turnRight()
  152. self.current_pos.direction = (self.current_pos.direction + 1) % 4
  153. return true
  154. end,
  155. turnLeft = function(self)
  156. turtle.turnLeft()
  157. self.current_pos.direction = (self.current_pos.direction - 1) % 4
  158. return true
  159. end
  160. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement