Compare commits
3 Commits
cef3cdf03d
...
60c5b3aaba
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
60c5b3aaba | ||
|
|
2c806bf994 | ||
|
|
b34cc8cec0 |
@@ -288,9 +288,8 @@ export class Turtle extends EventEmitter {
|
||||
/**
|
||||
* Run the current state's act() generator in a loop
|
||||
*/
|
||||
async _runStateLoop() {
|
||||
async _runStateLoop(consecutiveErrors = 0) {
|
||||
const state = this._state;
|
||||
let consecutiveErrors = 0;
|
||||
const MAX_CONSECUTIVE_ERRORS = 5;
|
||||
|
||||
try {
|
||||
@@ -312,10 +311,10 @@ export class Turtle extends EventEmitter {
|
||||
|
||||
if (isTimeout && consecutiveErrors < MAX_CONSECUTIVE_ERRORS) {
|
||||
console.warn(`[Turtle ${this.id}] Timeout in ${state.name} (${consecutiveErrors}/${MAX_CONSECUTIVE_ERRORS}), retrying...`);
|
||||
// Wait a bit then restart the state loop
|
||||
// Wait a bit then restart the state loop, passing the error count
|
||||
await new Promise(r => setTimeout(r, 2000));
|
||||
if (this._state === state) {
|
||||
this._runStateLoop(); // Restart the loop with the same state
|
||||
this._runStateLoop(consecutiveErrors);
|
||||
}
|
||||
} else {
|
||||
console.error(`[Turtle ${this.id}] State error in ${state.name}:`, error.message);
|
||||
|
||||
@@ -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 {
|
||||
|
||||
976
turtle.lua
976
turtle.lua
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user