 # Wither_builder

Nov 1st, 2014
391
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. rednet.open("right")
2.
3. xH = -175
4. yH = 15
5. zH = 539
6. homeFace = 1
7.
8. function compass()
9.     x,y,z = gps.locate()
10.     while turtle.forward() == false do
11.         turtle.turnRight()
12.     end
13.     x1,y1,z1 = gps.locate()
14.     direction = {x = x - x1, y = y - y1, z = z - z1}
15.     for k,v in pairs( direction ) do
16.         if k == "x" and v == 1 then
17.             facing = 1 -- west
18.         elseif k == "x" and v == -1 then
19.             facing = 3 -- east
20.         elseif k == "z" and v == 1 then
21.             facing = 2 -- north
22.         elseif k == "z" and v == -1 then
23.             facing = 0 -- south
24.         end
25.     end
26.     turtle.back()
27.     return facing
28. end
29.
30. function goHome()
31. while true do
32.     xL,yL,zL = gps.locate()
33.     print(yL)
34.     print(yH)
35.     x = xL - xH
36.     y = yL - yH
37.     z = zL - zH
38.     if y > 0 then
39.         turtle.down()
40.     elseif y < 0 then
41.         turtle.up()
42.     elseif z < 0 then
43.         currentDir = compass()
44.         if currentDir ~= 0 then
45.             turnTo(0)
46.         end
47.         while turtle.forward() == false do
48.             turtle.select(4)
49.             turtle.dig()
50.             turtle.forward()
51.             turtle.forward()
52.             turtle.turnRight()
53.             turtle.turnRight()
54.             turtle.place()
55.             turtle.turnRight()
56.             turtle.turnRight()
57.         end
58.     elseif z > 0 then
59.         currentDir = compass()
60.         if currentDir ~= 2 then
61.             turnTo(2)
62.         end
63.         while turtle.forward() == false do
64.             turtle.select(4)
65.             turtle.dig()
66.             turtle.forward()
67.             turtle.forward()
68.             turtle.turnRight()
69.             turtle.turnRight()
70.             turtle.place()
71.             turtle.turnRight()
72.             turtle.turnRight()
73.         end
74.     elseif x < 0 then
75.         currentDir = compass()
76.         if currentDir ~= 3 then
77.             turnTo(3)
78.         end
79.         while turtle.forward() == false do
80.             turtle.select(4)
81.             turtle.dig()
82.             turtle.forward()
83.             turtle.forward()
84.             turtle.turnRight()
85.             turtle.turnRight()
86.             turtle.place()
87.             turtle.turnRight()
88.             turtle.turnRight()
89.         end
90.     elseif x > 0 then
91.         currentDir = compass()
92.         if currentDir ~= 1 then
93.             turnTo(1)
94.         end
95.         while turtle.forward() == false do
96.             turtle.select(4)
97.             turtle.dig()
98.             turtle.forward()
99.             turtle.forward()
100.             turtle.turnRight()
101.             turtle.turnRight()
102.             turtle.place()
103.             turtle.turnRight()
104.             turtle.turnRight()
105.         end
106.     else
107.         break
108.     end
109. end
110. end
111.
112.
113. function turnTo(Int)
114.     if facing ~= Int then
115.         local current = facing - Int
116.         if current < 0 then
117.             for i = 1, math.abs(current) do
118.                 turtle.turnRight()
119.             end
120.         else
121.             for i = 1,current do
122.             turtle.turnLeft()
123.             end
124.         end
125.     end
126. end
127.
128. goHome()
129. compass()
130. turnTo(homeFace)
131. while true do
132.   event, p1, p2 = os.pullEvent("rednet_message")
133.   if p1 == 33 and p2 == true then
134.     goHome()
135.     print("got home")
136.     compass()
137.     turnTo(homeFace)
138.     sleep(.5)
139.     event = os.pullEvent("redstone")
140.     for i = 1,2 do
141.       turtle.forward()
142.     end
143.     turtle.select(4)
144.     turtle.dig()
145.     turtle.forward()
146.     turtle.forward()
147.     turtle.turnRight()
148.     turtle.turnRight()
149.     turtle.place()
150.     turtle.turnRight()
151.     turtle.turnRight()
152.     turtle.down()
153.     turtle.select(1)
154.     turtle.place()
155.     turtle.up()
156.     turtle.turnRight()
157.     turtle.forward()
158.     turtle.turnLeft()
159.     turtle.place()
160.     for i = 1, 2 do
161.       turtle.turnLeft()
162.       turtle.forward()
163.       turtle.turnRight()
164.       turtle.place()
165.     end
166.     turtle.up()
167.     turtle.select(2)
168.     turtle.place()
169.     for i = 1,2 do
170.       turtle.turnRight()
171.       turtle.forward()
172.       turtle.turnLeft()
173.       turtle.place()
174.     end
175.     turtle.down()
176.     turtle.turnLeft()
177.     turtle.forward()
178.     turtle.turnLeft()
179.     turtle.select(4)
180.     turtle.dig()
181.     turtle.forward()
182.     turtle.forward()
183.     turtle.turnRight()
184.     turtle.turnRight()
185.     turtle.place()
186.     turtle.turnRight()
187.     turtle.turnRight()
188.     for i = 1,4 do
189.       turtle.forward()
190.     end
191.     turtle.turnRight()
192.     turtle.turnRight()
193.     turtle.select(3)
194.     turtle.refuel(1)
195.     sleep(11)
196.   else
197.     sleep(0.1)
198.   end
199. end
RAW Paste Data