Advertisement
krakaen

oc-machines

Apr 7th, 2019
785
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.22 KB | None | 0 0
  1. local sides = require("sides")
  2. local component = require("component")
  3. local event = require("event")
  4.  
  5. local currentCraft = ""
  6.  
  7. -- This will be filled automatically by the code, no need to modify it
  8. local transposerList = {
  9.     items = {
  10.         id = "",
  11.         side = ""  
  12.     },
  13.     fluids = {
  14.         output = {
  15.             id = "",   
  16.             side = ""
  17.         },
  18.         liquiddna = {
  19.             id = "",
  20.             side = ""
  21.         },
  22.         water = {
  23.             id = "",
  24.             side = ""
  25.         },
  26.         coal = {
  27.             id = "",
  28.             side = ""
  29.         },
  30.         redstone = {
  31.             id = "",
  32.             side = ""
  33.         },
  34.         mana = {
  35.             id = "",
  36.             side = ""
  37.         },
  38.         seedoil = {
  39.             id = "",
  40.             side = ""
  41.         },
  42.         ic2coolant = {
  43.             id = "",
  44.             side = ""
  45.         },
  46.         sewage = {
  47.             id = "",
  48.             side = ""
  49.         }
  50.     }
  51. }
  52.  
  53. -- add the recipe here, take in account that the name of the fluid needs to be the one opencomputer sees, not the JEI name
  54. local RECIPES = {
  55.     ludacrite = {
  56.         items = {
  57.             "biomesoplenty:gem.0",
  58.             "bigreactors:blockmetals.3",
  59.             "plustic:alumiteingot.0",
  60.             "botania:blazeblock.0",
  61.             "botania:storage.2",
  62.             "thermalfoundation:storage_alloy.7"
  63.         },
  64.         fluid = {
  65.             name = "liquiddna",
  66.             amount = 500
  67.         }              
  68.     },
  69.     wyvernCore = {
  70.         items = {
  71.             "minecraft:shulker_shell.0",
  72.             "bigreactors:ingotmetals.4",
  73.             "environmentaltech:pladium.0",
  74.             "minecraft:nether_star.0",
  75.             "draconicevolution:draconic_core.0"
  76.         },
  77.         fluid = {
  78.             name = "mana",
  79.             amount = 500
  80.         }              
  81.     },
  82.     intricateChipset = {
  83.         items = {
  84.             "forestry:chipsets.0",
  85.             "forestry:chipsets.1",
  86.             "forestry:chipsets.2",
  87.             "appliedenergistics2:material.17",
  88.             "mekanism:controlcircuit.3"
  89.         },
  90.         fluid = {
  91.             name = "water",
  92.             amount = 5000
  93.         }              
  94.     },
  95.     draconicEnergyCore = {
  96.         items = {
  97.             "draconicevolution:draconic_ingot.0",
  98.             "draconicevolution:wyvern_energy_core.0",
  99.             "draconicevolution:wyvern_core.0"
  100.         },
  101.         fluid = {
  102.             name = "mana",
  103.             amount = 500
  104.         }              
  105.     }, 
  106.     craftingCore = {
  107.         items = {
  108.             "extendedcrafting:material.18",
  109.             "extendedcrafting:pedestal.0",
  110.             "plustic:osmiridiumingot.0"
  111.         },
  112.         fluid = {
  113.             name = "coal",
  114.             amount = 2500
  115.         }              
  116.     }, 
  117.     pedestal = {
  118.         items = {
  119.             "extendedcrafting:material.2",
  120.             "extendedcrafting:storage.0",
  121.             "extendedcrafting:material.0"
  122.         },
  123.         fluid = {
  124.             name = "coal",
  125.             amount = 500
  126.         }              
  127.     }, 
  128.     overclocker = {
  129.         items = {
  130.             "mekanism:controlcircuit.0",
  131.             "thermalfoundation:material.321",
  132.             "ic2:cable.0"
  133.         },
  134.         fluid = {
  135.             name = "ic2coolant",
  136.             amount = 1500
  137.         }              
  138.     }, 
  139.     tier6Seed = {
  140.         items = {
  141.             "minecraft:wheat_seeds.0",
  142.             "mysticalagradditions:insanium.0",
  143.             "mysticalagriculture:crafting.21"
  144.         },
  145.         fluid = {
  146.             name = "sewage",
  147.             amount = 500
  148.         }              
  149.     },
  150.     basicChipset = {
  151.         items = {
  152.             "thermalfoundation:material.129",
  153.             "minecraft:redstone.0"
  154.         },
  155.         fluid = {
  156.             name = "water",
  157.             amount = 5000
  158.         }              
  159.     }, 
  160.     enhancedChipset = {
  161.         items = {
  162.             "thermalfoundation:material.163",
  163.             "minecraft:redstone.0"
  164.         },
  165.         fluid = {
  166.             name = "water",
  167.             amount = 5000
  168.         }              
  169.     },
  170.     refinedChipset = {
  171.         items = {
  172.             "minecraft:iron_ingot.0",
  173.             "minecraft:redstone.0"
  174.         },
  175.         fluid = {
  176.             name = "water",
  177.             amount = 5000
  178.         }              
  179.     },
  180.     hardenedCasing = {
  181.         items = {
  182.             "forestry:sturdy_machine.0",
  183.             "minecraft:diamond.0"
  184.         },
  185.         fluid = {
  186.             name = "water",
  187.             amount = 5000
  188.         }              
  189.     },
  190.     impregnatedCasing = {
  191.         items = {
  192.             "log"
  193.         },
  194.         fluid = {
  195.             name = "seedoil",
  196.             amount = 125
  197.         }              
  198.     },
  199.     impregnatedStick = {
  200.         items = {
  201.             "planks"
  202.         },
  203.         fluid = {
  204.             name = "seedoil",
  205.             amount = 50
  206.         }              
  207.     --},
  208.     --wyvernEnergyCore = {
  209.     --  items = {
  210.     --      "draconicevolution:draconic_core"
  211.     --  },
  212.     --  fluid = {
  213.     --      name = "redstone",
  214.     --      amount = 10000
  215.     --  }              
  216.     }
  217. }
  218.  
  219. function getCurrentRecipeName(items) -- items from inventory
  220.     local isRecipeFound = true
  221.     for recipeName, recipeData in pairs(RECIPES) do    
  222.         for recipeItemName, recipeItemData in pairs(recipeData.items) do
  223.             for itemName, itemData in pairs(items) do
  224.                 local damage = "0"
  225.                 if itemData["damage"] ~= nil then
  226.                     damage = itemData["damage"]
  227.                 end
  228.                 if string.match(itemData["name"] .. "." .. math.floor(damage), recipeItemData) then
  229.                     isRecipeFound = true
  230.                     break
  231.                 else
  232.                     isRecipeFound = false
  233.                 end
  234.             end
  235.             if isRecipeFound == false then
  236.                 break
  237.             end
  238.         end
  239.         if isRecipeFound then
  240.             return recipeName
  241.         end
  242.     end
  243.    
  244.     return nil
  245. end
  246.  
  247. function getInventoryItems()
  248.     local items = component.proxy(transposerList["items"]["id"]).getAllStacks(sides[transposerList["items"]["side"]]).getAll()                            
  249.     local realItems ={}
  250.     local increment = 1  
  251.    
  252.     for k,v in pairs(items) do
  253.         if v["name"] ~= "minecraft:air" then
  254.             realItems[increment] = v
  255.             increment = increment + 1
  256.         end
  257.     end
  258.    
  259.     return realItems
  260. end
  261.  
  262. function getTransposersInfo()
  263.     local transposers = component.list("transposer");
  264.     for id, data in pairs(transposers) do
  265.         getTransposerSides(id)
  266.     end
  267. end
  268.  
  269. function getTransposerSides(transposerId)
  270.     local possibleSides = {"bottom", "top", "back", "front", "right", "left"}
  271.     local transposer = component.proxy(transposerId)
  272.     local sides = {}
  273.    
  274.     for i=1, 6 do
  275.         if transposer.getInventoryName(i-1) ~= nil and transposer.getFluidInTank(i-1)["n"] < 1 then
  276.             transposerList["items"]["id"] = transposerId
  277.             transposerList["items"]["side"] = possibleSides[i]
  278.         elseif transposer.getFluidInTank(i-1)["n"] > 0 then
  279.             local fluid = transposer.getFluidInTank(i-1)[1]
  280.            
  281.             if fluid["name"] ~= nil then
  282.                 fluid["name"] = string.gsub(fluid["name"], "%.", "")
  283.                 print(fluid["name"])
  284.                 transposerList["fluids"][fluid["name"]]["id"] = transposerId
  285.                 transposerList["fluids"][fluid["name"]]["side"] = possibleSides[i]     
  286.             end    
  287.         end
  288.     end
  289. end
  290.  
  291. function getOutputLocation(transposer)
  292.     if transposer.getInventoryName(sides.up) == "actuallyadditions:block_phantom_liquiface" then
  293.         return sides.up
  294.     elseif transposer.getInventoryName(sides.down) == "actuallyadditions:block_phantom_liquiface" then
  295.         return sides.down
  296.     end
  297.     return nil
  298. end
  299.  
  300. function moveFluidToMachine(recipeName)
  301.     local fluidName = RECIPES[recipeName]["fluid"]["name"]
  302.     local fluidAmount = RECIPES[recipeName]["fluid"]["amount"]
  303.     local transposer = component.proxy(transposerList["fluids"][fluidName]["id"])
  304.     local inputSide = transposerList["fluids"][fluidName]["side"]  
  305.     local outputSide = getOutputLocation(transposer)
  306.    
  307.     if transposer.getTankLevel(outputSide) == 0 then
  308.         transposer.transferFluid(sides[inputSide], outputSide, fluidAmount)
  309.     end
  310.    
  311. end
  312.  
  313. function init()
  314.     getTransposersInfo()
  315. end
  316.  
  317. function loopDeLoop()  
  318.     while event.pull(1, "interrupted") == nil do
  319.         if getInventoryItems()[1] ~= nil then
  320.             local currentRecipe = getCurrentRecipeName(getInventoryItems())
  321.             if currentRecipe == nil then
  322.                 print("that's not a recipe you dum dum, check your items")
  323.             else
  324.                 print("crafting : " .. currentRecipe)
  325.                 moveFluidToMachine(currentRecipe)
  326.             end
  327.         end
  328.         local event, address, arg1, arg2, arg3 = event.pull(1)
  329.         if type(address) == "string" and component.isPrimary(address) then
  330.             if event == "key_down" and arg2 == keyboard.keys.q then
  331.                 os.exit()
  332.             end
  333.         end
  334.     end
  335. end
  336.  
  337. init()
  338. loopDeLoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement