bungeefield

advanced_carpenter

Jan 25th, 2021 (edited)
502
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local sides = require("sides")
  2. local component = require("component")
  3.  
  4. local chest_transposer = {}
  5. local in_chest = {}
  6. local out_chest = {}
  7. local tanks = {}
  8.  
  9. local tank_output = sides.up
  10.  
  11. local recipes = {
  12.   ["Basic Circuit Board"] = {fluid = "Water", amount = 5000},
  13.   ["Enhanced Circuit Board"] = {fluid = "Water", amount = 5000},
  14.   ["Refined Circuit Board"] = {fluid = "Water", amount = 5000},
  15.   ["Mulch"] = {fluid = "Water", amount = 5000},
  16.   ["Hardened Casing"] = {fluid = "Water", amount = 5000},
  17.   ["Impregnated Casing"] = {fluid = "Seed Oil", amount = 125},
  18.   ["Impregnated Stick"] = {fluid = "Seed Oil", amount = 50},
  19.   ["Wyvern Energy Core"] = {fluid = "Destabilized Redstone", amount = 10000},
  20.   ["Random Animal 1"] = {fluid = "Liquid Meat", amount = 125},
  21.   ["Random Animal 2"] = {fluid = "Liquid DNA", amount = 250},
  22.   ["Overclocker Upgrade"] = {fluid = "IC2 Coolant", amount = 1500},
  23.   ["Tier 6 Crafting Seed"] = {fluid = "Sewage", amount = 500},
  24.   ["Bog Earth"] = {fluid = "Water", amount = 2000},
  25.   ["Draconic Energy Core"] = {fluid = "Primal Mana", amount = 500},
  26.   ["Crafting Core"] = {fluid = "Liquifacted Coal", amount = 2500},
  27.   ["Pedestal"] = {fluid = "Liquifacted Coal", amount = 500},
  28.   ["Intricate Circuit Board"] = {fluid = "Water", amount = 5000},
  29.   ["Wyvern Core"] = {fluid = "Primal Mana", amount = 500},
  30.   ["Ludicrite Block"] = {fluid = "Liquid DNA", amount = 500}
  31. }
  32.  
  33. function print_table (t)
  34.   for key, value in pairs(t) do
  35.     print(key, value)
  36.   end
  37. end
  38. function table_length(T)
  39.   local count = 0
  40.   for _ in pairs(T) do count = count + 1 end
  41.   return count
  42. end
  43.  
  44. print("Scanning transposers...")
  45.  
  46. for address, name in component.list("transposer", false) do
  47.   local t = component.proxy(address)
  48.   local is_chest = false
  49.  
  50.   for i=0,5,1 do
  51.     local name = t.getInventoryName(i)
  52.     if not (name == nil) then
  53.       if string.match(name, "chest") then
  54.  
  55.         if name == "minecraft:chest" then
  56.           in_chest = i
  57.           print("Input chest found on transposer:", address)
  58.         else
  59.           out_chest = i
  60.           print("Output chest found on transposer:", address)
  61.         end
  62.         chest_transposer = t
  63.       else
  64.  
  65.         if not (i == tank_output) then
  66.           local fluid = t.getFluidInTank(i, 1).label
  67.  
  68.           local tank = {}
  69.           tank.transposer = t
  70.           tank. side = i
  71.           tank.transfer = function (amount)
  72.             return tank.transposer.transferFluid(tank.side, tank_output, amount)
  73.           end
  74.           tank.get_level = function ()
  75.             return tank.transposer.getTankLevel(tank.side, 1)
  76.           end
  77.  
  78.           tanks[fluid] = tank
  79.           print("Input tank of", fluid, "found on transposer:", address)
  80.         else
  81.           print("Output tank found on transposer:", address)
  82.         end
  83.       end
  84.     end
  85.   end
  86. end
  87.  
  88. print("Scanning complete")
  89.  
  90.  
  91. while true do
  92.   local raw_items = chest_transposer.getAllStacks(in_chest)
  93.   local items = {}
  94.   for i=1,6,1 do
  95.     if not (raw_items[i].size == 0) then
  96.       local item_name = raw_items[i].label
  97.       local item_amount = raw_items[i].size
  98.       items[item_name] = item_amount
  99.     end
  100.   end
  101.  
  102.   if not (table_length(items) == 0) then
  103.     local recipe = ""
  104.    
  105.     if items["Tin Ingot"] == 1 and
  106.         items["Redstone"] == 2 then
  107.       recipe = "Basic Circuit Board"
  108.  
  109.     elseif items["Bronze Ingot"] == 1 and
  110.         items["Redstone"] == 2 then
  111.       recipe = "Enhanced Circuit Board"
  112.  
  113.     elseif items["Iron Ingot"] == 1 and
  114.         items["Redstone"] == 2 then
  115.       recipe = "Refined Circuit Board"
  116.  
  117.     elseif items["Mulch"] == 1 and
  118.         items["Dirt"] == 8 then
  119.       recipe = "Humus"
  120.  
  121.     elseif items["Sturdy Casing"] == 1 and
  122.         items["Diamond"] == 4 then
  123.       recipe = "Hardened Casing"
  124.  
  125.     elseif items["Oak Wood"] == 4 then
  126.       recipe = "Impregnated Casing"
  127.  
  128.     elseif items["Oak Wood Planks"] == 2 then
  129.       recipe = "Impregnated Stick"
  130.  
  131.     elseif items["Draconic Core"] == 1 then
  132.       recipe = "Wyvern Energy Core"
  133.  
  134.     elseif items["Egg"] == 3 and
  135.         items["Magic Bean"] == 1 then
  136.       recipe = "Random Animal 2"
  137.  
  138.     elseif items["Tin Plate"] == 3 and
  139.         items["Basic Control Circuit"] == 1 and
  140.         items["Copper Cable"] == 1 then
  141.       recipe = "Overclocker Upgrade"
  142.  
  143.     elseif items["Seeds"] == 4 and --ACCEPTS ANYTHING IN 'listAllseed'
  144.         items["Insanium Essence"] == 2 and
  145.         items["Tier 5 Crafting Seed"] ==1 then
  146.       recipe = "Tier 6 Crafting Seed"
  147.  
  148.     elseif items["Mulch"] == 1 and
  149.         items["Dirt"] == 2 and
  150.         items["Sand"] == 2 then
  151.       recipe = "Bog Earth"
  152.  
  153.     elseif items["Awakened Draconium Ingot"] == 2 and
  154.         items["Wyvern Energy Core"] == 4 and
  155.         items["Wyvern Core"] == 1 then
  156.       recipe = "Draconic Energy Core"
  157.  
  158.     elseif items["Crystaltine Component"] == 3 and
  159.         items["Pedestal"] == 2 and
  160.         items["Osmiridium Ingot"] == 2 then
  161.       recipe = "Crafting Core"
  162.  
  163.     elseif items["Black Iron Slate"] == 1 and
  164.         items["Block of Black Iron"] == 1 and
  165.         items["Black Iron Ingot"] == 2 then
  166.       recipe = "Pedestal"
  167.  
  168.     elseif items["Basic Circuit Board"] == 1 and
  169.         items["Enhanced Circuit Board"] == 1 and
  170.         items["Refined Circuit Board"] == 1 and
  171.         items["Printed Engineering Circuit"] == 2 and
  172.         items["Ultimate Control Circuit"] == 1 then
  173.       recipe = "Intricate Circuit Board"
  174.  
  175.     elseif items["Shulker Shell"] == 1 and
  176.         items["Ludicrite Ingot"] == 2 and
  177.         items["Pladium"] == 1 and
  178.         items["Nether Star"] == 1 and
  179.         items["Draconic Core"] == 3 then
  180.       recipe = "Wyvern Core"
  181.  
  182.     elseif items["Ender Amethyst"] == 1 and
  183.         items["Blutonium Block"] == 1 and
  184.         items["Alumite Ingot"] == 1 and
  185.         items["Blaze Mesh"] == 1 and
  186.         items["Block of Elementium"] == 1 and
  187.         items["Block of Enderium"] == 2 then
  188.       recipe = "Ludicrite Block"
  189.  
  190.     end
  191.  
  192.     if not (recipe == "") then
  193.       print("Recipe detected for", recipe)
  194.       local tank = tanks[recipes[recipe].fluid]
  195.       local fluid_err_msg = false
  196.       repeat
  197.         if (not (tank.get_level() >= recipes[recipe].amount)) and (not fluid_err_msg) then
  198.           print("There is not enough fluid")
  199.           fluid_err_msg = true
  200.         end
  201.       until(tank.get_level() >= recipes[recipe].amount)
  202.       local tank_err_msg = false
  203.       repeat
  204.         local done = tank.transfer(recipes[recipe].amount)
  205.         if (not done) and (not tank_err_msg) then
  206.           print("Unable to export fluid")
  207.           tank_err_msg = true
  208.         end
  209.       until(done)
  210.       for i=1,6,1 do
  211.         local chest_err_msg = false
  212.         local stack_to_transfer_info = chest_transposer.getStackInSlot(in_chest, i)
  213.         local num_to_transfer = 0
  214.         if not (stack_to_transfer_info == nil) then
  215.           num_to_transfer = stack_to_transfer_info.size
  216.         end
  217.         repeat
  218.           local num_transferred = chest_transposer.transferItem(in_chest, out_chest, 64, i, i)
  219.           if (not (num_to_transfer == num_transferred)) and (not chest_err_msg)  then
  220.             print("Unable to export into output chest")
  221.             chest_err_msg = true
  222.           end
  223.         until(num_to_transfer == num_transferred)
  224.       end
  225.       print("Recipe completed")
  226.     end
  227.  
  228.    
  229.   end  
  230.  
  231.   --break
  232.   os.sleep(0.5)
  233. end
Add Comment
Please, Sign In to add comment