From 3f541ae9303fb8631e61d190adf94e8b60090aa5 Mon Sep 17 00:00:00 2001 From: MaxRobinsonTheGreat Date: Mon, 3 Jun 2024 19:09:22 -0500 Subject: [PATCH] moved shouldplacetorch to world --- src/agent/library/skills.js | 15 +-------------- src/agent/library/world.js | 13 +++++++++++++ src/agent/modes.js | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/agent/library/skills.js b/src/agent/library/skills.js index c409d6e..b848304 100644 --- a/src/agent/library/skills.js +++ b/src/agent/library/skills.js @@ -10,21 +10,8 @@ export function log(bot, message, chat=false) { bot.chat(message); } -export function shouldPlaceTorch(bot) { - if (!bot.modes.isOn('torch_placing') || bot.interrupt_code) return false; - const pos = world.getPosition(bot); - // TODO: check light level instead of nearby torches, block.light is broken - let nearest_torch = world.getNearestBlock(bot, 'torch', 6); - if (!nearest_torch) { - const block = bot.blockAt(pos); - let has_torch = bot.inventory.items().find(item => item.name === 'torch'); - return has_torch && block.name === 'air'; - } - return false; -} - async function autoLight(bot) { - if (shouldPlaceTorch(bot)) { + if (world.shouldPlaceTorch(bot)) { try { const pos = world.getPosition(bot); return await placeBlock(bot, 'torch', pos.x, pos.y, pos.z, true); diff --git a/src/agent/library/world.js b/src/agent/library/world.js index 9d6be62..0e32014 100644 --- a/src/agent/library/world.js +++ b/src/agent/library/world.js @@ -256,6 +256,19 @@ export async function isClearPath(bot, target) { return path.status === 'success'; } +export function shouldPlaceTorch(bot) { + if (!bot.modes.isOn('torch_placing') || bot.interrupt_code) return false; + const pos = getPosition(bot); + // TODO: check light level instead of nearby torches, block.light is broken + let nearest_torch = getNearestBlock(bot, 'torch', 6); + if (!nearest_torch) { + const block = bot.blockAt(pos); + let has_torch = bot.inventory.items().find(item => item.name === 'torch'); + return has_torch && block.name === 'air'; + } + return false; +} + export function getBiomeName(bot) { /** * Get the name of the biome the bot is in. diff --git a/src/agent/modes.js b/src/agent/modes.js index 4d5b83c..2d201d4 100644 --- a/src/agent/modes.js +++ b/src/agent/modes.js @@ -152,7 +152,7 @@ const modes = [ cooldown: 5, last_place: Date.now(), update: function (agent) { - if (skills.shouldPlaceTorch(agent.bot)) { + if (world.shouldPlaceTorch(agent.bot)) { if (Date.now() - this.last_place < this.cooldown * 1000) return; execute(this, agent, async () => { const pos = agent.bot.entity.position;