Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --NAFA - Not another Furnace Automater by CreeperGoBoom
- --This program works in 2 simple steps.
- --1. Network your chests and furnaces up.
- --2. Install this program onto a networked computer.
- local function httpGet(stringURL,stringFileNameToSaveTo)
- local h, err = http.get(stringURL)
- if not h then printError(err) return end
- local f = fs.open(stringFileNameToSaveTo, "w")
- f.write(h.readAll())
- f.close()
- h.close()
- end
- if not fs.exists("apis/CGBCoreLib.lua") then
- httpGet("https://pastebin.com/raw/xuMVS2GP","apis/CGBCoreLib.lua")
- end
- local core = require("apis/CGBCoreLib") --Contains complete function library used accross multiple programs and to minimize code size.
- local idprint = false --saves all item data into file idprint.lua
- term.clear()
- term.setCursorPos(1,1)
- print("Furnace Automater V1.1")
- local ingredients = {"minecraft:cobblestone","minecraft:sand","minecraft:iron_ore","minecraft:gold_ore","minecraft:log",}
- local fuels = {"minecraft:coal","minecraft:sapling"}
- local temp = {} --will store getItemMeta commands to be used with parallel
- --Gets peripheral names - API
- local furnaces = core.getPeripherals("furnace")
- local chests = core.getPeripherals("chest")
- local shulkers = core.getPeripherals("shulker")
- local data = {}
- local pData = {}
- local function getItemMeta(chestNum) --searches chests, parallelable
- local meta = {}
- local chest = peripheral.wrap(chests[chestNum])
- for i = 1 , chest.size() do
- meta[i] = chest.getItemMeta(i)
- end
- return meta
- end
- local function getItemList(chestNum)
- local chest = peripheral.wrap(chests[chestNum])
- local meta = chest.list()
- return meta
- end
- local function getChestInfo()
- local meta = {}
- for key, val in ipairs(chests) do
- print("getting chest meta")
- meta.chestName= val.name
- print("meta set")
- meta[val]=getItemList(key)
- print(textutils.serialise(meta))
- core.saveConfig("data/items.lua",meta)
- print("table updated")
- end
- if idprint == true then
- local sData = textutils.serialize(meta)
- core.fileWrite("idprint.lua",sData) end
- return meta
- end
- local function main()
- print("starting main")
- print("data = getChestInfo()")
- data = getChestInfo()
- print("chest info function run")
- --This section pushes items from chest(s) into furnace(s)
- for chestName , chestContents in pairs(data) do
- print("getting chest info 1/2")
- --print(chestName)
- for slot , item in pairs(chestContents) do
- print("getting chest info 2/2")
- --print(item.name,slot)
- print(item.name)
- --for furnaceNum , furnace in ipairs(furnaces) do --This is being iterated over too much
- --print("going through furnace list")
- for _ , ingredient in ipairs(ingredients) do
- --print("checking ingredients list")
- sleep(10)
- if item.name == ingredient then
- print("sending ingredients to furnaces")
- peripheral.call(chestName,"pushItems",furnaces[math.random(1,table.getn(furnaces))],slot,64,1) --randomly chooses furnace to send to from furnaces
- --peripheral.call(chestName,"pushItems",furnace,slot,64,1)
- end
- end
- for _ , fuel in pairs(fuels) do
- sleep(10)
- if item.name == fuel then
- peripheral.call(chestName,"pushItems",furnaces[math.random(1,table.getn(furnaces))],slot,64,2)
- --peripheral.call(chestName,"pushItems",furnace,slot,64,1)
- end
- end
- --end
- end
- end
- -- Output back to chests, always runs
- for _ , furnace in ipairs(furnaces) do
- for _ , chest in ipairs(chests) do
- sleep(10)
- local furnaceList = peripheral.call(furnace,"list")
- if furnaceList[3].count > 0 then --only pushes items out if theres something there else it wont call it, makes it more plethora friendly.
- peripheral.call(furnace,"pushItems",chest,3,64)
- break
- end
- end
- end
- --
- --return
- end
- local function secondary()
- --local event = {}
- local event = {os.pullEvent()}
- if event[1] == "redstone" then
- print("I see redstone")
- -- elseif event == "timer" then
- -- main()
- end
- end
- while true do
- parallel.waitForAny(main,secondary)
- --main()
- --secondary()
- --sleep(10)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement