Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Direction = {
- new = function (self, dir_name, ex, ze)
- local new = {}
- setmetatable(new, {__index = self})
- self.vector = {x = ex, z = ze}
- self.dir_name = dir_name
- return new
- end
- }
- Directions = {
- Direction:new("n", 0, -1), -- n
- Direction:new("e", 1, 0), -- e
- Direction:new("s", 0, 1), -- s
- Direction:new("w", -1, 0) -- w
- }
- -- Config = textutils.unserialize(fs.open("/heirteir/drone/config/config.data", "r").readAll())
- Command = {
- new = function (self, func)
- local new = {}
- setmetatable(new, {__index = self})
- self.command = func
- return new
- end,
- getCommand = function (self)
- return self.command
- end
- }
- CommandBuffer = {
- commands = {},
- running_command = false,
- new = function (self)
- local new = {}
- setmetatable(new, {__index = self})
- return new
- end,
- finishQueue = function (self)
- for val = 1,
- #self.commands,
- +1 do
- self:runNextCommand()
- end
- end,
- runNextCommand = function (self)
- if self.running_command then return end
- self.running_command = true
- if self.commands[0].getCommand() then table.remove(self.commands, 0) end
- self.running_command = false
- end,
- addCommand = function (self, func)
- table.insert(self.commands, Command:new(func))
- end
- }
- MiningDrone = {
- new = function (self, dir)
- local new = {}
- setmetatable(new, {__index = self})
- self.command_buffer = CommandBuffer:new()
- self.origin = {value = {0, 0, 0}, direction = dir}
- self.current_pos = {value = {0, 0, 0}, direction = dir}
- return new
- end,
- queryDirection = function(self)
- print("Please enter the facing direction: ")
- local input = read()
- local dir = 0
- for val = 1, #Directions, +1 do
- if Directions[val].dir_name == input then dir = val break end
- end
- self.current_pos.direction = dir
- end,
- stripMine = function (self)
- self:queryDirection()
- local up = true
- for val = 1, 20, +1 do
- if up then
- self:up(2)
- self:forward(1)
- else then
- self:down(2)
- self:forward(1)
- end
- up = not up
- end
- end,
- dig = function (self)
- while (turtle.detect()) do
- turtle.dig()
- sleep(0.4)
- end
- return true
- end,
- digUp = function (self)
- while (turtle.detectUp()) do
- turtle.DigUp()
- sleep(0.4)
- end
- end,
- digDown = function (self)
- while (turtle.detectDown()) do
- turtle.DigDown()
- sleep(0.4)
- end
- end,
- forward = function (self, amt)
- for val = 1, amt, +1 do
- self:dig()
- while not turtle.forward() do sleep(0.4) end
- end
- return true
- end,
- up = function (self, amt)
- for val = 1, amt, +1 do
- self:digUp()
- while not turtle.up() do sleep(0.4) end
- end
- end,
- down = function(self, amt)
- for val = 1, amt, +1 do
- self:digDown()
- while not turtle.down() do sleep(0.4) end
- end
- end,
- turn = function (self, amt)
- if amt < 0 then
- amt = math.abs(amt)
- for val = 1, amt, +1 do
- self::turnLeft()
- end
- elseif amt > 0 then
- amt = math.abs(amt)
- for val = 1, amt, +1 do
- self::turnRight()
- end
- end
- end,
- turnRight = function(self)
- turtle.turnRight()
- self.current_pos.direction = (self.current_pos.direction + 1) % 4
- return true
- end,
- turnLeft = function(self)
- turtle.turnLeft()
- self.current_pos.direction = (self.current_pos.direction - 1) % 4
- return true
- end
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement