Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- load the API
- os.loadAPI("ocs/apis/sensor")
- -- wrap the sensor
- local invSensor = sensor.wrap("left")
- modem = peripheral.wrap("top")
- modem.setDefaultChannel(1)
- modem.setListening(1,true)
- local inBounds = function(position)
- if position.X <= 4 and position.X >= -4 and
- position.Z <= 3 and position.Z >= -1 and
- position.Y <= -1 and position.Y >= -4 then
- return true
- else
- return false
- end
- end
- local convName = function(name)
- name = name:lower()
- name = name:gsub(" ", "_")
- name = name:gsub('%(', "")
- name = name:gsub('%)', "")
- return name
- end
- local getInventory = function()
- local targets = invSensor.getTargets()
- local inventory={}
- for k,v in pairs(targets) do
- local position = v.Position
- if inBounds(position) then
- local details = invSensor.getTargetDetails(k)
- for i,v in pairs(details.Slots) do
- if v.Name == "" then
- name = v.RawName
- else
- name = convName(v.Name)
- end
- if name == "empty" then
- name = "_"
- if inventory[name] == nil then
- inventory[name] = 0
- end
- inventory[name] = inventory[name] + 64
- else
- if inventory[name] == nil then
- inventory[name] = 0
- end
- inventory[name] = inventory[name] + v.Size
- end
- end
- end
- end
- return inventory
- end
- local netListen = function()
- local msg = {Command = nil, Payload = nil}
- local id
- while true do
- local event,side,id,channel,srmsg = os.pullEvent("lan_message")
- local msg = textutils.unserialize(srmsg)
- if type(msg) == "table" then
- print(msg.Command)
- if msg.Command == "invDisplay.reportReq" then
- local storage = getInventory()
- local reply = {Command = "invSensor.report",Payload = {Inventory = storage}}
- reply = textutils.serialize(reply)
- modem.send(reply)
- end
- end
- end
- end
- netListen()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement