SHOW:
|
|
- or go back to the newest paste.
| 1 | _G["gpi"] = {}
| |
| 2 | North,South,West,East,Invalid = 0,1,2,3,-1 | |
| 3 | gpi.direction = -1 | |
| 4 | gpi.location = {0,0,0}
| |
| 5 | function gpi.locate(x,y,z) | |
| 6 | if x == nil then | |
| 7 | x2, y2, z2 = gps.locate(5) | |
| 8 | if x2 then | |
| 9 | oldTForward() | |
| 10 | local x3, y3, z3 = gps.locate(5) | |
| 11 | if x3 then | |
| 12 | if x3 ~= x2 then | |
| 13 | if x3 > x2 then | |
| 14 | gpi.direction = 3 | |
| 15 | else | |
| 16 | gpi.direction = 2 | |
| 17 | end | |
| 18 | else | |
| 19 | if z3 ~= z2 then | |
| 20 | if z3 > z2 then | |
| 21 | gpi.direction = 1 | |
| 22 | else | |
| 23 | gpi.direction = -1 | |
| 24 | end | |
| 25 | else | |
| 26 | gpi.direction = -1 | |
| 27 | end | |
| 28 | end | |
| 29 | end | |
| 30 | end | |
| 31 | elseif y == nil then | |
| 32 | error("Error: 3 or 0 Coordinates required.")
| |
| 33 | end | |
| 34 | turtle.back() | |
| 35 | gpi.location[1] = x2 | |
| 36 | gpi.location[2] = y2 | |
| 37 | gpi.location[3] = z2 | |
| 38 | return x2, y2, z2, gpi.direction | |
| 39 | end | |
| 40 | oldTForward = turtle.forward | |
| 41 | gpi.locate() | |
| 42 | function gpi.forward() | |
| 43 | if turtle.getFuelLevel() == "unlimited" or turtle.getFuelLevel <= 1 then | |
| 44 | if gpi.direction > -1 and gpi.direction < 4 then | |
| 45 | if oldTForward() then | |
| 46 | if gpi.direction == 0 then | |
| 47 | gpi.location[3] = gpi.location[3] - 1 | |
| 48 | oldTForward() | |
| 49 | elseif gpi.direction == 1 then | |
| 50 | gpi.location[3] = gpi.location[3] + 1 | |
| 51 | oldTForward() | |
| 52 | elseif gpi.direction == 2 then | |
| 53 | gpi.location[1] = gpi.location[1] - 1 | |
| 54 | oldTForward() | |
| 55 | elseif gpi.direction == 3 then | |
| 56 | gpi.location[1] = gpi.location[1] + 1 | |
| 57 | oldTForward() | |
| 58 | end | |
| 59 | return gpi.location[1], gpi.location[2], gpi.location[3] | |
| 60 | else | |
| 61 | return false | |
| 62 | end | |
| 63 | else | |
| 64 | return false | |
| 65 | end | |
| 66 | else | |
| 67 | return false | |
| 68 | end | |
| 69 | end | |
| 70 | turtle.forward = gpi.forward | |
| 71 | ||
| 72 | function gpi.restore() | |
| 73 | turtle.forward = oldTForward | |
| 74 | turtle.back = oldTBack | |
| 75 | turtle.turnLeft = oldTLeft | |
| 76 | turtle.turnRight = oldTRight | |
| 77 | turtle.up = oldTUp | |
| 78 | turtle.down = oldTDown | |
| 79 | end | |
| 80 | ||
| 81 | oldTLeft = turtle.turnLeft | |
| 82 | function gpi.turnLeft() | |
| 83 | if gpi.direction > -1 and gpi.direction < 4 then | |
| 84 | if gpi.direction == 0 then | |
| 85 | gpi.direction = 2 | |
| 86 | oldTLeft() | |
| 87 | elseif gpi.direction == 1 then | |
| 88 | gpi.direction = 3 | |
| 89 | oldTLeft() | |
| 90 | elseif gpi.direction == 2 then | |
| 91 | gpi.direction = 1 | |
| 92 | oldTLeft() | |
| 93 | elseif gpi.direction == 3 then | |
| 94 | gpi.direction = 0 | |
| 95 | oldTLeft() | |
| 96 | end | |
| 97 | return gpi.direction | |
| 98 | else | |
| 99 | return false | |
| 100 | end | |
| 101 | end | |
| 102 | turtle.turnLeft = gpi.turnLeft | |
| 103 | oldTRight = turtle.turnRight() | |
| 104 | function gpi.turnRight() | |
| 105 | if gpi.direction > -1 and gpi.direction < 4 then | |
| 106 | if gpi.direction == 0 then | |
| 107 | gpi.direction = 3 | |
| 108 | oldTRight() | |
| 109 | elseif gpi.direction == 1 then | |
| 110 | gpi.direction = 2 | |
| 111 | oldTRight() | |
| 112 | elseif gpi.direction == 2 then | |
| 113 | gpi.direction = 0 | |
| 114 | oldTRight() | |
| 115 | elseif gpi.direciton == 3 then | |
| 116 | gpi.direction = 1 | |
| 117 | oldTRight() | |
| 118 | end | |
| 119 | return gpi.direction | |
| 120 | else | |
| 121 | return false | |
| 122 | end | |
| 123 | end | |
| 124 | turtle.turnRight = gpi.turnRight | |
| 125 | oldTBack = turtle.back | |
| 126 | function gpi.back() | |
| 127 | if turtle.getFuelLevel() == "unlimited" or turtle.getFuelLevel() >= 1 then | |
| 128 | if gpi.direction > -1 and gpi.direction < 4 then | |
| 129 | if oldTBack() then | |
| 130 | oldTBack() | |
| 131 | if gpi.direction == 0 then | |
| 132 | gpi.location[3] = gpi.location[3] + 1 | |
| 133 | elseif gpi.direction == 1 then | |
| 134 | gpi.location[3] = gpi.location[3] - 1 | |
| 135 | elseif gpi.direction == 2 then | |
| 136 | gpi.location[1] = gpi.location[1] + 1 | |
| 137 | elseif gpi.direction == 3 then | |
| 138 | gpi.location[1] = gpi.location[1] - 1 | |
| 139 | end | |
| 140 | return gpi.location[1], gpi.location[2], gpi.location[3] | |
| 141 | else | |
| 142 | return false | |
| 143 | end | |
| 144 | else | |
| 145 | return false | |
| 146 | end | |
| 147 | else | |
| 148 | return false | |
| 149 | end | |
| 150 | end | |
| 151 | turtle.back = gpi.back | |
| 152 | oldTUp = turtle.up | |
| 153 | function gpi.up() | |
| 154 | if turtle.getFuelLevel() == "unlimited" or turtle.getFuelLevel >= 1 then | |
| 155 | if gpi.direction > -1 and gpi.direction < 4 then | |
| 156 | if oldTUp() then | |
| 157 | oldTUp() | |
| 158 | gpi.location[2] = gpi.location[2] + 1 | |
| 159 | return gpi.location[1], gpi.location[2], gpi.location[3] | |
| 160 | else | |
| 161 | return false | |
| 162 | end | |
| 163 | else | |
| 164 | return false | |
| 165 | end | |
| 166 | else | |
| 167 | return false | |
| 168 | end | |
| 169 | end | |
| 170 | turtle.up = gpi.up | |
| 171 | oldTDown = turtle.down | |
| 172 | function gpi.down() | |
| 173 | if turtle.getFuelLevel() == "unlimited" or turtle.getFuelLevel >= 1 then | |
| 174 | if gpi.direction > -1 and gpi.direction < 4 then | |
| 175 | if oldTDown() then | |
| 176 | oldTDown() | |
| 177 | gpi.location[2] = gpi.location[2] - 1 | |
| 178 | return gpi.location[1], gpi.location[2], gpi.location[3] | |
| 179 | else | |
| 180 | return false | |
| 181 | end | |
| 182 | else | |
| 183 | return false | |
| 184 | end | |
| 185 | else | |
| 186 | return false | |
| 187 | end | |
| 188 | end | |
| 189 | turtle.down = gpi.down | |
| 190 | function gpi.getDirection() | |
| 191 | return gpi.direction | |
| 192 | end | |
| 193 | function gpi.setDirection(dire) | |
| 194 | if not tonumber(dire) then | |
| 195 | error("Error: Got "..type(dire)..". Number Or Compass Expected.")
| |
| 196 | end | |
| 197 | if dire > -1 and dire < 4 then | |
| 198 | if gpi.direction > -1 and gpi.direction < 4 then | |
| 199 | while gpi.direction ~= dire do | |
| 200 | gpi.turnLeft() | |
| 201 | end | |
| 202 | return direction | |
| 203 | else | |
| 204 | return false | |
| 205 | end | |
| 206 | else | |
| 207 | return false | |
| 208 | end | |
| 209 | end |