Advertisement
Ganeesya

GAPI for ComputerCraft 1.64after

Mar 13th, 2015
11,378
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 19.65 KB | None | 0 0
  1. if turtle then
  2.     turtle.crucialForward = function()
  3.         if turtle.detect() then
  4.             return false
  5.         end
  6.         repeat
  7.         until turtle.forward()
  8.         return true
  9.     end
  10.  
  11.     turtle.crucialUp = function()
  12.         if turtle.detectUp() then
  13.             return false
  14.         end
  15.         repeat
  16.         until turtle.up()
  17.         return true
  18.     end
  19.  
  20.     turtle.crucialDown = function()
  21.         if turtle.detectDown() then
  22.             return false
  23.         end
  24.         repeat
  25.         until turtle.down()
  26.         return true
  27.     end
  28.  
  29.     turtle.crucialBack = function()
  30.         repeat
  31.         until turtle.back()
  32.         return true
  33.     end
  34.  
  35.     turtle.digForward = function()
  36.         repeat
  37.             turtle.dig()
  38.         until turtle.crucialForward()
  39.         return true
  40.     end
  41.  
  42.     turtle.digUpper = function()
  43.         repeat
  44.             turtle.digUp()
  45.         until turtle.crucialUp()
  46.         return true
  47.     end
  48.  
  49.     turtle.digDowner = function()
  50.         repeat
  51.             turtle.digDown()
  52.         until turtle.crucialDown()
  53.         return true
  54.     end
  55.  
  56.     turtle.inspectPlus = function(list,side)
  57.         if side == nil then side = "" end
  58.         local suc,ans = turtle["inspect"..side]()
  59.         if not suc then return nil end
  60.         return searchBlockType( list,ans.name )
  61.     end
  62.  
  63.     turtle.inspectPlusUp = function(list)
  64.         return turtle.inspectPlus(list,"Up")
  65.     end
  66.  
  67.     turtle.inspectPlusDown = function(list)
  68.         return turtle.inspectPlus(list,"Down")
  69.     end
  70. end
  71.  
  72. function openTable( table, spece )
  73.     local r = "\n"
  74.     for k,v in pairs(table) do
  75.         r = r .. spece .. k.." : "
  76.         if type(v) == "number" or type(v) == "string" then
  77.             r = r .. v .. "\n"
  78.         elseif type(v) == "table" then
  79.             r = r .. openTable( v, "   "..spece )
  80.         end
  81.     end
  82.     return r
  83. end
  84.  
  85. function PeriCheck()
  86.     local periList = peripheral.getNames()
  87.     local peris = { { side = "exit", type = nil, peri = nil } }
  88.     local j = 2
  89.     for i,e in pairs(periList) do
  90.         peris[j] = {}
  91.         peris[j].side = e
  92.         peris[j].type = peripheral.getType(e)
  93.         peris[j].meth = peripheral.getMethods(e)
  94.         peris[j].peri = peripheral.wrap(e)
  95.         j = j + 1
  96.     end
  97.  
  98.     local p = 1
  99.     local meth = 1
  100.     local review = true
  101.     local methans = ""
  102.  
  103.     while true do
  104.         ------------- view ----------------
  105.         if review then
  106.             term.clear()
  107.             term.setCursorPos(1, 1)
  108.             write(peris[p].side.."\n")
  109.             if peris[p].type ~= nil then
  110.                 write("type:"..peris[p].type.."\n")
  111.             end
  112.             if peris[p].meth ~= nil then
  113.                 write("Method "..meth..":"..peris[p].meth[meth].."\n")
  114.             end
  115.             -- if peris[p].peri ~= nil then
  116.             --  local ans = peris[p].peri[peris[p].meth[meth]]()
  117.             --  if type(ans) == "number" or type(ans) == "string" then
  118.             --      write("ans "..meth..":"..ans.."\n")
  119.             --  end
  120.             -- end
  121.             write(methans)
  122.         end
  123.         review = false
  124.  
  125.         local eve = {os.pullEvent()}
  126.  
  127.         ----------- key -------------
  128.         if eve[1] == "key" then
  129.             if eve[2] == 208 then -- up key
  130.                 meth = meth + 1
  131.                 if meth > #(peris[p].meth) then
  132.                     meth = 1
  133.                 end
  134.             end
  135.             if eve[2] == 200 then -- down key
  136.                 meth = meth - 1
  137.                 if meth < 1 then
  138.                     meth = #(peris[p].meth)
  139.                 end
  140.             end    
  141.             if eve[2] == 205 then -- left key
  142.                 p = p + 1
  143.                 if p > #peris then
  144.                     p = 1
  145.                 end
  146.                 meth = 1
  147.             end
  148.             if eve[2] == 203 then -- right key
  149.                 p = p - 1
  150.                 if p < 1 then
  151.                     p = #peris
  152.                 end
  153.                 meth = 1
  154.             end
  155.  
  156.             methans = ""
  157.             if eve[2] == 57 or p1 == 28 then -- space key
  158.                 if peris[p].side == "exit" then
  159.                     break
  160.                 else
  161.                     if peris[p].peri ~= nil then
  162.                         local ans = peris[p].peri[peris[p].meth[meth]]()
  163.                         if type(ans) == "number" or type(ans) == "string" then
  164.                             methans = "ans "..meth..":"..ans.."\n"
  165.                         elseif type(ans) == "table" then
  166.                             methans = methans .. "ans \n"
  167.                             methans = methans .. openTable( ans, "   " )
  168.  
  169.                             local f = fs.open("methans","w")
  170.                             f.write(methans)
  171.                             f.close()
  172.                         end
  173.                     end
  174.                 end
  175.             end
  176.             review = true
  177.         end
  178.     end
  179. end
  180.  
  181. function collect()
  182.     for i = 1 , 15 do
  183.         for j = i , 16 do
  184.             if turtle.getItemSpace(i) ~= 0 and turtle.getItemCount(j) > 0 then
  185.                 turtle.select(i)
  186.                 if turtle.compareTo(j) or turtle.getItemCount(i) == 0 then
  187.                     turtle.select(j)
  188.                     turtle.transferTo(i)
  189.                 end
  190.             end
  191.         end
  192.     end
  193.     turtle.select(1)
  194. end
  195.  
  196. function refillBlock( slot )
  197.     if slot == nil then return end
  198.     for i = 1,16 do
  199.         if i ~= slot and turtle.getItemSpace(slot) > 0 and turtle.getItemCount(i) > 0 then
  200.             turtle.select(i)
  201.             if turtle.compareTo(slot) then
  202.                 turtle.transferTo(slot)
  203.             end
  204.         end
  205.     end
  206. end
  207.  
  208. function mat_s( side, size )
  209.     if size == nil then
  210.         size = 30
  211.     end
  212.  
  213.     if turtle.getItemCount(1) == 0 then
  214.         write("need block on slot 1\n")
  215.         return
  216.     end
  217.  
  218.     local turns = 0
  219.     local long = 0
  220.  
  221.     while turns < 4 do
  222.         if not turtle.crucialForward() then
  223.             turtle.turnLeft()
  224.             long = 0
  225.             turns = turns + 1
  226.         elseif turtle["detect"..side]() then
  227.             turtle.crucialBack()
  228.             turtle.turnLeft()
  229.             long = 0
  230.             turns = turns + 1
  231.         else
  232.             if turtle.getItemCount(1) == 1 then
  233.                 refillBlock(1)
  234.             end
  235.             turtle.select(1)
  236.             turtle["place"..side]()
  237.             long = long + 1
  238.             turns = 0
  239.         end
  240.         if long > size then
  241.             turtle.turnLeft()
  242.             long = 0
  243.             turns = turns + 1
  244.         end
  245.     end
  246. end
  247.  
  248. function mat( size )
  249.     mat_s( "Down", size )
  250. end
  251.  
  252. function roof( size )
  253.     mat_s( "Up", size )
  254. end
  255.  
  256. function addToFile( fname, add)
  257.     local f = fs.open(fname,"a")
  258.     f.writeLine(add)
  259.     f.close()
  260. end
  261.  
  262. function searchBlockType( list ,code )
  263.     for k,v in pairs(list) do
  264.         for i,b in pairs(v.IDS) do
  265.             if b == code then
  266.                 return k
  267.             end
  268.         end
  269.     end
  270.  
  271.     local selectlist = {}
  272.     for k,v in pairs(list) do
  273.         if v.canadd then
  274.             selectlist[#selectlist + 1] = k
  275.         end
  276.     end
  277.  
  278.     local sel = 1
  279.     while true do
  280.         term.clear()
  281.         term.setCursorPos(1, 1)
  282.         write("find new block type.\n"..code.." is...\n")
  283.         for i,v in pairs(selectlist) do
  284.             if sel == i then
  285.                 write(">")
  286.             else
  287.                 write(" ")
  288.             end
  289.             write(v.."\n")
  290.         end
  291.  
  292.         local eve = {os.pullEvent("key")}
  293.  
  294.         if eve[2] == 208 then -- up key
  295.             sel = sel + 1
  296.             if sel > #selectlist then
  297.                 sel = 1
  298.             end
  299.         end
  300.         if eve[2] == 200 then -- down key
  301.             sel = sel - 1
  302.             if sel < 1 then
  303.                 sel = #selectlist
  304.             end
  305.         end    
  306.         if eve[2] == 57 or p1 == 28 then -- space key
  307.             addToFile( "idlist/"..selectlist[sel],code)
  308.             list[selectlist[sel]].IDS[#(list[selectlist[sel]].IDS) + 1] = code
  309.             return selectlist[sel]
  310.         end
  311.     end
  312. end
  313.  
  314. function loadList( fname, defaults)
  315.     if fs.exists(fname) then
  316.         local r = {}
  317.         local f = fs.open(fname,"r")
  318.         local line = f.readLine()
  319.         while line ~= nil do
  320.             r[#r+1] = line
  321.             line = f.readLine()
  322.         end
  323.         f.close()
  324.         return r
  325.     else
  326.         if defaults == nil then
  327.             defaults = {}
  328.         else
  329.             local f = fs.open(fname,"w")
  330.             for k,v in pairs(defaults) do
  331.                 f.writeLine(v)
  332.             end
  333.             f.close()
  334.         end
  335.         return defaults
  336.     end
  337. end
  338.  
  339. function selectFromType( list, t )
  340.     for i = 1,16 do
  341.         local ans = turtle.getItemDetail(i)
  342.         if ans ~= nil then
  343.             if searchBlockType(list,ans.name) == t then
  344.                 turtle.select(i)
  345.                 return i
  346.             end
  347.         end
  348.     end
  349.     return -1
  350. end
  351.  
  352. function selectFromCode( c )
  353.     for i = 1,16 do
  354.         local ans = turtle.getItemDetail(i)
  355.         if ans ~= nil then
  356.             if ans.name == c then
  357.                 turtle.select(i)
  358.                 return i
  359.             end
  360.         end
  361.     end
  362.     return -1
  363. end
  364.  
  365. function setFlg( fname, flg)
  366.     local f = fs.open(fname,"w")
  367.     f.write(flg)
  368.     f.close()
  369. end
  370.  
  371. function getFlg( fname)
  372.     if fs.exists(fname) == false then return false end
  373.     local f = fs.open(fname,"r")
  374.     local a = f.readAll()
  375.     f.close()
  376.     if a == "true" then
  377.         return true
  378.     else
  379.         return false
  380.     end
  381. end
  382.  
  383. function digTreeInit(list)
  384.     if getFlg("Flg/digtree") then
  385.         if not turtle.detect() then turtle.crucialUp() end
  386.         while true do
  387.             if turtle.inspectPlusUp(list) ~= "tree" then break end
  388.             turtle.dig()
  389.             turtle.turnRight()
  390.             turtle.dig()
  391.             turtle.turnRight()
  392.             turtle.dig()
  393.             turtle.turnRight()
  394.             turtle.dig()
  395.             turtle.turnRight()
  396.             turtle.digUpper()
  397.         end
  398.  
  399.         while turtle.crucialDown() do
  400.         end
  401.  
  402.         if turtle.inspectPlusDown(list) == "tree" then
  403.             turtle.digDown()
  404.         else
  405.             turtle.crucialUp()
  406.         end
  407.  
  408.         if selectFromType(list,"sap") ~= -1 then
  409.             turtle.placeDown()
  410.         end        
  411.         setFlg("Flg/digtree",false)
  412.     end
  413. end
  414.  
  415. function workFarm( list, side )
  416.     local SeedList = {}
  417.     SeedList["minecraft:wheat"] = "minecraft:wheat_seeds"
  418.     SeedList["minecraft:potatoes"] = "minecraft:potato"
  419.     SeedList["minecraft:carrots"] = "minecraft:carrot"
  420.     SeedList["minecraft:nether_wart"] = "minecraft:nether_wart"
  421.  
  422.     local LvlList = {}
  423.     LvlList["minecraft:wheat"] = 7
  424.     LvlList["minecraft:potatoes"] = 7
  425.     LvlList["minecraft:carrots"] = 7
  426.     LvlList["minecraft:nether_wart"] = 3
  427.  
  428.     if side == nil then
  429.         side = ""
  430.     end
  431.     if not turtle["detect"..side]() then return false end
  432.  
  433.     local suc,ans = turtle["inspect"..side]()
  434.     if not suc then return false end
  435.  
  436.     local mode = searchBlockType(list,ans.name)
  437.  
  438.     turtle.select(1)
  439.  
  440.     if mode == "tree" then
  441.         if side == "" then
  442.             turtle.digForward()
  443.             setFlg("Flg/digtree",true)
  444.             local uplong = 0
  445.             while true do
  446.                 turtle.dig()
  447.                 turtle.turnRight()
  448.                 turtle.dig()
  449.                 turtle.turnRight()
  450.                 turtle.dig()
  451.                 turtle.turnRight()
  452.                 turtle.dig()
  453.                 turtle.turnRight()
  454.                 suc,ans = turtle.inspectUp()
  455.                 if not suc then break end
  456.                 if searchBlockType(list,ans.name) ~= "tree" then
  457.                     turtle.digUp()
  458.                     break
  459.                 end
  460.                 turtle.digUpper()
  461.                 uplong = uplong + 1
  462.             end
  463.             for i = 1,uplong do
  464.                 turtle.crucialDown()
  465.             end
  466.             turtle.digDown()
  467.             if selectFromType(list,"sap") ~= -1 then
  468.                 turtle.placeDown()
  469.             end        
  470.             setFlg("Flg/digtree",false)
  471.         end
  472.  
  473.     elseif mode == "plant" then
  474.         if side == "Down" and ans.metadata == LvlList[ans.name] then
  475.             turtle.digDown()
  476.             if selectFromCode(SeedList[ans.name]) ~= -1 then
  477.                 turtle.placeDown()
  478.             end
  479.         end
  480.  
  481.     elseif mode == "sign" then
  482.         local sidep = "front"
  483.         if side == "Down" then sidep = "bottom" end
  484.         if side == "Up" then sidep = "top" end
  485.  
  486.         local p = peripheral.wrap(sidep)
  487.         local signcode = p.getLine(1)
  488.  
  489.         if signcode == ">" then turtle.turnRight() end
  490.         if signcode == "<" then turtle.turnLeft() end
  491.         if signcode == "A" then turtle.up() end
  492.         if signcode == "V" then turtle.down() end
  493.         if signcode == ">>" then
  494.             turtle.turnRight()
  495.             turtle.turnRight()
  496.         end
  497.         if signcode == "<<" then
  498.             turtle.turnLeft()
  499.             turtle.turnLeft()
  500.         end
  501.  
  502.         if signcode == "wait" then
  503.             local timecode = p.getLine(2)
  504.             write("waiting "..timecode.."ms.")
  505.             local tnum = tonumber(timecode)
  506.             if tnum ~= nil then sleep(tnum) end
  507.         end
  508.         if signcode == "alarm" then
  509.             local timecode = p.getLine(2)
  510.             write("waiting alarm"..timecode.."ost.")
  511.             local tnum = tonumber(timecode)
  512.             if tnum ~= nil then
  513.                 local alarmNum = os.setAlarm(tnum)
  514.                 repeat
  515.                     local eve = {os.pullEvent("alarm")}
  516.                 until eve[2] == alarmNum
  517.             end
  518.         end
  519.  
  520.     elseif mode == "chest" then
  521.         if side == "Down" then
  522.             local findsap = false
  523.             local findseed = false
  524.             for i = 1,16 do
  525.                 local ans = turtle.getItemDetail(i)
  526.                 if ans ~= nil then
  527.                     if searchBlockType(list,ans.name) == "sap" and not findsap then
  528.                         findsap = true
  529.                     elseif ans.name == "minecraft:wheat_seeds" and not findseed then
  530.                         findseed = true
  531.                     else
  532.                         turtle.select(i)
  533.                         turtle.dropDown()
  534.                     end
  535.                 end
  536.             end
  537.         end
  538.         if side == "Up" then
  539.             collect()
  540.             for i=1,16 do
  541.                 if turtle.getItemCount(i) == 0 then
  542.                     turtle.select(i)
  543.                     break
  544.                 end
  545.             end
  546.             while turtle.getFuelLevel() < 1000 do
  547.                 if not turtle.suckUp() then break end
  548.                 if not turtle.refuel() then
  549.                     turtle.dropUp()
  550.                     break
  551.                 end
  552.             end
  553.         end
  554.  
  555.     elseif mode == "sap" then
  556.     elseif mode == "frame" then
  557.         if side == "" then
  558.             turtle.turnLeft()
  559.             if turtle.inspectPlus(list) == "frame" then
  560.                 turtle.turnLeft()
  561.                 turtle.turnLeft()
  562.             end
  563.         end
  564.     else
  565.         turtle["dig"..side]()
  566.     end
  567.  
  568.     return true
  569. end
  570.  
  571. function farm()
  572.     local IDList =  { tree = { canadd = true, IDS = loadList("idlist/tree"
  573.                                                             ,{"minecraft:log"})}
  574.                     , sap  = { canadd = true, IDS = loadList("idlist/sap"
  575.                                                             ,{"minecraft:sapling"})}
  576.                     , digs = { canadd = true, IDS = loadList("idlist/digs" 
  577.                                                             ,{"minecraft:melon_block"
  578.                                                             , "minecraft:pumpkin"
  579.                                                             , "minecraft:reeds"
  580.                                                             , "minecraft:leaves"} ) }
  581.                     , plant = {canadd = false,IDS ={ "minecraft:wheat"
  582.                                                     ,"minecraft:potatoes"
  583.                                                     ,"minecraft:carrots"
  584.                                                     ,"minecraft:nether_wart"}}
  585.                     , sign = {canadd = false, IDS ={"minecraft:standing_sign"
  586.                                                    ,"minecraft:wall_sign"
  587.                                                    ,"Flatsigns:blockFlatSign"}}
  588.                     , chest = {canadd = true, IDS = loadList("idlist/chest"
  589.                                                             ,{"minecraft:chest"
  590.                                                             , "EnderStorage:enderChest"})}
  591.                     , seed = {canadd = false, IDS ={"minecraft:wheat_seeds"
  592.                                                    ,"minecraft:potato"
  593.                                                    ,"minecraft:carrot"}}
  594.                     , frame = {canadd = true,IDS =loadList("idlist/frame")}}
  595.     digTreeInit(IDList)
  596.     while true do
  597.         workFarm(IDList,"Down")
  598.         workFarm(IDList,"Up")
  599.         if not workFarm(IDList,"") then
  600.             turtle.crucialForward()
  601.         end
  602.     end
  603. end
  604.  
  605. function syousuu (num,level)
  606.     local r = num * 10^level
  607.     return (math.floor(r) / 10^level)
  608. end
  609.  
  610. function kmg( num )
  611.     local kmgList = {"","K","M","G","T"}
  612.     local f = 1
  613.     while num > 1000 do
  614.         num = num / 1000
  615.         f = f + 1
  616.     end
  617.     if f > 5 then
  618.         f = 5
  619.     end
  620.     return syousuu(num,0) .. kmgList[f]
  621. end
  622.  
  623. function getEUData(peri)
  624.     local st = peri.getEUStored()
  625.     local max = peri.getEUCapacity()
  626.     local p = 100 / max * st
  627.     return syousuu(p,0).."% " .. kmg(st).."/"..kmg(max)
  628. end
  629.  
  630. function getRFData(peri)
  631.     local st = peri.getEnergyStored()
  632.     local max = peri.getMaxEnergyStored()
  633.     local p = 100 / max * st
  634.     return syousuu(p,0).."% " .. kmg(st).."/"..kmg(max)
  635. end
  636.  
  637. function getTankData(peri)
  638.     local ans = peri.getTankInfo()
  639.     local st = 0
  640.     local typ = "empty"
  641.     if not ans then return "no data" end
  642.     if ans[1].contents ~= nil then
  643.         if ans[1].contents.amount ~= nil then
  644.             st = ans[1].contents.amount
  645.         end
  646.         if ans[1].contents.rawName ~= nil then
  647.             typ = ans[1].contents.rawName
  648.         end
  649.     end
  650.     local max = ans[1].capacity
  651.     local p = 100 / max * st
  652.     return typ.." "..syousuu(p,0).."% " .. kmg(st).."/"..kmg(max)
  653. end
  654.  
  655. function getAspectData(peri)
  656.     local asplist = peri.getAspects()
  657.     local r = ""
  658.     for k, v in pairs(asplist) do
  659.         r = r .. v .. peri.getAspectCount(v) .. " "
  660.     end
  661.     if r == "" then r = " Aspect:empty" end
  662.     return r
  663. end
  664.  
  665. function isEU( side )
  666.     if peripheral.wrap(side).getEUStored ~= nil then
  667.         return true
  668.     end
  669.     return false
  670. end
  671.  
  672. function isRF( side )
  673.     if peripheral.wrap(side).getEnergyStored ~= nil then
  674.         return true
  675.     end
  676.     return false
  677. end
  678.  
  679. function isTank( side )
  680.     if peripheral.wrap(side).getTankInfo ~= nil then
  681.         return true
  682.     end
  683.     return false
  684. end
  685.  
  686. function isThaum( side )
  687.     if peripheral.wrap(side).getAspects ~= nil then
  688.         return true
  689.     end
  690.     return false
  691. end
  692.  
  693. function monisClr(monis)
  694.     term.clear()
  695.     term.setCursorPos(1, 1)
  696.     for i,e in pairs(monis) do
  697.         e.clear()
  698.         e.setCursorPos(1, 1)
  699.     end
  700. end
  701.  
  702. function monisWrite(monis,str,clr)
  703.     if term.isColor() then term.setTextColor(clr) end
  704.     write(str.."\n")
  705.     if term.isColor() then term.setTextColor(colors.white) end
  706.     if monis == nil then return end
  707.     for i,e in pairs(monis) do
  708.         if e.isColor() then e.setTextColor(clr) end
  709.         e.write(str)
  710.         if e.isColor() then e.setTextColor(colors.white) end
  711.         local x,y = e.getCursorPos()
  712.         y = y + 1
  713.         e.setCursorPos(1, y)
  714.     end
  715. end
  716.  
  717. function checker()
  718.     local periList = peripheral.getNames()
  719.     local looklist = {}
  720.     local monis = {}
  721.     local modem = ""
  722.     for i,e in pairs(periList) do
  723.         if isEU(e) then
  724.             looklist[#looklist+1] = {}
  725.             looklist[#looklist].type = "EU"
  726.             looklist[#looklist].peri = peripheral.wrap(e)
  727.             looklist[#looklist].func = getEUData
  728.             looklist[#looklist].clr  = colours.yellow
  729.             looklist[#looklist].txt  = ""
  730.         end
  731.         if isRF(e) then
  732.             looklist[#looklist+1] = {}
  733.             looklist[#looklist].type = "RF"
  734.             looklist[#looklist].peri = peripheral.wrap(e)
  735.             looklist[#looklist].func = getRFData
  736.             looklist[#looklist].clr  = colours.red
  737.             looklist[#looklist].txt  = ""
  738.         end
  739.         if isTank(e) then
  740.             looklist[#looklist+1] = {}
  741.             looklist[#looklist].type = "mb"
  742.             looklist[#looklist].peri = peripheral.wrap(e)
  743.             looklist[#looklist].func = getTankData
  744.             looklist[#looklist].clr  = colours.lime
  745.             looklist[#looklist].txt  = ""
  746.         end
  747.         if isThaum(e) then
  748.             looklist[#looklist+1] = {}
  749.             looklist[#looklist].type = "ASP"
  750.             looklist[#looklist].peri = peripheral.wrap(e)
  751.             looklist[#looklist].func = getAspectData
  752.             looklist[#looklist].clr  = colors.purple
  753.             looklist[#looklist].txt  = ""
  754.         end
  755.         if peripheral.getType(e) == "monitor" then
  756.             monis[#monis+1] = peripheral.wrap(e)
  757.         end
  758.         if peripheral.getType(e) == "modem" then
  759.             modem = e
  760.         end
  761.     end
  762.     if modem ~= "" then rednet.open(modem) end
  763.     while true do
  764.         local send = {channel="gapi",sender=os.getComputerID(),line={}}
  765.         monisClr(monis)
  766.         for i,e in pairs(looklist) do
  767.             e.txt = e.type..i.." "..e.func(e.peri)
  768.             monisWrite(monis,e.txt,e.clr)
  769.             send.line[#(send.line) + 1] = {t=e.txt,c=e.clr}
  770.         end
  771.         rednet.broadcast(textutils.serialize(send))
  772.         sleep(1)
  773.     end
  774. end
  775.  
  776. function moniter(ch)
  777.     if not ch then ch = "gapi" end
  778.     local monis = {}
  779.     local modem = ""
  780.     local mem = {}
  781.     for i,e in pairs(peripheral.getNames()) do
  782.         if peripheral.getType(e) == "monitor" then
  783.             monis[#monis+1] = peripheral.wrap(e)
  784.         end
  785.         if peripheral.getType(e) == "modem" then
  786.             modem = e
  787.         end
  788.     end
  789.     if modem ~= "" then rednet.open(modem) end
  790.     while true do
  791.         monisClr(monis)
  792.         write("hearing ch:"..ch.."\n")
  793.         for k, v in pairs(mem) do
  794.             for l, b in pairs(v.line) do
  795.                 monisWrite(monis,b.t,b.c)
  796.             end
  797.             monisWrite(monis,"",colors.white)
  798.         end
  799.         local eve = {os.pullEvent()}
  800.         if eve[1] == "rednet_message" then
  801.             local depack = textutils.unserialize(eve[3])
  802.             if depack and depack.channel and depack.channel == ch then
  803.                 mem[eve[2]] = depack
  804.             end
  805.         end
  806.     end
  807. end
  808.  
  809. function rdig()
  810.     local IDList = { ok = { canadd = true, IDS = loadList("idlist/ok")}
  811.                     , non  = { canadd = true, IDS = loadList("idlist/non")}
  812.                     , lava = { canadd = false,IDS = "minecraft:flowing_lava"}}
  813.     while true do
  814.         if not turtle.detect() then
  815.             turtle.turnLeft()
  816.             if not turtle.detect() then
  817.                 break
  818.             end
  819.         end
  820.         local ans = turtle.inspectPlus(IDList)
  821.         if ans == "ok" or ans == "lava" then
  822.             turtle.digForward()
  823.         else
  824.             break
  825.         end
  826.         ans = turtle.inspectPlusUp(IDList)
  827.         if ans == "ok" then
  828.             turtle.digUp()
  829.         elseif ans == "lava" then
  830.             turtle.up()
  831.             turtle.down()
  832.         end
  833.         ans = turtle.inspectPlusDown(IDList)
  834.         if ans == "ok" then
  835.             turtle.digDown()
  836.         elseif ans == "lava" then
  837.             turtle.down()
  838.             turtle.up()
  839.         end
  840.     end
  841. end
  842.  
  843. args = {...}
  844. if #args == 0 then
  845.     write("need argments\n")
  846.     monisWrite(nil,"gapi mat (size)",colours.yellow)
  847.     --write("naruto moving and set blocks on ground.\n")
  848.     monisWrite(nil,"gapi roof (size)",colours.yellow)
  849.     --write("naruto moving and set blocks over head.\n")
  850.     monisWrite(nil,"gapi farm",colours.yellow)
  851.     --write("can sign controll farming.>,<,A,V,<<,>>,alarm,wait.\n")
  852.     --write("tree farm, only straight tree(spruce tree).\n")
  853.     monisWrite(nil,"gapi checker",colours.yellow)
  854.     --write("EU RF liquid Tank checking. auto monitor out.\n")
  855.     monisWrite(nil,"gapi pcheck",colours.yellow)
  856.     --write("periphral data watching.\n")
  857.     monisWrite(nil,"gapi moni",colours.yellow)
  858. else
  859.     code = string.lower(args[1])
  860.     if code == "mat" then
  861.         mat(args[2])
  862.     end
  863.     if code == "rdig" then
  864.         rdig()
  865.     end
  866.     if code == "roof" then
  867.         roof(args[2])
  868.     end
  869.     if code == "farm" then
  870.         farm()
  871.     end
  872.     if code == "checker" then
  873.         checker()
  874.     end
  875.     if code == "pcheck" then
  876.         PeriCheck()
  877.     end
  878.     if code == "moni" then
  879.         moniter(args[2])
  880.     end
  881. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement