· 6 years ago · Mar 24, 2020, 07:22 PM
1-- Generic Digging API
2
3function goForwardAndDig(length)
4 print("Going forward and digging "..length.." Spaces")
5 for i=1,length do
6 turtle.dig()
7 turtle.forward()
8 end
9end
10
11function goForward(length)
12 print("Going forward "..length.." Spaces")
13 for i=1,length do
14 turtle.forward()
15 end
16end
17
18function goUpAndDig(height)
19 print("Going Up and digging "..height.." Spaces")
20 for i=1, height do
21 turtle.digUp()
22 turtle.up()
23 end
24end
25
26function goUp(height)
27 print("Going Up "..height.." Spaces")
28 for i=1, height do
29 turtle.up()
30 end
31end
32
33function turnLeft(times)
34 print("Turning Left "..times.." times")
35 for i=1,times do
36 turtle.turnLeft()
37 end
38end
39
40function turnRight(times)
41 print("Turning Right "..times.." times")
42 for i=1,times do
43 turtle.turnRight()
44 end
45end
46
47function goDownAndDig(depth)
48 print("Going Down and digging "..depth.." Spaces")
49 for i=1,depth do
50 turtle.digDown()
51 turtle.down()
52 end
53end
54
55function goDown(depth)
56 print("Going Down "..depth.." Spaces")
57 for i=1,depth do
58 turtle.down()
59 end
60end
61
62checkForInput = function()
63 timeout = os.startTimer(1)
64 sEvent, param = os.pullEvent()
65 if(sEvent == "key") then
66 print("I detected a Keystroke "..param)
67 return true
68 elseif sEvent == "timer" and param == timeout
69 return false
70 end
71 print("No Key detected. Proceeding Job")
72end
73
74checkRednet = function()
75 local id, message = rednet.receive(os.getComputerLabel(), 1)
76 if message == "stop" then
77 print(message.." I am stopping")
78 return true
79 end
80 return false
81end
82
83function refuel()
84 for i = 1, 16 do -- loop through the slots
85 turtle.select(i) -- change to the slot
86 if turtle.refuel(0) then -- if it's valid fuel
87 local halfStack = math.ceil(turtle.getItemCount(i)/2) -- work out half of the amount of fuel in the slot
88 turtle.refuel(halfStack) -- consume half the stack as fuel
89 break
90 end
91 end
92end
93
94return {goDown = goDown,
95 goDownAndDig = goDownAndDig,
96 turnRight = turnRight,
97 turnLeft = turnLeft,
98 goUp = goUp,
99 goUpAndDig = goUpAndDig,
100 goForward = goForward,
101 goForwardAndDig = goForwardAndDig,
102 checkForInput = checkForInput,
103 checkRednet = checkRednet,
104 refuel = refuel
105 }