coupe.lua

a guest
Feb 19th, 2020
92
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. saplings = 1 -- the slot where the saplings are
2. charbon = 2
3. bois=3
4. coffre=4
5. home=vector.new(-668,65,-1)
6.
7. function goTo(x,y,z)
8.     local position = vector.new(gps.locate(2))
9.     local home = vector.new(x,y,z)
10.     local deplacement = home:sub(position)
11.     local move = home:sub(vector.new(gps.locate(2)))
12.
13.     while move.y > 0 do
14.         turtle.up()
15.         move = home:sub(vector.new(gps.locate(2)))
16.     end
17.
18.     turtle.forward()
19.     move = home:sub(vector.new(gps.locate(2)))
20.     if math.abs(deplacement.x) - math.abs(move.x) == 0 then
21.         turtle.back()
22.         turtle.turnLeft()
23.         turtle.forward()
24.         move = home:sub(vector.new(gps.locate(2)))
25.     end
26.     if math.abs(deplacement.x) - math.abs(move.x) == -1 then
27.         turtle.turnLeft()
28.         turtle.turnLeft()
29.     end
30.     while math.abs(home:sub(vector.new(gps.locate(2))).x) > 0 do
31.         if not turtle.forward() then
32.             turtle.up()
33.         end
34.     end
35.
36.     turtle.turnLeft()
37.     turtle.forward()
38.     move = home:sub(vector.new(gps.locate(2)))
39.     if math.abs(deplacement.z) - math.abs(move.z) == -1 then
40.         turtle.turnLeft()
41.         turtle.turnLeft()
42.     end
43.     while math.abs(home:sub(vector.new(gps.locate(2))).z) > 0 do
44.         turtle.forward()
45.     end
46.
47.     move = home:sub(vector.new(gps.locate(2)))
48.     while move.y < 0 do
49.         turtle.down()
50.         move = home:sub(vector.new(gps.locate(2)))
51.     end
52. end
53.
54.
55. function recupSaplings()
56.     turtle.turnLeft()
57.     turtle.select(saplings)
58.     turtle.suck(64-turtle.getItemCount(saplings))
59.     turtle.turnRight()
60. end
61.
62. function reEnergy()
63.     turtle.select(charbon)
64.     turtle.suckDown(64-turtle.getItemCount(charbon))
65.     if turtle.getFuelLevel() < 800 then
66.         turtle.refuel()
67.     end
68.     if turtle.getFuelLevel() < 100 then
69.         print('No much fuel !')
70.         os.shutdown()
71.     end
72.     turtle.select(saplings)
73. end
74.
75. function pose()
76.     turtle.select(bois)
77.     turtle.drop(turtle.getItemCount(bois)-1)
78.     turtle.select(saplings)
79. end
80.
81.
82. function oriente()
83.     turtle.select(saplings)
84.     while not turtle.compare() do
85.         turtle.turnRight()
86.     end
87.     turtle.turnLeft()
88. end
89.
90.
91. function init()
92.     goTo(home.x,home.y,home.z)
93.     oriente()
94.
95.     turtle.select(saplings) -- select the saplings
96.     while turtle.getItemCount(saplings) > 0 do -- while more saplings in inventory
97.         turtle.select(coffre)
98.         turtle.turnLeft()
99.         if turtle.compare() then
100.             reEnergy()
101.             pose()
102.         end
103.         turtle.turnRight()
104.         turtle.select(saplings)
105.         for i = 1, 5 do -- plant 5 saplings in a row
106.             turtle.turnRight()
107.             if not turtle.compare() then -- if not a sapling, then a tree grew
108.                 turtle.dig()
109.                 turtle.forward()
110.                 turtle.select(bois)
111.                 while turtle.compareUp() do -- dig tree out
112.                     turtle.digUp()
113.                     turtle.up()
114.                 end
115.                 turtle.select(saplings)
116.                 while not turtle.detectDown() do -- back down to ground
117.                     turtle.down()
118.                 end
119.                 turtle.back()
120.                 turtle.place() -- put down new sapling
121.             end
122.             turtle.turnLeft()
123.             turtle.forward()
124.         end
125.
126.         turtle.turnRight()
127.         turtle.forward()
128.         turtle.forward()
129.         turtle.forward()
130.         turtle.turnRight()
131.         turtle.forward()
132.
133.         for i = 1, 5 do -- plant 5 saplings in a row
134.             turtle.turnLeft()
135.             if not turtle.compare() then -- if not a sapling, then a tree grew
136.                 turtle.dig()
137.                 turtle.forward()
138.                 turtle.select(bois)
139.                 while turtle.compareUp() do -- dig tree out
140.                     turtle.digUp()
141.                     turtle.up()
142.                 end
143.                 turtle.select(saplings)
144.                 while not turtle.detectDown() do -- back down to ground
145.                     turtle.down()
146.                 end
147.                 turtle.back()
148.                 turtle.place() -- put down new sapling
149.             end
150.             turtle.turnRight()
151.             turtle.forward()
152.         end
153.         turtle.turnRight()
154.         turtle.forward()
155.         recupSaplings()
156.         turtle.forward()
157.         turtle.forward()
158.         turtle.turnRight()
159.         turtle.forward()
160.         os.sleep(180) -- sleep for 60 seconds to allow trees to grow
161.     end
162. end
RAW Paste Data