From cc48a38aded592ba8f670385fcfa6e2ea82e8b9b Mon Sep 17 00:00:00 2001 From: Kolby Nottingham Date: Wed, 6 Mar 2024 15:53:22 -0800 Subject: [PATCH] build bed --- src/agent/npc/construction/shelter.json | 6 ++--- src/agent/npc/item_goal.js | 16 +++++++++++-- src/agent/npc/utils.js | 31 +++++++++++++++++++++++++ src/utils/mcdata.js | 18 ++++++++++++++ 4 files changed, 66 insertions(+), 5 deletions(-) diff --git a/src/agent/npc/construction/shelter.json b/src/agent/npc/construction/shelter.json index 410afb5..96aec7e 100644 --- a/src/agent/npc/construction/shelter.json +++ b/src/agent/npc/construction/shelter.json @@ -20,8 +20,8 @@ ], [ ["dirt", "dirt", "dirt", "dirt", "dirt"], - ["dirt", "chest", "air", "air", "dirt"], - ["dirt", "air", "air", "air", "dirt"], + ["dirt", "chest", "air", "bed", "dirt"], + ["dirt", "air", "air", "bed", "dirt"], ["dirt", "air", "air", "air", "dirt"], ["dirt", "dirt", "door", "dirt", "dirt"] ], @@ -30,7 +30,7 @@ ["dirt", "air", "air", "air", "dirt"], ["dirt", "air", "air", "air", "dirt"], ["dirt", "air", "air", "air", "dirt"], - ["dirt", "dirt", "", "dirt", "dirt"] + ["dirt", "dirt", "door", "dirt", "dirt"] ], [ ["air", "air", "air", "air", "air"], diff --git a/src/agent/npc/item_goal.js b/src/agent/npc/item_goal.js index 0c89ce8..db19dc9 100644 --- a/src/agent/npc/item_goal.js +++ b/src/agent/npc/item_goal.js @@ -15,7 +15,8 @@ const blacklist = [ '_wood', 'stripped_', 'crimson', - 'warped' + 'warped', + 'dye' ] @@ -206,12 +207,23 @@ class ItemWrapper { let recipes = mc.getItemCraftingRecipes(this.name); if (recipes) { for (let recipe of recipes) { + let includes_blacklisted = false; + for (let ingredient in recipe) { + for (let match of blacklist) { + if (ingredient.includes(match)) { + includes_blacklisted = true; + break; + } + } + if (includes_blacklisted) break; + } + if (includes_blacklisted) continue; this.add_method(new ItemNode(this.manager, this, this.name).setRecipe(recipe)) } } let block_sources = mc.getItemBlockSources(this.name); - if (block_sources.length > 0 && this.name !== 'torch') { // Do not collect placed torches + if (block_sources.length > 0 && this.name !== 'torch' && !this.name.includes('bed')) { // Do not collect placed torches or beds for (let block_source of block_sources) { if (block_source === 'grass_block') continue; // Dirt nodes will collect grass blocks let tool = mc.getBlockTool(block_source); diff --git a/src/agent/npc/utils.js b/src/agent/npc/utils.js index b63b544..a92a38a 100644 --- a/src/agent/npc/utils.js +++ b/src/agent/npc/utils.js @@ -3,6 +3,7 @@ import * as mc from '../../utils/mcdata.js'; export function getTypeOfGeneric(bot, block_name) { + // Get type of wooden block if (mc.MATCHING_WOOD_BLOCKS.includes(block_name)) { // Return most common wood type in inventory @@ -37,6 +38,34 @@ export function getTypeOfGeneric(bot, block_name) { // Return oak return 'oak_' + block_name; } + + // Get type of bed + if (block_name === 'bed') { + + // Return most common wool type in inventory + let type_count = {}; + let max_count = 0; + let max_type = null; + let inventory = world.getInventoryCounts(bot); + for (const item in inventory) { + for (const color of mc.WOOL_COLORS) { + if (item === color + '_wool') { + if (type_count[color] === undefined) + type_count[color] = 0; + type_count[color] += inventory[item]; + if (type_count[color] > max_count) { + max_count = type_count[color]; + max_type = color; + } + } + } + } + if (max_type !== null) + return max_type + '_' + block_name; + + // Return white + return 'white_' + block_name; + } return block_name; } @@ -46,6 +75,8 @@ export function blockSatisfied(target_name, block) { return block.name == 'dirt' || block.name == 'grass_block'; } else if (mc.MATCHING_WOOD_BLOCKS.includes(target_name)) { return block.name.endsWith(target_name); + } else if (target_name == 'bed') { + return block.name.endsWith('bed'); } return block.name == target_name; } diff --git a/src/utils/mcdata.js b/src/utils/mcdata.js index 1ffbec7..eeeb957 100644 --- a/src/utils/mcdata.js +++ b/src/utils/mcdata.js @@ -27,6 +27,24 @@ export const MATCHING_WOOD_BLOCKS = [ 'pressure_plate', 'trapdoor' ] +export const WOOL_COLORS = [ + 'white', + 'orange', + 'magenta', + 'light_blue', + 'yellow', + 'lime', + 'pink', + 'gray', + 'light_gray', + 'cyan', + 'purple', + 'blue', + 'brown', + 'green', + 'red', + 'black' +] export function initBot(username) {