mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-08-22 15:13:45 +02:00
crafting bugs
This commit is contained in:
parent
a7218d274f
commit
a7ebe00929
4 changed files with 50 additions and 37 deletions
|
@ -1,5 +1,5 @@
|
||||||
import pf from 'mineflayer-pathfinder';
|
import pf from 'mineflayer-pathfinder';
|
||||||
import { getAllBlockIds, getAllBiomes } from '../../utils/mcdata.js';
|
import * as mc from '../../utils/mcdata.js';
|
||||||
|
|
||||||
|
|
||||||
export function getNearestFreeSpace(bot, size=1, distance=8) {
|
export function getNearestFreeSpace(bot, size=1, distance=8) {
|
||||||
|
@ -39,26 +39,7 @@ export function getNearestFreeSpace(bot, size=1, distance=8) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export function getNearbyBlocks(bot, maxDistance, count=null) {
|
export function getNearestBlocks(bot, block_types=null, distance=16, count=10000) {
|
||||||
if (maxDistance == null) maxDistance = 16;
|
|
||||||
if (count == null) count = 10000;
|
|
||||||
let positions = bot.findBlocks({matching: getAllBlockIds(['air']), maxDistance: maxDistance, count: count});
|
|
||||||
let blocks = [];
|
|
||||||
for (let i = 0; i < positions.length; i++) {
|
|
||||||
let block = bot.blockAt(positions[i]);
|
|
||||||
let distance = positions[i].distanceTo(bot.entity.position);
|
|
||||||
blocks.push({ block: block, distance: distance });
|
|
||||||
}
|
|
||||||
blocks.sort((a, b) => a.distance - b.distance);
|
|
||||||
let res = [];
|
|
||||||
for (let i = 0; i < blocks.length; i++) {
|
|
||||||
res.push(blocks[i].block);
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
export function getNearestBlocks(bot, block_types, distance=16, count=null) {
|
|
||||||
/**
|
/**
|
||||||
* Get a list of the nearest blocks of the given types.
|
* Get a list of the nearest blocks of the given types.
|
||||||
* @param {Bot} bot - The bot to get the nearest block for.
|
* @param {Bot} bot - The bot to get the nearest block for.
|
||||||
|
@ -70,17 +51,32 @@ export function getNearestBlocks(bot, block_types, distance=16, count=null) {
|
||||||
* let woodBlocks = world.getNearestBlocks(bot, ['oak_log', 'birch_log'], 16, 1);
|
* let woodBlocks = world.getNearestBlocks(bot, ['oak_log', 'birch_log'], 16, 1);
|
||||||
**/
|
**/
|
||||||
// if blocktypes is not a list, make it a list
|
// if blocktypes is not a list, make it a list
|
||||||
|
let block_ids = [];
|
||||||
|
if (block_types === null) {
|
||||||
|
block_ids = mc.getAllBlockIds(['air']);
|
||||||
|
}
|
||||||
|
else {
|
||||||
if (!Array.isArray(block_types))
|
if (!Array.isArray(block_types))
|
||||||
block_types = [block_types];
|
block_types = [block_types];
|
||||||
|
for(let block_type of block_types) {
|
||||||
|
block_ids.push(mc.getBlockId(block_type));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let positions = bot.findBlocks({matching: block_ids, maxDistance: distance, count: count});
|
||||||
let blocks = [];
|
let blocks = [];
|
||||||
for (let block of getNearbyBlocks(bot, distance, count)) {
|
for (let i = 0; i < positions.length; i++) {
|
||||||
if (block_types.includes(block.name)) {
|
let block = bot.blockAt(positions[i]);
|
||||||
blocks.push(block);
|
let distance = positions[i].distanceTo(bot.entity.position);
|
||||||
if (count !== null && blocks.length >= count)
|
blocks.push({ block: block, distance: distance });
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
blocks.sort((a, b) => a.distance - b.distance);
|
||||||
|
|
||||||
|
let res = [];
|
||||||
|
for (let i = 0; i < blocks.length; i++) {
|
||||||
|
res.push(blocks[i].block);
|
||||||
}
|
}
|
||||||
return blocks;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -235,7 +231,7 @@ export function getNearbyBlockTypes(bot, distance=16) {
|
||||||
* @example
|
* @example
|
||||||
* let blocks = world.getNearbyBlockTypes(bot);
|
* let blocks = world.getNearbyBlockTypes(bot);
|
||||||
**/
|
**/
|
||||||
let blocks = getNearbyBlocks(bot, distance);
|
let blocks = getNearestBlocks(bot, null, distance);
|
||||||
let found = [];
|
let found = [];
|
||||||
for (let i = 0; i < blocks.length; i++) {
|
for (let i = 0; i < blocks.length; i++) {
|
||||||
if (!found.includes(blocks[i].name)) {
|
if (!found.includes(blocks[i].name)) {
|
||||||
|
@ -269,5 +265,5 @@ export function getBiomeName(bot) {
|
||||||
* let biome = world.getBiomeName(bot);
|
* let biome = world.getBiomeName(bot);
|
||||||
**/
|
**/
|
||||||
const biomeId = bot.world.getBiome(bot.entity.position);
|
const biomeId = bot.world.getBiome(bot.entity.position);
|
||||||
return getAllBiomes()[biomeId].name;
|
return mc.getAllBiomes()[biomeId].name;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
["dirt", "dirt", "dirt", "dirt", "dirt"],
|
["dirt", "dirt", "dirt", "dirt", "dirt"],
|
||||||
["dirt", "air", "air", "air", "dirt"],
|
["dirt", "chest", "air", "air", "dirt"],
|
||||||
["dirt", "air", "air", "air", "dirt"],
|
["dirt", "air", "air", "air", "dirt"],
|
||||||
["dirt", "air", "air", "air", "dirt"],
|
["dirt", "air", "air", "air", "dirt"],
|
||||||
["dirt", "dirt", "door", "dirt", "dirt"]
|
["dirt", "dirt", "door", "dirt", "dirt"]
|
||||||
|
|
|
@ -27,10 +27,11 @@ export function getTypeOfGeneric(bot, block_name) {
|
||||||
return max_type + '_' + block_name;
|
return max_type + '_' + block_name;
|
||||||
|
|
||||||
// Return nearest wood type
|
// Return nearest wood type
|
||||||
let blocks = world.getNearbyBlocks(bot, 32);
|
let log_types = mc.WOOD_TYPES.map((wood) => wood + '_log');
|
||||||
for (const block of blocks) {
|
let blocks = world.getNearestBlocks(bot, log_types, 16, 1);
|
||||||
if (block.name.endsWith('log'))
|
if (blocks.length > 0) {
|
||||||
return block.name.split('_')[0] + '_' + block_name;
|
let wood = blocks[0].name.split('_')[0];
|
||||||
|
return wood + '_' + block_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return oak
|
// Return oak
|
||||||
|
|
|
@ -75,6 +75,22 @@ export function getItemName(itemId) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getBlockId(blockName) {
|
||||||
|
let block = mcdata.blocksByName[blockName];
|
||||||
|
if (block) {
|
||||||
|
return block.id;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getBlockName(blockId) {
|
||||||
|
let block = mcdata.blocks[blockId]
|
||||||
|
if (block) {
|
||||||
|
return block.name;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
export function getAllItems(ignore) {
|
export function getAllItems(ignore) {
|
||||||
if (!ignore) {
|
if (!ignore) {
|
||||||
ignore = [];
|
ignore = [];
|
||||||
|
|
Loading…
Add table
Reference in a new issue