mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-09-03 12:53:09 +02:00
small fixes
This commit is contained in:
parent
74e061c48f
commit
ab340a7b6d
3 changed files with 23 additions and 18 deletions
|
@ -29,6 +29,7 @@ Run `node main.js`
|
||||||
You can configure details in `settings.json`. Here is an example settings for connecting to a non-local server:
|
You can configure details in `settings.json`. Here is an example settings for connecting to a non-local server:
|
||||||
```
|
```
|
||||||
{
|
{
|
||||||
|
"minecraft_version": "1.20.1",
|
||||||
"host": "111.222.333.444",
|
"host": "111.222.333.444",
|
||||||
"port": 55920,
|
"port": 55920,
|
||||||
"auth": "microsoft",
|
"auth": "microsoft",
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
{
|
{
|
||||||
|
"minecraft_version": "1.20.1",
|
||||||
"host": "localhost",
|
"host": "localhost",
|
||||||
"port": 55916,
|
"port": 55916,
|
||||||
"auth": "offline",
|
"auth": "offline",
|
||||||
"allow_insecure_coding": false
|
"allow_insecure_coding": true
|
||||||
}
|
}
|
|
@ -278,7 +278,7 @@ export async function attackEntity(bot, entity, kill=true) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function defendSelf(bot, range=8) {
|
export async function defendSelf(bot, range=9) {
|
||||||
/**
|
/**
|
||||||
* Defend yourself from all nearby hostile mobs until there are no more.
|
* Defend yourself from all nearby hostile mobs until there are no more.
|
||||||
* @param {MinecraftBot} bot, reference to the minecraft bot.
|
* @param {MinecraftBot} bot, reference to the minecraft bot.
|
||||||
|
@ -336,24 +336,27 @@ export async function collectBlock(bot, blockType, num=1) {
|
||||||
blocktypes.push('deepslate_'+blockType);
|
blocktypes.push('deepslate_'+blockType);
|
||||||
|
|
||||||
let collected = 0;
|
let collected = 0;
|
||||||
const blocks = world.getNearestBlocks(bot, blocktypes, 64, num);
|
|
||||||
if (blocks.length === 0) {
|
|
||||||
log(bot, `Could not find any ${blockType} to collect.`);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
const first_block = blocks[0];
|
|
||||||
await bot.tool.equipForBlock(first_block);
|
|
||||||
const itemId = bot.heldItem ? bot.heldItem.type : null
|
|
||||||
if (!first_block.canHarvest(itemId)) {
|
|
||||||
log(bot, `Don't have right tools to harvest ${blockType}.`);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let block of blocks) {
|
for (let i=0; i<num; i++) {
|
||||||
|
const blocks = world.getNearestBlocks(bot, blocktypes, 64, 1);
|
||||||
|
if (blocks.length === 0) {
|
||||||
|
if (collected === 0)
|
||||||
|
log(bot, `No ${blockType} nearby to collect.`);
|
||||||
|
else
|
||||||
|
log(bot, `No more ${blockType} nearby to collect.`);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
const block = blocks[0];
|
||||||
|
await bot.tool.equipForBlock(block);
|
||||||
|
const itemId = bot.heldItem ? bot.heldItem.type : null
|
||||||
|
if (!block.canHarvest(itemId)) {
|
||||||
|
log(bot, `Don't have right tools to harvest ${blockType}.`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
await bot.collectBlock.collect(block);
|
await bot.collectBlock.collect(block);
|
||||||
collected++;
|
collected++;
|
||||||
autoLight(bot);
|
await autoLight(bot);
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
if (err.name === 'NoChests') {
|
if (err.name === 'NoChests') {
|
||||||
|
@ -667,7 +670,7 @@ export async function followPlayer(bot, username) {
|
||||||
const enemy = world.getNearestEntityWhere(bot, entity => mc.isHostile(entity), attack_distance);
|
const enemy = world.getNearestEntityWhere(bot, entity => mc.isHostile(entity), attack_distance);
|
||||||
if (enemy) {
|
if (enemy) {
|
||||||
log(bot, `Found ${enemy.name}, attacking!`, true);
|
log(bot, `Found ${enemy.name}, attacking!`, true);
|
||||||
await defendSelf(bot, 8);
|
await defendSelf(bot);
|
||||||
acted = true;
|
acted = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -680,7 +683,7 @@ export async function followPlayer(bot, username) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (bot.entity.position.distanceTo(player.position) < follow_distance) {
|
if (bot.entity.position.distanceTo(player.position) < follow_distance) {
|
||||||
acted = autoLight(bot);
|
acted = await autoLight(bot);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (acted) { // if we did something then resume following
|
if (acted) { // if we did something then resume following
|
||||||
|
|
Loading…
Add table
Reference in a new issue