-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdigTree.lua
83 lines (83 loc) · 1.85 KB
/
digTree.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
-- dig a tree
min_energy = 20
-- where to consume the wood that robot diggs down
textutils.slowPrint("consume the log that dug down ?")
repeat
print("enter y or n")
consume_ans = io.read()
until(consume_ans == "y" or consume_ans == "n")
if consume_ans == "y"
then
consume_ans = true
else
consume_ans = false
end
-- when the energy is zero, remind you to give it food
if consume_ans
then
if turtle.getFuelLevel() == 0
then
turtle.digUp()
turtle.refuel(1)
turtle.up()
end
else
if turtle.getFuelLevel() <= min_energy
then
turtle.refuel()
if turtle.getFuelLevel() <= min_energy
then
textutils.slowPrint("i am still hungry!")
end
-- repeat until you have put something in and fuel level is greater than 20
repeat
turtle.refuel()
until(turtle.getFuelLevel() > min_energy)
end
print("energy ", turtle.getFuelLevel())
textutils.slowPrint("i think i can have a try!")
end
print("working...")
height = 0
-- robot must be able to go back to ground
while true
do
turtle.digUp()
turtle.up()
height = height + 1
energy = turtle.getFuelLevel()
-- no logs anymore
if not turtle.detectUp()
then
break
-- consume logs
elseif energy == 0 and consume_ans
then
turtle.refuel(1)
-- go back
elseif height + 1 >= energy and not consume_ans
then
break
else
end
end
-- while going down, check all the things
while true
do
if energy == 0 and consume_ans
then
turtle.refuel(1)
end
detectInf, state = turtle.inspectDown()
if detectInf == true
then
if state.name == "minecraft:vine"
then
turtle.digDown()
else
break
end
end
turtle.down()
end
print("energy remains ", turtle.getFuelLevel())