View difference between Paste ID: WB4bd0Wb and mWMv7rtr
SHOW: | | - or go back to the newest paste.
1
local tArgs = {...}
2
3
if #tArgs ~= 7 then
4
	print("Not enough Arguments")
5
	error()
6
end
7
8
if tArgs[4] ~= "north" or tArgs[4] ~= "east" or tArgs[4] ~= "south" or tArgs[4] ~= "west" then
9
	print("Argument 4 must be = north, east, south or west.")
10
	error()
11
end
12
13
local cDir = tArgs[4]
14
local cX = tonumber(tArgs[1])
15
local cY = tonumber(tArgs[2])
16
local cZ = tonumber(tArgs[3])
17
18
function turnRight()
19
  if cDir == "north" then
20
    cDir = "east"
21
  elseif cDir == "east" then
22
    cDir = "south"
23
  elseif cDir == "south" then
24
    cDir = "west"
25
  elseif cDir == "west" then
26
    cDir = "north"
27
  else
28
    print("Error!!")
29
	error()
30
  end
31
  turtle.turnRight()
32
end
33
34
function turnLeft()
35
	if cDir == "north" then
36
		cDir = "west"
37
	elseif cDir == "east" then
38
		cDir = "north"
39
	elseif cDir == "south" then
40
		cDir = "east"
41
	elseif cDir == "west" then
42
		cDir = "south"
43
	else
44
		print("Error!!")
45
		error()
46
	end
47
	turtle.turnLeft()
48
end
49
50
function turnTo(dir)
51
  if cDir ~= dir then
52
    repeat
53
     turnRight()
54
    until cDir == dir
55
  end
56
end
57
58
function moveForward()
59
  if cDir == "north" then
60
    cZ = cZ-1
61
  elseif cDir == "east" then
62
    cX = cX+1 
63
  elseif cDir == "south" then
64
    cZ = cZ+1
65
  elseif cDir == "west" then
66
    cX = cX-1
67
  else
68
    print("Error!!")
69
	error()
70
  end
71
  while not turtle.forward() do
72
    turtle.dig()
73
  end
74
end
75
76
function moveUp()
77
  cY = cY+1
78
  while not turtle.up() do
79
    turtle.digUp()
80
  end
81
end
82
83
function moveDown()
84
  cY = cY-1
85
  while not turtle.down() do
86
    turtle.digDown()
87
  end
88
end
89
    
90
function moveToX(x)
91
  if cX < x then
92
    turnTo("east")
93
    repeat
94
      moveForward()
95
    until cX == x 
96
  elseif cX > x then
97
    turnTo("west")
98
    repeat
99
      moveForward()
100
    until cX == x 
101
  else
102
    --print("already there")
103
  end
104
end
105
106
function moveToZ(z)
107
  if cZ < z then
108
    turnTo("south")
109
    repeat
110
      moveForward()
111
    until cZ == z 
112
  elseif cZ > z then
113
    turnTo("north")
114
    repeat
115
      moveForward()
116
    until cZ == z
117
  else
118
   --print("already there")
119
  end
120
end     
121
122
function moveToY(y)
123
  if cY < y then
124
    repeat
125
      moveUp()
126
    until cY == y
127
  elseif cY > y then
128
    repeat
129
      moveDown()
130
    until cY == y
131
  else
132
   --print("already there")
133
  end
134
end
135
136
function goTo(x, y, z)
137
  moveToX(x)  
138
  moveToY(y)
139
  moveToZ(z)
140
  turnTo("north")
141
end
142
143
goTo(tonumber(tArgs[5]), tonumber(tArgs[6]), tonumber(tArgs[7]))