Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- X+(0)
- ^
- Z-(3) < Turtle > Z+(1)
- v
- X-(2)
- ]]--
- x = 0
- y = 0
- z = 0
- dir = 0
- autoFuel = false --refuels using picked up fuel items (eg. coal + wood)
- allowDrain = false --allow turtle to take directions even if there is not enough fuel
- hardFuelLimit = false --dont allow turtle to refuel if the next fuel item exceeds limit (will stop using items after cap is reached regardless of this option, allow autofuel + allowDrain for trips exceeding fuel limit)
- --[[ END OF VARIABLES ]]--
- fuel = turtle.getFuelLevel()
- needsFuel = true
- if (fuel == "unlimited") then
- needsFuel = false
- autoFuel = false
- allowDrain = true
- else
- fuelLim = turtle.getFuelLimit()
- end
- function align(toward)
- for i=1, math.abs(toward - dir) do
- if (toward < dir) then
- turtle.turnLeft()
- dir = (dir + 3) % 4
- else
- turtle.turnRight()
- dir = (dir + 1) % 4
- end
- end
- end
- function distTo(destX, destY, destZ)
- return math.abs(destX - x) + math.abs(destY - y) + math.abs(destZ - z)
- end
- function refuel(amount)
- fuel = turtle.getFuelLevel()
- total = fuel + amount
- for i=1, 16 do
- turtle.select(i)
- turtle.refuel(1)
- fuelVal = turtle.getFuelLevel() - fuel
- if (fuelVal > 0) then
- turtle.refuel(math.min(64,math.ceil(math.min(fuelLim, (amount - fuelVal)) / fuelVal)))
- fuel = turtle.getFuelLevel()
- amount = total - fuel
- if (amount <= 0) then
- return true
- end
- end
- end
- return false
- end
- function dig(toward, spaces)
- spaces = spaces or 1
- align(toward)
- for i=1, spaces do
- while not (turtle.forward()) do
- turtle.dig()
- turtle.attack()
- end
- if (dir == 0) then
- x = x + 1
- elseif (dir == 1) then
- z = z + 1
- elseif (dir == 2) then
- x = x - 1
- elseif (dir == 3) then
- z = z - 1
- end
- end
- end
- function digTo(newX, newY, newZ)
- xDist = newX - x
- yDist = newY - y
- zDist = newZ - z
- if (xDist > 0) then
- align(0)
- elseif (xDist < 0) then
- align(2)
- end
- dig(dir, math.abs(xDist))
- if (zDist > 0) then
- align(1)
- elseif (zDist < 0 ) then
- align(3)
- end
- dig(dir, math.abs(zDist))
- for i=1, math.abs(yDist) do
- if (yDist > 0) then
- while not (turtle.up()) do
- turtle.digUp()
- turtle.attackUp()
- end
- y = y + 1
- elseif (yDist < 0) then
- while not (turtle.down()) do
- turtle.digDown()
- turtle.attackDown()
- end
- y = y - 1
- end
- end
- return true
- end
- function digSquare(corner, width, length)
- --[[ corner values, width is always x, length is always z
- 3----0
- | |
- 2----1
- ]]--
- if (corner == 0 or corner == 1) then
- align(3)
- elseif (corner == 2 or corner == 3) then
- align(1)
- else
- return 0
- end
- for i=1, length do
- if (i ~= 1) then
- if (i % 2 == corner % 2) then
- align(dir - 1)
- dig(dir)
- align(dir - 1)
- else
- align(dir + 1)
- dig(dir)
- align(dir + 1)
- end
- end
- dig(dir, width - 1)
- end
- end
- function digCube(corner, width, length, depth)
- for i=1, depth do
- digSquare(corner, width, length)
- digTo(x, y-1, z)
- align(0)
- if (length % 2 == 1) then
- corner = (corner + 2) % 4
- else
- corner = (corner + 1) - 2 * (corner % 2)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment