mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-04-21 21:52:07 +02:00
Merge pull request #224 from kolbytn/better-smelting
can smelt charcoal, use wood fuel
This commit is contained in:
commit
da5dcb6e3c
4 changed files with 57 additions and 22 deletions
|
@ -345,17 +345,17 @@ export const actionsList = [
|
|||
return 'Self-prompting stopped.';
|
||||
}
|
||||
},
|
||||
{
|
||||
name: '!npcGoal',
|
||||
description: 'Set a simple goal for an item or building to automatically work towards. Do not use for complex goals.',
|
||||
params: {
|
||||
'name': { type: 'string', description: 'The name of the goal to set. Can be item or building name. If empty will automatically choose a goal.' },
|
||||
'quantity': { type: 'int', description: 'The quantity of the goal to set. Default is 1.', domain: [1, Number.MAX_SAFE_INTEGER] }
|
||||
},
|
||||
perform: async function (agent, name=null, quantity=1) {
|
||||
await agent.npc.setGoal(name, quantity);
|
||||
agent.bot.emit('idle'); // to trigger the goal
|
||||
return 'Set npc goal: ' + agent.npc.data.curr_goal.name;
|
||||
}
|
||||
},
|
||||
// { // commented for now, causes confusion with goal command
|
||||
// name: '!npcGoal',
|
||||
// description: 'Set a simple goal for an item or building to automatically work towards. Do not use for complex goals.',
|
||||
// params: {
|
||||
// 'name': { type: 'string', description: 'The name of the goal to set. Can be item or building name. If empty will automatically choose a goal.' },
|
||||
// 'quantity': { type: 'int', description: 'The quantity of the goal to set. Default is 1.', domain: [1, Number.MAX_SAFE_INTEGER] }
|
||||
// },
|
||||
// perform: async function (agent, name=null, quantity=1) {
|
||||
// await agent.npc.setGoal(name, quantity);
|
||||
// agent.bot.emit('idle'); // to trigger the goal
|
||||
// return 'Set npc goal: ' + agent.npc.data.curr_goal.name;
|
||||
// }
|
||||
// },
|
||||
];
|
||||
|
|
|
@ -212,7 +212,6 @@ export async function executeCommand(agent, message) {
|
|||
if (parsed.args) {
|
||||
numArgs = parsed.args.length;
|
||||
}
|
||||
console.log('parsed command:', parsed);
|
||||
if (numArgs !== numParams(command))
|
||||
return `Command ${command.name} was given ${numArgs} args, but requires ${numParams(command)} args.`;
|
||||
else {
|
||||
|
|
|
@ -120,11 +120,11 @@ export async function smeltItem(bot, itemName, num=1) {
|
|||
* await skills.smeltItem(bot, "raw_iron");
|
||||
* await skills.smeltItem(bot, "beef");
|
||||
**/
|
||||
const foods = ['beef', 'chicken', 'cod', 'mutton', 'porkchop', 'rabbit', 'salmon', 'tropical_fish'];
|
||||
if (!itemName.includes('raw') && !foods.includes(itemName)) {
|
||||
log(bot, `Cannot smelt ${itemName}, must be a "raw" item, like "raw_iron".`);
|
||||
|
||||
if (!mc.isSmeltable(itemName)) {
|
||||
log(bot, `Cannot smelt ${itemName}. Hint: make sure you are smelting the 'raw' item.`);
|
||||
return false;
|
||||
} // TODO: allow cobblestone, sand, clay, etc.
|
||||
}
|
||||
|
||||
let placedFurnace = false;
|
||||
let furnaceBlock = undefined;
|
||||
|
@ -173,10 +173,19 @@ export async function smeltItem(bot, itemName, num=1) {
|
|||
|
||||
// fuel the furnace
|
||||
if (!furnace.fuelItem()) {
|
||||
let fuel = bot.inventory.items().find(item => item.name === 'coal' || item.name === 'charcoal');
|
||||
let put_fuel = Math.ceil(num / 8);
|
||||
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`);
|
||||
let fuel = mc.getSmeltingFuel(bot);
|
||||
if (!fuel) {
|
||||
log(bot, `You have no fuel to smelt ${num} ${itemName}, you need ${put_fuel} coal, charcoal, or wood.`);
|
||||
if (placedFurnace)
|
||||
await collectBlock(bot, 'furnace', 1);
|
||||
return false;
|
||||
}
|
||||
log(bot, `Using ${fuel.name} as fuel.`);
|
||||
|
||||
const put_fuel = Math.ceil(num / mc.getFuelSmeltOutput(fuel.name));
|
||||
|
||||
if (fuel.count < put_fuel) {
|
||||
log(bot, `You don't have enough ${fuel.name} to smelt ${num} ${itemName}; you need ${put_fuel}.`);
|
||||
if (placedFurnace)
|
||||
await collectBlock(bot, 'furnace', 1);
|
||||
return false;
|
||||
|
|
|
@ -193,6 +193,33 @@ export function getItemCraftingRecipes(itemName) {
|
|||
return recipes;
|
||||
}
|
||||
|
||||
export function isSmeltable(itemName) {
|
||||
const misc_smeltables = ['beef', 'chicken', 'cod', 'mutton', 'porkchop', 'rabbit', 'salmon', 'tropical_fish', 'potato', 'kelp', 'sand', 'cobblestone', 'clay_ball'];
|
||||
return itemName.includes('raw') || itemName.includes('log') || misc_smeltables.includes(itemName);
|
||||
}
|
||||
|
||||
export function getSmeltingFuel(bot) {
|
||||
let fuel = bot.inventory.items().find(i => i.name === 'coal' || i.name === 'charcoal')
|
||||
if (fuel)
|
||||
return fuel;
|
||||
fuel = bot.inventory.items().find(i => i.name.includes('log') || i.name.includes('planks'))
|
||||
if (fuel)
|
||||
return fuel;
|
||||
return bot.inventory.items().find(i => i.name === 'coal_block' || i.name === 'lava_bucket');
|
||||
}
|
||||
|
||||
export function getFuelSmeltOutput(fuelName) {
|
||||
if (fuelName === 'coal' || fuelName === 'charcoal')
|
||||
return 8;
|
||||
if (fuelName.includes('log') || fuelName.includes('planks'))
|
||||
return 1.5
|
||||
if (fuelName === 'coal_block')
|
||||
return 80;
|
||||
if (fuelName === 'lava_bucket')
|
||||
return 100;
|
||||
return 0;
|
||||
}
|
||||
|
||||
export function getItemSmeltingIngredient(itemName) {
|
||||
return {
|
||||
baked_potato: 'potato',
|
||||
|
|
Loading…
Add table
Reference in a new issue