mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-04-21 21:52:07 +02:00
Merge branch 'main' into self-prompt
This commit is contained in:
commit
30a172aa9d
7 changed files with 20 additions and 14 deletions
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"minecraft_version": "1.20.4",
|
||||
"host": "localhost",
|
||||
"host": "127.0.0.1",
|
||||
"port": 55916,
|
||||
"auth": "offline",
|
||||
"allow_insecure_coding": false
|
||||
|
|
|
@ -212,6 +212,7 @@ export class Agent {
|
|||
});
|
||||
this.bot.on('idle', () => {
|
||||
this.bot.clearControlStates();
|
||||
this.bot.pathfinder.stop(); // clear any lingering pathfinder
|
||||
this.bot.modes.unPauseAll();
|
||||
this.coder.executeResume();
|
||||
});
|
||||
|
|
|
@ -15,7 +15,8 @@ async function autoLight(bot) {
|
|||
let nearest_torch = world.getNearestBlock(bot, 'torch', 6);
|
||||
if (!nearest_torch) {
|
||||
let has_torch = bot.inventory.items().find(item => item.name === 'torch');
|
||||
if (has_torch) {
|
||||
const curr_block = agent.bot.blockAt(pos);
|
||||
if (has_torch && curr_block.name === 'air') {
|
||||
try {
|
||||
log(bot, `Placing torch at ${bot.entity.position}.`);
|
||||
return await placeBlock(bot, 'torch', bot.entity.position.x, bot.entity.position.y, bot.entity.position.z);
|
||||
|
@ -773,7 +774,7 @@ export async function avoidEnemies(bot, distance=16) {
|
|||
* @example
|
||||
* await skills.avoidEnemies(bot, 8);
|
||||
**/
|
||||
|
||||
bot.modes.pause('self_preservation'); // prevents damage-on-low-health from interrupting the bot
|
||||
let enemy = world.getNearestEntityWhere(bot, entity => mc.isHostile(entity), distance);
|
||||
while (enemy) {
|
||||
const follow = new pf.goals.GoalFollow(enemy, distance+1); // move a little further away
|
||||
|
@ -783,9 +784,10 @@ export async function avoidEnemies(bot, distance=16) {
|
|||
await new Promise(resolve => setTimeout(resolve, 500));
|
||||
enemy = world.getNearestEntityWhere(bot, entity => mc.isHostile(entity), distance);
|
||||
if (bot.interrupt_code) {
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
bot.pathfinder.stop();
|
||||
log(bot, `Moved ${distance} away from enemies.`);
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -74,7 +74,7 @@ const modes = [
|
|||
if (enemy && await world.isClearPath(agent.bot, enemy)) {
|
||||
agent.bot.chat(`Aaa! A ${enemy.name}!`);
|
||||
execute(this, agent, async () => {
|
||||
await skills.avoidEnemies(agent.bot, 16);
|
||||
await skills.avoidEnemies(agent.bot, 24);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -86,11 +86,11 @@ const modes = [
|
|||
on: true,
|
||||
active: false,
|
||||
update: async function (agent) {
|
||||
const enemy = world.getNearestEntityWhere(agent.bot, entity => mc.isHostile(entity), 9);
|
||||
const enemy = world.getNearestEntityWhere(agent.bot, entity => mc.isHostile(entity), 8);
|
||||
if (enemy && await world.isClearPath(agent.bot, enemy)) {
|
||||
agent.bot.chat(`Fighting ${enemy.name}!`);
|
||||
execute(this, agent, async () => {
|
||||
await skills.defendSelf(agent.bot, 9);
|
||||
await skills.defendSelf(agent.bot, 8);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -155,9 +155,12 @@ const modes = [
|
|||
if (torches.length > 0) {
|
||||
const torch = torches[0];
|
||||
const pos = agent.bot.entity.position;
|
||||
execute(this, agent, async () => {
|
||||
await skills.placeBlock(agent.bot, torch.name, pos.x, pos.y, pos.z);
|
||||
});
|
||||
const curr_block = agent.bot.blockAt(pos);
|
||||
if (curr_block.name === 'air') {
|
||||
execute(this, agent, async () => {
|
||||
await skills.placeBlock(agent.bot, torch.name, pos.x, pos.y, pos.z);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -164,7 +164,7 @@ export class Prompter {
|
|||
user_message = await this.replaceStrings(user_message, messages, null, null, null, last_goals);
|
||||
let user_messages = [{role: 'user', content: user_message}];
|
||||
|
||||
let res = await this.model.sendRequest(user_messages, system_message);
|
||||
let res = await this.chat_model.sendRequest(user_messages, system_message);
|
||||
|
||||
let goal = null;
|
||||
try {
|
||||
|
@ -180,4 +180,4 @@ export class Prompter {
|
|||
goal.quantity = parseInt(goal.quantity);
|
||||
return goal;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
export class Local {
|
||||
constructor(model_name, url) {
|
||||
this.model_name = model_name;
|
||||
this.url = url || 'http://localhost:11434';
|
||||
this.url = url || 'http://127.0.0.1:11434';
|
||||
this.chat_endpoint = '/api/chat';
|
||||
this.embedding_endpoint = '/api/embeddings';
|
||||
}
|
||||
|
|
|
@ -68,7 +68,7 @@ export function initBot(username) {
|
|||
|
||||
export function isHuntable(mob) {
|
||||
if (!mob || !mob.name) return false;
|
||||
const animals = ['chicken', 'cod', 'cow', 'llama', 'mooshroom', 'pig', 'pufferfish', 'rabbit', 'salmon', 'sheep', 'squid', 'tropical_fish', 'turtle'];
|
||||
const animals = ['chicken', 'cow', 'llama', 'mooshroom', 'pig', 'rabbit', 'sheep'];
|
||||
return animals.includes(mob.name.toLowerCase()) && !mob.metadata[16]; // metadata 16 is not baby
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue