mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-04-21 21:52:07 +02:00
moved shouldplacetorch to world
This commit is contained in:
parent
3342a6deb9
commit
3f541ae930
3 changed files with 15 additions and 15 deletions
|
@ -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);
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue