-
Notifications
You must be signed in to change notification settings - Fork 3
/
do_simple.cc.lua
111 lines (105 loc) · 2.46 KB
/
do_simple.cc.lua
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
local tArgs = { ... }
if #tArgs < 1 then
print( "Usage: do <command> [repeat]" )
return
end
function digladder()
turtle.digDown()
turtle.down()
end
local tHandlers = {
["fd"] = turtle.forward,
["forward"] = turtle.foreward,
["forwards"] = turtle.foreward,
["bk"] = turtle.back,
["back"] = turtle.back,
["up"] = turtle.up,
["dn"] = turtle.down,
["down"] = turtle.down,
["lt"] = turtle.turnLeft,
["left"] = turtle.turnLeft,
["rt"] = turtle.turnRight,
["right"] = turtle.turnRight,
["dg"] = turtle.dig,
["dig"] = turtle.dig,
["dgd"] = turtle.digDown,
["digdown"] = turtle.digDown,
["dgu"] = turtle.digUp,
["digup"] = turtle.digUp,
["pl"] = turtle.place,
["place"] = turtle.place,
["pld"] = turtle.placeDown,
["placedown"] = turtle.placeDown,
["plu"] = turtle.placeUp,
["placeup"] = turtle.placeUp,
["sel"] = turtle.select,
["select"] = turtle.select,
["sk"] = turtle.suck,
["suck"] = turtle.suck,
["skd"] = turtle.suckDown,
["suckdown"] = turtle.suckDown,
["sku"] = turtle.suckUp,
["suckup"] = turtle.suckUp,
["dp"] = turtle.drop,
["drop"] = turtle.drop,
["dpd"] = turtle.dropDown,
["dropdown"] = turtle.dropDown,
["dpu"] = turtle.dropUp,
["dropup"] = turtle.dropUp,
["rf"] = turtle.refuel,
["refuel"] = turtle.refuel,
["dd"] = digladder
}
-- if Ben's "t" location tracking API is installed, use those movement commands instead.
if t and t.initLoc then
tHandlers["fd"] = t.fd
tHandlers["forward"] = t.fd
tHandlers["forwards"] = t.fd
tHandlers["bk"] = t.bk
tHandlers["back"] = t.bk
tHandlers["up"] = t.up
tHandlers["dn"] = t.dn
tHandlers["down"] = t.dn
tHandlers["lt"] = t.lt
tHandlers["left"] = t.lt
tHandlers["rt"] = t.rt
tHandlers["right"] = t.rt
end
local nArg = 1
while nArg <= #tArgs do
local sDirection = tArgs[nArg]
local nDistance = 1
if nArg < #tArgs then
local num = tonumber( tArgs[nArg + 1] )
if num then
nDistance = num
nArg = nArg + 1
end
end
nArg = nArg + 1
local fnHandler = tHandlers[string.lower(sDirection)]
if fnHandler then
if fnHandler == turtle.select then
if nDistance < 1 or nDistance > 16 then
print("Invalid slot selection")
return
end
fnHandler(nDistance)
else
while nDistance > 0 do
if fnHandler() then
nDistance = nDistance - 1
elseif turtle.getFuelLevel() == 0 then
print( "Out of fuel" )
return
else
sleep(0.5)
end
end
end
else
print( "No such direction: "..sDirection )
print( "Try: forward, back, up, down" )
return
end
end