mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-09-10 03:53:07 +02:00
getnearestblock replaced getcraftingtable
This commit is contained in:
parent
b72bf3f697
commit
0e51d8c8f6
3 changed files with 17 additions and 22 deletions
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue