Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local forwardVector = {
- [0] = vec.new( 0, 0, -1),
- [1] = vec.new( 1, 0, 0),
- [2] = vec.new( 0, 0, 1),
- [3] = vec.new(-1, 0, 0)
- }
- local upVector = vec.new(0, 1, 0)
- local stringToDir = {
- ["north"] = 0,
- ["west "] = 1,
- ["south"] = 2,
- ["east "] = 3
- }
- local dirToString = {
- [0] = "north",
- [1] = "west",
- [2] = "south",
- [3] = "east",
- }
- local pos = vec.new()
- local dir = 0
- local refuelLimit = 500
- local nop = function() end
- --MAYBE CHANGE
- local function slotHasFuel(n)
- local s = turtle.getItemDetail(n)
- if s ~= nil then
- return s.name:find("coal" ) ~= nil or
- s.name:find("wood" ) ~= nil or
- s.name:find("log" ) ~= nil or
- s.name:find("blaze_rod") ~= nil or
- s.name:find("lava" ) ~= nil or
- s.name == "minecraft:stick"
- else
- return false
- end
- end
- function refuel(force)
- if force == nil then force = false end
- local s = false
- if turtle.getFuelLevel() < refuelLimit or force then
- local oldSlot = turtle.getSelectedSlot()
- for i = 1, 16 do
- if slotHasFuel(i) then
- turtle.select(i)
- turtle.refuel(64)
- s = true
- end
- end
- turtle.select(oldSlot)
- end
- --CHANGE THIS
- -- if s == false then
- -- os.queueEvent("noFuel")
- -- end
- return s
- end
- function setPos(x, y, z)
- pos:change(x, y, z)
- end
- function setPosGPS()
- local s = vec.fromGPS()
- if s == nil then return false end
- setPos(s)
- return true
- end
- function getPos()
- return pos
- end
- function setDir(d)
- dir = d % 4
- end
- function getDir()
- return dir
- end
- function setRefuelLimit(n)
- refuelLimit = n
- end
- function getRefuelLimit()
- return refuelLimit
- end
- local dirMap = {
- [0] = 0,
- [1] = 1,
- [2] = 2,
- [3] = -1
- }
- function face(d)
- if type(d) == "string" then
- d = stringToDir[d:lower()]
- assert(d ~= nil, "Unexpected direction. Use either 'North', 'West', 'South', or 'East.'")
- end
- d = d % 4
- rt(dirMap[(d - dir) % 4])
- end
- function rt(n, func)
- if not n then n = 1 end
- if not func then func = nop end
- if n < 0 then return lt(-n, func) end
- local i = 0
- while i < n or n == 0 do
- if func(i) then break end
- turtle.turnRight()
- dir = (dir + 1) % 4
- i = i + 1
- end
- return i
- end
- function lt(n, func)
- if not n then n = 1 end
- if not func then func = nop end
- if n < 0 then return rt(-n, func) end
- local i = 0
- while i < n or n == 0 do
- if func(i) then break end
- turtle.turnLeft()
- dir = (dir - 1) % 4
- i = i + 1
- end
- return i
- end
- function fd(n, func, canBreak)
- if not n then n = 1 end
- if not func then func = nop end
- if n < 0 then return bk(-n, func) end
- if canBreak == nil then canBreak = true end
- local i = 0
- while i < n or n == 0 do
- if func(i) then break end
- refuel()
- if not turtle.forward() then
- if canBreak then
- repeat until not turtle.dig()
- if not turtle.forward() then break end
- else
- break
- end
- end
- pos = pos + forwardVector[dir]
- i = i + 1
- end
- return i
- end
- function bk(n, func)
- if not n then n = 1 end
- if not func then func = nop end
- if n < 0 then return fd(-n, func) end
- local i = 0
- while i < n or n == 0 do
- if func(i) then break end
- refuel()
- if not turtle.back() then break end
- pos = pos - forwardVector[dir]
- i = i + 1
- end
- return i
- end
- function up(n, func, canBreak)
- if not n then n = 1 end
- if not func then func = nop end
- if n < 0 then return dn(-n, func) end
- if canBreak == nil then canBreak = true end
- local i = 0
- while i < n or n == 0 do
- if func(i) then break end
- refuel()
- if not turtle.up() then
- if canBreak then
- repeat until not turtle.digUp()
- if not turtle.up() then break end
- else
- break
- end
- end
- pos = pos + upVector
- i = i + 1
- end
- return i
- end
- function dn(n, func, canBreak)
- if not n then n = 1 end
- if not func then func = nop end
- if n < 0 then return up(-n, func) end
- if canBreak == nil then canBreak = true end
- local i = 0
- while i < n or n == 0 do
- if func(i) then break end
- refuel()
- if not turtle.down() then
- if canBreak then
- repeat until not turtle.digDown()
- if not turtle.down() then break end
- else
- break
- end
- end
- pos = pos - upVector
- i = i + 1
- end
- return i
- end
- function insFd()
- return {turtle.inspect()}
- end
- function insUp()
- return {turtle.inspectUp()}
- end
- function insDn()
- return {turtle.inspectDown()}
- end
- atkFd = turtle.attack
- atkUp = turtle.attackUp
- atkDn = turtle.attackDown
- digFd = turtle.dig
- digUp = turtle.digUp
- digDn = turtle.digDown
- plcFd = turtle.place
- plcUp = turtle.placeUp
- plcDn = turtle.placeDown
- dctFd = turtle.detect
- dctUp = turtle.detectUp
- dctDn = turtle.detectDown
- cmpFd = turtle.compare
- cmpUp = turtle.compareUp
- cmpDn = turtle.compareDown
- sucFd = turtle.suck
- sucUp = turtle.suckUp
- sucDn = turtle.suckDown
- drpFd = turtle.drop
- drpUp = turtle.dropUp
- drpDn = turtle.dropDown
- getFuelLevel = turtle.getFuelLevel
- select = turtle.select
- getSelectedSlot = turtle.getSelectedSlot
- getItemDetail = turtle.getItemDetail
- transferTo = turtle.transferTo
- equipLeft = turtle.equipLeft
- equipRight = turtle.equipRight
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement