Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("inv")
- os.loadAPI("t")
- local COAL = "coal"
- local CHAR = "char"
- local STARTX =
- local STARTY =
- local STARTZ =
- function round(exact)
- quantum = 1
- local quant,frac = math.modf(exact/quantum)
- return quantum * (quant + (frac > 0.5 and 1 or 0))
- end
- function refuelIfNeeded()
- local fuelLevel = turtle.getFuelLevel()
- if fuelLevel < 70 then
- print("Fuel level is " .. fuelLevel .. ", refueling...")
- if inv.selectItem(COAL) then
- turtle.refuel(1)
- print("Refueled! new level is " .. turtle.getFuelLevel())
- return true
- end
- printError("No fuel in inventory!")
- end
- return false
- end
- turtle.turnLeft()
- local x,y,z = gps.locate(15)
- x = round(x)
- y = round(y)
- z = round(z)
- print(x,y,z)
- t.fw()
- local newX, newY, newZ = gps.locate(15)
- t.back()
- newX = round(newX)
- newY = round(newY)
- newZ = round(newZ)
- if x > newX then
- turtle.turnLeft()
- turtle.turnLeft()
- end
- if z > newZ then
- turtle.turnRight()
- elseif z < newZ then
- turtle.turnLeft()
- end
- local difx = math.abs(x - STARTX)
- local dify = math.abs(y - STARTY)
- local difz = math.abs(z - STARTZ)
- print(difx,dify,difz)
- if x > STARTX then
- turtle.turnLeft()
- turtle.turnLeft()
- t.fw(difx)
- turtle.turnLeft()
- turtle.turnLeft()
- elseif x < STARTX then
- t.fw(difx)
- end
- if z > STARTZ then
- turtle.turnLeft()
- t.fw(difz)
- turtle.turnRight()
- elseif z < STARTZ then
- turtle.turnRight()
- t.fw(difz)
- turtle.turnLeft()
- end
- turtle.turnLeft()
Add Comment
Please, Sign In to add comment