Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --(( Settings ))--
- -- wether or not if the turtle should
- -- attack mobs if they are in their way
- local killMobs = true
- --
- local destroyBlocks = false
- -- apis to load, file path
- -- will be loaded in ascending order, top to bottom
- -- will ignore file extension when loading
- -- ex: 'dig.lua' can be refered as 'dig'
- local apis = {
- "dig.lua",
- "gps.lua",
- "farm.lua",
- "item.lua",
- }
- _G.oldAPISyntax = "_old"
- --(( Variables ))--
- -- the directory of the program running
- local programDir = shell.getRunningProgram() -- get the full path
- programDir = programDir:match("^.+/") or "" -- get the folder
- -- load apis
- --(( Functions ))--
- -- table input should be indexed by integers
- -- example input: {"john","brad","tony","steve"} ", " ", and "
- -- example output: "john, brad, tony, and steve"
- local function combine( t,seperator,lastSeperator )
- local str = ""
- for index,value in ipairs(t) do
- if index == 1 then
- str = str .. value
- elseif index > 1 and index < #t then
- str = str .. seperator .. value
- elseif index == #t then
- str = str .. lastSeperator .. value
- end
- end
- return str
- end
- local function loadAPIs( t )
- local failed = {} -- apis that failed to load
- -- loop through all apis
- for _,path in ipairs(apis) do
- local fullPath = programDir .. path
- local fileName = fs.getName(fullPath)-- remove directory
- local apiName = fileName
- apiName = apiName:match("^.+%.") or apiName.."." -- remove the file extension
- apiName = apiName:sub(0,-2) -- remove the dot at the end
- -- if its already loaded; unload it first
- --if _G[apiName] then
- -- os.unloadAPI(apiName)
- --end
- -- load api, move its global position
- local oldvar = _G[fileName]
- if os.loadAPI(fullPath) then
- -- in case theres an api already loaded
- if _G[apiName] ~= nil and _G[apiName.._G.oldAPISyntax]==nil then
- _G[apiName.._G.oldAPISyntax] = _G[apiName]
- end
- _G[apiName] = _G[fileName]
- else
- table.insert(failed,fullPath)
- end
- -- in case of overriding, reset
- _G[fileName] = oldvar
- -- give it functions
- if type(_G[apiName]) == "table" then
- if type(_G[apiName].init) == "function" then
- local state,err = pcall(_G[apiName].init,_G)
- if not state then print(apiName..": "..err)table.insert(failed,fullPath) end
- end
- end
- end
- if #failed == 1 then
- error("Unable to load API "..failed[1].."!",0)
- elseif #failed > 1 then
- error("Unable to load APIs "..combine(failed,", ",", and ").."!",0)
- end
- end
- function _G.mult( num )
- if num > 0 then return 1 end
- if num < 0 then return -1 end
- return 0
- end
- --(( Error checking ))--
- -- load apis
- loadAPIs()
- --(( Main program ))--
- print("main step 1")
- farm.setOffset( 3,4,1 )print("main step 2")
- farm.setSize( 7,-5,4 )print("main step 3")
- if not gps.autoSetPosition() then error("unable to locate position via gps",0) end print("main step 4")
- gps.setHome(245,60,-765,gps.east)print("main step 5")
- gps.goto(gps.getHome())
- item.addStoragePathCheckpoint(246,60,-765)
- item.addStoragePathCheckpoint(244,60,-765)
- item.setItemAccess(item.types.dirt,244,60,-766,gps.down)
- item.setItemAccess(item.types.sapling,244,60,-765,gps.down)
- item.setItemAccess(item.types.dropoff,244,60,-764,gps.down)
- --(( EOF ))--
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement