Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function show_items(items)
- for slot, item in pairs(items) do
- local item_s = ("%s (%d)"):format(item.name, item.count)
- print(slot .. ": " .. item_s)
- end
- end
- local function show_item_details(inventory, items)
- for slot, item in pairs(items) do
- local details = inventory.getItemDetail(slot)
- local item_s = textutils.serialize(details.tags)
- print(slot .. ": " .. item_s)
- end
- end
- local function tags_contain_tag(tags, tag)
- for tag_, value in pairs(tags) do
- if (tag_ == tag and value == true) then
- return true
- end
- end
- return false
- end
- local function items_contains_tag(inventory, items, tag)
- for slot, item in pairs(items) do
- local details = inventory.getItemDetail(slot)
- local tags = details.tags
- if tags_contain_ore(tags, tag) then
- return true
- end
- end
- return false
- end
- local function transfer_matching_tag(inventory, other_inventory, tag, limit)
- local own_items = inventory.list()
- local total_limit = limit;
- local limit = total_limit % 64;
- for slot, item in pairs(own_items) do
- local details = inventory.getItemDetail(slot)
- local tags = details.tags
- while (limit > 0) do
- if (tags_contain_ore(tags, tag)) then
- inventory.pushItems(other_inventory, slot, limit)
- end
- total_limit = total_limit - limit
- limit = total_limit % 64
- end
- end
- end
- local function ingot_count(item_name, goal_id)
- rednet.send(goal_id, "GET /ingots/" .. item_name)
- local id, message
- repeat
- id, message = rednet.receive("ores")
- until id == goal_id and string.match(message, "%d+") ~= nil
- local count = math.tointeger(message)
- if count == nil then
- print(("ERROR: %d is nil (was %s)"):format(count, message))
- end
- return count
- end
- local function find_item(inventory, items, item_name)
- for slot, item in pairs(items) do
- if item.name == item_name then
- return slot
- end
- end
- return nil
- end
- local function transfer_items(inventory, other_inventory, goal_id)
- local this_items = inventory.list()
- local other_items = other_inventory.list()
- for slot, item in pairs(other_items) do
- local ingot = ingots[item.name]
- local ingot_count_ = ingot_count(ingot, goal_id)
- if ingot_count_ ~= nil then
- if ingot_count_ < 8 then
- local dust = corresponding_dust(item.name)
- local dust_slot = find_item(inventory, this_items, dust)
- inventory.push(other_inventory, dust_slot, 8)
- end
- end
- end
- end
- local function main()
- local input_inventory = peripheral.wrap("right")
- local output_inventory = peripheral.wrap("left")
- rednet.host("ores", "dust")
- local ingot_manager_id
- repeat
- ingot_manager_id = rednet.lookup("ores", "ingots")
- os.sleep(30)
- until ingot_manager_id ~= nil
- while true do
- transfer_items(input_inventory, output_inventory, ingot_manager_id)
- os.sleep(120)
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement