Advertisement
melzneni

Turti Std

Aug 14th, 2023 (edited)
1,809
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 25.53 KB | None | 0 0
  1. local TYPE_FUNCTION = 1
  2. local TYPE_VALUE = 2
  3. local TYPE_VAR = 3
  4. local TYPE_USER_FUNCTION = 4
  5. local TYPE_DEFAULT_FUNCTION = 5
  6. local TYPE_ARR = 6
  7. local MODE_TEST = 1
  8. local MODE_MC = 2
  9.  
  10. local test = false
  11.  
  12. if os.loadAPI == nil then
  13.     DFE = require("turtleStd")
  14.     test = true
  15.     DFE.setTest(true)
  16. else
  17.     DFE = require("DFE")
  18.     test = false
  19.     DFE.setTest(false)
  20. end
  21.  
  22. turtleAdapter = DFE.turtleAdapter
  23.  
  24. local storage
  25. local save
  26.  
  27. local gpsAdapter = {
  28.     locate = function()
  29.         local x, y, z = gps.locate()
  30.         if x == nil then
  31.             if not test then
  32.                 shell.run("gps", "locate")
  33.             end
  34.             error("unable to execute gps.locate()")
  35.         end
  36.         return { x, y, z }
  37.     end
  38. }
  39.  
  40. local AREA_EMPTY = -1
  41. local AREA_SET = -2
  42.  
  43. function swapInArray(arr1, arr2, index)
  44.     local v = arr1[index]
  45.     arr1[index] = arr2[index]
  46.     arr2[index] = v;
  47. end
  48.  
  49. function trim(s)
  50.     return (string.gsub(s, "^%s*(.-)%s*$", "%1"))
  51. end
  52.  
  53. local defaultFunctions = {
  54.     shellRun = {
  55.         type = TYPE_DEFAULT_FUNCTION, pars = { 1, 10 },
  56.         fct = function(...)
  57.             if shell == nil then
  58.                 return
  59.             end
  60.             return shell.run(table.unpack(arg))
  61.         end
  62.     },
  63.     shellExecute = {
  64.         type = TYPE_DEFAULT_FUNCTION, pars = { 1, 10 },
  65.         fct = function(...)
  66.             if shell == nil then
  67.                 return
  68.             end
  69.             return shell.execute(table.unpack(arg))
  70.         end
  71.     },
  72.     findText = {
  73.         type = TYPE_DEFAULT_FUNCTION,
  74.         pars = { 2 },
  75.         nonCritical = true,
  76.         fct = function(txt, pattern)
  77.             return txt:find(pattern)
  78.         end
  79.     },
  80.     splitText = {
  81.         type = TYPE_DEFAULT_FUNCTION, pars = { 2 },
  82.         nonCritical = true,
  83.         fct = function(txt, pattern)
  84.             return toTurtiArray(splitTextPattern(txt, pattern, true))
  85.         end
  86.     },
  87.     stringLower = {
  88.         type = TYPE_DEFAULT_FUNCTION, pars = { 1 },
  89.         nonCritical = true,
  90.         fct = function(s)
  91.             return string.lower(s)
  92.         end
  93.     },
  94.     stringUpper = {
  95.         type = TYPE_DEFAULT_FUNCTION, pars = { 1 },
  96.         nonCritical = true,
  97.         fct = function(s)
  98.             return string.upper(s)
  99.         end
  100.     },
  101.     tonumber = {
  102.         type = TYPE_DEFAULT_FUNCTION, pars = { 1 },
  103.         nonCritical = true,
  104.         fct = function(value)
  105.             return tonumber(trim(value))
  106.         end
  107.     },
  108.     input = {
  109.         type = TYPE_DEFAULT_FUNCTION, pars = { 0, 1 },
  110.         fct = function(label)
  111.             if label then
  112.                 io.write("input<" .. label .. ">: ")
  113.             else
  114.                 io.write("input: ")
  115.             end
  116.             return io.read()
  117.         end
  118.     },
  119.     activateSave = {
  120.         type = TYPE_DEFAULT_FUNCTION, pars = { 1 },
  121.         fct = function(value)
  122.             storage.save = value;
  123.         end
  124.     },
  125.     inspectName = {
  126.         type = TYPE_DEFAULT_FUNCTION, pars = { 0 },
  127.         fct = function()
  128.             local success, data = turtle.inspect()
  129.             if not success then
  130.                 return nil
  131.             end
  132.             return data.name
  133.         end
  134.     },
  135.     inspectNameUp = {
  136.         type = TYPE_DEFAULT_FUNCTION, pars = { 0 },
  137.         fct = function()
  138.             local success, data = turtle.inspectUp()
  139.             if not success then
  140.                 return nil
  141.             end
  142.             return data.name
  143.         end
  144.     },
  145.     inspectNameDown = {
  146.         type = TYPE_DEFAULT_FUNCTION, pars = { 0 },
  147.         fct = function()
  148.             local success, data = turtle.inspectDown()
  149.             if not success then
  150.                 return nil
  151.             end
  152.             return data.name
  153.         end
  154.     },
  155.     craft = {
  156.         type = TYPE_DEFAULT_FUNCTION,
  157.         pars = { 0, 1 },
  158.         fct = function(...)
  159.             return turtle.craft(...)
  160.         end
  161.     },
  162.     printf = {
  163.         type = TYPE_DEFAULT_FUNCTION,
  164.         pars = { 1 },
  165.         nonCritical = true,
  166.         fct = function(src)
  167.             local tagOpen = src:find("<")
  168.             while tagOpen ~= nil do
  169.                 write(src:sub(1, tagOpen - 1))
  170.                 src = src:sub(tagOpen + 1)
  171.                 local tagClose = src:find(">")
  172.                 local command = src:sub(1, tagClose - 1)
  173.                 src = src:sub(tagClose + 1)
  174.  
  175.                 tagOpen = src:find("<")
  176.                 if not tagOpen then
  177.                     write(src)
  178.                     break
  179.                 end
  180.                 local body = src:sub(1, tagOpen - 1)
  181.                 src = src:sub(tagOpen + 1)
  182.                 tagClose = src:find(">")
  183.                 if not tagClose then
  184.                     write(body .. "<" .. src)
  185.                     break
  186.                 end
  187.  
  188.                 local cSep = command:find(":")
  189.                 if cSep then
  190.                     local name = command:sub(1, cSep - 1)
  191.                     local argument = command:sub(cSep + 1)
  192.                     if name == "c" then
  193.                         if not test then
  194.                             local oldColor = term.getTextColor()
  195.                             term.setTextColor(colors[argument])
  196.                             write(body)
  197.                             term.setTextColor(oldColor)
  198.                         else
  199.                             write(body)
  200.                         end
  201.                     end
  202.                 end
  203.  
  204.                 src = src:sub(tagClose + 1)
  205.                 tagOpen = src:find("<")
  206.             end
  207.             write(src .. "\n")
  208.         end
  209.     },
  210.     print = {
  211.         type = TYPE_DEFAULT_FUNCTION, pars = { 1, 1000 },
  212.         nonCritical = true,
  213.         fct = function(...)
  214.             local args = { ... }
  215.             if #args == 0 then
  216.                 write("null\n")
  217.                 return
  218.             end
  219.             local first = true
  220.             for i, v in ipairs(args) do
  221.                 if first then
  222.                     first = false
  223.                 else
  224.                     write(" ")
  225.                 end
  226.                 if v == nil then
  227.                     write("null")
  228.                 elseif type(v) == "table" then
  229.                     printTable(v, true)
  230.                 else
  231.                     write(tostring(v))
  232.                 end
  233.             end
  234.             write("\n")
  235.         end
  236.     },
  237.     mvFwd = {
  238.         type = TYPE_DEFAULT_FUNCTION, pars = { 0, 1 },
  239.         fct = function(steps)
  240.             local par = tonumber(steps)
  241.             if par == nil then
  242.                 par = 1
  243.             end
  244.             for i = 1, par do
  245.                 turtleAdapter.forward()
  246.             end
  247.         end
  248.     },
  249.     mvBack = {
  250.         type = TYPE_DEFAULT_FUNCTION, pars = { 0, 1 },
  251.         fct = function(steps)
  252.             local par = tonumber(steps)
  253.             if par == nil then
  254.                 par = 1
  255.             end
  256.             turtleAdapter.turnLeft()
  257.             turtleAdapter.turnLeft()
  258.             for i = 1, par do
  259.                 turtleAdapter.forward()
  260.             end
  261.             turtleAdapter.turnLeft()
  262.             turtleAdapter.turnLeft()
  263.             return moved
  264.         end
  265.     },
  266.     mvUp = { type = TYPE_DEFAULT_FUNCTION, pars = { 0, 1 },
  267.              fct = function(steps)
  268.                  local par = tonumber(steps)
  269.                  if par == nil then
  270.                      par = 1
  271.                  end
  272.                  for i = 1, par do
  273.                      turtleAdapter.up()
  274.                  end
  275.                  return moved
  276.              end
  277.     },
  278.     mvDown = {
  279.         type = TYPE_DEFAULT_FUNCTION, pars = { 0, 1 },
  280.         fct = function(steps)
  281.             local par = tonumber(steps)
  282.             if par == nil then
  283.                 par = 1
  284.             end
  285.             for i = 1, par do
  286.                 turtleAdapter.down()
  287.             end
  288.             return moved
  289.         end
  290.     },
  291.     left = {
  292.         type = TYPE_DEFAULT_FUNCTION, pars = { 0, 1 },
  293.         fct = function(steps)
  294.             local par = tonumber(steps)
  295.             if par == nil then
  296.                 par = 1
  297.             end
  298.             for i = 1, par do
  299.                 turtleAdapter.turnLeft()
  300.             end
  301.         end
  302.     },
  303.     right = {
  304.         type = TYPE_DEFAULT_FUNCTION, pars = { 0, 1 },
  305.         fct = function(steps)
  306.             local par = tonumber(steps)
  307.             if par == nil then
  308.                 par = 1
  309.             end
  310.             for i = 1, par do
  311.                 turtleAdapter.turnRight()
  312.             end
  313.         end
  314.     },
  315.     equipLeft = {
  316.         type = TYPE_DEFAULT_FUNCTION, pars = { 0, 1 },
  317.         fct = function(slot)
  318.             if slot then
  319.                 turtle.select(slot + 1)
  320.             end
  321.             return turtle.equipLeft()
  322.         end
  323.     },
  324.     equipRight = {
  325.         type = TYPE_DEFAULT_FUNCTION, pars = { 0, 1 },
  326.         fct = function(slot)
  327.             if slot then
  328.                 turtle.select(slot + 1)
  329.             end
  330.             return turtle.equipRight()
  331.         end
  332.     },
  333.     getItemName = {
  334.         type = TYPE_DEFAULT_FUNCTION, pars = { 1 },
  335.         fct = function(slot)
  336.             return turtleAdapter.getItemName(slot + 1)
  337.         end
  338.     },
  339.     getItemSpace = {
  340.         type = TYPE_DEFAULT_FUNCTION, pars = { 1 },
  341.         fct = function(slot)
  342.             return turtleAdapter.getItemSpace(slot + 1)
  343.         end
  344.     },
  345.     getItemCount = {
  346.         type = TYPE_DEFAULT_FUNCTION, pars = { 1 },
  347.         fct = function(slot)
  348.             return turtleAdapter.getItemCount(slot + 1)
  349.         end
  350.     },
  351.     dig = {
  352.         type = TYPE_DEFAULT_FUNCTION, pars = { 0, 2 },
  353.         fct = function(slot, expected)
  354.             if not slot then
  355.                 return turtleAdapter.dig()
  356.             end
  357.             if not test then
  358.                 while true do
  359.                     local name = turtleAdapter.getItemName(slot + 1)
  360.                     if name == nil or expected == nil or name == expected then
  361.                         break
  362.                     end
  363.                     turtleAdapter.dropUp()
  364.                 end
  365.             end
  366.             turtleAdapter.select(slot + 1)
  367.             return turtleAdapter.dig()
  368.         end
  369.     },
  370.     digUp = {
  371.         type = TYPE_DEFAULT_FUNCTION, pars = { 0, 2 },
  372.         fct = function(slot, expected)
  373.             if not slot then
  374.                 return turtleAdapter.digUp()
  375.             end
  376.             if not test then
  377.                 while true do
  378.                     local name = turtleAdapter.getItemName(slot + 1)
  379.                     if name == nil or expected == nil or name == expected then
  380.                         break
  381.                     end
  382.                     turtleAdapter.dropUp()
  383.                 end
  384.             end
  385.             turtleAdapter.select(slot + 1)
  386.             return turtleAdapter.digUp()
  387.         end
  388.     },
  389.     digDown = {
  390.         type = TYPE_DEFAULT_FUNCTION, pars = { 0, 2 },
  391.         fct = function(slot, expected)
  392.             if not slot then
  393.                 return turtleAdapter.digDown()
  394.             end
  395.             if not test then
  396.                 while true do
  397.                     local name = turtleAdapter.getItemName(slot + 1)
  398.                     if name == nil or expected == nil or name == expected then
  399.                         break
  400.                     end
  401.                     turtleAdapter.dropUp()
  402.                 end
  403.             end
  404.             turtleAdapter.select(slot + 1)
  405.             return turtleAdapter.digDown()
  406.         end
  407.     },
  408.     place = {
  409.         type = TYPE_DEFAULT_FUNCTION, pars = { 1 },
  410.         fct = function(slot)
  411.             turtleAdapter.select(slot + 1)
  412.             return turtleAdapter.place()
  413.         end
  414.     },
  415.     placeUp = {
  416.         type = TYPE_DEFAULT_FUNCTION, pars = { 1 },
  417.         fct = function(slot)
  418.             turtleAdapter.select(slot + 1)
  419.             return turtleAdapter.placeUp()
  420.         end
  421.     },
  422.     placeDown = {
  423.         type = TYPE_DEFAULT_FUNCTION, pars = { 1 },
  424.         fct = function(slot)
  425.             turtleAdapter.select(slot + 1)
  426.             return turtleAdapter.placeDown()
  427.         end
  428.     },
  429.     peripheral = {
  430.         type = TYPE_DEFAULT_FUNCTION, pars = { 2, 456412 },
  431.         fct = function(side, method, ...)
  432.             return peripheral.call(side, method, ...)
  433.         end
  434.     },
  435.     setTestOutput = {
  436.         type = TYPE_DEFAULT_FUNCTION, pars = { 1 },
  437.         fct = function(value)
  438.             if type(value) ~= "boolean" then
  439.                 error("arg of function 'setstorageData.testOutput' needs to be of type 'boolean'")
  440.             end
  441.             storage.testOutput = value
  442.         end
  443.     },
  444.     drop = {
  445.         type = TYPE_DEFAULT_FUNCTION, pars = { 1, 2 },
  446.         fct = function(slot, num)
  447.             turtleAdapter.select(slot + 1)
  448.             if num ~= nil then
  449.                 turtleAdapter.drop(num)
  450.             else
  451.                 turtleAdapter.drop(1)
  452.             end
  453.         end
  454.     },
  455.     dropUp = {
  456.         type = TYPE_DEFAULT_FUNCTION, pars = { 1, 2 },
  457.         fct = function(slot, num)
  458.             turtleAdapter.select(slot + 1)
  459.             if num ~= nil then
  460.                 turtleAdapter.dropUp(num)
  461.             else
  462.                 turtleAdapter.dropUp(1)
  463.             end
  464.         end
  465.     },
  466.     dropDown = {
  467.         type = TYPE_DEFAULT_FUNCTION, pars = { 1, 2 },
  468.         fct = function(slot, num)
  469.             turtleAdapter.select(slot + 1)
  470.             if num ~= nil then
  471.                 turtleAdapter.dropDown(num)
  472.             else
  473.                 turtleAdapter.dropDown(1)
  474.             end
  475.         end
  476.     },
  477.     select = {
  478.         type = TYPE_DEFAULT_FUNCTION, pars = { 1 },
  479.         fct = function(slot)
  480.             turtle.select(slot + 1)
  481.         end
  482.     },
  483.     suck = {
  484.         type = TYPE_DEFAULT_FUNCTION, pars = { 0, 2 },
  485.         fct = function(slot, num)
  486.             if not num then
  487.                 num = 1
  488.             end
  489.             if slot then
  490.                 turtleAdapter.select(slot + 1)
  491.             end
  492.             turtleAdapter.suck(num)
  493.         end
  494.     },
  495.     suckUp = {
  496.         type = TYPE_DEFAULT_FUNCTION, pars = { 0, 2 },
  497.         fct = function(slot, num)
  498.             if not num then
  499.                 num = 1
  500.             end
  501.             if slot then
  502.                 turtleAdapter.select(slot + 1)
  503.             end
  504.             turtleAdapter.suckUp(num)
  505.         end
  506.     },
  507.     suckDown = {
  508.         type = TYPE_DEFAULT_FUNCTION, pars = { 0, 2 },
  509.         fct = function(slot, num)
  510.             if not num then
  511.                 num = 1
  512.             end
  513.             if slot then
  514.                 turtleAdapter.select(slot + 1)
  515.             end
  516.             turtleAdapter.suckDown(num)
  517.         end
  518.     },
  519.     redstone = {
  520.         type = TYPE_DEFAULT_FUNCTION, pars = { 2 },
  521.         fct = function(side, value)
  522.             redstone.setOutput(side, value)
  523.         end
  524.     },
  525.     getRedstoneInput = {
  526.         type = TYPE_DEFAULT_FUNCTION, pars = {},
  527.         fct = function(side)
  528.             return redstone.getInput(side)
  529.         end
  530.     },
  531.     refuel = {
  532.         type = TYPE_DEFAULT_FUNCTION, pars = { 0 },
  533.         fct = function()
  534.             for i = 1, 16 do
  535.                 turtleAdapter.select(i)
  536.                 turtleAdapter.refuel()
  537.             end
  538.         end
  539.     },
  540.     getFuelLevel = {
  541.         type = TYPE_DEFAULT_FUNCTION, pars = { 0 },
  542.         fct = function()
  543.             return turtleAdapter.getFuelLevel()
  544.         end
  545.     },
  546.     clearTerminal = {
  547.         type = TYPE_DEFAULT_FUNCTION, pars = { 0 },
  548.         nonCritical = true,
  549.         fct = function()
  550.             if term == nil then
  551.                 return
  552.             end
  553.             term.clear()
  554.             term.setCursorPos(1, 1)
  555.         end
  556.     },
  557.     sleep = {
  558.         type = TYPE_DEFAULT_FUNCTION, pars = { 1 },
  559.         fct = function(seconds)
  560.             local storage = ThreadManager.currentThread.storage
  561.             if seconds > 2 then
  562.                 if storage.toSleep ~= nil then
  563.                     seconds = storage.toSleep - (storage.currTime - storage.sleepStart)
  564.                 end
  565.                 storage.sleepStart = os.clock()
  566.                 storage.currTime = os.clock()
  567.                 storage.toSleep = seconds
  568.                 local printLast = 0
  569.                 local count = 0
  570.                 while storage.currTime - storage.sleepStart < seconds do
  571.                     sleep(0.1)
  572.                     yield()
  573.                     storage.currTime = os.clock()
  574.                     if storage.currTime - storage.sleepStart > printLast + 1 then
  575.                         printLast = printLast + 1
  576.                         --[[if count ~= 0 then
  577.                             if not test then
  578.                                 local x, y = term.getCursorPos()
  579.                                 term.setCursorPos(1, y - 1)
  580.                             end
  581.                         else
  582.                             count = 1
  583.                         end]]--
  584.                         --print("slept: ", printLast, "/", storage.toSleep, "s")
  585.                         save()
  586.                     end
  587.                 end
  588.                 storage.toSleep = nil
  589.             else
  590.                 sleep(seconds)
  591.             end
  592.         end
  593.     }
  594. }
  595.  
  596. function getDefaultFunctions()
  597.     return defaultFunctions
  598. end
  599.  
  600. function setTest(value)
  601.     test = value
  602.     if test then
  603.         _G.sleep = function(n)
  604.             -- seconds
  605.             local t0 = os.clock()
  606.             while os.clock() - t0 <= n do
  607.             end
  608.         end
  609.         _G.turtle = {
  610.             forward = function()
  611.                 if storage.testOutput then
  612.                     print("fct: turtle.forward()")
  613.                 end
  614.                 if storage.direction == 0 then
  615.                     storage.pos[1] = storage.pos[1] + 1
  616.                 elseif storage.direction == 1 then
  617.                     storage.pos[3] = storage.pos[3] + 1
  618.                 elseif storage.direction == 2 then
  619.                     storage.pos[1] = storage.pos[1] - 1
  620.                 elseif storage.direction == 3 then
  621.                     storage.pos[3] = storage.pos[3] - 1
  622.                 end
  623.                 return true
  624.             end,
  625.             back = function()
  626.                 if storage.testOutput then
  627.                     print("fct: turtle.back()")
  628.                 end
  629.                 if storage.direction == 0 then
  630.                     storage.pos[1] = storage.pos[1] - 1
  631.                 elseif storage.direction == 1 then
  632.                     storage.pos[3] = storage.pos[3] - 1
  633.                 elseif storage.direction == 2 then
  634.                     storage.pos[1] = storage.pos[1] + 1
  635.                 elseif storage.direction == 3 then
  636.                     storage.pos[3] = storage.pos[3] + 1
  637.                 end
  638.                 return true
  639.             end,
  640.             up = function()
  641.                 if storage.testOutput then
  642.                     print("fct: turtle.up()")
  643.                 end
  644.                 storage.pos[2] = storage.pos[2] + 1
  645.                 return true
  646.             end,
  647.             down = function()
  648.                 if storage.testOutput then
  649.                     print("fct: turtle.down()")
  650.                 end
  651.                 if test then
  652.                     storage.pos[2] = storage.pos[2] - 1
  653.                 end
  654.                 return true
  655.             end,
  656.             turnLeft = function()
  657.                 if storage.testOutput then
  658.                     print("fct: turtle.turnLeft()")
  659.                 end
  660.                 storage.direction = storage.direction - 1
  661.                 if storage.direction < 0 then
  662.                     storage.direction = storage.direction + 4
  663.                 end
  664.                 return true
  665.             end,
  666.             turnRight = function()
  667.                 if storage.testOutput then
  668.                     print("fct: turtle.turnRight()")
  669.                 end
  670.                 storage.direction = storage.direction + 1
  671.                 if storage.direction > 3 then
  672.                     storage.direction = storage.direction - 4
  673.                 end
  674.                 return true
  675.             end,
  676.             select = function(id)
  677.                 if storage.testOutput then
  678.                     print("fct: turtle.select(" .. id .. ")")
  679.                 end
  680.                 return true
  681.             end,
  682.             place = function()
  683.                 if storage.testOutput then
  684.                     print("fct: turtle.place()")
  685.                 end
  686.                 return true
  687.             end,
  688.             placeUp = function()
  689.                 if storage.testOutput then
  690.                     print("fct: turtle.placeUp()")
  691.                 end
  692.                 return true
  693.             end,
  694.             placeDown = function()
  695.                 if storage.testOutput then
  696.                     print("fct: turtle.placeDown()")
  697.                 end
  698.                 return true
  699.             end,
  700.             dig = function()
  701.                 if storage.testOutput then
  702.                     print("fct: turtle.dig()")
  703.                 end
  704.                 return true
  705.             end,
  706.             digUp = function()
  707.                 if storage.testOutput then
  708.                     print("fct: turtle.digUp()")
  709.                 end
  710.                 return true
  711.             end,
  712.             digDown = function()
  713.                 if storage.testOutput then
  714.                     print("fct: turtle.digDown()")
  715.                 end
  716.                 return true
  717.             end,
  718.             attack = function()
  719.                 if storage.testOutput then
  720.                     print("fct: turtle.attack()")
  721.                 end
  722.                 return true
  723.             end,
  724.             attackUp = function()
  725.                 if storage.testOutput then
  726.                     print("fct: turtle.attackUp()")
  727.                 end
  728.                 return true
  729.             end,
  730.             attackDown = function()
  731.                 if storage.testOutput then
  732.                     print("fct: turtle.attackDown()")
  733.                 end
  734.                 return true
  735.             end,
  736.             detect = function()
  737.                 if storage.space ~= nil then
  738.                     local pos = storage.pos
  739.                     local o = storage.direction
  740.                     if o == 0 then
  741.                         if #storage.space > pos[1] then
  742.                             return #storage.space[pos[1] + 1][pos[2]][pos[3]] == AREA_SET
  743.                         end
  744.                         return false
  745.                     elseif o == 1 then
  746.                         if #storage.space[1][1] > pos[3] then
  747.                             return #storage.space[pos[1]][pos[2]][pos[3] + 1] == AREA_SET
  748.                         end
  749.                         return false
  750.                     elseif o == 2 then
  751.                         if #storage.space < pos[1] then
  752.                             return #storage.space[pos[1] - 1][pos[2]][pos[3]] == AREA_SET
  753.                         end
  754.                         return false
  755.                     elseif o == 3 then
  756.                         if #storage.space[1][1] < pos[3] then
  757.                             return #storage.space[pos[1]][pos[2]][pos[3] - 1] == AREA_SET
  758.                         end
  759.                         return false
  760.                     end
  761.                     error("fail:" .. o)
  762.                 else
  763.                     return false;
  764.                 end
  765.             end,
  766.             detectUp = function()
  767.                 if storage.space ~= nil then
  768.                     local pos = storage.pos
  769.                     if #storage.space[1] > pos[2] then
  770.                         return #storage.space[pos[1]][pos[2] + 1][pos[3]] == AREA_SET
  771.                     end
  772.                     return false
  773.                 else
  774.                     return false;
  775.                 end
  776.             end,
  777.             detectDown = function()
  778.                 if storage.space ~= nil then
  779.                     local pos = storage.pos
  780.                     if #storage.space[1] < pos[2] then
  781.                         return #storage.space[pos[1]][pos[2] - 1][pos[3]] == AREA_SET
  782.                     end
  783.                     return false
  784.                 else
  785.                     return false;
  786.                 end
  787.             end,
  788.             getItemCount = function(id)
  789.                 return 0
  790.             end
  791.         }
  792.         _G.gps = {
  793.             locate = function()
  794.                 return storage.pos[1], storage.pos[2], storage.pos[3]
  795.             end
  796.         }
  797.         _G.peripheral = {
  798.             call = function(arg1, arg2)
  799.                 if storage.testOutput then
  800.                     print("fct: peripheral.call(" .. arg1 .. ", " .. arg2 .. ")")
  801.                 end
  802.             end
  803.         }
  804.     end
  805. end
  806.  
  807. setTest(test)
  808.  
  809. return {
  810.     api = defaultFunctions,
  811.     onInitStorage = function(_storage, _save)
  812.         storage = _storage
  813.         DFE.setStorageData(storage)
  814.         save = _save
  815.         if not storage.activeNetworks then
  816.             storage.activeNetworks = {}
  817.             storage.currentCallId = 0
  818.             storage.responses = {}
  819.             storage.callConfirmations = {}
  820.             storage.confirmationTimeout = CONFIRMATION_TIMEOUT
  821.         end
  822.         if test and storage.pos == nil then
  823.             storage.pos = { 0, 0, 0 }
  824.         end
  825.         if storage.direction == nil then
  826.             storage.direction = 0
  827.         end
  828.         if storage.nullOr == nil then
  829.             storage.nullOr = 0
  830.         end
  831.         if storage.testOutput == nil then
  832.             storage.testOutput = true
  833.         end
  834.     end,
  835. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement