Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- receiver.lua
- -- Receives camera/hologram data and voice recordings from sender
- local hologram = peripheral.find("hologram")
- local speaker = peripheral.find("speaker")
- local modem = peripheral.find("modem")
- if not hologram then
- print("No hologram found!")
- return
- end
- if not speaker then
- print("No speaker found!")
- return
- end
- if not modem then
- print("No modem found!")
- return
- end
- -- Configuration
- local CHANNEL_LISTEN = 1
- local HOLOGRAM_SCALE = 0.1
- -- Entity filter settings (receive from sender)
- local SHOW_PLAYERS = true
- local SHOW_MOBS = true
- local SHOW_ANIMALS = true
- local SHOW_ITEMS = false
- -- Setup
- modem.open(CHANNEL_LISTEN)
- hologram.on()
- hologram.setScale(HOLOGRAM_SCALE)
- hologram.showEntities(true)
- hologram.setEntityFilter(SHOW_PLAYERS, SHOW_MOBS, SHOW_ANIMALS, SHOW_ITEMS)
- print("=== Camera & Voice Receiver ===")
- print("Listening on channel: " .. CHANNEL_LISTEN)
- print("Hologram scale: " .. HOLOGRAM_SCALE)
- print("Entity filters: Players=" .. tostring(SHOW_PLAYERS) ..
- ", Mobs=" .. tostring(SHOW_MOBS) ..
- ", Animals=" .. tostring(SHOW_ANIMALS) ..
- ", Items=" .. tostring(SHOW_ITEMS))
- print("Press Ctrl+T to stop")
- print("")
- -- Recording controls
- local isRecording = false
- local recordingStartTime = 0
- -- Helper function to format entity count by type
- local function countEntitiesByType(entities)
- local counts = {players = 0, mobs = 0, animals = 0, items = 0, other = 0}
- for _, e in ipairs(entities) do
- if e.isPlayer then
- counts.players = counts.players + 1
- elseif e.entityType then
- local t = e.entityType:lower()
- if t:find("zombie") or t:find("skeleton") or t:find("creeper") or
- t:find("spider") or t:find("enderman") or t:find("witch") or
- t:find("blaze") or t:find("ghast") or t:find("slime") then
- counts.mobs = counts.mobs + 1
- elseif t:find("cow") or t:find("pig") or t:find("sheep") or
- t:find("chicken") or t:find("horse") or t:find("wolf") or
- t:find("cat") or t:find("rabbit") or t:find("villager") then
- counts.animals = counts.animals + 1
- elseif t:find("item") then
- counts.items = counts.items + 1
- else
- counts.other = counts.other + 1
- end
- end
- end
- return counts
- end
- local lastEntityCount = 0
- while true do
- -- Poll for messages instead of using events
- if modem.hasMessage() then
- local msg = modem.receive()
- if msg and msg.message and type(msg.message) == "table" then
- local message = msg.message
- if message.type == "hologram" or message.type == "entities" then
- -- Handle entity data (new API)
- if message.entities and message.center then
- hologram.setEntityData(message.entities, message.center)
- local entityCount = #message.entities
- if entityCount ~= lastEntityCount then
- lastEntityCount = entityCount
- if entityCount > 0 then
- local counts = countEntitiesByType(message.entities)
- local parts = {}
- if counts.players > 0 then table.insert(parts, counts.players .. " player(s)") end
- if counts.mobs > 0 then table.insert(parts, counts.mobs .. " mob(s)") end
- if counts.animals > 0 then table.insert(parts, counts.animals .. " animal(s)") end
- if counts.items > 0 then table.insert(parts, counts.items .. " item(s)") end
- if counts.other > 0 then table.insert(parts, counts.other .. " other") end
- print("[HOLO] Displaying: " .. table.concat(parts, ", "))
- else
- print("[HOLO] No entities in view")
- end
- end
- -- Backward compatibility: handle old player data format
- elseif message.players and message.center then
- -- Convert old player format to new entity format
- local entities = {}
- for _, p in ipairs(message.players) do
- table.insert(entities, {
- name = p.name or "Unknown",
- uuid = p.uuid or "",
- x = p.x or 0,
- y = p.y or 0,
- z = p.z or 0,
- yaw = p.yaw or 0,
- pitch = p.pitch or 0,
- entityType = "player",
- isPlayer = true
- })
- end
- hologram.setEntityData(entities, message.center)
- if #entities ~= lastEntityCount then
- lastEntityCount = #entities
- if lastEntityCount > 0 then
- print("[HOLO] Displaying " .. lastEntityCount .. " player(s) (legacy format)")
- else
- print("[HOLO] No players in view")
- end
- end
- end
- elseif message.type == "voice" then
- if message.packets and #message.packets > 0 then
- print("[VOICE] Playing " .. #message.packets .. " packets from " .. (message.player or "unknown"))
- speaker.playRecordingPackets(message.packets)
- end
- elseif message.type == "command" then
- -- Handle remote commands for recording control
- if message.command == "start_recording" then
- if not isRecording then
- hologram.startRecording()
- isRecording = true
- recordingStartTime = os.epoch("utc") / 1000
- print("[REC] Started recording")
- end
- elseif message.command == "stop_recording" then
- if isRecording then
- hologram.stopRecording()
- isRecording = false
- local duration = (os.epoch("utc") / 1000) - recordingStartTime
- print("[REC] Stopped recording (" .. string.format("%.1f", duration) .. "s)")
- end
- elseif message.command == "play" then
- hologram.play()
- print("[REC] Playing recording")
- elseif message.command == "pause" then
- hologram.pause()
- print("[REC] Paused playback")
- elseif message.command == "stop" then
- hologram.stop()
- print("[REC] Stopped playback")
- elseif message.command == "set_loop" then
- hologram.setLoop(message.value == true)
- print("[REC] Loop: " .. tostring(message.value))
- elseif message.command == "set_speed" then
- hologram.setPlaybackSpeed(message.value or 1.0)
- print("[REC] Speed: " .. tostring(message.value) .. "x")
- elseif message.command == "set_filter" then
- if message.filter then
- hologram.setEntityFilter(
- message.filter.players ~= false,
- message.filter.mobs ~= false,
- message.filter.animals ~= false,
- message.filter.items == true
- )
- print("[FILTER] Updated entity filters")
- end
- end
- end
- end
- else
- -- Small sleep to avoid busy-waiting
- sleep(0.05)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment