mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-08-04 22:35:35 +02:00
smelting command, minor cleanup
This commit is contained in:
parent
5448b018c7
commit
cb9de90d11
7 changed files with 48 additions and 18 deletions
|
@ -1,6 +0,0 @@
|
||||||
{
|
|
||||||
"name": "andy",
|
|
||||||
"bio": "You are playing minecraft and assisting other players in tasks.",
|
|
||||||
"memory": "",
|
|
||||||
"turns": []
|
|
||||||
}
|
|
|
@ -146,12 +146,12 @@ export class Coder {
|
||||||
}
|
}
|
||||||
|
|
||||||
async executeResume(func=null, name=null, timeout=10) {
|
async executeResume(func=null, name=null, timeout=10) {
|
||||||
console.log('resuming code...')
|
|
||||||
if (func != null) {
|
if (func != null) {
|
||||||
this.resume_func = func;
|
this.resume_func = func;
|
||||||
this.resume_name = name;
|
this.resume_name = name;
|
||||||
}
|
}
|
||||||
if (this.resume_func != null && this.agent.isIdle()) {
|
if (this.resume_func != null && this.agent.isIdle()) {
|
||||||
|
console.log('resuming code...')
|
||||||
this.interruptible = true;
|
this.interruptible = true;
|
||||||
let res = await this.execute(this.resume_func, timeout);
|
let res = await this.execute(this.resume_func, timeout);
|
||||||
this.interruptible = false;
|
this.interruptible = false;
|
||||||
|
|
|
@ -144,9 +144,18 @@ export const actionsList = [
|
||||||
'num': '(number) The number of times to craft the recipe. This is NOT the number of output items, as it may craft many more items depending on the recipe.'
|
'num': '(number) The number of times to craft the recipe. This is NOT the number of output items, as it may craft many more items depending on the recipe.'
|
||||||
},
|
},
|
||||||
perform: wrapExecution(async (agent, recipe_name, num) => {
|
perform: wrapExecution(async (agent, recipe_name, num) => {
|
||||||
for (let i=0; i<num; i++) {
|
await skills.craftRecipe(agent.bot, recipe_name, num);
|
||||||
await skills.craftRecipe(agent.bot, recipe_name);
|
})
|
||||||
}
|
},
|
||||||
|
{
|
||||||
|
name: '!smeltItem',
|
||||||
|
description: 'Smelt the given item the given number of times.',
|
||||||
|
params: {
|
||||||
|
'item_name': '(string) The name of the input item to smelt.',
|
||||||
|
'num': '(number) The number of times to smelt the item.'
|
||||||
|
},
|
||||||
|
perform: wrapExecution(async (agent, recipe_name, num) => {
|
||||||
|
await skills.smeltItem(agent.bot, recipe_name, num);
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { writeFileSync, readFileSync, mkdirSync } from 'fs';
|
import { writeFileSync, readFileSync } from 'fs';
|
||||||
|
|
||||||
|
|
||||||
export class History {
|
export class History {
|
||||||
|
|
|
@ -40,7 +40,7 @@ async function equipHighestAttack(bot) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export async function craftRecipe(bot, itemName) {
|
export async function craftRecipe(bot, itemName, num=1) {
|
||||||
/**
|
/**
|
||||||
* Attempt to craft the given item name from a recipe. May craft many items.
|
* Attempt to craft the given item name from a recipe. May craft many items.
|
||||||
* @param {MinecraftBot} bot, reference to the minecraft bot.
|
* @param {MinecraftBot} bot, reference to the minecraft bot.
|
||||||
|
@ -90,7 +90,7 @@ export async function craftRecipe(bot, itemName) {
|
||||||
|
|
||||||
const recipe = recipes[0];
|
const recipe = recipes[0];
|
||||||
console.log('crafting...');
|
console.log('crafting...');
|
||||||
await bot.craft(recipe, 1, craftingTable);
|
await bot.craft(recipe, num, craftingTable);
|
||||||
log(bot, `Successfully crafted ${itemName}, you now have ${world.getInventoryCounts(bot)[itemName]} ${itemName}.`);
|
log(bot, `Successfully crafted ${itemName}, you now have ${world.getInventoryCounts(bot)[itemName]} ${itemName}.`);
|
||||||
if (placedTable) {
|
if (placedTable) {
|
||||||
await collectBlock(bot, 'crafting_table', 1);
|
await collectBlock(bot, 'crafting_table', 1);
|
||||||
|
@ -116,10 +116,21 @@ export async function smeltItem(bot, itemName, num=1) {
|
||||||
return false;
|
return false;
|
||||||
} // TODO: allow cobblestone, sand, clay, etc.
|
} // TODO: allow cobblestone, sand, clay, etc.
|
||||||
|
|
||||||
|
let placedFurnace = false;
|
||||||
let furnaceBlock = undefined;
|
let furnaceBlock = undefined;
|
||||||
furnaceBlock = world.getNearestBlock(bot, 'furnace', 6);
|
furnaceBlock = world.getNearestBlock(bot, 'furnace', 6);
|
||||||
if (!furnaceBlock){
|
if (!furnaceBlock){
|
||||||
log(bot, `There is no furnace nearby.`)
|
// Try to place furnace
|
||||||
|
let hasFurnace = world.getInventoryCounts(bot)['furnace'] > 0;
|
||||||
|
if (hasFurnace) {
|
||||||
|
let pos = world.getNearestFreeSpace(bot, 1, 6);
|
||||||
|
await placeBlock(bot, 'furnace', pos.x, pos.y, pos.z);
|
||||||
|
furnaceBlock = world.getNearestBlock(bot, 'furnace', 6);
|
||||||
|
placedFurnace = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!furnaceBlock){
|
||||||
|
log(bot, `There is no furnace nearby and you have no furnace.`)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
await bot.lookAt(furnaceBlock.position);
|
await bot.lookAt(furnaceBlock.position);
|
||||||
|
@ -132,12 +143,16 @@ export async function smeltItem(bot, itemName, num=1) {
|
||||||
// TODO: check if furnace is currently burning fuel. furnace.fuel is always null, I think there is a bug.
|
// TODO: check if furnace is currently burning fuel. furnace.fuel is always null, I think there is a bug.
|
||||||
// This only checks if the furnace has an input item, but it may not be smelting it and should be cleared.
|
// This only checks if the furnace has an input item, but it may not be smelting it and should be cleared.
|
||||||
log(bot, `The furnace is currently smelting ${mc.getItemName(input_item.type)}.`);
|
log(bot, `The furnace is currently smelting ${mc.getItemName(input_item.type)}.`);
|
||||||
|
if (placedFurnace)
|
||||||
|
await collectBlock(bot, 'furnace', 1);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// check if the bot has enough items to smelt
|
// check if the bot has enough items to smelt
|
||||||
let inv_counts = world.getInventoryCounts(bot);
|
let inv_counts = world.getInventoryCounts(bot);
|
||||||
if (!inv_counts[itemName] || inv_counts[itemName] < num) {
|
if (!inv_counts[itemName] || inv_counts[itemName] < num) {
|
||||||
log(bot, `You do not have enough ${itemName} to smelt.`);
|
log(bot, `You do not have enough ${itemName} to smelt.`);
|
||||||
|
if (placedFurnace)
|
||||||
|
await collectBlock(bot, 'furnace', 1);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,6 +162,8 @@ export async function smeltItem(bot, itemName, num=1) {
|
||||||
let put_fuel = Math.ceil(num / 8);
|
let put_fuel = Math.ceil(num / 8);
|
||||||
if (!fuel || fuel.count < put_fuel) {
|
if (!fuel || fuel.count < put_fuel) {
|
||||||
log(bot, `You do not have enough coal or charcoal to smelt ${num} ${itemName}, you need ${put_fuel} coal or charcoal`);
|
log(bot, `You do not have enough coal or charcoal to smelt ${num} ${itemName}, you need ${put_fuel} coal or charcoal`);
|
||||||
|
if (placedFurnace)
|
||||||
|
await collectBlock(bot, 'furnace', 1);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
await furnace.putFuel(fuel.type, null, put_fuel);
|
await furnace.putFuel(fuel.type, null, put_fuel);
|
||||||
|
@ -180,6 +197,9 @@ export async function smeltItem(bot, itemName, num=1) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (placedFurnace) {
|
||||||
|
await collectBlock(bot, 'furnace', 1);
|
||||||
|
}
|
||||||
if (total === 0) {
|
if (total === 0) {
|
||||||
log(bot, `Failed to smelt ${itemName}.`);
|
log(bot, `Failed to smelt ${itemName}.`);
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -172,7 +172,6 @@ export function getInventoryCounts(bot) {
|
||||||
inventory[item.name] += item.count;
|
inventory[item.name] += item.count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log(inventory)
|
|
||||||
return inventory;
|
return inventory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,12 +42,20 @@ export function isHostile(mob) {
|
||||||
return (mob.type === 'mob' || mob.type === 'hostile') && mob.name !== 'iron_golem' && mob.name !== 'snow_golem';
|
return (mob.type === 'mob' || mob.type === 'hostile') && mob.name !== 'iron_golem' && mob.name !== 'snow_golem';
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getItemId(item) {
|
export function getItemId(itemName) {
|
||||||
return mcdata.itemsByName[item].id;
|
let item = mcdata.itemsByName[itemName];
|
||||||
|
if (item) {
|
||||||
|
return item.id;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getItemName(itemId) {
|
export function getItemName(itemId) {
|
||||||
return mcdata.items[itemId].name;
|
let item = mcdata.items[itemId]
|
||||||
|
if (item) {
|
||||||
|
return item.name;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getAllItems(ignore) {
|
export function getAllItems(ignore) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue