Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local storage = "actuallyadditions:giantchest_1"
- local spatial = "back"
- local state_file = "state.tbl"
- local storage_to_spatial = "down"
- local spatial_to_storage = "up"
- local function save()
- local f = fs.open(state_file, "w")
- f.write(textutils.serialise(state))
- f.close()
- end
- local function load()
- if not fs.exists(state_file) then return end
- local f = fs.open(state_file, "r")
- local d = textutils.unserialise(f.readAll())
- f.close()
- return d
- end
- local state = {} or load()
- local cells = {
- ["7ce8"] = "empty",
- ["f361"] = "test"
- }
- local function find_by_hash(inventory, hash)
- for slot, item in pairs(inventory) do
- if item.nbtHash:match(hash) then return slot end
- end
- end
- local function find_by_name(inventory, name)
- for hash, cname in pairs(cells) do
- if cname == name then
- return find_by_hash(inventory, hash)
- end
- end
- end
- local function load_cell(slot)
- peripheral.call(storage, "pushItems", storage_to_spatial, slot, 1, 1)
- end
- local function unload_cell()
- peripheral.call(spatial, "pushItems", spatial_to_storage, 2, 1)
- end
- local function reload_cell()
- peripheral.call(spatial, "pushItems", "self", 2, 1, 1)
- end
- local function pulse_spatial()
- redstone.setOutput(spatial, true)
- sleep(0.2)
- redstone.setOutput(spatial, false)
- sleep(0.2)
- end
- while true do
- write "Cell: "
- local cell = read()
- local inv = peripheral.call(storage, "list")
- local slot = find_by_name(inv, cell)
- if not slot then printError(cell .. " not found.")
- elseif state.currently_open == cell then
- print(cell, "already loaded")
- else
- if state.currently_open then
- print("Unloading", state.currently_open)
- load_cell(find_by_name(inv, state.currently_open))
- pulse_spatial()
- unload_cell()
- state.currently_open = nil
- save()
- end
- print("Loading", cell)
- load_cell(slot)
- pulse_spatial()
- unload_cell()
- state.currently_open = cell
- save()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement