Clor

OC/AE Assemblery line GT5U integration

May 26th, 2019
380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 12.81 KB | None | 0 0
  1. --dofile("recipes")
  2. recipes = {
  3.     MotorLUV = { label = "Gold Nugget", items = { { 1, 1 }, { 2, 2 }, { 3, 64 }, { 3, 64 }, { 3, 64 }, { 3, 64 }, { 4, 2 } }, fluids = { { 5, 144 }, { 6, 250 } } },
  4.     PistonLUV = { label = "Sand", items = { { 13, 1 }, { 7, 6 }, { 8, 4 }, { 9, 32 }, { 10, 4 }, { 11, 1 }, { 12, 2 }, { 4, 4 } }, fluids = { { 5, 144 }, { 6, 250 } } },
  5.     RoboarmLUV = { label = "Stone", items = { { 2, 4 }, { 11, 1 }, { 12, 3 }, { 13, 2 }, { 14, 1 }, { 15, 2 }, { 16, 2 }, { 17, 6 }, { 4, 6 } }, fluids = { { 5, 576 }, { 6, 250 } } },
  6.     MotorZPM = { label = "Dirt", items = { { 1, 2 }, { 18, 4 }, { 19, 4 }, { 20, 16 }, { 21, 64 }, { 21, 64 }, { 21, 64 }, { 21, 64 }, { 22, 2 } }, fluids = { { 5, 288 }, { 6, 750 } } },
  7.     PistonZPM = { label = "Gravel", items = { { 27, 1 }, { 23, 6 }, { 19, 4 }, { 20, 32 }, { 24, 4 }, { 25, 1 }, { 26, 2 }, { 22, 4 } }, fluids = { { 5, 288 }, { 6, 750 } } },
  8.     RoboarmZPM = { label = "Coal", items = { { 18, 4 }, { 25, 1 }, { 26, 3 }, { 27, 2 }, { 28, 1 }, { 15, 4 }, { 16, 4 }, { 17, 12 }, { 22, 6 } }, fluids = { { 5, 1152 }, { 6, 750 } } },
  9.     EmiterLUV = { label = "Sugar", items = { { 29, 1 }, { 31, 1 }, { 32, 2 }, { 33, 4 }, { 17, 7 }, { 30, 64 }, { 30, 64 }, { 30, 64 }, { 4, 7 } }, fluids = { { 5, 576 } } },
  10.     EmiterZPM = { label = "Redstone", items = { { 35, 1 }, { 34, 1 }, { 31, 2 }, { 32, 4 }, { 16, 7 }, { 36, 64 }, { 36, 64 }, { 36, 64 }, { 22, 7 } }, fluids = { { 5, 576 } } },
  11.     ConveyorLUV = { label = "Paper", items = { { 13, 2 }, { 7, 2 }, { 8, 4 }, { 9, 32 }, { 4, 2 } }, fluids = { { 37, 1440 }, { 6, 250 } } },
  12.     ConveyorZPM = { label = "Flint", items = { { 27, 2 }, { 23, 2 }, { 19, 4 }, { 20, 32 }, { 22, 2 } }, fluids = { { 37, 2880 }, { 6, 750 } } },
  13.     FieldGeneratorLUV = { label = "Bricks", items = { { 29, 1 }, { 7, 6 }, { 39, 1 }, { 34, 4 }, { 15, 8 }, { 38, 64 }, { 38, 64 }, { 38, 64 }, { 38, 64 }, { 4, 8 } }, fluids = { { 5, 576 } } },
  14.     NeuroProcessingUnit = { label = "Grass", items = { { 43, 1 }, { 42, 8 }, { 45, 8 }, { 44, 4 }, { 49, 8 }, { 46, 64 }, { 47, 4 } }, fluids = { { 40, 250 }, { 41, 100 }, { 48, 1000 } } },
  15.     LapatronLUV = { label = "Apple", items = { { 58, 1 }, { 50, 32 }, { 51, 4 }, { 52, 36 }, { 52, 36 }, { 53, 64 }, { 57, 32 }, { 56, 32 }, { 54, 32 }, { 55, 32 }, { 21, 64 } }, fluids = { { 5, 720 } } },
  16.     BatteryZPM = { label = "Glass", items = { { 59, 16 }, { 60, 1 }, { 60, 1 }, { 60, 1 }, { 60, 1 }, { 61, 8 }, { 62, 2 }, { 63, 64 }, { 63, 64 }, { 57, 8 }, { 64, 32 } }, fluids = { { 5, 2880 }, { 48, 16000 } } },
  17.     TEST = { label = "Carrot", items = { { 3, 16 }, { 3, 16 }, { 3, 16 }, { 3, 16 }, { 3, 16 }, { 3, 16 }, { 3, 16 }, { 3, 16 } }, fluids = { } },
  18. }
  19.  
  20. local sides = require("sides")
  21. local comp = require("component")
  22. local tp = comp.proxy("b1becc1e-4445-432e-97f0-f33a588c162e")
  23. local outputTp = comp.proxy("1b1f8e79-318c-47a3-958e-4234af111a2a")
  24. local rs = comp.redstone
  25. local meItem = comp.proxy("1637b950-8a1b-4fa6-903b-9b4419e4e319")
  26. local meFluid = comp.proxy("26e1d51c-dc6f-40af-ae6c-0282d4ce76f6")
  27. local db = comp.database
  28. local assLine = comp.gt_machine
  29. local gpu = comp.gpu
  30.  
  31. -- мультижидкости крекер
  32. local oilTp = comp.proxy("04c928eb-1d3d-4780-aaa7-921c5b736541")
  33. local fSides = { sides.north, sides.west, sides.east }
  34.  
  35. local recipeChestSide = sides.right
  36. local itemIntSide = sides.left
  37. local redItemSide = sides.back
  38. local redfluidSide = sides.left
  39. local inputChestSide = sides.back
  40. local outputChestSide = sides.front
  41. local outputInterfaceSide = sides.right
  42. local inputTankSide = sides.bottom
  43. local fluidIntSide = sides.front -- с какой стороны от транспозера стоит ж интерфейс
  44. local fluidIntTankSide = sides.back -- с какой стороны от ж интерфейса стоит транспозер
  45.  
  46. local clear = "                                                                                                   "
  47. local streamMode = false
  48. local recipeName = "missing" .. clear
  49. local prevRecipeName = "missing" .. clear
  50. local line = 0
  51.  
  52. local colors = {
  53.     white = 0xffffff,
  54.     orange = 0xff9200,
  55.     magenta = 0xff00ff,
  56.     lightblue = 0x99dbff,
  57.     yellow = 0xffff00,
  58.     lime = 0x00ff00,
  59.     pink = 0xffb6bf,
  60.     gray = 0x787878,
  61.     silver = 0xc3c3c3,
  62.     cyan = 0x00ffff,
  63.     purple = 0x990080,
  64.     blue = 0x0000ff,
  65.     brown = 0x992440,
  66.     green = 0x009200,
  67.     red = 0xff0000,
  68.     black = 0x000000
  69. }
  70.  
  71. local e = 1
  72. function oilCrackingUnit()
  73.     gpu.set(106,45, "OilCreacingUnit")
  74.     if oilTp.getFluidInTank(sides.south, 1).amount == 0 then
  75.         n = 1
  76.         while true do
  77.             if oilTp.getFluidInTank(fSides[e], 1).amount >= oilTp.getFluidInTank(sides.south, 1).capacity then
  78.                 oilTp.transferFluid(fSides[e], sides.south, oilTp.getFluidInTank(sides.south, 1).capacity)
  79.                 gpu.set(126,45, "transfer " .. e)
  80.                 if e == 3 then
  81.                     e = 1
  82.                 else
  83.                     e = e + 1
  84.                 end
  85.                 return
  86.             end
  87.  
  88.             if e == 3 then
  89.                 e = 1
  90.             else
  91.                 e = e + 1
  92.             end
  93.  
  94.             if (n >= 3) then
  95.                 gpu.set(126,45, "no fluids")
  96.                 return
  97.             end
  98.  
  99.             n = n + 1
  100.         end
  101.     end
  102. end
  103.  
  104. function dbPrint()
  105.     local s1, s2, l1, l2, len, temp
  106.     len = 38
  107.     gpu.set(38, 1, "Data Base List")
  108.     for i = 1, 81, 2 do
  109.         temp = ((i + 1) / 2) + 1
  110.         s1 = db.get(i)
  111.         if (s1 ~= nil) then
  112.             l1 = s1.label
  113.             l1 = string.sub(l1, 1, len)
  114.         else
  115.             l1 = "empty"
  116.         end
  117.         gpu.set(1, temp, tostring(i))
  118.         gpu.set(4, temp, l1)
  119.         if i < 81 then
  120.             s2 = db.get(i + 1)
  121.             if (s2 ~= nil) then
  122.                 l2 = s2.label
  123.                 l2 = string.sub(l2, 1, len)
  124.             else
  125.                 l2 = "empty"
  126.             end
  127.             gpu.set(44, temp, tostring(i + 1))
  128.             gpu.set(48, temp, l2)
  129.         end
  130.         line = (i + 1) / 2
  131.     end
  132. end
  133.  
  134. function init()
  135.     gpu.fill(1, 1, 160, 50, ' ')
  136.     gpu.set(100, 1, "║║║║║║║║║║║║║║║║║║║║║║║║║║║║║║║║║║║║║║║║║║║║║║║║║║", true)
  137.     gpu.set(101, 1, "      OC/AE automation integration GT5U Assembly Line")
  138.     gpu.set(160 - 27, 50, "Desing by Dimach and Clor#D")
  139.     gpu.set(106, 5, "Stream Mode status")
  140.     gpu.set(106, 6, "Preparing recipe  ")
  141.     gpu.set(106, 7, "Crafting recipe   ")
  142.     gpu.set(106, 8, "Assembly Line status")
  143.     n = 20
  144.     gpu.set(106, n, "Recipes List : ")
  145.     for k, _ in pairs(recipes) do
  146.         n = n + 1
  147.         gpu.set(106, n, k)
  148.     end
  149.     dbPrint()
  150. end
  151. local offset = 106 + 22
  152. function update()
  153.     gpu.set(offset, 5, tostring(streamMode) .. clear)
  154.     gpu.set(offset, 6, recipeName)
  155.     gpu.set(offset, 7, prevRecipeName)
  156.     if assLine.hasWork() then
  157.         gpu.set(offset, 8, "       ")
  158.         gpu.setBackground(colors.green)
  159.         gpu.set(offset, 8, "enable")
  160.     else
  161.         gpu.setBackground(colors.red)
  162.         gpu.set(offset, 8, "disable")
  163.     end
  164.     gpu.setBackground(colors.black)
  165. end
  166.  
  167. function cPrint(str)
  168.     s = string.sub(str, 1, 99)
  169.     if line < 50 then
  170.         line = line + 1
  171.         gpu.set(1, line, s)
  172.     else
  173.         gpu.copy(1, 1, 99, 50, 0, -1)
  174.         gpu.set(1, line, clear)
  175.         gpu.set(1, line, s)
  176.     end
  177.     update()
  178. end
  179.  
  180. function moveItems(recipe)
  181.     cPrint("Start moving items")
  182.     for k, v in ipairs(recipe.items) do
  183.         local stackLabel = db.get(v[1]).label
  184.         local stack
  185.         local toChest
  186.         local recCount = v[2]
  187.         local count = 0
  188.         for i = 1, 9 do
  189.             stack = tp.getStackInSlot(recipeChestSide, i)
  190.             if stack ~= nil and stack.label == stackLabel then
  191.                 count = count + stack.size
  192.             end
  193.         end
  194.         if count >= recCount then
  195.             local n = 1
  196.             while recCount > 0 or n <= 9 do
  197.                 stack = tp.getStackInSlot(recipeChestSide, n)
  198.                 if stack ~= nil and stack.label == stackLabel then
  199.                     if recCount <= stack.size then
  200.                         tp.transferItem(recipeChestSide, inputChestSide, recCount, n, 1)
  201.                         cPrint("Transfer from chest " .. stackLabel)
  202.                         recCount = 0
  203.                     else
  204.                         tp.transferItem(recipeChestSide, inputChestSide, stack.size, n, 1)
  205.                         recCount = recCount - stack.size
  206.                         cPrint("Transfer part from chest " .. stackLabel)
  207.                     end
  208.                 end
  209.                 n = n + 1
  210.             end
  211.             toChest = true
  212.         else
  213.             toChest = false
  214.         end
  215.         if (not toChest) then
  216.             cPrint("Request " .. stackLabel)
  217.             meItem.setInterfaceConfiguration(1, db.address, v[1], v[2])
  218.             cPrint("Wait " .. stackLabel)
  219.             repeat
  220.                 os.sleep(0.5)
  221.                 stack = tp.getStackInSlot(itemIntSide, 1)
  222.             until stack ~= nul and stack.size == v[2] and stack.label == stackLabel
  223.             cPrint("Transfer " .. stackLabel)
  224.             tp.transferItem(itemIntSide, inputChestSide, v[2], 1, 1)
  225.             meItem.setInterfaceConfiguration(1, db.address, 1, 0)
  226.         end
  227.         rs.setBundledOutput(redItemSide, k - 1, 255)
  228.         os.sleep(1)
  229.         rs.setBundledOutput(redItemSide, k - 1, 0)
  230.         cPrint("Done " .. stackLabel)
  231.     end
  232.     cPrint("Items ready")
  233. end
  234.  
  235. function moveFluids(recipe)
  236.     cPrint("Start moving fluids")
  237.     for k, v in ipairs(recipe.fluids) do
  238.         local stackLabel = db.get(v[1]).label
  239.         local stack
  240.         local recCount = v[2]
  241.         cPrint("Request " .. stackLabel)
  242.         meFluid.setFluidInterfaceConfiguration(fluidIntTankSide, db.address, v[1])
  243.         cPrint("Wait " .. stackLabel)
  244.         while recCount > 10000 do
  245.             repeat
  246.                 os.sleep(0.5)
  247.                 stack = tp.getTankLevel(fluidIntSide, 1)
  248.             until stack == 10000
  249.             cPrint("Transfer 10000L " .. stackLabel)
  250.             tp.transferFluid(fluidIntSide, inputTankSide, 10000)
  251.             recCount = recCount - 10000
  252.         end
  253.         repeat
  254.             os.sleep(0.5)
  255.             stack = tp.getTankLevel(fluidIntSide, 1)
  256.         until stack >= recCount
  257.         cPrint("Transfer " .. stackLabel)
  258.         tp.transferFluid(fluidIntSide, inputTankSide, recCount)
  259.         meFluid.setFluidInterfaceConfiguration(fluidIntTankSide, db.address, 0)
  260.         rs.setBundledOutput(redfluidSide, k - 1, 255)
  261.         repeat
  262.             os.sleep(0.5)
  263.         until (tp.getTankLevel(fluidIntSide, 1) == 0) and (tp.getTankLevel(inputTankSide, 1) == 0)
  264.         rs.setBundledOutput(redfluidSide, k - 1, 0)
  265.         cPrint("Done " .. stackLabel)
  266.     end
  267.     cPrint("Fluids ready")
  268. end
  269.  
  270. init()
  271. while true do
  272.     cPrint("System standby...")
  273.     local checkItem
  274.  
  275.     repeat
  276.         os.sleep(0.5)
  277.         oilCrackingUnit()
  278.         checkItem = tp.getStackInSlot(recipeChestSide, 1)
  279.         if outputTp.getStackInSlot(outputChestSide, 1) ~= nil then
  280.             outputTp.transferItem(outputChestSide, outputInterfaceSide, 64, 1, 8)
  281.             cPrint(prevRecipeName .. " Ready")
  282.             prevRecipeName = "missing" .. clear
  283.             streamMode = false
  284.             update()
  285.         end
  286.     until checkItem ~= nil
  287.  
  288.     local recipe
  289.     for k, v in pairs(recipes) do
  290.         if v.label == checkItem.label then
  291.             cPrint("Found valid recipe: " .. k)
  292.             recipeName = k
  293.             recipe = v
  294.             break
  295.         end
  296.     end
  297.  
  298.     if recipe ~= nil then
  299.         moveItems(recipe)
  300.         moveFluids(recipe)
  301.  
  302.         if streamMode then
  303.             repeat
  304.                 os.sleep(0.5)
  305.             until outputTp.getStackInSlot(outputChestSide, 1) ~= nil
  306.             repeat
  307.                 os.sleep(0.5)
  308.             until assLine.hasWork()
  309.  
  310.             for i = 9, 1, -1 do
  311.                 tp.transferItem(recipeChestSide, itemIntSide, 64, i, i)
  312.             end
  313.             cPrint("Recipe chest clear")
  314.             outputTp.transferItem(outputChestSide, outputInterfaceSide, 64, 1, 8)
  315.             cPrint(prevRecipeName .. " Ready")
  316.             prevRecipeName = "missing" .. clear
  317.             update()
  318.         else
  319.             repeat
  320.                 os.sleep(0.5)
  321.             until assLine.hasWork()
  322.  
  323.             for i = 9, 1, -1 do
  324.                 tp.transferItem(recipeChestSide, itemIntSide, 64, i, i)
  325.             end
  326.         end
  327.         streamMode = true
  328.         prevRecipeName = recipeName
  329.         recipeName = "missing" .. clear
  330.         update()
  331.     else
  332.         cPrint("Marker invalid: " .. checkItem.label)
  333.     end
  334. end
Advertisement
Add Comment
Please, Sign In to add comment