Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local interface = {}
- local component = require("component")
- --local ser = require("serialization")
- if component.isAvailable("me_interface") == false then
- print("No interface attached found")
- os.exit()
- end
- local meInterface = component.getPrimary('me_interface')
- local directionChest = "NONE" -- Where the chest is connected to the interface
- local exportTime = 0.8 -- time to wait after exporting an item
- function interface.setDirection(direction)
- if direction ~= "UP" then
- if direction ~= "SOUTH" then
- if direction ~= "NORTH" then
- if direction ~= "WEST" then
- if direction ~= "EAST" then
- if direction ~= "DOWN" then
- return false, "Direction must be UP, NORTH, SOUTH, WEST, EAST or DOWN"
- end
- end
- end
- end
- end
- end
- directionChest = direction
- if meInterface.canExport(direction) == false then
- return false, "Interface can't export to " .. direction
- end
- return true
- end
- function interface.setExportTime(time)
- if time < 0 then
- return false, "Export time must be 0 or positive"
- end
- exportTime = time
- return true
- end
- function getItem(selection)
- local tmpTable = {}
- local x = meInterface.getItemsInNetwork() -- Get all items in network
- for key, value in pairs(x) do -- loop over the list
- if key ~= "n" then
- if value.label == selection then -- label of selected item found
- -- build the fingerprint
- tmpTable["id"] = value.name
- tmpTable["dmg"] = value.damage
- return tmpTable, value.size -- return amount of items in network and the fingerprint
- end
- end
- end
- return false, "Item not found" -- return nil if not found
- end
- function interface.getItemList()
- local returnTable = {}
- local x = meInterface.getItemsInNetwork() -- Get all items in network
- if x == nil then
- return false, "No items found"
- end
- for key, value in pairs(x) do -- loop over the list
- if key ~= "n" then
- local tmpTable = {} -- clear temp table
- tmpTable["size"] = value.size
- tmpTable["label"] = value.label
- table.insert(returnTable, tmpTable) -- insert item in return table
- end
- end
- return returnTable -- return the list
- end
- function interface.export(itemLabel, amount, dots)
- if directionChest == "NONE" then
- return false, "Direction not set"
- end
- if directionChest ~= "UP" then
- if directionChest ~= "SOUTH" then
- if directionChest ~= "NORTH" then
- if directionChest ~= "WEST" then
- if directionChest ~= "EAST" then
- if directionChest ~= "DOWN" then
- return false, "Direction must be UP, NORTH, SOUTH, WEST, EAST or DOWN"
- end
- end
- end
- end
- end
- end
- if meInterface.canExport(directionChest) == false then
- return false, "Interface can't export to " .. directionChest
- end
- local item, count = getItem(itemLabel)
- if item == false then
- return false, "Item not found"
- end
- if count < amount then
- amount = count
- end
- for x = 1, amount do
- meInterface.exportItem(item, directionChest, 1, 0) -- Export item
- os.sleep(exportTime) -- wait for export
- if dots == true then
- io.write(".")
- end
- end
- return true, amount
- end
- return interface
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement