Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local success = false
- local data = nil
- local x = 0
- local y = 0
- local z = 0
- local facing = 0
- local dropx = 2
- local dropy = 9
- local dropz = 254
- local pathx = 7
- local refuelx = 3
- local refuely = 10
- local refuelz = 251
- local height = 0;
- ---------------------------------------
- -- 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 lightUp()
- redstone.setOutput("back", true)
- redstone.setOutput("right", true)
- redstone.setOutput("left", true)
- redstone.setOutput("top", true)
- redstone.setOutput("bottom", true)
- end
- 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 = 3
- elseif (x - tempx) == -1 then
- facing = 1
- else
- if (y - tempy) == 1 then
- facing = 2
- else
- facing = 4
- end
- end
- gb()
- changeFacing(1)
- end
- local function mx(n)
- if n > 0 then
- changeFacing(3)
- elseif n < 0 then
- changeFacing(1)
- 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(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 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
- gu()
- end
- end
- end
- local function dropOff()
- locate()
- mx(-math.abs(pathx-x))
- if y > dropy then
- my(-math.abs(dropy-y))
- elseif y < dropy then
- my(math.abs(dropy-y))
- end
- mz(dropz-z)
- locate()
- mx(math.abs(dropx-x))
- locate()
- changeFacing(1)
- end
- local function refuel()
- if turtle.getFuelLevel()<500 then
- print("Fuck")
- return
- 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:wood" then
- chopTree()
- end
- end
- calibrate()
- end
- local function findLog()
- repeat
- tl()
- success, data = turtle.inspect()
- until data.name == "minecraft:log"
- end
- local function chop2x2()
- data = nil
- repeat
- height = height - 1
- dd()
- gd()
- findLog()
- df()
- findLog()
- df()
- until height == 0
- gu()
- end
- local function chopTree()
- success, data = turtle.inspect()
- if data.name == "minecraft:log" then
- df()
- gf()
- while success do
- success, data = turtle.inspectUp()
- if data.name == "minecraft:log" then
- du()
- gu()
- height = height + 1
- else
- break
- end
- end
- success, data = turtle.inspect()
- if data.name == "minecraft:log" then
- df()
- gf()
- du()
- findLog()
- df()
- gf()
- du()
- findLog()
- df()
- gf()
- du()
- gb()
- else
- gd()
- height = height - 1
- success, data = turtle.inspect()
- if data.name == "minecraft:log" then
- df()
- gf()
- findLog()
- df()
- gf()
- findLog()
- df()
- end
- end
- if data.name == "minecraft:log" then
- chop2x2()
- else
- repeat
- gd()
- height = height - 1
- until height == 0
- end
- else
- print("No tree found")
- end
- end
- ---------------------------------------
- --------- MAIN ---------
- ---------------------------------------
- calibrate()
- dropOff()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement