Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if turtle then
- turtle.crucialForward = function()
- if turtle.detect() then
- return false
- end
- repeat
- until turtle.forward()
- return true
- end
- turtle.crucialUp = function()
- if turtle.detectUp() then
- return false
- end
- repeat
- until turtle.up()
- return true
- end
- turtle.crucialDown = function()
- if turtle.detectDown() then
- return false
- end
- repeat
- until turtle.down()
- return true
- end
- turtle.crucialBack = function()
- repeat
- until turtle.back()
- return true
- end
- turtle.digForward = function()
- repeat
- turtle.dig()
- until turtle.crucialForward()
- return true
- end
- turtle.digUpper = function()
- repeat
- turtle.digUp()
- until turtle.crucialUp()
- return true
- end
- turtle.digDowner = function()
- repeat
- turtle.digDown()
- until turtle.crucialDown()
- return true
- end
- turtle.inspectPlus = function(list,side)
- if side == nil then side = "" end
- local suc,ans = turtle["inspect"..side]()
- if not suc then return nil end
- return searchBlockType( list,ans.name )
- end
- turtle.inspectPlusUp = function(list)
- return turtle.inspectPlus(list,"Up")
- end
- turtle.inspectPlusDown = function(list)
- return turtle.inspectPlus(list,"Down")
- end
- end
- function openTable( table, spece )
- local r = "\n"
- for k,v in pairs(table) do
- r = r .. spece .. k.." : "
- if type(v) == "number" or type(v) == "string" then
- r = r .. v .. "\n"
- elseif type(v) == "table" then
- r = r .. openTable( v, " "..spece )
- end
- end
- return r
- end
- function PeriCheck()
- local periList = peripheral.getNames()
- local peris = { { side = "exit", type = nil, peri = nil } }
- local j = 2
- for i,e in pairs(periList) do
- peris[j] = {}
- peris[j].side = e
- peris[j].type = peripheral.getType(e)
- peris[j].meth = peripheral.getMethods(e)
- peris[j].peri = peripheral.wrap(e)
- j = j + 1
- end
- local p = 1
- local meth = 1
- local review = true
- local methans = ""
- while true do
- ------------- view ----------------
- if review then
- term.clear()
- term.setCursorPos(1, 1)
- write(peris[p].side.."\n")
- if peris[p].type ~= nil then
- write("type:"..peris[p].type.."\n")
- end
- if peris[p].meth ~= nil then
- write("Method "..meth..":"..peris[p].meth[meth].."\n")
- end
- -- if peris[p].peri ~= nil then
- -- local ans = peris[p].peri[peris[p].meth[meth]]()
- -- if type(ans) == "number" or type(ans) == "string" then
- -- write("ans "..meth..":"..ans.."\n")
- -- end
- -- end
- write(methans)
- end
- review = false
- local eve = {os.pullEvent()}
- ----------- key -------------
- if eve[1] == "key" then
- if eve[2] == 208 then -- up key
- meth = meth + 1
- if meth > #(peris[p].meth) then
- meth = 1
- end
- end
- if eve[2] == 200 then -- down key
- meth = meth - 1
- if meth < 1 then
- meth = #(peris[p].meth)
- end
- end
- if eve[2] == 205 then -- left key
- p = p + 1
- if p > #peris then
- p = 1
- end
- meth = 1
- end
- if eve[2] == 203 then -- right key
- p = p - 1
- if p < 1 then
- p = #peris
- end
- meth = 1
- end
- methans = ""
- if eve[2] == 57 or p1 == 28 then -- space key
- if peris[p].side == "exit" then
- break
- else
- if peris[p].peri ~= nil then
- local ans = peris[p].peri[peris[p].meth[meth]]()
- if type(ans) == "number" or type(ans) == "string" then
- methans = "ans "..meth..":"..ans.."\n"
- elseif type(ans) == "table" then
- methans = methans .. "ans \n"
- methans = methans .. openTable( ans, " " )
- local f = fs.open("methans","w")
- f.write(methans)
- f.close()
- end
- end
- end
- end
- review = true
- end
- end
- end
- function collect()
- for i = 1 , 15 do
- for j = i , 16 do
- if turtle.getItemSpace(i) ~= 0 and turtle.getItemCount(j) > 0 then
- turtle.select(i)
- if turtle.compareTo(j) or turtle.getItemCount(i) == 0 then
- turtle.select(j)
- turtle.transferTo(i)
- end
- end
- end
- end
- turtle.select(1)
- end
- function refillBlock( slot )
- if slot == nil then return end
- for i = 1,16 do
- if i ~= slot and turtle.getItemSpace(slot) > 0 and turtle.getItemCount(i) > 0 then
- turtle.select(i)
- if turtle.compareTo(slot) then
- turtle.transferTo(slot)
- end
- end
- end
- end
- function mat_s( side, size )
- if size == nil then
- size = 30
- end
- if turtle.getItemCount(1) == 0 then
- write("need block on slot 1\n")
- return
- end
- local turns = 0
- local long = 0
- while turns < 4 do
- if not turtle.crucialForward() then
- turtle.turnLeft()
- long = 0
- turns = turns + 1
- elseif turtle["detect"..side]() then
- turtle.crucialBack()
- turtle.turnLeft()
- long = 0
- turns = turns + 1
- else
- if turtle.getItemCount(1) == 1 then
- refillBlock(1)
- end
- turtle.select(1)
- turtle["place"..side]()
- long = long + 1
- turns = 0
- end
- if long > size then
- turtle.turnLeft()
- long = 0
- turns = turns + 1
- end
- end
- end
- function mat( size )
- mat_s( "Down", size )
- end
- function roof( size )
- mat_s( "Up", size )
- end
- function addToFile( fname, add)
- local f = fs.open(fname,"a")
- f.writeLine(add)
- f.close()
- end
- function searchBlockType( list ,code )
- for k,v in pairs(list) do
- for i,b in pairs(v.IDS) do
- if b == code then
- return k
- end
- end
- end
- local selectlist = {}
- for k,v in pairs(list) do
- if v.canadd then
- selectlist[#selectlist + 1] = k
- end
- end
- local sel = 1
- while true do
- term.clear()
- term.setCursorPos(1, 1)
- write("find new block type.\n"..code.." is...\n")
- for i,v in pairs(selectlist) do
- if sel == i then
- write(">")
- else
- write(" ")
- end
- write(v.."\n")
- end
- local eve = {os.pullEvent("key")}
- if eve[2] == 208 then -- up key
- sel = sel + 1
- if sel > #selectlist then
- sel = 1
- end
- end
- if eve[2] == 200 then -- down key
- sel = sel - 1
- if sel < 1 then
- sel = #selectlist
- end
- end
- if eve[2] == 57 or p1 == 28 then -- space key
- addToFile( "idlist/"..selectlist[sel],code)
- list[selectlist[sel]].IDS[#(list[selectlist[sel]].IDS) + 1] = code
- return selectlist[sel]
- end
- end
- end
- function loadList( fname, defaults)
- if fs.exists(fname) then
- local r = {}
- local f = fs.open(fname,"r")
- local line = f.readLine()
- while line ~= nil do
- r[#r+1] = line
- line = f.readLine()
- end
- f.close()
- return r
- else
- if defaults == nil then
- defaults = {}
- else
- local f = fs.open(fname,"w")
- for k,v in pairs(defaults) do
- f.writeLine(v)
- end
- f.close()
- end
- return defaults
- end
- end
- function selectFromType( list, t )
- for i = 1,16 do
- local ans = turtle.getItemDetail(i)
- if ans ~= nil then
- if searchBlockType(list,ans.name) == t then
- turtle.select(i)
- return i
- end
- end
- end
- return -1
- end
- function selectFromCode( c )
- for i = 1,16 do
- local ans = turtle.getItemDetail(i)
- if ans ~= nil then
- if ans.name == c then
- turtle.select(i)
- return i
- end
- end
- end
- return -1
- end
- function setFlg( fname, flg)
- local f = fs.open(fname,"w")
- f.write(flg)
- f.close()
- end
- function getFlg( fname)
- if fs.exists(fname) == false then return false end
- local f = fs.open(fname,"r")
- local a = f.readAll()
- f.close()
- if a == "true" then
- return true
- else
- return false
- end
- end
- function digTreeInit(list)
- if getFlg("Flg/digtree") then
- if not turtle.detect() then turtle.crucialUp() end
- while true do
- if turtle.inspectPlusUp(list) ~= "tree" then break end
- turtle.dig()
- turtle.turnRight()
- turtle.dig()
- turtle.turnRight()
- turtle.dig()
- turtle.turnRight()
- turtle.dig()
- turtle.turnRight()
- turtle.digUpper()
- end
- while turtle.crucialDown() do
- end
- if turtle.inspectPlusDown(list) == "tree" then
- turtle.digDown()
- else
- turtle.crucialUp()
- end
- if selectFromType(list,"sap") ~= -1 then
- turtle.placeDown()
- end
- setFlg("Flg/digtree",false)
- end
- end
- function workFarm( list, side )
- local SeedList = {}
- SeedList["minecraft:wheat"] = "minecraft:wheat_seeds"
- SeedList["minecraft:potatoes"] = "minecraft:potato"
- SeedList["minecraft:carrots"] = "minecraft:carrot"
- SeedList["minecraft:nether_wart"] = "minecraft:nether_wart"
- local LvlList = {}
- LvlList["minecraft:wheat"] = 7
- LvlList["minecraft:potatoes"] = 7
- LvlList["minecraft:carrots"] = 7
- LvlList["minecraft:nether_wart"] = 3
- if side == nil then
- side = ""
- end
- if not turtle["detect"..side]() then return false end
- local suc,ans = turtle["inspect"..side]()
- if not suc then return false end
- local mode = searchBlockType(list,ans.name)
- turtle.select(1)
- if mode == "tree" then
- if side == "" then
- turtle.digForward()
- setFlg("Flg/digtree",true)
- local uplong = 0
- while true do
- turtle.dig()
- turtle.turnRight()
- turtle.dig()
- turtle.turnRight()
- turtle.dig()
- turtle.turnRight()
- turtle.dig()
- turtle.turnRight()
- suc,ans = turtle.inspectUp()
- if not suc then break end
- if searchBlockType(list,ans.name) ~= "tree" then
- turtle.digUp()
- break
- end
- turtle.digUpper()
- uplong = uplong + 1
- end
- for i = 1,uplong do
- turtle.crucialDown()
- end
- turtle.digDown()
- if selectFromType(list,"sap") ~= -1 then
- turtle.placeDown()
- end
- setFlg("Flg/digtree",false)
- end
- elseif mode == "plant" then
- if side == "Down" and ans.metadata == LvlList[ans.name] then
- turtle.digDown()
- if selectFromCode(SeedList[ans.name]) ~= -1 then
- turtle.placeDown()
- end
- end
- elseif mode == "sign" then
- local sidep = "front"
- if side == "Down" then sidep = "bottom" end
- if side == "Up" then sidep = "top" end
- local p = peripheral.wrap(sidep)
- local signcode = p.getLine(1)
- if signcode == ">" then turtle.turnRight() end
- if signcode == "<" then turtle.turnLeft() end
- if signcode == "A" then turtle.up() end
- if signcode == "V" then turtle.down() end
- if signcode == ">>" then
- turtle.turnRight()
- turtle.turnRight()
- end
- if signcode == "<<" then
- turtle.turnLeft()
- turtle.turnLeft()
- end
- if signcode == "wait" then
- local timecode = p.getLine(2)
- write("waiting "..timecode.."ms.")
- local tnum = tonumber(timecode)
- if tnum ~= nil then sleep(tnum) end
- end
- if signcode == "alarm" then
- local timecode = p.getLine(2)
- write("waiting alarm"..timecode.."ost.")
- local tnum = tonumber(timecode)
- if tnum ~= nil then
- local alarmNum = os.setAlarm(tnum)
- repeat
- local eve = {os.pullEvent("alarm")}
- until eve[2] == alarmNum
- end
- end
- elseif mode == "chest" then
- if side == "Down" then
- local findsap = false
- local findseed = false
- for i = 1,16 do
- local ans = turtle.getItemDetail(i)
- if ans ~= nil then
- if searchBlockType(list,ans.name) == "sap" and not findsap then
- findsap = true
- elseif ans.name == "minecraft:wheat_seeds" and not findseed then
- findseed = true
- else
- turtle.select(i)
- turtle.dropDown()
- end
- end
- end
- end
- if side == "Up" then
- collect()
- for i=1,16 do
- if turtle.getItemCount(i) == 0 then
- turtle.select(i)
- break
- end
- end
- while turtle.getFuelLevel() < 1000 do
- if not turtle.suckUp() then break end
- if not turtle.refuel() then
- turtle.dropUp()
- break
- end
- end
- end
- elseif mode == "sap" then
- elseif mode == "frame" then
- if side == "" then
- turtle.turnLeft()
- if turtle.inspectPlus(list) == "frame" then
- turtle.turnLeft()
- turtle.turnLeft()
- end
- end
- else
- turtle["dig"..side]()
- end
- return true
- end
- function farm()
- local IDList = { tree = { canadd = true, IDS = loadList("idlist/tree"
- ,{"minecraft:log"})}
- , sap = { canadd = true, IDS = loadList("idlist/sap"
- ,{"minecraft:sapling"})}
- , digs = { canadd = true, IDS = loadList("idlist/digs"
- ,{"minecraft:melon_block"
- , "minecraft:pumpkin"
- , "minecraft:reeds"
- , "minecraft:leaves"} ) }
- , plant = {canadd = false,IDS ={ "minecraft:wheat"
- ,"minecraft:potatoes"
- ,"minecraft:carrots"
- ,"minecraft:nether_wart"}}
- , sign = {canadd = false, IDS ={"minecraft:standing_sign"
- ,"minecraft:wall_sign"
- ,"Flatsigns:blockFlatSign"}}
- , chest = {canadd = true, IDS = loadList("idlist/chest"
- ,{"minecraft:chest"
- , "EnderStorage:enderChest"})}
- , seed = {canadd = false, IDS ={"minecraft:wheat_seeds"
- ,"minecraft:potato"
- ,"minecraft:carrot"}}
- , frame = {canadd = true,IDS =loadList("idlist/frame")}}
- digTreeInit(IDList)
- while true do
- workFarm(IDList,"Down")
- workFarm(IDList,"Up")
- if not workFarm(IDList,"") then
- turtle.crucialForward()
- end
- end
- end
- function syousuu (num,level)
- local r = num * 10^level
- return (math.floor(r) / 10^level)
- end
- function kmg( num )
- local kmgList = {"","K","M","G","T"}
- local f = 1
- while num > 1000 do
- num = num / 1000
- f = f + 1
- end
- if f > 5 then
- f = 5
- end
- return syousuu(num,0) .. kmgList[f]
- end
- function getEUData(peri)
- local st = peri.getEUStored()
- local max = peri.getEUCapacity()
- local p = 100 / max * st
- return syousuu(p,0).."% " .. kmg(st).."/"..kmg(max)
- end
- function getRFData(peri)
- local st = peri.getEnergyStored()
- local max = peri.getMaxEnergyStored()
- local p = 100 / max * st
- return syousuu(p,0).."% " .. kmg(st).."/"..kmg(max)
- end
- function getTankData(peri)
- local ans = peri.getTankInfo()
- local st = 0
- local typ = "empty"
- if not ans then return "no data" end
- if ans[1].contents ~= nil then
- if ans[1].contents.amount ~= nil then
- st = ans[1].contents.amount
- end
- if ans[1].contents.rawName ~= nil then
- typ = ans[1].contents.rawName
- end
- end
- local max = ans[1].capacity
- local p = 100 / max * st
- return typ.." "..syousuu(p,0).."% " .. kmg(st).."/"..kmg(max)
- end
- function getAspectData(peri)
- local asplist = peri.getAspects()
- local r = ""
- for k, v in pairs(asplist) do
- r = r .. v .. peri.getAspectCount(v) .. " "
- end
- if r == "" then r = " Aspect:empty" end
- return r
- end
- function isEU( side )
- if peripheral.wrap(side).getEUStored ~= nil then
- return true
- end
- return false
- end
- function isRF( side )
- if peripheral.wrap(side).getEnergyStored ~= nil then
- return true
- end
- return false
- end
- function isTank( side )
- if peripheral.wrap(side).getTankInfo ~= nil then
- return true
- end
- return false
- end
- function isThaum( side )
- if peripheral.wrap(side).getAspects ~= nil then
- return true
- end
- return false
- end
- function monisClr(monis)
- term.clear()
- term.setCursorPos(1, 1)
- for i,e in pairs(monis) do
- e.clear()
- e.setCursorPos(1, 1)
- end
- end
- function monisWrite(monis,str,clr)
- if term.isColor() then term.setTextColor(clr) end
- write(str.."\n")
- if term.isColor() then term.setTextColor(colors.white) end
- if monis == nil then return end
- for i,e in pairs(monis) do
- if e.isColor() then e.setTextColor(clr) end
- e.write(str)
- if e.isColor() then e.setTextColor(colors.white) end
- local x,y = e.getCursorPos()
- y = y + 1
- e.setCursorPos(1, y)
- end
- end
- function checker()
- local periList = peripheral.getNames()
- local looklist = {}
- local monis = {}
- local modem = ""
- for i,e in pairs(periList) do
- if isEU(e) then
- looklist[#looklist+1] = {}
- looklist[#looklist].type = "EU"
- looklist[#looklist].peri = peripheral.wrap(e)
- looklist[#looklist].func = getEUData
- looklist[#looklist].clr = colours.yellow
- looklist[#looklist].txt = ""
- end
- if isRF(e) then
- looklist[#looklist+1] = {}
- looklist[#looklist].type = "RF"
- looklist[#looklist].peri = peripheral.wrap(e)
- looklist[#looklist].func = getRFData
- looklist[#looklist].clr = colours.red
- looklist[#looklist].txt = ""
- end
- if isTank(e) then
- looklist[#looklist+1] = {}
- looklist[#looklist].type = "mb"
- looklist[#looklist].peri = peripheral.wrap(e)
- looklist[#looklist].func = getTankData
- looklist[#looklist].clr = colours.lime
- looklist[#looklist].txt = ""
- end
- if isThaum(e) then
- looklist[#looklist+1] = {}
- looklist[#looklist].type = "ASP"
- looklist[#looklist].peri = peripheral.wrap(e)
- looklist[#looklist].func = getAspectData
- looklist[#looklist].clr = colors.purple
- looklist[#looklist].txt = ""
- end
- if peripheral.getType(e) == "monitor" then
- monis[#monis+1] = peripheral.wrap(e)
- end
- if peripheral.getType(e) == "modem" then
- modem = e
- end
- end
- if modem ~= "" then rednet.open(modem) end
- while true do
- local send = {channel="gapi",sender=os.getComputerID(),line={}}
- monisClr(monis)
- for i,e in pairs(looklist) do
- e.txt = e.type..i.." "..e.func(e.peri)
- monisWrite(monis,e.txt,e.clr)
- send.line[#(send.line) + 1] = {t=e.txt,c=e.clr}
- end
- rednet.broadcast(textutils.serialize(send))
- sleep(1)
- end
- end
- function moniter(ch)
- if not ch then ch = "gapi" end
- local monis = {}
- local modem = ""
- local mem = {}
- for i,e in pairs(peripheral.getNames()) do
- if peripheral.getType(e) == "monitor" then
- monis[#monis+1] = peripheral.wrap(e)
- end
- if peripheral.getType(e) == "modem" then
- modem = e
- end
- end
- if modem ~= "" then rednet.open(modem) end
- while true do
- monisClr(monis)
- write("hearing ch:"..ch.."\n")
- for k, v in pairs(mem) do
- for l, b in pairs(v.line) do
- monisWrite(monis,b.t,b.c)
- end
- monisWrite(monis,"",colors.white)
- end
- local eve = {os.pullEvent()}
- if eve[1] == "rednet_message" then
- local depack = textutils.unserialize(eve[3])
- if depack and depack.channel and depack.channel == ch then
- mem[eve[2]] = depack
- end
- end
- end
- end
- function rdig()
- local IDList = { ok = { canadd = true, IDS = loadList("idlist/ok")}
- , non = { canadd = true, IDS = loadList("idlist/non")}
- , lava = { canadd = false,IDS = "minecraft:flowing_lava"}}
- while true do
- if not turtle.detect() then
- turtle.turnLeft()
- if not turtle.detect() then
- break
- end
- end
- local ans = turtle.inspectPlus(IDList)
- if ans == "ok" or ans == "lava" then
- turtle.digForward()
- else
- break
- end
- ans = turtle.inspectPlusUp(IDList)
- if ans == "ok" then
- turtle.digUp()
- elseif ans == "lava" then
- turtle.up()
- turtle.down()
- end
- ans = turtle.inspectPlusDown(IDList)
- if ans == "ok" then
- turtle.digDown()
- elseif ans == "lava" then
- turtle.down()
- turtle.up()
- end
- end
- end
- args = {...}
- if #args == 0 then
- write("need argments\n")
- monisWrite(nil,"gapi mat (size)",colours.yellow)
- --write("naruto moving and set blocks on ground.\n")
- monisWrite(nil,"gapi roof (size)",colours.yellow)
- --write("naruto moving and set blocks over head.\n")
- monisWrite(nil,"gapi farm",colours.yellow)
- --write("can sign controll farming.>,<,A,V,<<,>>,alarm,wait.\n")
- --write("tree farm, only straight tree(spruce tree).\n")
- monisWrite(nil,"gapi checker",colours.yellow)
- --write("EU RF liquid Tank checking. auto monitor out.\n")
- monisWrite(nil,"gapi pcheck",colours.yellow)
- --write("periphral data watching.\n")
- monisWrite(nil,"gapi moni",colours.yellow)
- else
- code = string.lower(args[1])
- if code == "mat" then
- mat(args[2])
- end
- if code == "rdig" then
- rdig()
- end
- if code == "roof" then
- roof(args[2])
- end
- if code == "farm" then
- farm()
- end
- if code == "checker" then
- checker()
- end
- if code == "pcheck" then
- PeriCheck()
- end
- if code == "moni" then
- moniter(args[2])
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement