From 60c5b3aaba3cfe906a7b7dcb9a32224be724e6de Mon Sep 17 00:00:00 2001 From: MayaTheShy Date: Fri, 20 Feb 2026 04:03:34 -0500 Subject: [PATCH] feat: add chunk analysis endpoint to compute ore density from discovered blocks --- server/server.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/server/server.js b/server/server.js index a7f21e3..5e30b70 100644 --- a/server/server.js +++ b/server/server.js @@ -1056,6 +1056,51 @@ app.post('/api/chunks', (req, res) => { } }); +// Analyze a chunk (compute ore density from discovered blocks) +app.post('/api/chunks/:x/:z/analyze', (req, res) => { + try { + const chunkX = parseInt(req.params.x); + const chunkZ = parseInt(req.params.z); + + // Chunk bounds in world coordinates (16x16 columns, full Y range) + const minX = chunkX * 16; + const maxX = minX + 15; + const minZ = chunkZ * 16; + const maxZ = minZ + 15; + + // Get all blocks in the chunk from the DB + const blocks = db.getBlocksInArea(minX, -64, minZ, maxX, 320, maxZ); + + // Count ores + const oreCounts = {}; + let totalBlocks = 0; + + if (blocks && Array.isArray(blocks)) { + for (const block of blocks) { + totalBlocks++; + if (block.block_name && block.block_name.includes('ore')) { + oreCounts[block.block_name] = (oreCounts[block.block_name] || 0) + 1; + } + } + } + + const analysis = { + x: chunkX, + z: chunkZ, + totalBlocks, + ores: oreCounts, + scannedAt: Date.now(), + }; + + // Save the analysis + db.saveChunkAnalysis(chunkX, chunkZ, analysis); + + res.json(analysis); + } catch (error) { + res.status(500).json({ error: error.message }); + } +}); + // Search blocks by name pattern in area app.get('/api/world/blocks/search', (req, res) => { try {