Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Script by Savage_Me55iah of CraftAU.com.au and Nuqube.co--
- local version, pastebinCode = "v1.5", "bCnEcEma"
- --Other Savage_Me55iah scripts @ http://pastebin.com/u/Savage_Me55iah
- --INSTRUCTIONS ON USE--
- --Instruction video on http://youtube.com/savagemessiah5
- --Contact Savage_Me55iah @ CraftAU.com.au or Nuqube.co or http://www.computercraft.info/forums2/ with suggestions/fixes/bugs
- -- CHANGELOG --
- --V1.0
- --V1.1 - Complete rewrite to run smoother
- --V1.2 - PneumaticCraft plants support added
- --V1.3 - Rewritten to flexibly support different mods/plants, section under plant data
- --v1.4 - Bug fixes
- --v1.5 - Restart from pause
- --v1.5 - Added Chococraft & Witchery mod compatable
- -- SETUP --
- local pause = false
- local grown = false
- label = os.getComputerLabel() or false
- if label == false then
- print("Please Type label here: ")
- os.setComputerLabel(tostring(read()))
- end
- function boolean_check(params)
- local answer = nil
- if tostring(params) == "true" then
- answer = true
- else
- answer = false
- end
- return answer
- end
- local settings_file = "config"
- local settings_template = [[-- adjust these configuration options as necessary.
- -- IMPORTANT!, API won't load if there are spaces in the values
- COMPUTER_LABEL = "${label}"
- COMPUTER_ID = ${id}
- TYPES = ${types}
- USE_ROWS = "${use_rows}"
- TIMER_1 = ${timer_1}
- TIMER_MAX = ${timer_max}
- TIMER_MIN = ${timer_min}
- FIRST_RUN = "${first_run}"
- ]]
- local function interpolate(s, params)
- return s:gsub('($%b{})', function(w) return params[w:sub(3, -2)] or w end)
- end
- do
- save_settings = function()
- local filehandler = fs.open(tostring(settings_file), "w")
- if tostring(CONFIG) == "nil" then
- settings = {
- label = os.getComputerLabel(),
- id = os.getComputerID(),
- types = 7,
- use_rows = "true",
- timer_1 = 100,
- timer_max = 400,
- timer_min = 100,
- first_run = "true"
- }
- else
- settings = {
- label = CONFIG.COMPUTER_LABEL or os.getComputerLabel(),
- id = os.getComputerID(),
- types = CONFIG.TYPES or 7,
- use_rows = CONFIG.USE_ROWS or "true",
- timer_1 = CONFIG.TIMER_1 or 100,
- timer_max = CONFIG.TIMER_MAX or 400,
- timer_min = CONFIG.TIMER_MIN or 100,
- first_run = CONFIG.FIRST_RUN or "true"
- }
- end
- filehandler.write(interpolate(settings_template, settings))
- filehandler.close()
- end
- end
- if fs.exists(settings_file) == false then
- save_settings()
- return
- else
- os.unloadAPI(settings_file)
- if os.loadAPI(settings_file) == false then print("ERROR: Could not load the settings file!") end
- CONFIG = nil
- for k, v in pairs(_G) do
- if k == settings_file then CONFIG = v break end
- end
- if CONFIG == nil then log_add("CONFIG came up nil", true) end
- end
- local current = 2
- local home_param = false
- local x = 1
- local tArgs = {...}
- local update = tostring(tArgs[1]) or nil
- -- PLANT DATA --
- local plants = {}
- function plant_add(mod, dir, meta, drop, stk, replant)
- local num = table.maxn(plants) + 1
- plants[num] = {
- ["mod"] = mod,
- ["dir"] = dir,
- ["meta"] = meta,
- ["drop"] = drop,
- ["stk"] = stk,
- ["replant"] = replant
- }
- end
- plant_add("pneumaticcraft:", "down", {[6] = true, [13] = true}, "true", 16, true)
- plant_add("pneumaticcraft:heliumplant", "up", {[6] = true, [13] = true}, "true", 16, true)
- plant_add("minecraft:", "down", {[7] = true}, "false", 16, true)
- plant_add("minecraft:nether_wart", "down", {[3] = true}, "false", 16, true)
- plant_add("minecraft:pumpkin", "down", {[0] = true, [1] = true, [2] = true, [3] = true, [4] = true}, "false", 16, false)
- plant_add("minecraft:pumpkin_stem", "down", {[7] = false}, "false", 16, false)
- plant_add("minecraft:melon", "down", {[0] = true}, "false", 16, false)
- plant_add("minecraft:melon_stem", "down", {[7] = false}, "false", 16, false)
- --plant_add("minecraft:reeds", "down", {[0] = true}, "false", 16, false)
- --plant_add("minecraft:cactus", "down", {[0] = true}, "false", 16, false)
- plant_add("magicalcrops:", "down", {[7] = true}, "false", 16, true)
- plant_add("thaumcraft:", "down", {[7] = true}, "false", 16, true)
- plant_add("thaumcraft:blockmanapod", "up", {[7] = true}, "false", 16, true)
- plant_add("thaumcraft:itemmanabean", "up", {[7] = true}, "false", 16, true)
- plant_add("harvestcraft:", "down", {[7] = true}, "false", 16, true)
- plant_add("extrautilities:", "down", {[7] = true}, "false", 16, true)
- plant_add("natura:n crops", "down", {[3] = true, [8] = true}, "false", 16, true)
- plant_add("witchery:", "down", {[4] = true}, "false", 16, true)
- plant_add("chococraft:", "down", {[4] = true}, "false", 64, true)
- plant_add("ExtraUtilities:plant/ender_lilly", "down", {[7] = true}, "false", 16, true)
- -- COMMANDS --
- function drop_off(loc, num)
- local param, num = nil, num or 64
- if loc then param = not turtle.dropUp(num) else param = not turtle.dropDown(num) end
- return param
- end
- function mv_f()
- -- print("MV_F")
- if turtle.getFuelLevel() < 200 then
- -- print(turtle.getFuelLevel())
- turtle.select(1)
- if turtle.getItemCount() ~= 1 then
- print("refueling")
- turtle.refuel(1)
- else
- print("ERROR: NO FUEL")
- os.pullEvent()
- end
- end
- local params = turtle.forward()
- local z = 1
- while params ~= true and z < 20 do
- params = turtle.forward()
- z = z + 1
- end
- if z > 19 then home_param = true print("mv_f() break") end
- end
- function find_home(params)
- if params == true then turtle.turnLeft() end
- home_param = false
- print("HOME")
- --LOOKING FOR HOME CHEST
- local home, chest_loc = false, true
- while home == false do
- while turtle.detect() do
- turtle.turnLeft()
- end
- if turtle.detectUp() then
- local chest = {turtle.inspectUp()}
- if tostring(string.find(chest[2]["name"], "chest")) ~= "nil" or tostring(string.find(chest[2]["name"], "chest")) ~= "nil" then home = true chest_loc = true end
- end
- if turtle.detectDown() then
- local chest = {turtle.inspectDown()}
- if tostring(string.find(chest[2]["name"], "chest")) ~= "nil" or tostring(string.find(chest[2]["name"], "chest")) ~= "nil" then home = true chest_loc = false end
- end
- if home == false then
- while turtle.detect() == false and home_param == false do
- mv_f()
- end
- if home_param then turtle.turnLeft() end
- end
- end
- if boolean_check(CONFIG.FIRST_RUN) ~= true then
- --ADJUSTING TIMER
- if boolean_check(grown) == false then
- CONFIG.TIMER_1 = tonumber(CONFIG.TIMER_1) + 10
- save_settings()
- else
- CONFIG.TIMER_1 = tonumber(CONFIG.TIMER_1) - 10
- save_settings()
- end
- if tonumber(CONFIG.TIMER_1) > tonumber(CONFIG.TIMER_MAX) then
- CONFIG.TIMER_1 = tonumber(CONFIG.TIMER_1) - 10
- save_settings()
- elseif tonumber(CONFIG.TIMER_MIN) > tonumber(CONFIG.TIMER_1) then
- CONFIG.TIMER_1 = tonumber(CONFIG.TIMER_1) + 10
- save_settings()
- end
- --EMPTYING
- for num=2,(tonumber(CONFIG.TYPES) + 1) do
- local paramsA, paramsB = turtle.getItemDetail(num), 16
- if turtle.getItemCount(num) > 0 then
- for a,b in pairs(plants) do
- if tostring(string.find(paramsA["name"]:lower(), plants[a]["mod"])) ~= "nil" then paramsB = tonumber(plants[a]["stk"]) end
- end
- end
- if turtle.getItemCount(num) > tonumber(paramsB) then
- turtle.select(num)
- pause = drop_off(chest_loc, turtle.getItemCount() - tonumber(paramsB))
- end
- end
- for num=(tonumber(CONFIG.TYPES) + 2),16 do
- if turtle.getItemCount(num) > 0 then turtle.select(num) pause = drop_off(chest_loc, 64) end
- turtle.select(1)
- end
- else
- CONFIG.FIRST_RUN = "false"
- save_settings()
- end
- turtle.turnRight()
- turtle.select(1)
- turtle.suck((64 - turtle.getItemCount()))
- turtle.turnLeft()
- end
- function even(params)
- print("EVEN")
- local num1, num2, answer = tonumber(params / 2), math.floor(tonumber(params / 2)), nil
- local num3 = (num1 - num2) or nil
- if num3 == 0.5 then
- answer = false
- else
- answer = true
- end
- return answer or nil
- end
- function column()
- local finish = false
- while finish == false and finish2 == false do
- local paramsA, paramsB = nil, nil
- --IDENTIFYING AND CHECKING GROWTH
- term.clear() term.setCursorPos(1,1)
- if turtle.detectDown() then
- paramsA = {turtle.inspectDown()}
- for a,b in pairs(paramsA[2]) do print(a..": "..b) end
- for a,b in pairs(plants) do
- if tostring(string.find(paramsA[2]["name"]:lower(), plants[a]["mod"])) ~= "nil" and plants[a]["meta"][paramsA[2]["metadata"]] then
- paramsB = a
- elseif tostring(string.find(paramsA[2]["name"]:lower(), plants[a]["mod"])) ~= "nil" and not plants[a]["meta"][paramsA[2]["metadata"]] then
- paramsB = nil
- end
- end
- end
- if turtle.detectUp() and tostring(paramsB) == "nil" then
- paramsA = {turtle.inspectUp()}
- for a,b in pairs(paramsA[2]) do print(a..": "..b) end
- for a,b in pairs(plants) do
- if tostring(string.find(paramsA[2]["name"]:lower(), plants[a]["mod"])) ~= "nil" and plants[a]["meta"][paramsA[2]["metadata"]] then
- paramsB = a
- elseif tostring(string.find(paramsA[2]["name"]:lower(), plants[a]["mod"])) ~= "nil" and not plants[a]["meta"][paramsA[2]["metadata"]] then
- paramsB = nil
- end
- end
- end
- --MINING IF GROWN
- if tostring(paramsB) ~= "nil" then
- if boolean_check(CONFIG.USE_ROWS) then turtle.select(x + 1) end
- if plants[paramsB]["dir"] == "up" then
- turtle.digUp() turtle.suckUp()
- else
- turtle.digDown() turtle.suckDown()
- end
- grown = true
- end
- finish = turtle.detect()
- paramsC, paramsD, paramsE = nil, nil, nil
- if boolean_check(CONFIG.USE_ROWS) then
- turtle.select(x + 1)
- if turtle.getItemCount() > 1 then
- paramsC = turtle.getItemDetail()
- for a,b in pairs(paramsC) do print(a..": "..b) end
- for a,b in pairs(plants) do
- if tostring(string.find(paramsC["name"]:lower(), plants[a]["mod"])) ~= "nil" then paramsD, paramsE = a, plants[a]["replant"] print("plant mod matched: "..plants[a]["mod"]) end
- if paramsC["name"]:lower() == "pneumaticcraft:plasticplant" and tonumber(paramsC["damage"]) == 11 then paramsD, paramsE = 2, plants[2]["replant"] end
- end
- end
- if paramsE then
- if turtle.detectUp() == false and tostring(paramsD) ~= "nil" then
- if plants[paramsD]["dir"] == "up" then
- if boolean_check(plants[paramsD]["drop"]) then turtle.dropUp(1) else turtle.placeUp() end
- end
- end
- if turtle.detectDown() == false and tostring(paramsD) ~= "nil" then
- if plants[paramsD]["dir"] == "down" then
- if boolean_check(plants[paramsD]["drop"]) then turtle.dropDown(1) else turtle.digDown() turtle.placeDown() end
- end
- end
- end
- else
- local y = 2
- while turtle.getItemCount(y) < 2 and y < (CONFIG.TYPES + 1) do y = y + 1 end
- turtle.select(y)
- if turtle.getItemCount() > 1 then
- local params = turtle.getItemDetail()
- for a,b in pairs(plants) do
- if string.find(params["name"]:lower(), plants[a]["mod"]) ~= "nil" then params2, params3 = a, plants[a]["replant"] end
- if params["name"]:lower() == "pneumaticcraft:plasticplant" and tonumber(params["damage"]) == 11 then params2, params3 = 2, plants[2]["replant"] end
- end
- end
- print(params2.." : "..params3)
- if params3 then
- if turtle.detectUp() == false and tostring(params2) ~= "nil" then
- if tostring(plants[params2]["dir"]) == "up" then
- if boolean_check(plants[params2]["drop"]) then turtle.dropUp(1) print("drop") else turtle.placeUp() print("place") end
- end
- elseif turtle.detectDown() == false and tostring(params2) ~= "nil" then
- if tostring(plants[params2]["dir"]) == "down" then
- if boolean_check(plants[params2]["drop"]) then turtle.dropDown(1) print("drop") else turtle.placeDown() print("place") end
- end
- end
- end
- end
- turtle.select(1)
- mv_f()
- sleep(1)
- end
- end
- function run()
- finish2, x = false, 1
- grown = false
- while finish2 == false do
- term.clear() term.setCursorPos(1,1)
- print("COLUMN: "..x)
- column()
- if even(x) then
- turtle.turnRight()
- mv_f()
- turtle.turnRight()
- else
- turtle.turnLeft()
- mv_f()
- turtle.turnLeft()
- end
- if x >= tonumber(CONFIG.TYPES) then finish2 = true end
- x = x + 1
- end
- local y = 1
- while turtle.detect() ~= true and y ~= 3 do turtle.turnRight() y = y + 1 end
- find_home()
- end
- find_home()
- if update ~= "update" then
- while true do
- os.startTimer(tonumber(CONFIG.TIMER_1))
- term.clear()
- term.setCursorPos(1,1)
- print("NAME: "..os.getComputerLabel())
- print("ID: "..os.getComputerID())
- print("ROWS: "..tostring(CONFIG.USE_ROWS))
- print("TIMER: "..tonumber(CONFIG.TIMER_1))
- print("PAUSE: "..tostring(pause))
- local event = os.pullEvent()
- if not pause and event ~= "turtle_inventory" then
- run()
- else
- find_home()
- end
- end
- else
- print("UPDATING")
- shell.run("pastebin get "..pastebinCode.." update")
- if fs.exists("update") then
- fs.delete(shell.getRunningProgram())
- fs.copy("update", shell.getRunningProgram())
- fs.delete("update")
- print("UPDATE SUCCESS")
- else
- print("UPDATE FAILED")
- end
- sleep(2)
- os.reboot()
- end
Advertisement
Add Comment
Please, Sign In to add comment