getnearestblock replaced getcraftingtable

This commit is contained in:
MaxRobinsonTheGreat 2023-11-15 17:01:06 -06:00
parent b72bf3f697
commit 0e51d8c8f6
3 changed files with 17 additions and 22 deletions

View file

@ -1,6 +1,6 @@
import { readFileSync } from 'fs';
import { getCraftingTable, getNearbyMobTypes, getNearbyPlayerNames, getNearbyBlockTypes, getInventoryCounts } from './world.js';
import { getNearestBlock, getNearbyMobTypes, getNearbyPlayerNames, getNearbyBlockTypes, getInventoryCounts } from './world.js';
import { getAllItems } from './mcdata.js';
@ -23,7 +23,7 @@ export function getInventory(bot) {
let inventory = getInventoryCounts(bot);
let res = 'INVENTORY';
for (const item in inventory) {
if (inventory[item] > 0)
if (inventory[item] && inventory[item] > 0)
res += `\n- ${item}: ${inventory[item]}`;
}
if (res == 'INVENTORY') {
@ -62,7 +62,7 @@ export function getNearbyEntities(bot) {
export function getCraftable(bot) {
const table = getCraftingTable(bot);
const table = getNearestBlock(bot, 'crafting_table');
let res = 'CRAFTABLE_ITEMS';
for (const item of getAllItems()) {
let recipes = bot.recipesFor(item.id, null, 1, table);

View file

@ -23,6 +23,9 @@ export function getItemId(item) {
return mcdata.itemsByName[item].id;
}
export function getItemName(itemId) {
return mcdata.items[itemId].name;
}
export function getAllItems(ignore) {
if (!ignore) {

View file

@ -1,16 +1,18 @@
import { getAllBlockIds, getAllBlocks, getAllItems } from './mcdata.js';
export function getCraftingTable(bot) {
const blocks = getNearbyBlocks(bot, 50);
let table = null;
for (const block of blocks) {
if (block.name == 'crafting_table') {
table = block;
break;
}
export function getNearestBlock(bot, block_type) {
let block_locs = bot.findBlocks({
matching: (block) => {
return block && block.type === bot.registry.blocksByName[block_type].id
},
maxDistance: 6,
count: 1
});
if (block_locs.length > 0) {
return bot.blockAt(block_locs[0]);
}
return table;
return null;
}
@ -99,16 +101,6 @@ export function getInventoryCounts(bot) {
inventory[item.name] = item.count;
}
}
for (const item of getAllItems()) {
if (!inventory.hasOwnProperty(item.name)) {
inventory[item.name] = 0;
}
}
for (const item of getAllBlocks()) {
if (!inventory.hasOwnProperty(item.name)) {
inventory[item.name] = 0;
}
}
return inventory;
}