mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-04-22 06:02: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);
|
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) {
|
async function autoLight(bot) {
|
||||||
if (shouldPlaceTorch(bot)) {
|
if (world.shouldPlaceTorch(bot)) {
|
||||||
try {
|
try {
|
||||||
const pos = world.getPosition(bot);
|
const pos = world.getPosition(bot);
|
||||||
return await placeBlock(bot, 'torch', pos.x, pos.y, pos.z, true);
|
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';
|
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) {
|
export function getBiomeName(bot) {
|
||||||
/**
|
/**
|
||||||
* Get the name of the biome the bot is in.
|
* Get the name of the biome the bot is in.
|
||||||
|
|
|
@ -152,7 +152,7 @@ const modes = [
|
||||||
cooldown: 5,
|
cooldown: 5,
|
||||||
last_place: Date.now(),
|
last_place: Date.now(),
|
||||||
update: function (agent) {
|
update: function (agent) {
|
||||||
if (skills.shouldPlaceTorch(agent.bot)) {
|
if (world.shouldPlaceTorch(agent.bot)) {
|
||||||
if (Date.now() - this.last_place < this.cooldown * 1000) return;
|
if (Date.now() - this.last_place < this.cooldown * 1000) return;
|
||||||
execute(this, agent, async () => {
|
execute(this, agent, async () => {
|
||||||
const pos = agent.bot.entity.position;
|
const pos = agent.bot.entity.position;
|
||||||
|
|
Loading…
Add table
Reference in a new issue