Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Opens the file for writing out errors.
- outputfile = "manualAttentionNeeded"
- local file = fs.open( outputfile, "w" )
- local colony = peripheral.find("colonyIntegrator") -- Finds the peripheral if one is connected
- if colony == nil then error("colonyIntegrator not found") end
- if not colony.isInColony then error("Block is not in a colony") end
- local refinedstorage = peripheral.find("rsBridge") -- Finds the peripheral if one is connected
- if refinedstorage == nil then error("rsBridge not found") end
- --Coordinates of builder hut blocks
- first_builder_coords = {y=69, x=227, z=-2291} --Jade
- second_builder_coords = {y=64, x=220, z=-2315} --Ayleen
- third_builder_coords = {y=64, x=346, z=-2305} --Billy
- first_builder_items_needed
- second_builder_items_needed
- third_builder_items_needed
- function getBuilderWorkOrders ()
- work_orders = colony.getWorkOrders()
- file.write(textutils.serialize(work_orders))
- for order in pairs(work_orders) do
- if work_orders[order]["isClaimed"] == true then
- print("Claimed " .. work_orders[order]["id"])
- if work_orders[order]["builder"] == first_builder_coords then
- first_builder_items_needed = colony.getWorkOrderResources(work_orders[order][id])
- elseif work_orders[order]["builder"] == second_builder_coords then
- second_builder_items_needed = colony.getWorkOrderResources(work_orders[order][id])
- elseif work_orders[order]["builder"] == third_builder_coords then
- third_builder_items_needed = colony.getWorkOrderResources(work_orders[order][id])
- else
- print("Coordinates do not match for id " .. work_orders[order]["id"])
- end
- else print("Not Claimed" .. work_orders[order]["id"])
- end
- end
- getBuilderWorkOrders()
- items_needed = {items_needed_jade, items_needed_ayleen, items_needed_billy}
- print("\nCreating missing items...")
- --Loop through each builder
- for i in pairs(items_needed) do
- --Loop through each item needed.
- for index in pairs(items_needed[i]) do
- local item_needed_name = items_needed[i][index]["item"]["name"]
- local item_needed_count = items_needed[i][index]["item"]["count"]
- local item_needed_status = items_needed[i][index]["status"]
- local item_storage_count = refinedstorage.getItem({name = item_needed_name})["count"]
- --Make sure the item is needed by the builder
- if item_needed_status ~= "NOT_NEEDED" then
- if item_storage_count == nil then
- item_storage_count = 0
- end
- --If the item has a crafting recipe and there is not enough already in storage, craft the remainder needed.
- if refinedstorage.hasPattern({name=item_needed_name}) and item_needed_count - item_storage_count > 0 then
- --Write out what item and how many are in storage out of the total needed.
- file.write("\n")
- file.write(textutils.serialize(item_needed_name))
- file.write(" " .. textutils.serialize(item_storage_count) .. "/" .. textutils.serialize(item_needed_count))
- file.write("\nPreparing to create " .. item_needed_count - item_storage_count)
- refinedstorage.craftItem({name=item_needed_name}, item_needed_count - item_storage_count)
- end
- if not refinedstorage.hasPattern({name=item_needed_name}) and item_needed_count - item_storage_count > 0 then --Pattern does not exist, and needs to be created manually.
- file.write("\nPattern Needed for " .. item_needed_name)
- end
- end
- end
- end
- print("Waiting 30s for items to finish crafting...")
- sleep(0)
- print("Outputing Items...")
- i = 0
- index = 0
- for i in pairs(items_needed) do
- --Loop through each item needed.
- for index in pairs(items_needed[i]) do
- local item_needed_name = items_needed[i][index]["item"]["name"]
- local item_needed_count = items_needed[i][index]["item"]["count"]
- local item_needed_status = items_needed[i][index]["status"]
- local output_side = nil
- --Calculate Output Side based on building.
- if i == 1 then
- output_side = "up"
- elseif i == 2 then
- output_side = "north"
- elseif i == 3 then
- output_side = "west"
- else
- output_side = "north"
- end
- --Make sure the item is needed by the builder
- if item_needed_status ~= "NOT_NEEDED" then
- --Extract as many of the item as we need, up to the amount available.
- refinedstorage.extractItem({name=item_needed_name}, item_needed_count, output_side)
- end
- end
- end
- print("Please view " .. outputfile .. " for information on missing items.")
- file.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement