Advertisement
CreeperNukeBoom

Temporary #1

Mar 2nd, 2020
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.26 KB | None | 0 0
  1. --NAFA - Not another Furnace Automater by CreeperGoBoom
  2. --This program works in 2 simple steps.
  3. --1. Network your chests and furnaces up.
  4. --2. Install this program onto a networked computer.
  5.  
  6.  
  7. local function httpGet(stringURL,stringFileNameToSaveTo)
  8.   local h, err = http.get(stringURL)
  9.   if not h then printError(err) return end
  10.   local f = fs.open(stringFileNameToSaveTo, "w")
  11.   f.write(h.readAll())
  12.   f.close()
  13.   h.close()
  14. end
  15.  
  16. if not fs.exists("apis/CGBCoreLib.lua") then
  17.   httpGet("https://pastebin.com/raw/xuMVS2GP","apis/CGBCoreLib.lua")
  18. end
  19.  
  20. local core = require("apis/CGBCoreLib") --Contains complete function library used accross multiple programs and to minimize code size.
  21. local idprint = false   --saves all item data into file idprint.lua
  22.  
  23.  
  24. term.clear()
  25. term.setCursorPos(1,1)
  26. print("Furnace Automater V1.1")
  27.  
  28. local ingredients = {"minecraft:cobblestone","minecraft:sand","minecraft:iron_ore","minecraft:gold_ore","minecraft:log",}
  29. local fuels = {"minecraft:coal","minecraft:sapling"}
  30. local temp = {}  --will store getItemMeta commands to be used with parallel
  31.  
  32. --Gets peripheral names - API
  33. local furnaces = core.getPeripherals("furnace")
  34. local chests = core.getPeripherals("chest")
  35. local shulkers = core.getPeripherals("shulker")
  36. local data = {}
  37.  
  38. local pData = {}
  39.  
  40. local function getItemMeta(chestNum) --searches chests, parallelable
  41.   local meta = {}
  42.   local chest = peripheral.wrap(chests[chestNum])
  43.   for i = 1 , chest.size() do
  44.     meta[i] = chest.getItemMeta(i)
  45.   end
  46.   return meta
  47. end
  48.  
  49. local function getItemList(chestNum)
  50.   local chest = peripheral.wrap(chests[chestNum])
  51.   local meta = chest.list()
  52.   return meta
  53. end
  54.  
  55. local function getChestInfo()
  56.   local meta = {}
  57.   for key, val in ipairs(chests) do
  58.     print("getting chest meta")
  59.     meta.chestName= val.name
  60.     print("meta set")
  61.     meta[val]=getItemList(key)
  62.     print(textutils.serialise(meta))
  63.     core.saveConfig("data/items.lua",meta)
  64.     print("table updated")
  65.   end
  66.   if idprint == true then
  67.     local sData = textutils.serialize(meta)
  68.     core.fileWrite("idprint.lua",sData) end
  69.   return meta
  70. end
  71.  
  72. local function main()
  73.   print("starting main")
  74.   print("data = getChestInfo()")
  75.   data = getChestInfo()
  76.   print("chest info function run")
  77.   --This section pushes items from chest(s) into furnace(s)
  78.   for chestName , chestContents in pairs(data) do
  79.     print("getting chest info 1/2")
  80.     --print(chestName)
  81.     for slot , item in pairs(chestContents) do
  82.       print("getting chest info 2/2")
  83.       --print(item.name,slot)
  84.       print(item.name)
  85.       --for furnaceNum , furnace in ipairs(furnaces) do   --This is being iterated over too much
  86.         --print("going through furnace list")
  87.         for _ , ingredient in ipairs(ingredients) do
  88.           --print("checking ingredients list")
  89.           sleep(10)
  90.           if item.name == ingredient then
  91.             print("sending ingredients to furnaces")
  92.             peripheral.call(chestName,"pushItems",furnaces[math.random(1,table.getn(furnaces))],slot,64,1) --randomly chooses furnace to send to from furnaces
  93.             --peripheral.call(chestName,"pushItems",furnace,slot,64,1)
  94.           end
  95.         end
  96.         for _ , fuel in pairs(fuels) do
  97.           sleep(10)
  98.           if item.name == fuel then
  99.             peripheral.call(chestName,"pushItems",furnaces[math.random(1,table.getn(furnaces))],slot,64,2)
  100.             --peripheral.call(chestName,"pushItems",furnace,slot,64,1)
  101.           end  
  102.         end
  103.       --end
  104.     end
  105.   end
  106.   -- Output back to chests, always runs
  107.   for _ , furnace in ipairs(furnaces) do
  108.     for _ , chest in ipairs(chests) do
  109.       sleep(10)
  110.       local furnaceList = peripheral.call(furnace,"list")
  111.       if furnaceList[3].count > 0 then --only pushes items out if theres something there else it wont call it, makes it more plethora friendly.
  112.         peripheral.call(furnace,"pushItems",chest,3,64)
  113.         break
  114.       end
  115.     end
  116.   end
  117.   --
  118.   --return
  119. end
  120.  
  121. local function secondary()
  122.   --local event = {}
  123.   local event = {os.pullEvent()}
  124.   if event[1] == "redstone" then
  125.     print("I see redstone")
  126.   -- elseif event == "timer" then
  127.     -- main()
  128.   end
  129. end
  130.  
  131.  
  132.  
  133. while true do
  134.   parallel.waitForAny(main,secondary)
  135.   --main()
  136.   --secondary()
  137.   --sleep(10)
  138. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement