Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local scanInterval = 0.2
- local renderInterval = 0.05
- local scannerRange = 8
- local scannerWidth = scannerRange * 2 + 1
- local size = 0.5
- local cellSize = 16
- local offsetX = 75
- local offsetY = 75
- local ores = {
- ["minecraft:diamond_ore"] = 10,
- ["minecraft:emerald_ore"] = 10,
- ["minecraft:gold_ore"] = 8,
- ["minecraft:redstone_ore"] = 5,
- ["minecraft:lapis_ore"] = 5,
- ["minecraft:iron_ore"] = 2,
- ["minecraft:coal_ore"] = 1
- }
- local colours = {
- ["minecraft:coal_ore"] = { 150, 150, 150 },
- ["minecraft:iron_ore"] = { 255, 150, 50 },
- ["minecraft:lava"] = { 150, 75, 0 },
- ["minecraft:gold_ore"] = { 255, 255, 0 },
- ["minecraft:diamond_ore"] = { 0, 255, 255 },
- ["minecraft:redstone_ore"] = { 255, 0, 0 },
- ["minecraft:lapis_ore"] = { 0, 50, 255 },
- ["minecraft:emerald_ore"] = { 0, 255, 0 }
- }
- local modules = peripheral.find("neuralInterface")
- if not modules then error("Must have a neural interface", 0) end
- if not modules.hasModule("plethora:scanner") then error("The block scanner is missing", 0) end
- if not modules.hasModule("plethora:glasses") then error("The overlay glasses are missing", 0) end
- local canvas = modules.canvas()
- canvas.clear()
- local block_text = {}
- local blocks = {}
- for x = -scannerRange, scannerRange, 1 do
- block_text[x] = {}
- blocks[x] = {}
- for z = -scannerRange, scannerRange, 1 do
- block_text[x][z] = canvas.addText({ 0, 0 }, " ", 0xFFFFFFFF, size)
- blocks[x][z] = { y = nil, block = nil }
- end
- end
- canvas.addText({ offsetX, offsetY }, "^", 0xFFFFFFFF, size * 2)
- local function scan()
- while true do
- local scanned_blocks = modules.scan()
- for x = -scannerRange, scannerRange do
- for z = -scannerRange, scannerRange do
- local best_score, best_block, best_y = -1
- for y = -scannerRange, scannerRange do
- local scanned = scanned_blocks[scannerWidth ^ 2 * (x + scannerRange) + scannerWidth * (y + scannerRange) + (z + scannerRange) + 1]
- if scanned then
- local new_score = ores[scanned.name]
- if new_score and new_score > best_score then
- best_block = scanned.name
- best_score = new_score
- best_y = y
- end
- end
- end
- -- Update our block table with this information.
- blocks[x][z].block = best_block
- blocks[x][z].y = best_y
- end
- end
- sleep(scanInterval)
- end
- end
- local function render()
- while true do
- -- Get player metadata and calculate rotation angle
- local meta = modules.getMetaOwner and modules.getMetaOwner()
- local angle = meta and math.rad(-meta.yaw % 360) or math.rad(180)
- -- Calculate rotation matrices
- local cosAngle = math.cos(angle)
- local sinAngle = math.sin(angle)
- -- Debug: Print the player's angle
- print("Player angle (yaw): " .. (meta and meta.yaw or "unknown"))
- -- Update the overlay display
- for x = -scannerRange, scannerRange do
- for z = -scannerRange, scannerRange do
- local text = block_text[x][z]
- local block = blocks[x][z]
- if block.block then
- -- Rotate positions based on player's facing direction
- local rotatedX = cosAngle * x - sinAngle * z
- local rotatedZ = sinAngle * x + cosAngle * z
- -- Convert rotated positions to screen coordinates
- local screenX = math.floor(rotatedX * size * cellSize)
- local screenY = math.floor(rotatedZ * size * cellSize)
- -- Update text position and appearance
- text.setPosition(offsetX + screenX, offsetY + screenY)
- text.setText(tostring(block.y))
- text.setColor(table.unpack(colours[block.block]))
- -- Debug: Log position updates
- print(("Block %s at (%d, %d) rendered at (%d, %d)"):format(
- block.block, x, z, screenX, screenY
- ))
- else
- -- Clear text for empty positions
- text.setText(" ")
- end
- end
- end
- -- Delay for rendering interval
- sleep(renderInterval)
- end
- end
- parallel.waitForAll(render, scan)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement