Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local x = 0
- local y = 0
- local z = 0
- local facing = 0
- local homex = -21
- local homey = 17
- local homez = 253
- local yupper = 45
- local xupper = 3
- local fuelSlot = 1
- local sapSlot = 2
- local success = false
- local data = nil
- waitTimer = 0
- local ready = true
- local loopCheck = true
- ---------------------------------------
- -- BASIC FUNCTIONS FOR TURTLE CONTROL -
- ---------------------------------------
- local function gf(n)
- if n==nil then
- n=1
- end
- for i=1,n,1 do
- turtle.forward()
- end
- end
- local function gb(n)
- if n==nil then
- n=1
- end
- for i=1,n,1 do
- turtle.back()
- end
- end
- local function gu(n)
- if n==nil then
- n=1
- end
- for i=1,n,1 do
- turtle.up()
- end
- end
- local function gd(n)
- if n==nil then
- n=1
- end
- for i=1,n,1 do
- turtle.down()
- end
- end
- local function tl()
- turtle.turnLeft()
- if facing == 1 then
- facing = 4
- else
- facing = facing - 1
- end
- end
- local function tr()
- turtle.turnRight()
- if facing == 4 then
- facing = 1
- else
- facing = facing + 1
- end
- end
- local function pf() turtle.place() end
- local function pu() turtle.placeUp() end
- local function pd() turtle.placeDown() end
- local function df() return turtle.dig() end
- local function du() turtle.digUp() end
- local function dd() turtle.digDown() end
- local function sf() turtle.suck() end
- local function su(n)
- if n==nil then
- while turtle.suckUp() do end
- else
- for i=1,n do
- turtle.suckUp()
- end
- end
- end
- local function sd(n)
- if n==nil then
- while turtle.suckDown() do end
- else
- for i=1,n do
- turtle.suckDown()
- end
- end
- end
- local function Df() turtle.drop() end
- local function Du() turtle.dropUp() end
- local function Dd(n)
- if n==nil then n=64 end
- turtle.dropDown(n)
- end
- local function ss(s) turtle.select(s) end
- local function cf() turtle.compare() end
- local function cu() turtle.compareUp() end
- ---------------------------------------
- -- Building Blocks --
- ---------------------------------------
- local function locate()
- x,y,z = gps.locate(5)
- if not x then
- print("Failed to get my location!")
- else
- print("I am at (" .. x .. ", " .. y .. ", " .. z .. ")")
- end
- end
- local function refuel()
- if turtle.getFuelLevel()<80 then
- ss(fuelSlot)
- turtle.refuel(1)
- end
- end
- local function changeFacing(goal)
- while facing ~= goal do
- tl()
- end
- end
- local function calibrate()
- locate()
- local tempx = x
- local tempy = y
- gf()
- locate()
- if (x - tempx) == 1 then
- facing = 2
- elseif (x - tempx) == -1 then
- facing = 4
- else
- if (y - tempy) == 1 then
- facing = 1
- else
- facing = 3
- end
- end
- gb()
- changeFacing(1)
- end
- local function mx(n)
- if n > 0 then
- changeFacing(2)
- elseif n < 0 then
- changeFacing(4)
- n = n*-1
- end
- for i=1,n do
- --if turtle.detect() then
- --df()
- --end
- gf()
- end
- end
- local function my(n)
- if n > 0 then
- changeFacing(1)
- elseif n < 0 then
- changeFacing(3)
- n = n*-1
- end
- for i=1,n do
- --if turtle.detect() then
- --df()
- --end
- gf()
- end
- end
- local function mz(n)
- if n > 0 then
- for i=1,n do
- if turtle.detectUp() then
- du()
- end
- gu()
- end
- elseif n < 0 then
- for i=1,-n do
- if turtle.detectDown() then
- dd()
- end
- gd()
- end
- end
- end
- local function home()
- mz(10)
- locate()
- if x > homex then
- mx(-math.abs(homex-x))
- elseif x < homex then
- mx(math.abs(homex-x))
- end
- if y > homey then
- my(-math.abs(homey-y))
- elseif y < homey then
- my(math.abs(homey-y))
- end
- if z > homez then
- mz(-math.abs(homez-z))
- elseif z < homez then
- mz(math.abs(homez-z))
- end
- locate()
- ready = true
- changeFacing(1)
- loopCheck = false
- end
- local function refuel()
- if turtle.getFuelLevel()<500 then
- print("Fuck")
- end
- end
- local function checkFull()
- --TODO:Drop off when full
- end
- local function checkSaps()
- --TODO:Go back for saplings
- end
- local function tempReload()
- --TODO: Write a reload function
- end
- local function calibrate2()
- success, data = turtle.inspect()
- if success then
- if data.name == "minecraft:log" then
- chopTree()
- end
- end
- calibrate()
- end
- local function chopTree()
- waitTimer = 0
- success,data = turtle.inspect()
- while data.name ~= "minecraft:log" do
- os.sleep(5)
- if data.name == "minecraft:sapling" then
- waitTimer = waitTimer + 1
- if waitTimer > 4 then
- break
- end
- end
- success,data = turtle.inspect()
- print(waitTimer)
- end
- if data.name == "minecraft:log" then
- df()
- gf()
- while success do
- success,data = turtle.inspectUp()
- if data.name == "minecraft:log" then
- du()
- gu()
- z = z + 1
- else
- break
- end
- end
- for i=z,homez+2,-1 do
- gd()
- end
- ss(sapSlot)
- pd()
- else
- gu()
- gf()
- end
- z = homez
- end
- local function nextTree()
- locate()
- if y == yupper then
- if x == xupper then
- home()
- else
- tr()
- end
- elseif y == (homey + 4) then
- if x ~= homex then
- tl()
- end
- end
- if turtle.detect() then
- df()
- end
- gf()
- gd()
- gf()
- gf()
- end
- ---------------------------------------
- --------- MAIN ---------
- ---------------------------------------
- calibrate2()
- while loopCheck do
- nextTree()
- chopTree()
- refuel()
- checkFull()
- checkSaps()
- end
- gb()
- gb()
- gb()
- gb()
Advertisement
Add Comment
Please, Sign In to add comment