feat: add chunk analysis endpoint to compute ore density from discovered blocks

This commit is contained in:
MayaTheShy
2026-02-20 04:03:34 -05:00
parent 2c806bf994
commit 60c5b3aaba

View File

@@ -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 {