Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- file = "runes.data"
- chest_side = "right"
- vacuum_side = "bottom"
- altar_dir = "down"
- vacuum_push_dir = "south"
- config_sides = {"right", "left"}
- config_width = 12
- function print_r ( t )
- s = ""
- local print_r_cache={}
- local function sub_print_r(t,indent)
- if (print_r_cache[tostring(t)]) then
- s = s .. indent.."*"..tostring(t) .. "\n"
- else
- print_r_cache[tostring(t)]=true
- if (type(t)=="table") then
- for pos,val in pairs(t) do
- if (type(val)=="table") then
- s = s .. indent.."["..pos.."] => "..tostring(t).." {" .. "\n"
- sub_print_r(val,indent..string.rep(" ",string.len(pos)+8))
- s = s .. indent..string.rep(" ",string.len(pos)+6).."}" .. "\n"
- elseif (type(val)=="string") then
- s = s .. indent.."["..pos..'] => "'..val..'"' .. "\n"
- else
- s = s .. indent.."["..pos.."] => "..tostring(val) .. "\n"
- end
- end
- else
- s = s .. indent..tostring(t) .. "\n"
- end
- end
- end
- if (type(t)=="table") then
- s = s .. tostring(t).." {" .. "\n"
- sub_print_r(t," ")
- s = s .. "}" .. "\n"
- else
- sub_print_r(t," ")
- end
- s = s .. "\n"
- return s
- end
- function debug(o)
- local h = fs.open("debug", "a")
- h.write(print_r(o))
- h.write('\n')
- h.close()
- end
- function config()
- runes = {}
- if fs.exists(file) then
- h = fs.open(file, "r")
- runes = textutils.unserialize(h.readAll())
- h.close()
- end
- for _, side in pairs(config_sides) do
- s = peripheral.wrap(side)
- for i=1, s.getInventorySize() do
- stack = s.getStackInSlot(i)
- if stack ~= nil then
- if i % config_width == 1 then
- rune = stack['raw_name']
- runes[rune] = {}
- else
- table.insert(runes[rune], {stack['qty'], stack['mod_id'], stack['raw_name']})
- end
- end
- end
- end
- h = fs.open(file, "w")
- h.write(textutils.serialize(runes))
- h.write('\n')
- h.close()
- end
- function check(c, rune)
- local present = 0
- c.condenseItems()
- sleep(0.1)
- for j, item in pairs(rune) do
- local all_stacks = c.getAllStacks()
- for i, stack in pairs(all_stacks) do
- local all = stack.all()
- if all['mod_id'] == item[2] and all['raw_name'] == item[3] and all['qty'] >= item[1] then
- present = present + 1
- end
- end
- end
- if present == #rune then
- return true
- else
- return false
- end
- end
- function craft(c, rune)
- for j, item in pairs(rune) do
- local all_stacks = c.getAllStacks()
- for i, stack in pairs(all_stacks) do
- local all = stack.all()
- if all['mod_id'] == item[2] and all['raw_name'] == item[3] and all['qty'] >= item[1] then
- c.pushItem(altar_dir, i, item[1])
- end
- end
- end
- sleep(5)
- local all_stacks = c.getAllStacks()
- for i, stack in pairs(all_stacks) do
- local all = stack.all()
- if all['id'] == "Botania:livingrock" then
- c.pushItem(altar_dir, i, 1)
- break
- end
- end
- redstone.setOutput(vacuum_side, true)
- local v = peripheral.wrap(vacuum_side)
- stacks = #v.getAllStacks()
- while stacks == 0 do
- sleep(0.5)
- stacks = #v.getAllStacks()
- if stacks ~= 0 then
- break
- end
- end
- sleep(0.1)
- redstone.setOutput(vacuum_side, false)
- for i, stack in pairs(v.getAllStacks()) do
- v.pushItem(vacuum_push_dir, i)
- end
- sleep(0.5)
- end
- function cleanup()
- redstone.setOutput(vacuum_side, false)
- local v = peripheral.wrap(vacuum_side)
- for i, stack in pairs(v.getAllStacks()) do
- v.pushItem(vacuum_push_dir, i)
- end
- sleep(1)
- end
- function run()
- c = peripheral.wrap(chest_side)
- cleanup(c)
- if fs.exists(file) then
- h = fs.open(file, "r")
- runes = textutils.unserialize(h.readAll())
- h.close()
- else
- print("ERROR: no data found! Run with argument 'config' to do that now.")
- shell.exit()
- end
- while true do
- local all_stacks = c.getAllStacks()
- for i, stack in pairs(all_stacks) do
- for j, rune in pairs(runes) do
- local all = stack.all()
- if all['mod_id'] == rune[1][2] and all['raw_name'] == rune[1][3] and all['qty'] >= rune[1][1] then
- print("Found rune: " .. i-1)
- if check(c, rune) then
- craft(c, rune)
- end
- end
- end
- end
- sleep(1)
- end
- end
- action = ...
- if action == "config" then
- config()
- else
- cleanup()
- run()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement