· 6 years ago · Mar 02, 2020, 12:38 PM
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
7local 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()
14end
15
16if not fs.exists("apis/CGBCoreLib.lua") then
17 httpGet("https://pastebin.com/raw/xuMVS2GP","apis/CGBCoreLib.lua")
18end
19
20local core = require("apis/CGBCoreLib") --Contains complete function library used accross multiple programs and to minimize code size.
21local idprint = false --saves all item data into file idprint.lua
22
23
24term.clear()
25term.setCursorPos(1,1)
26print("Furnace Automater V1.1")
27
28local ingredients = {"minecraft:cobblestone","minecraft:sand","minecraft:iron_ore","minecraft:gold_ore","minecraft:log",}
29local fuels = {"minecraft:coal","minecraft:sapling"}
30local temp = {} --will store getItemMeta commands to be used with parallel
31
32--Gets peripheral names - API
33local furnaces = core.getPeripherals("furnace")
34local chests = core.getPeripherals("chest")
35local shulkers = core.getPeripherals("shulker")
36local data = {}
37
38local pData = {}
39
40local 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
47end
48
49local function getChestInfo()
50 local meta = {}
51 for key, val in ipairs(chests) do
52 meta.chestName= val.name
53 meta[val]=getItemMeta(key)
54 end
55 if idprint == true then
56 local sData = textutils.serialize(meta)
57 core.fileWrite("idprint.lua",sData) end
58 return meta
59end
60
61local function main()
62 data = getChestInfo()
63 --This section pushes items from chest(s) into furnace(s)
64 for chestName , chestContents in pairs(data) do
65 --print(chestName)
66 for slot , item in pairs(chestContents) do
67 --print(item.name,slot)
68
69 for furnaceNum , furnace in ipairs(furnaces) do
70 for _ , ingredient in ipairs(ingredients) do
71 if item.name == ingredient then
72 peripheral.call(chestName,"pushItems",furnaces[math.random(1,table.getn(furnaces))],slot,64,1) --randomly chooses furnace to send to from furnaces
73 --peripheral.call(chestName,"pushItems",furnace,slot,64,1)
74 end
75 end
76 for _ , fuel in pairs(fuels) do
77 if item.name == fuel then
78 peripheral.call(chestName,"pushItems",furnaces[math.random(1,table.getn(furnaces))],slot,64,2)
79 --peripheral.call(chestName,"pushItems",furnace,slot,64,1)
80 end
81 end
82 end
83 end
84 end
85 -- Output back to chests, always runs
86 for _ , furnace in ipairs(furnaces) do
87 for _ , chest in ipairs(chests) do
88 peripheral.call(furnace,"pushItems",chest,3,64)
89 end
90 end
91end
92
93local function secondary()
94 local event = {}
95 event = os.pullEvent()
96 if event[1] == "redstone" then
97 print("I see redstone")
98 io.read()
99 end
100end
101
102while true do
103 parallel.waitForAny(main,secondary)
104end