-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathautolevel.lua
More file actions
64 lines (58 loc) · 1.42 KB
/
autolevel.lua
File metadata and controls
64 lines (58 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
local shell = require("shell")
local robot = require("robot")
local ic = require("component").inventory_controller
local inventory = require("inventory")
local autolevel = {}
local AutoLevel = {}
function AutoLevel:start()
robot.select(1)
ic.equip()
local tool = ic.getStackInInternalSlot(1)
if tool == nil or type(tool.maxDamage) ~= "number" then
ic.equip()
print("I dont seem to have a tool equipped!")
return false
end
ic.equip()
self.toolName = tool.name
robot.place()
while true do
if not robot.swing() then
-- equip a fresh tool...
if not inventory.equipFreshTool(self.toolName) then
print("lost durability on tool and can't find a fresh one in my inventory!")
return false
end
if not robot.place() then
print("failed to place")
return
end
else
if not robot.place() then
print("failed to place")
return
end
end
end
end
function AutoLevel:applyDefaults() --luacheck: no unused args
end
function autolevel.new(o)
o = o or {}
setmetatable(o, { __index = AutoLevel })
o:applyDefaults()
return o
end
local args, options = shell.parse( ... )
if args[1] == 'help' then
print("commands: start")
elseif args[1] == 'start' then
if (args[2] == 'help') then
print("usage: autolevel start")
else
local a = autolevel.new({options = options})
a:applyDefaults()
a:start()
end
end
return autolevel