mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-04-21 21:52:07 +02:00
fixed timeout+smeltitem
This commit is contained in:
parent
663f7f9b1a
commit
48fd28a10f
2 changed files with 7 additions and 6 deletions
|
@ -83,7 +83,7 @@ export class Coder {
|
||||||
console.error('Error writing code execution file: ' + result);
|
console.error('Error writing code execution file: ' + result);
|
||||||
return {success: false, message: result, interrupted: false, timedout: false};
|
return {success: false, message: result, interrupted: false, timedout: false};
|
||||||
}
|
}
|
||||||
|
let TIMEOUT;
|
||||||
try {
|
try {
|
||||||
console.log('executing code...\n');
|
console.log('executing code...\n');
|
||||||
let execution_file = await import('.'+filename);
|
let execution_file = await import('.'+filename);
|
||||||
|
@ -91,10 +91,10 @@ export class Coder {
|
||||||
this.current_code = this.queued_code;
|
this.current_code = this.queued_code;
|
||||||
|
|
||||||
this.executing = true;
|
this.executing = true;
|
||||||
const TIMEOUT = this._startTimeout(10);
|
TIMEOUT = this._startTimeout(1);
|
||||||
await execution_file.main(this.agent.bot); // open fire
|
await execution_file.main(this.agent.bot); // open fire
|
||||||
clearTimeout(TIMEOUT);
|
|
||||||
this.executing = false;
|
this.executing = false;
|
||||||
|
clearTimeout(TIMEOUT);
|
||||||
|
|
||||||
this.agent.bot.emit('finished_executing');
|
this.agent.bot.emit('finished_executing');
|
||||||
let output = this.formatOutput(this.agent.bot);
|
let output = this.formatOutput(this.agent.bot);
|
||||||
|
@ -104,8 +104,10 @@ export class Coder {
|
||||||
return {success:true, message: output, interrupted, timedout};
|
return {success:true, message: output, interrupted, timedout};
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.executing = false;
|
this.executing = false;
|
||||||
|
clearTimeout(TIMEOUT);
|
||||||
|
|
||||||
this.agent.bot.emit('finished_executing');
|
this.agent.bot.emit('finished_executing');
|
||||||
console.error("Code execution triggered catch:" + err);
|
console.error("Code execution triggered catch: " + err);
|
||||||
let message = this.formatOutput(this.agent.bot);
|
let message = this.formatOutput(this.agent.bot);
|
||||||
message += '!!Code threw exception!! Error: ' + err;
|
message += '!!Code threw exception!! Error: ' + err;
|
||||||
let interrupted = this.agent.bot.interrupt_code;
|
let interrupted = this.agent.bot.interrupt_code;
|
||||||
|
|
|
@ -57,13 +57,12 @@ export async function smeltItem(bot, itemName, num=1) {
|
||||||
|
|
||||||
let furnaceBlock = undefined;
|
let furnaceBlock = undefined;
|
||||||
furnaceBlock = getNearestBlock(bot, 'furnace', 6);
|
furnaceBlock = getNearestBlock(bot, 'furnace', 6);
|
||||||
if (furnaceBlock === null){
|
if (!furnaceBlock){
|
||||||
log(bot, `There is no furnace nearby.`)
|
log(bot, `There is no furnace nearby.`)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
await bot.lookAt(furnaceBlock.position);
|
await bot.lookAt(furnaceBlock.position);
|
||||||
|
|
||||||
|
|
||||||
console.log('smelting...');
|
console.log('smelting...');
|
||||||
const furnace = await bot.openFurnace(furnaceBlock);
|
const furnace = await bot.openFurnace(furnaceBlock);
|
||||||
// check if the furnace is already smelting something
|
// check if the furnace is already smelting something
|
||||||
|
|
Loading…
Add table
Reference in a new issue