mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-08-11 17:55:34 +02:00
Merge pull request #4 from icwhite/procedural_generation_save
Procedural generation save
This commit is contained in:
commit
cda69eee73
21 changed files with 4013417 additions and 182516 deletions
104
andy_0.json
104
andy_0.json
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "andy_0",
|
"name": "Andy_0",
|
||||||
"model": "gpt-4o",
|
"model": "gpt-4o-mini",
|
||||||
"modes": {
|
"modes": {
|
||||||
"hunting": false
|
"hunting": false
|
||||||
},
|
},
|
||||||
|
@ -9,7 +9,7 @@
|
||||||
"conversation_examples": [
|
"conversation_examples": [
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"role": "assistant",
|
"role": "user",
|
||||||
"content": "Hey! let's collaborate to build a stone pickaxe!"
|
"content": "Hey! let's collaborate to build a stone pickaxe!"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -17,7 +17,7 @@
|
||||||
"content": "Cool, let me check what is in my inventory !inventory\nI have 10 oak logs. What do you have?"
|
"content": "Cool, let me check what is in my inventory !inventory\nI have 10 oak logs. What do you have?"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"role": "assistant",
|
"role": "user",
|
||||||
"content": "Let me check !inventory \nI have 10 stones."
|
"content": "Let me check !inventory \nI have 10 stones."
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -25,13 +25,13 @@
|
||||||
"content": "Let me give you the stones and you can craft the pickaxe. !givePlayer(\"stone\", 10, \"playername\")"
|
"content": "Let me give you the stones and you can craft the pickaxe. !givePlayer(\"stone\", 10, \"playername\")"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"role": "assistant",
|
"role": "user",
|
||||||
"content": "Thanks for the stones! Now I can craft the pickaxe. !craftItem(\"stone_pickaxe\", 1)"
|
"content": "Thanks for the stones! Now I can craft the pickaxe. !craftItem(\"stone_pickaxe\", 1)"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"role": "assistant",
|
"role": "user",
|
||||||
"content": "Hey! let's collaborate to build shears!"
|
"content": "Hey! let's collaborate to build shears!"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -39,7 +39,7 @@
|
||||||
"content": "Cool, let me check what is in my inventory !inventory\nI have 1 iron ingot. What do you have?"
|
"content": "Cool, let me check what is in my inventory !inventory\nI have 1 iron ingot. What do you have?"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"role": "assistant",
|
"role": "user",
|
||||||
"content": "Let me check !inventory \nI have 1 iron ingot. "
|
"content": "Let me check !inventory \nI have 1 iron ingot. "
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -47,7 +47,7 @@
|
||||||
"content": "Nice let's check what we need to craft shears. !getCraftingPlan(\"shears\", 1)"
|
"content": "Nice let's check what we need to craft shears. !getCraftingPlan(\"shears\", 1)"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"role": "assistant",
|
"role": "user",
|
||||||
"content": "We need 2 iron ingots to craft the shears. Could you share your iron ingot with me?"
|
"content": "We need 2 iron ingots to craft the shears. Could you share your iron ingot with me?"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -55,10 +55,58 @@
|
||||||
"content": "Yes, here is my iron ingot !givePlayer(\"iron_ingot\", 1, \"playername\")"
|
"content": "Yes, here is my iron ingot !givePlayer(\"iron_ingot\", 1, \"playername\")"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"role": "assistant",
|
"role": "user",
|
||||||
"content": "Thanks for the iron ingot! Now I can craft the shears. !craftItem(\"shears\", 1)"
|
"content": "Thanks for the iron ingot! Now I can craft the shears. !craftItem(\"shears\", 1)"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"role": "user",
|
||||||
|
"content": "Hey! Let's collaborate to build a brush"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"role": "assistant",
|
||||||
|
"content": "Cool, let's check what we need for that !getCraftingPlan(\"brush\", 1)"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"role": "system",
|
||||||
|
"content": "CRAFTING_PLAN\n- 2 sticks\n- 2 feathers\n- 1 iron ingot"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"role": "assistant",
|
||||||
|
"content": "We need 2 sticks, 2 feathers, and 1 iron ingot to craft the brush. Do you have any of these items?"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"role": "user",
|
||||||
|
"content": "Let me check !inventory \nI have 2 sticks and 2 feathers."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"role": "assistant",
|
||||||
|
"content": "Great! I have 1 iron ingot. Let me give you my iron ingot and you can craft the brush. !givePlayer(\"iron_ingot\", 1, \"playername\")"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"role": "user",
|
||||||
|
"content": "Thanks for the iron ingot! Now I can craft the brush. !craftItem(\"brush\", 1)"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"role": "user",
|
||||||
|
"content": "Hey! Let's collaborate to build a brush"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"role": "assistant",
|
||||||
|
"content": "Cool, let's check what we need for that !getCraftingPlan(\"brush\", 1)"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"role": "system",
|
||||||
|
"content": "no such tool"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"role": "assistant",
|
||||||
|
"content": "I'm sorry, I don't have the crafting plan for a brush. Let me check my inventory to see if I have the items needed. !inventory Do you have access to the crafting plan?"
|
||||||
|
}
|
||||||
|
],
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"role": "user",
|
"role": "user",
|
||||||
|
@ -109,24 +157,6 @@
|
||||||
"content": "terrance: (FROM OTHER BOT)I can build the base, you can build the walls. !newAction(\"Build a 10x10 wall of a house at x:942, y:54, z:1355\")"
|
"content": "terrance: (FROM OTHER BOT)I can build the base, you can build the walls. !newAction(\"Build a 10x10 wall of a house at x:942, y:54, z:1355\")"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
[
|
|
||||||
{
|
|
||||||
"role": "system",
|
|
||||||
"content": "trade something with zorro_34"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"role": "assistant",
|
|
||||||
"content": "!startConversation(\"zorro_34\", \"Hey let's trade. What do you have?\")"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"role": "user",
|
|
||||||
"content": "zorro_34: (FROM OTHER BOT)Let's see... !inventory\nI have a wooden pickaxe, cobblestone, and cooked chicken"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"role": "assistant",
|
|
||||||
"content": "Okay, could I trade you a cobblestone for a cooked chicken?"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"role": "user",
|
"role": "user",
|
||||||
|
@ -141,26 +171,6 @@
|
||||||
"content": "rupert: (FROM OTHER BOT)Alright, I'll build the walls! !newAction('Build a 10x10 wall of a house at the same location')"
|
"content": "rupert: (FROM OTHER BOT)Alright, I'll build the walls! !newAction('Build a 10x10 wall of a house at the same location')"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
[
|
|
||||||
{
|
|
||||||
"role": "user",
|
|
||||||
"content": "gort: (FROM OTHER BOT)Let's do it, onward!"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"role": "assistant",
|
|
||||||
"content": "Alright, I'll start by getting some cobblestone. !collectBlocks('stone', 10)"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[
|
|
||||||
{
|
|
||||||
"role": "user",
|
|
||||||
"content": "derg: (FROM OTHER BOT)Thanks, see you later!"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"role": "assistant",
|
|
||||||
"content": "See you later. !endConversation(\"derg\")"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"role": "user",
|
"role": "user",
|
||||||
|
|
|
@ -108,7 +108,7 @@ def launch_parallel_experiments(task_path,
|
||||||
num_exp,
|
num_exp,
|
||||||
exp_name,
|
exp_name,
|
||||||
num_agents=2,
|
num_agents=2,
|
||||||
model="gpt-4o",
|
model="gpt-4o-mini",
|
||||||
api="openai",
|
api="openai",
|
||||||
num_parallel=1,
|
num_parallel=1,
|
||||||
s3=False,
|
s3=False,
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
{
|
{
|
||||||
"name": "jill",
|
"name": "jill",
|
||||||
|
|
||||||
"model": "gpt-4o-mini",
|
"model": "gpt-4o-mini",
|
||||||
|
|
||||||
"conversation_examples": [
|
"conversation_examples": [
|
||||||
|
|
104
jill_0.json
104
jill_0.json
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "jill_0",
|
"name": "Jill_0",
|
||||||
"model": "gpt-4o",
|
"model": "gpt-4o-mini",
|
||||||
"modes": {
|
"modes": {
|
||||||
"hunting": false
|
"hunting": false
|
||||||
},
|
},
|
||||||
|
@ -9,7 +9,7 @@
|
||||||
"conversation_examples": [
|
"conversation_examples": [
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"role": "assistant",
|
"role": "user",
|
||||||
"content": "Hey! let's collaborate to build a stone pickaxe!"
|
"content": "Hey! let's collaborate to build a stone pickaxe!"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -17,7 +17,7 @@
|
||||||
"content": "Cool, let me check what is in my inventory !inventory\nI have 10 oak logs. What do you have?"
|
"content": "Cool, let me check what is in my inventory !inventory\nI have 10 oak logs. What do you have?"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"role": "assistant",
|
"role": "user",
|
||||||
"content": "Let me check !inventory \nI have 10 stones."
|
"content": "Let me check !inventory \nI have 10 stones."
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -25,13 +25,13 @@
|
||||||
"content": "Let me give you the stones and you can craft the pickaxe. !givePlayer(\"stone\", 10, \"playername\")"
|
"content": "Let me give you the stones and you can craft the pickaxe. !givePlayer(\"stone\", 10, \"playername\")"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"role": "assistant",
|
"role": "user",
|
||||||
"content": "Thanks for the stones! Now I can craft the pickaxe. !craftItem(\"stone_pickaxe\", 1)"
|
"content": "Thanks for the stones! Now I can craft the pickaxe. !craftItem(\"stone_pickaxe\", 1)"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"role": "assistant",
|
"role": "user",
|
||||||
"content": "Hey! let's collaborate to build shears!"
|
"content": "Hey! let's collaborate to build shears!"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -39,7 +39,7 @@
|
||||||
"content": "Cool, let me check what is in my inventory !inventory\nI have 1 iron ingot. What do you have?"
|
"content": "Cool, let me check what is in my inventory !inventory\nI have 1 iron ingot. What do you have?"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"role": "assistant",
|
"role": "user",
|
||||||
"content": "Let me check !inventory \nI have 1 iron ingot. "
|
"content": "Let me check !inventory \nI have 1 iron ingot. "
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -47,7 +47,7 @@
|
||||||
"content": "Nice let's check what we need to craft shears. !getCraftingPlan(\"shears\", 1)"
|
"content": "Nice let's check what we need to craft shears. !getCraftingPlan(\"shears\", 1)"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"role": "assistant",
|
"role": "user",
|
||||||
"content": "We need 2 iron ingots to craft the shears. Could you share your iron ingot with me?"
|
"content": "We need 2 iron ingots to craft the shears. Could you share your iron ingot with me?"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -55,10 +55,58 @@
|
||||||
"content": "Yes, here is my iron ingot !givePlayer(\"iron_ingot\", 1, \"playername\")"
|
"content": "Yes, here is my iron ingot !givePlayer(\"iron_ingot\", 1, \"playername\")"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"role": "assistant",
|
"role": "user",
|
||||||
"content": "Thanks for the iron ingot! Now I can craft the shears. !craftItem(\"shears\", 1)"
|
"content": "Thanks for the iron ingot! Now I can craft the shears. !craftItem(\"shears\", 1)"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"role": "user",
|
||||||
|
"content": "Hey! Let's collaborate to build a brush"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"role": "assistant",
|
||||||
|
"content": "Cool, let's check what we need for that !getCraftingPlan(\"brush\", 1)"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"role": "system",
|
||||||
|
"content": "CRAFTING_PLAN\n- 2 sticks\n- 2 feathers\n- 1 iron ingot"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"role": "assistant",
|
||||||
|
"content": "We need 2 sticks, 2 feathers, and 1 iron ingot to craft the brush. Do you have any of these items?"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"role": "user",
|
||||||
|
"content": "Let me check !inventory \nI have 2 sticks and 2 feathers."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"role": "assistant",
|
||||||
|
"content": "Great! I have 1 iron ingot. Let me give you my iron ingot and you can craft the brush. !givePlayer(\"iron_ingot\", 1, \"playername\")"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"role": "user",
|
||||||
|
"content": "Thanks for the iron ingot! Now I can craft the brush. !craftItem(\"brush\", 1)"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"role": "user",
|
||||||
|
"content": "Hey! Let's collaborate to build a brush"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"role": "assistant",
|
||||||
|
"content": "Cool, let's check what we need for that !getCraftingPlan(\"brush\", 1)"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"role": "system",
|
||||||
|
"content": "no such tool"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"role": "assistant",
|
||||||
|
"content": "I'm sorry, I don't have the crafting plan for a brush. Let me check my inventory to see if I have the items needed. !inventory Do you have access to the crafting plan?"
|
||||||
|
}
|
||||||
|
],
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"role": "user",
|
"role": "user",
|
||||||
|
@ -109,24 +157,6 @@
|
||||||
"content": "terrance: (FROM OTHER BOT)I can build the base, you can build the walls. !newAction(\"Build a 10x10 wall of a house at x:942, y:54, z:1355\")"
|
"content": "terrance: (FROM OTHER BOT)I can build the base, you can build the walls. !newAction(\"Build a 10x10 wall of a house at x:942, y:54, z:1355\")"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
[
|
|
||||||
{
|
|
||||||
"role": "system",
|
|
||||||
"content": "trade something with zorro_34"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"role": "assistant",
|
|
||||||
"content": "!startConversation(\"zorro_34\", \"Hey let's trade. What do you have?\")"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"role": "user",
|
|
||||||
"content": "zorro_34: (FROM OTHER BOT)Let's see... !inventory\nI have a wooden pickaxe, cobblestone, and cooked chicken"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"role": "assistant",
|
|
||||||
"content": "Okay, could I trade you a cobblestone for a cooked chicken?"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"role": "user",
|
"role": "user",
|
||||||
|
@ -141,26 +171,6 @@
|
||||||
"content": "rupert: (FROM OTHER BOT)Alright, I'll build the walls! !newAction('Build a 10x10 wall of a house at the same location')"
|
"content": "rupert: (FROM OTHER BOT)Alright, I'll build the walls! !newAction('Build a 10x10 wall of a house at the same location')"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
[
|
|
||||||
{
|
|
||||||
"role": "user",
|
|
||||||
"content": "gort: (FROM OTHER BOT)Let's do it, onward!"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"role": "assistant",
|
|
||||||
"content": "Alright, I'll start by getting some cobblestone. !collectBlocks('stone', 10)"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[
|
|
||||||
{
|
|
||||||
"role": "user",
|
|
||||||
"content": "derg: (FROM OTHER BOT)Thanks, see you later!"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"role": "assistant",
|
|
||||||
"content": "See you later. !endConversation(\"derg\")"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"role": "user",
|
"role": "user",
|
||||||
|
|
|
@ -130,7 +130,6 @@ export class Agent {
|
||||||
//wait for a bit so inventory is cleared
|
//wait for a bit so inventory is cleared
|
||||||
await new Promise((resolve) => setTimeout(resolve, 500));
|
await new Promise((resolve) => setTimeout(resolve, 500));
|
||||||
|
|
||||||
console.log(this.task && "agent_number" in this.task && this.task.agent_number > 1);
|
|
||||||
if (this.task && "agent_number" in this.task && this.task.agent_number > 1) {
|
if (this.task && "agent_number" in this.task && this.task.agent_number > 1) {
|
||||||
var initial_inventory = this.task.initial_inventory[this.name];
|
var initial_inventory = this.task.initial_inventory[this.name];
|
||||||
console.log("Initial inventory:", initial_inventory);
|
console.log("Initial inventory:", initial_inventory);
|
||||||
|
@ -218,11 +217,6 @@ export class Agent {
|
||||||
this._setupEventHandlers(save_data, init_message);
|
this._setupEventHandlers(save_data, init_message);
|
||||||
this.startEvents();
|
this.startEvents();
|
||||||
|
|
||||||
|
|
||||||
console.log("HERE IS THE LOGGED TASK")
|
|
||||||
|
|
||||||
console.log(this.task)
|
|
||||||
|
|
||||||
this.task.initBotTask();
|
this.task.initBotTask();
|
||||||
|
|
||||||
|
|
||||||
|
@ -301,7 +295,7 @@ export class Agent {
|
||||||
message: `You have restarted and this message is auto-generated. Continue the conversation with me.`,
|
message: `You have restarted and this message is auto-generated. Continue the conversation with me.`,
|
||||||
start: true
|
start: true
|
||||||
};
|
};
|
||||||
convoManager.recieveFromBot(this.last_sender, msg_package);
|
convoManager.receiveFromBot(this.last_sender, msg_package);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (init_message) {
|
else if (init_message) {
|
||||||
|
@ -346,9 +340,6 @@ export class Agent {
|
||||||
|
|
||||||
async handleMessage(source, message, max_responses=null) {
|
async handleMessage(source, message, max_responses=null) {
|
||||||
await this.checkTaskDone();
|
await this.checkTaskDone();
|
||||||
// if (this.task && this.validator && this.validator.validate()) {
|
|
||||||
// this.killBots();
|
|
||||||
// }
|
|
||||||
if (!source || !message) {
|
if (!source || !message) {
|
||||||
console.warn('Received empty message from', source);
|
console.warn('Received empty message from', source);
|
||||||
return false;
|
return false;
|
||||||
|
@ -646,22 +637,8 @@ export class Agent {
|
||||||
|
|
||||||
async update(delta) {
|
async update(delta) {
|
||||||
await this.bot.modes.update();
|
await this.bot.modes.update();
|
||||||
await this.self_prompter.update(delta);
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (this.task && this.taskTimeout) {
|
|
||||||
const elapsedTime = (Date.now() - this.taskStartTime) / 1000;
|
|
||||||
if (elapsedTime >= this.taskTimeout) {
|
|
||||||
console.log('Task timeout reached. Task unsuccessful.');
|
|
||||||
await this.cleanKill('Task unsuccessful: Timeout reached', 3);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.error("Caught an error while checking timeout reached",e);
|
|
||||||
}
|
|
||||||
this.self_prompter.update(delta);
|
this.self_prompter.update(delta);
|
||||||
await this.checkTaskDone();
|
await this.checkTaskDone();
|
||||||
|
|
||||||
// if (this.task.data) {
|
// if (this.task.data) {
|
||||||
// let res = this.task.isDone();
|
// let res = this.task.isDone();
|
||||||
// if (res) {
|
// if (res) {
|
||||||
|
|
|
@ -2,7 +2,7 @@ import * as world from '../library/world.js';
|
||||||
import * as mc from '../../utils/mcdata.js';
|
import * as mc from '../../utils/mcdata.js';
|
||||||
import { getCommandDocs } from './index.js';
|
import { getCommandDocs } from './index.js';
|
||||||
import convoManager from '../conversation.js';
|
import convoManager from '../conversation.js';
|
||||||
import { checkLevelBlueprint, checkBlueprint } from '../construction_tasks.js';
|
import { checkLevelBlueprint, checkBlueprint } from '../task_types/construction_tasks.js';
|
||||||
|
|
||||||
const pad = (str) => {
|
const pad = (str) => {
|
||||||
return '\n' + str + '\n';
|
return '\n' + str + '\n';
|
||||||
|
|
|
@ -19,10 +19,16 @@ export class ConstructionTaskValidator {
|
||||||
let total_blocks = result.mismatches.length + result.matches.length;
|
let total_blocks = result.mismatches.length + result.matches.length;
|
||||||
score = (result.matches.length / total_blocks) * 100;
|
score = (result.matches.length / total_blocks) * 100;
|
||||||
console.log(`Task is ${score}% complete`);
|
console.log(`Task is ${score}% complete`);
|
||||||
return valid;
|
return {
|
||||||
|
"valid": valid,
|
||||||
|
"score": score
|
||||||
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error validating task:', error);
|
console.error('Error validating task:', error);
|
||||||
return false;
|
return {
|
||||||
|
"valid": false,
|
||||||
|
"score": 0
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -71,7 +77,6 @@ export class Blueprint {
|
||||||
explain() {
|
explain() {
|
||||||
var explanation = "";
|
var explanation = "";
|
||||||
|
|
||||||
// todo: we need to limit this to be a certain amount of levels to not overload memory...
|
|
||||||
for (let item of this.data.levels) {
|
for (let item of this.data.levels) {
|
||||||
var coordinates = item.coordinates;
|
var coordinates = item.coordinates;
|
||||||
explanation += `Level ${item.level}: `;
|
explanation += `Level ${item.level}: `;
|
||||||
|
@ -907,11 +912,46 @@ export function proceduralGeneration(m = 20,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// uncomment to visualize blueprint output
|
||||||
|
// printMatrix(matrix)
|
||||||
|
|
||||||
return matrixToBlueprint(matrix, [148,-60,-170])
|
return matrixToBlueprint(matrix, [148,-60,-170])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* for cutesy output
|
||||||
|
* @param matrix
|
||||||
|
*/
|
||||||
|
function printMatrix(matrix) {
|
||||||
|
matrix.forEach((layer, layerIndex) => {
|
||||||
|
console.log(`Layer ${layerIndex}:`);
|
||||||
|
layer.forEach(row => {
|
||||||
|
console.log(
|
||||||
|
row.map(cell => {
|
||||||
|
switch (cell) {
|
||||||
|
case 'stone': return '█'; // Wall
|
||||||
|
case 'air': return '.'; // Open space
|
||||||
|
case 'dark_oak_door[half=upper, hinge=left]': return 'D';
|
||||||
|
case 'dark_oak_door[half=lower, hinge=left]': return 'D';
|
||||||
|
case 'oak_stairs[facing=north]': return 'S'; // Stairs
|
||||||
|
case 'oak_stairs[facing=east]': return 'S'; // Stairs
|
||||||
|
case 'oak_stairs[facing=south]': return 'S'; // Stairs
|
||||||
|
case 'oak_stairs[facing=west]': return 'S'; // Stairs
|
||||||
|
case 'glass': return 'W'
|
||||||
|
|
||||||
|
|
||||||
|
default: return '?'; // Unknown or unmarked space
|
||||||
|
}
|
||||||
|
}).join(' ')
|
||||||
|
);
|
||||||
|
});
|
||||||
|
console.log('---');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a 3D matrix into a Minecraft blueprint format
|
* Converts a 3D matrix into a Minecraft blueprint format
|
||||||
* @param {Array<Array<Array<string>>>} matrix - 3D matrix of block types
|
* @param {Array<Array<Array<string>>>} matrix - 3D matrix of block types
|
|
@ -326,6 +326,12 @@ export class CookingTaskInitiator {
|
||||||
['minecraft:honey_bottle', 1], // Non-stackable
|
['minecraft:honey_bottle', 1], // Non-stackable
|
||||||
['minecraft:glow_berries', 64],
|
['minecraft:glow_berries', 64],
|
||||||
['minecraft:bowl', 64],
|
['minecraft:bowl', 64],
|
||||||
|
['minecraft:golden_carrot', 64],
|
||||||
|
['minecraft:golden_apple', 64],
|
||||||
|
['minecraft:enchanted_golden_apple', 64],
|
||||||
|
['minecraft:cooked_mutton', 64],
|
||||||
|
['minecraft:cooked_salmon', 64],
|
||||||
|
['minecraft:cooked_cod', 64]
|
||||||
['minecraft:gold_ingot', 64],
|
['minecraft:gold_ingot', 64],
|
||||||
['minecraft:oak_planks', 64],
|
['minecraft:oak_planks', 64],
|
||||||
];
|
];
|
||||||
|
|
|
@ -2,8 +2,18 @@ import { readFileSync } from 'fs';
|
||||||
import { executeCommand } from './commands/index.js';
|
import { executeCommand } from './commands/index.js';
|
||||||
import { getPosition } from './library/world.js';
|
import { getPosition } from './library/world.js';
|
||||||
import settings from '../../settings.js';
|
import settings from '../../settings.js';
|
||||||
|
import { Vec3 } from 'vec3';
|
||||||
|
import { ConstructionTaskValidator, Blueprint } from './task_types/construction_tasks.js';
|
||||||
import { CookingTaskInitiator } from './task_types/cooking_tasks.js';
|
import { CookingTaskInitiator } from './task_types/cooking_tasks.js';
|
||||||
import { ConstructionTaskValidator, Blueprint } from './construction_tasks.js';
|
|
||||||
|
//todo: modify validator code to return an object with valid and score -> do more testing hahah
|
||||||
|
//todo: figure out how to log these things to the same place as bots/histories
|
||||||
|
// export class CraftTaskValidator {
|
||||||
|
// constructor(data, agent) {
|
||||||
|
// this.target = data.target;
|
||||||
|
// this.number_of_target = data.number_of_target;
|
||||||
|
// this.agent = agent;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validates the presence of required items in an agent's inventory
|
* Validates the presence of required items in an agent's inventory
|
||||||
|
@ -14,8 +24,9 @@ import { ConstructionTaskValidator, Blueprint } from './construction_tasks.js';
|
||||||
function checkItemPresence(data, agent) {
|
function checkItemPresence(data, agent) {
|
||||||
// Helper function to check if target is a dictionary with quantities
|
// Helper function to check if target is a dictionary with quantities
|
||||||
function isTargetDictionaryWithQuantities(target) {
|
function isTargetDictionaryWithQuantities(target) {
|
||||||
return typeof target === 'object' &&
|
return typeof target === 'object' &&
|
||||||
!Array.isArray(target) &&
|
!Array.isArray(target) &&
|
||||||
|
|
||||||
target !== null &&
|
target !== null &&
|
||||||
Object.values(target).every(value => typeof value === 'number');
|
Object.values(target).every(value => typeof value === 'number');
|
||||||
}
|
}
|
||||||
|
@ -62,10 +73,10 @@ function checkItemPresence(data, agent) {
|
||||||
try {
|
try {
|
||||||
// First normalize targets to always have a consistent format
|
// First normalize targets to always have a consistent format
|
||||||
const targets = normalizeTargets(data.target);
|
const targets = normalizeTargets(data.target);
|
||||||
|
|
||||||
// Determine the required quantities
|
// Determine the required quantities
|
||||||
const requiredQuantities = isTargetDictionaryWithQuantities(data.target)
|
const requiredQuantities = isTargetDictionaryWithQuantities(data.target)
|
||||||
? data.target
|
? data.target
|
||||||
: normalizeQuantities(targets, data.number_of_target);
|
: normalizeQuantities(targets, data.number_of_target);
|
||||||
|
|
||||||
// Count items in inventory
|
// Count items in inventory
|
||||||
|
@ -84,7 +95,6 @@ function checkItemPresence(data, agent) {
|
||||||
for (const [item, requiredCount] of Object.entries(requiredQuantities)) {
|
for (const [item, requiredCount] of Object.entries(requiredQuantities)) {
|
||||||
const itemName = item.toLowerCase();
|
const itemName = item.toLowerCase();
|
||||||
const currentCount = inventoryCount[itemName] || 0;
|
const currentCount = inventoryCount[itemName] || 0;
|
||||||
|
|
||||||
if (currentCount < requiredCount) {
|
if (currentCount < requiredCount) {
|
||||||
allTargetsMet = false;
|
allTargetsMet = false;
|
||||||
missingItems.push({
|
missingItems.push({
|
||||||
|
@ -111,6 +121,20 @@ function checkItemPresence(data, agent) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class CookingCraftingTaskValidator {
|
||||||
|
constructor(data, agent) {
|
||||||
|
this.data = data;
|
||||||
|
this.agent = agent;
|
||||||
|
}
|
||||||
|
validate() {
|
||||||
|
const result = checkItemPresence(this.data, this.agent);
|
||||||
|
return {
|
||||||
|
"valid": result.success,
|
||||||
|
"score": result.success ? 1 : 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export class Task {
|
export class Task {
|
||||||
constructor(agent, task_path, task_id) {
|
constructor(agent, task_path, task_id) {
|
||||||
this.agent = agent;
|
this.agent = agent;
|
||||||
|
@ -139,10 +163,8 @@ export class Task {
|
||||||
if (this.task_type === 'construction') {
|
if (this.task_type === 'construction') {
|
||||||
this.validator = new ConstructionTaskValidator(this.data, this.agent);
|
this.validator = new ConstructionTaskValidator(this.data, this.agent);
|
||||||
} else if (this.task_type === 'cooking' || this.task_type === 'techtree') {
|
} else if (this.task_type === 'cooking' || this.task_type === 'techtree') {
|
||||||
this.validator = () => {
|
this.validator = new CookingCraftingTaskValidator(this.data, this.agent);
|
||||||
const result = checkItemPresence(this.data, this.agent);
|
|
||||||
return result.success;
|
|
||||||
};
|
|
||||||
} else {
|
} else {
|
||||||
this.validator = null;
|
this.validator = null;
|
||||||
}
|
}
|
||||||
|
@ -157,7 +179,6 @@ export class Task {
|
||||||
this.blocked_actions.push('!endGoal');
|
this.blocked_actions.push('!endGoal');
|
||||||
if (this.conversation)
|
if (this.conversation)
|
||||||
this.blocked_actions.push('!endConversation');
|
this.blocked_actions.push('!endConversation');
|
||||||
console.log('Task loaded:', this.data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.name = this.agent.name;
|
this.name = this.agent.name;
|
||||||
|
@ -181,7 +202,7 @@ export class Task {
|
||||||
}
|
}
|
||||||
|
|
||||||
// If goal is an object, get the goal for this agent's count_id
|
// If goal is an object, get the goal for this agent's count_id
|
||||||
if (typeof this.data.goal === 'object') {
|
if (typeof this.data.goal === 'object' && this.data.goal !== null) {
|
||||||
const agentId = this.agent.count_id.toString();
|
const agentId = this.agent.count_id.toString();
|
||||||
return (this.data.goal[agentId] || '') + add_string;
|
return (this.data.goal[agentId] || '') + add_string;
|
||||||
}
|
}
|
||||||
|
@ -194,7 +215,6 @@ export class Task {
|
||||||
const tasksFile = readFileSync(task_path, 'utf8');
|
const tasksFile = readFileSync(task_path, 'utf8');
|
||||||
const tasks = JSON.parse(tasksFile);
|
const tasks = JSON.parse(tasksFile);
|
||||||
let task = tasks[task_id];
|
let task = tasks[task_id];
|
||||||
console.log('Loaded task:', task);
|
|
||||||
if (!task) {
|
if (!task) {
|
||||||
throw new Error(`Task ${task_id} not found`);
|
throw new Error(`Task ${task_id} not found`);
|
||||||
}
|
}
|
||||||
|
@ -210,29 +230,35 @@ export class Task {
|
||||||
}
|
}
|
||||||
|
|
||||||
isDone() {
|
isDone() {
|
||||||
if (this.validator && this.validator.validate()) //todo: error here
|
let res = null;
|
||||||
return {"message": 'Task successful', "code": 2};
|
if (this.validator)
|
||||||
|
res = this.validator.validate();
|
||||||
|
if (res && res.valid) {
|
||||||
|
return {"message": 'Task successful', "score": res.score};
|
||||||
|
}
|
||||||
let other_names = this.available_agents.filter(n => n !== this.name);
|
let other_names = this.available_agents.filter(n => n !== this.name);
|
||||||
const elapsedTime = (Date.now() - this.taskStartTime) / 1000;
|
const elapsedTime = (Date.now() - this.taskStartTime) / 1000;
|
||||||
|
|
||||||
if (elapsedTime >= 30 && this.available_agents.length !== this.data.agent_count) {
|
if (elapsedTime >= 30 && this.available_agents.length !== this.data.agent_count) {
|
||||||
console.log('No other agents found. Task unsuccessful.');
|
console.log('No other agents found. Task unsuccessful.');
|
||||||
return {"message": 'No other agents found', "code": 3};
|
return {"message": 'No other agents found', "score": 0};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.taskTimeout) {
|
if (this.taskTimeout) {
|
||||||
if (elapsedTime >= this.taskTimeout) {
|
if (elapsedTime >= this.taskTimeout) {
|
||||||
console.log('Task timeout reached. Task unsuccessful.');
|
console.log('Task timeout reached. Task unsuccessful.');
|
||||||
return {"message": 'Task timeout reached', "code": 4};
|
if (res) {
|
||||||
|
return {"message": 'Task timeout reached', "score": res.score};
|
||||||
|
} else {
|
||||||
|
return {"message": 'Task timeout reached', "score": 0};
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async initBotTask() {
|
||||||
|
|
||||||
initBotTask = async () => {
|
|
||||||
await this.agent.bot.chat(`/clear ${this.name}`);
|
await this.agent.bot.chat(`/clear ${this.name}`);
|
||||||
console.log(`Cleared ${this.name}'s inventory.`);
|
console.log(`Cleared ${this.name}'s inventory.`);
|
||||||
|
|
||||||
|
@ -241,13 +267,12 @@ export class Task {
|
||||||
|
|
||||||
if (this.data === null)
|
if (this.data === null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (this.task_type === 'cooking') {
|
if (this.task_type === 'cooking') {
|
||||||
this.initiator = new CookingTaskInitiator(this.data, this.agent);
|
this.initiator = new CookingTaskInitiator(this.data, this.agent);
|
||||||
} else {
|
} else {
|
||||||
this.initiator = null;
|
this.initiator = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.teleportBots();
|
await this.teleportBots();
|
||||||
|
|
||||||
//wait for a bit so bots are teleported
|
//wait for a bit so bots are teleported
|
||||||
|
@ -255,8 +280,8 @@ export class Task {
|
||||||
|
|
||||||
if (this.data.initial_inventory) {
|
if (this.data.initial_inventory) {
|
||||||
console.log("Setting inventory...");
|
console.log("Setting inventory...");
|
||||||
let initialInventory;
|
let initialInventory = {};
|
||||||
|
|
||||||
// Handle multi-agent inventory assignment
|
// Handle multi-agent inventory assignment
|
||||||
if (this.data.agent_count > 1) {
|
if (this.data.agent_count > 1) {
|
||||||
initialInventory = this.data.initial_inventory[this.agent.count_id.toString()] || {};
|
initialInventory = this.data.initial_inventory[this.agent.count_id.toString()] || {};
|
||||||
|
@ -337,7 +362,6 @@ export class Task {
|
||||||
console.log(`Teleporting ${this.name} to human ${human_player_name}`)
|
console.log(`Teleporting ${this.name} to human ${human_player_name}`)
|
||||||
bot.chat(`/tp ${this.name} ${human_player_name}`)
|
bot.chat(`/tp ${this.name} ${human_player_name}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
await new Promise((resolve) => setTimeout(resolve, 200));
|
await new Promise((resolve) => setTimeout(resolve, 200));
|
||||||
|
|
||||||
// now all bots are teleport on top of each other (which kinda looks ugly)
|
// now all bots are teleport on top of each other (which kinda looks ugly)
|
||||||
|
@ -368,17 +392,6 @@ export class Task {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.goal) {
|
|
||||||
console.log('Setting goal:', this.goal);
|
|
||||||
await executeCommand(this.agent, `!goal("${this.goal}")`);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.conversation && this.agent.count_id === 0) {
|
|
||||||
let other_name = this.available_agents.filter(n => n !== this.name)[0];
|
|
||||||
await executeCommand(this.agent, `!startConversation("${other_name}", "${this.conversation}")`);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (this.data.type === 'construction'){
|
if (this.data.type === 'construction'){
|
||||||
//Ensures construction is cleaned out first. -> relies on cheats which are turned off?
|
//Ensures construction is cleaned out first. -> relies on cheats which are turned off?
|
||||||
if (this.blueprint){
|
if (this.blueprint){
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
|
|
||||||
// Read and parse the JSON file
|
// Read and parse the JSON file
|
||||||
const tasks = JSON.parse(fs.readFileSync('./example_multiagent_construction_tasks.json'));
|
const tasks = JSON.parse(fs.readFileSync('./test_multiagent_construction_tasks.json'));
|
||||||
|
|
||||||
// Validate format and count variants
|
// Validate format and count variants
|
||||||
const counts = {};
|
const counts = {};
|
|
@ -1,5 +1,5 @@
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import {proceduralGeneration} from "../../src/agent/construction_tasks.js";
|
import {proceduralGeneration} from "../../src/agent/task_types/construction_tasks.js";
|
||||||
|
|
||||||
function createInitialInventory(blueprint, agents) {
|
function createInitialInventory(blueprint, agents) {
|
||||||
/*
|
/*
|
||||||
|
@ -20,7 +20,7 @@ function createInitialInventory(blueprint, agents) {
|
||||||
|
|
||||||
// Initialize inventories
|
// Initialize inventories
|
||||||
for (let i = 0; i < agents; i++) {
|
for (let i = 0; i < agents; i++) {
|
||||||
inventories[i] = {};
|
inventories[i] = {'diamond_pickaxe':1};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Count materials in blueprint
|
// Count materials in blueprint
|
||||||
|
@ -30,7 +30,9 @@ function createInitialInventory(blueprint, agents) {
|
||||||
if (block !== 'air') {
|
if (block !== 'air') {
|
||||||
// Check if material contains 'door' or 'ladder' and convert appropriately
|
// Check if material contains 'door' or 'ladder' and convert appropriately
|
||||||
let materialKey = block;
|
let materialKey = block;
|
||||||
if (block.includes('door')) {
|
if (block.includes('dark_oak_door')) {
|
||||||
|
materialKey = 'dark_oak_door';
|
||||||
|
} else if (block.includes('oak_door')) {
|
||||||
materialKey = 'oak_door';
|
materialKey = 'oak_door';
|
||||||
} else if (block.includes('ladder')) {
|
} else if (block.includes('ladder')) {
|
||||||
materialKey = 'ladder';
|
materialKey = 'ladder';
|
||||||
|
@ -47,9 +49,6 @@ function createInitialInventory(blueprint, agents) {
|
||||||
inventories[currentAgent][material] = count;
|
inventories[currentAgent][material] = count;
|
||||||
currentAgent = (currentAgent + 1) % agents;
|
currentAgent = (currentAgent + 1) % agents;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Todo: add tools to all agents (diamond pickaxe)
|
|
||||||
|
|
||||||
|
|
||||||
return inventories;
|
return inventories;
|
||||||
|
@ -61,9 +60,8 @@ function calculateSpaceNeeded(rooms) {
|
||||||
return baseSize + scaleFactor;
|
return baseSize + scaleFactor;
|
||||||
}
|
}
|
||||||
|
|
||||||
function generateConstructionTasks() {
|
function generateConstructionTasks(variants) {
|
||||||
const tasks = {};
|
const tasks = {};
|
||||||
const variants = 1
|
|
||||||
const materialLevels = 5;
|
const materialLevels = 5;
|
||||||
const roomCounts = [4, 6, 8];
|
const roomCounts = [4, 6, 8];
|
||||||
const windowStyles = [0, 1, 2];
|
const windowStyles = [0, 1, 2];
|
||||||
|
@ -102,7 +100,7 @@ function generateConstructionTasks() {
|
||||||
agent_count: 2,
|
agent_count: 2,
|
||||||
initial_inventory: createInitialInventory(blueprint, 2),
|
initial_inventory: createInitialInventory(blueprint, 2),
|
||||||
timeout: timeout+(300*r), // 5 minute per additional level of complexity
|
timeout: timeout+(300*r), // 5 minute per additional level of complexity
|
||||||
blueprint: blueprint, //todo: make a pointer?
|
blueprint: blueprint,
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -114,13 +112,13 @@ function generateConstructionTasks() {
|
||||||
return tasks;
|
return tasks;
|
||||||
}
|
}
|
||||||
|
|
||||||
const tasks = generateConstructionTasks();
|
const tasks = generateConstructionTasks(1);
|
||||||
// Clear existing file content
|
// Clear existing file content
|
||||||
fs.writeFileSync('./example_multiagent_construction_tasks.json', '');
|
fs.writeFileSync('./test_multiagent_construction_tasks.json', '');
|
||||||
// re-add
|
// re-add
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
'./example_multiagent_construction_tasks.json',
|
'./test_multiagent_construction_tasks.json',
|
||||||
JSON.stringify(tasks, null, 2)
|
JSON.stringify(tasks, null, 2)
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log("Generated tasks saved to example_multiagent_construction_tasks.json");
|
console.log("Generated tasks saved to test_multiagent_construction_tasks.json");
|
File diff suppressed because it is too large
Load diff
3831928
tasks/construction_tasks/train_multiagent_construction_tasks.json
Normal file
3831928
tasks/construction_tasks/train_multiagent_construction_tasks.json
Normal file
File diff suppressed because it is too large
Load diff
BIN
test/.DS_Store
vendored
BIN
test/.DS_Store
vendored
Binary file not shown.
|
@ -1,69 +0,0 @@
|
||||||
import mineflayer from 'mineflayer';
|
|
||||||
import { Vec3 } from 'vec3';
|
|
||||||
import { ConstructionTaskValidator, Blueprint, checkBlueprint, checkLevelBlueprint } from '../src/agent/tasks.js';
|
|
||||||
import { Agent } from '../src/agent/agent.js';
|
|
||||||
|
|
||||||
try {
|
|
||||||
const agent = new Agent("../andy.json",
|
|
||||||
false,
|
|
||||||
null,
|
|
||||||
0,
|
|
||||||
"../example_tasks.json",
|
|
||||||
"construction_house");
|
|
||||||
await new Promise((resolve) => setTimeout(resolve, 10000));
|
|
||||||
let result = await checkBlueprint(agent);
|
|
||||||
// console.log(result);
|
|
||||||
// const levelResult = await checkLevelBlueprint(agent, 0);
|
|
||||||
// console.log(levelResult);
|
|
||||||
} catch (error) {
|
|
||||||
console.error('An error occurred:', error);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// const validator = new ConstructionTaskValidator();
|
|
||||||
|
|
||||||
const blueprintData = {
|
|
||||||
"materials": {
|
|
||||||
"oak_planks": 20,
|
|
||||||
"oak_door": 1,
|
|
||||||
"stone": 26,
|
|
||||||
},
|
|
||||||
"levels": [
|
|
||||||
{
|
|
||||||
"level": 0,
|
|
||||||
"coordinates": [142, -60, -179],
|
|
||||||
"placement":
|
|
||||||
[
|
|
||||||
["stone", "stone", "oak_door", "stone", "stone"],
|
|
||||||
["stone", "air", "air", "air", "stone"],
|
|
||||||
["stone", "air", "air", "air", "stone"],
|
|
||||||
["stone", "stone", "stone", "stone", "stone"]
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"level": 1,
|
|
||||||
"coordinates": [142, -59, -179],
|
|
||||||
"placement":
|
|
||||||
[
|
|
||||||
["stone", "stone", "oak_door", "stone", "stone"],
|
|
||||||
["stone", "air", "air", "air", "stone"],
|
|
||||||
["stone", "air", "air", "air", "stone"],
|
|
||||||
["stone", "stone", "stone", "stone", "stone"]
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"level": 2,
|
|
||||||
"coordinates": [142, -58, -179],
|
|
||||||
"placement":
|
|
||||||
[
|
|
||||||
["oak_planks", "oak_planks", "oak_planks", "oak_planks", "oak_planks"],
|
|
||||||
["oak_planks", "oak_planks", "oak_planks", "oak_planks", "oak_planks"],
|
|
||||||
["oak_planks", "oak_planks", "oak_planks", "oak_planks", "oak_planks"],
|
|
||||||
["oak_planks", "oak_planks", "oak_planks", "oak_planks", "oak_planks"]
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
};
|
|
|
@ -1,22 +0,0 @@
|
||||||
import { Blueprint } from '../src/agent/tasks.js';
|
|
||||||
import { readFileSync } from 'fs';
|
|
||||||
|
|
||||||
//load file from example_tasks.json
|
|
||||||
const object = JSON.parse(readFileSync('example_tasks.json', 'utf8'));
|
|
||||||
console.log(object.construction_house.blueprint);
|
|
||||||
const blueprint = new Blueprint(object.construction_house.blueprint);
|
|
||||||
const placement = object.construction_house.blueprint.levels[0].placement;
|
|
||||||
console.log(placement);
|
|
||||||
var placement_string = "[\n";
|
|
||||||
for (let row of placement) {
|
|
||||||
placement_string += "[";
|
|
||||||
for (let i = 0; i < row.length - 1; i++) {
|
|
||||||
let item = row[i];
|
|
||||||
placement_string += `${item}, `;
|
|
||||||
}
|
|
||||||
let final_item = row[row.length - 1];
|
|
||||||
placement_string += `${final_item}],\n`;
|
|
||||||
}
|
|
||||||
placement_string += "]";
|
|
||||||
console.log(placement_string);
|
|
||||||
console.log(blueprint.explain());
|
|
|
@ -1,165 +0,0 @@
|
||||||
import mineflayer from "mineflayer";
|
|
||||||
|
|
||||||
const bot = mineflayer.createBot({
|
|
||||||
host: 'localhost', // Replace with your server IP or hostname
|
|
||||||
port: 55916, // Replace with your server port
|
|
||||||
username: 'andy', // Replace with your bot's username
|
|
||||||
// password: 'your_bot_password' // Only if the server has online-mode=true
|
|
||||||
});
|
|
||||||
|
|
||||||
bot.on('spawn', async () => {
|
|
||||||
// generate a blueprint
|
|
||||||
const blueprint = {
|
|
||||||
"levels": [
|
|
||||||
{
|
|
||||||
"level": 0,
|
|
||||||
"coordinates": [142, -60, -179],
|
|
||||||
"placement": [
|
|
||||||
["stone", "stone", "oak_door", "stone", "stone"],
|
|
||||||
["stone", "air", "air", "air", "stone"],
|
|
||||||
["stone", "air", "air", "air", "stone"],
|
|
||||||
["stone", "stone", "stone", "stone", "stone"]
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"level": 1,
|
|
||||||
"coordinates": [142, -59, -179],
|
|
||||||
"placement": [
|
|
||||||
["stone", "stone", "air", "stone", "stone"],
|
|
||||||
["stone", "air", "air", "air", "stone"],
|
|
||||||
["stone", "air", "air", "air", "stone"],
|
|
||||||
["stone", "stone", "stone", "stone", "stone"]
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"level": 2,
|
|
||||||
"coordinates": [142, -58, -179],
|
|
||||||
"placement": [
|
|
||||||
["stone", "stone", "stone", "stone", "stone"],
|
|
||||||
["stone", "stone", "stone", "stone", "stone"],
|
|
||||||
["stone", "stone", "stone", "stone", "stone"],
|
|
||||||
["stone", "stone", "stone", "stone", "stone"],
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
};
|
|
||||||
|
|
||||||
// have andy build the blueprint automatically
|
|
||||||
const result = autoBuild(blueprint);
|
|
||||||
// const result = clearHouse(blueprint)
|
|
||||||
const commands = result.commands;
|
|
||||||
const nearbyPosition = result.nearbyPosition;
|
|
||||||
for (const command of commands) {
|
|
||||||
bot.chat(command);
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(commands.slice(-10));
|
|
||||||
|
|
||||||
// Print out the location nearby the blueprint
|
|
||||||
console.log(`tp ${nearbyPosition.x} ${nearbyPosition.y} ${nearbyPosition.z}`)
|
|
||||||
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Takes in the blueprint, and then converts it into a set of /setblock commands for the bot to follow
|
|
||||||
* @Returns: An object containing the setblock commands as a list of strings, and a position nearby the blueprint but not in it
|
|
||||||
* @param blueprint
|
|
||||||
*/
|
|
||||||
export function autoBuild(blueprint) {
|
|
||||||
const commands = [];
|
|
||||||
|
|
||||||
let minX = Infinity, maxX = -Infinity;
|
|
||||||
let minY = Infinity, maxY = -Infinity;
|
|
||||||
let minZ = Infinity, maxZ = -Infinity;
|
|
||||||
|
|
||||||
for (const level of blueprint.levels) {
|
|
||||||
// console.log(level.level)
|
|
||||||
const baseX = level.coordinates[0];
|
|
||||||
const baseY = level.coordinates[1];
|
|
||||||
const baseZ = level.coordinates[2];
|
|
||||||
const placement = level.placement;
|
|
||||||
|
|
||||||
// Update bounds
|
|
||||||
minX = Math.min(minX, baseX);
|
|
||||||
maxX = Math.max(maxX, baseX + placement[0].length - 1);
|
|
||||||
minY = Math.min(minY, baseY);
|
|
||||||
maxY = Math.max(maxY, baseY);
|
|
||||||
minZ = Math.min(minZ, baseZ);
|
|
||||||
maxZ = Math.max(maxZ, baseZ + placement.length - 1);
|
|
||||||
|
|
||||||
// Loop through the 2D placement array
|
|
||||||
for (let z = 0; z < placement.length; z++) {
|
|
||||||
for (let x = 0; x < placement[z].length; x++) {
|
|
||||||
const blockType = placement[z][x];
|
|
||||||
if (blockType) {
|
|
||||||
const setblockCommand = `/setblock ${baseX + x} ${baseY} ${baseZ + z} ${blockType}`;
|
|
||||||
commands.push(setblockCommand);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calculate a position nearby the blueprint but not in it
|
|
||||||
const nearbyPosition = {
|
|
||||||
x: maxX + 5, // Move 5 blocks to the right
|
|
||||||
y: minY, // Stay on the lowest level of the blueprint
|
|
||||||
z: minZ // Stay aligned with the front of the blueprint
|
|
||||||
};
|
|
||||||
|
|
||||||
return { commands, nearbyPosition};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Takes in a blueprint, and returns a set of commands to clear up the space.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
export function autoDelete(blueprint) {
|
|
||||||
const commands = [];
|
|
||||||
|
|
||||||
let minX = Infinity, maxX = -Infinity;
|
|
||||||
let minY = Infinity, maxY = -Infinity;
|
|
||||||
let minZ = Infinity, maxZ = -Infinity;
|
|
||||||
|
|
||||||
for (const level of blueprint.levels) {
|
|
||||||
const baseX = level.coordinates[0];
|
|
||||||
const baseY = level.coordinates[1];
|
|
||||||
const baseZ = level.coordinates[2];
|
|
||||||
const placement = level.placement;
|
|
||||||
|
|
||||||
// Update bounds
|
|
||||||
minX = Math.min(minX, baseX);
|
|
||||||
maxX = Math.max(maxX, baseX + placement[0].length - 1);
|
|
||||||
minY = Math.min(minY, baseY);
|
|
||||||
maxY = Math.max(maxY, baseY);
|
|
||||||
minZ = Math.min(minZ, baseZ);
|
|
||||||
maxZ = Math.max(maxZ, baseZ + placement.length - 1);
|
|
||||||
|
|
||||||
// Loop through the 2D placement array
|
|
||||||
for (let z = 0; z < placement.length; z++) {
|
|
||||||
for (let x = 0; x < placement[z].length; x++) {
|
|
||||||
const blockType = placement[z][x];
|
|
||||||
if (blockType) {
|
|
||||||
const setblockCommand = `/setblock ${baseX + x} ${baseY} ${baseZ + z} air`;
|
|
||||||
commands.push(setblockCommand);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calculate a position nearby the blueprint but not in it
|
|
||||||
const nearbyPosition = {
|
|
||||||
x: maxX + 5, // Move 5 blocks to the right
|
|
||||||
y: minY, // Stay on the lowest level of the blueprint
|
|
||||||
z: minZ // Stay aligned with the front of the blueprint
|
|
||||||
};
|
|
||||||
|
|
||||||
return { commands, nearbyPosition };
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -1,147 +0,0 @@
|
||||||
import mineflayer from 'mineflayer';
|
|
||||||
import { Vec3 } from 'vec3';
|
|
||||||
import { ConstructionTaskValidator, Blueprint } from '../src/agent/tasks.js';
|
|
||||||
import { Agent } from '../src/agent/agent.js';
|
|
||||||
|
|
||||||
const bot = mineflayer.createBot({
|
|
||||||
host: 'localhost', // Replace with your server IP or hostname
|
|
||||||
port: 55916, // Replace with your server port
|
|
||||||
username: 'andy', // Replace with your bot's username
|
|
||||||
// password: 'your_bot_password' // Only if the server has online-mode=true
|
|
||||||
});
|
|
||||||
|
|
||||||
bot.on('spawn', async () => {
|
|
||||||
bot.chat("/setblock ~ ~ ~ stone");
|
|
||||||
console.log("Bot spawned. Starting blueprint check...");
|
|
||||||
await new Promise((resolve) => setTimeout(resolve, 5000));
|
|
||||||
const blockAtLocation = await bot.blockAt(new Vec3(142, -60, -179));
|
|
||||||
console.log(blockAtLocation);
|
|
||||||
const blueprint = new Blueprint(blueprintData);
|
|
||||||
console.log(blueprint.explain());
|
|
||||||
console.log(blueprint.explainLevel(0));
|
|
||||||
try {
|
|
||||||
const check_level = await blueprint.checkLevel(bot, 0);
|
|
||||||
console.log(check_level);
|
|
||||||
let check_blueprint = await blueprint.check(bot);
|
|
||||||
console.log(check_blueprint);
|
|
||||||
let level_diff = await blueprint.explainLevelDifference(bot, 0);
|
|
||||||
console.log(level_diff);
|
|
||||||
let blueprint_diff = await blueprint.explainBlueprintDifference(bot);
|
|
||||||
console.log(blueprint_diff);
|
|
||||||
} catch (err) {
|
|
||||||
console.error("Error checking blueprint:", err);
|
|
||||||
}
|
|
||||||
// console.log(blueprint.checkLevel(bot, 0));
|
|
||||||
// console.log(blueprint.check(bot));
|
|
||||||
// console.log(blueprint.explainBlueprintDifference(bot, blueprintData));
|
|
||||||
// console.log(blueprint.explainLevelDifference(bot, 0));
|
|
||||||
bot.quit();
|
|
||||||
});
|
|
||||||
|
|
||||||
async function checkBluepint(bot, blueprintData) {
|
|
||||||
const materials = blueprintData.materials;
|
|
||||||
const levels = blueprintData.levels;
|
|
||||||
const mismatches = [];
|
|
||||||
const matches = [];
|
|
||||||
|
|
||||||
for (let i = 0; i < levels.length; i++) {
|
|
||||||
const levelData = levels[i];
|
|
||||||
const result = await checkLevelBlueprint(bot, levelData);
|
|
||||||
mismatches.push(...result.mismatches);
|
|
||||||
matches.push(...result.matches);
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
"mismatches": mismatches,
|
|
||||||
"matches": matches
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
async function checkLevelBlueprint(bot, levelData) {
|
|
||||||
const startCoords = levelData.coordinates;
|
|
||||||
const placement = levelData.placement;
|
|
||||||
const mismatches = [];
|
|
||||||
const matches = [];
|
|
||||||
|
|
||||||
for (let zOffset = 0; zOffset < placement.length; zOffset++) {
|
|
||||||
const row = placement[zOffset];
|
|
||||||
for (let xOffset = 0; xOffset < row.length; xOffset++) {
|
|
||||||
const blockName = row[xOffset];
|
|
||||||
|
|
||||||
const x = startCoords[0] + xOffset;
|
|
||||||
const y = startCoords[1];
|
|
||||||
const z = startCoords[2] + zOffset;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const blockAtLocation = await bot.blockAt(new Vec3(x, y, z));
|
|
||||||
if (!blockAtLocation || blockAtLocation.name !== blockName) {
|
|
||||||
mismatches.push({
|
|
||||||
level: levelData.level,
|
|
||||||
coordinates: [x, y, z],
|
|
||||||
expected: blockName,
|
|
||||||
actual: blockAtLocation ? bot.registry.blocks[blockAtLocation.type].name : 'air' // Assuming air if no block
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
matches.push({
|
|
||||||
level: levelData.level,
|
|
||||||
coordinates: [x, y, z],
|
|
||||||
expected: blockName,
|
|
||||||
actual: blockAtLocation ? bot.registry.blocks[blockAtLocation.type].name : 'air' // Assuming air if no block
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
console.error(`Error getting block at (${x}, ${y}, ${z}):`, err);
|
|
||||||
return false; // Stop checking if there's an issue getting blocks
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
"mismatches": mismatches,
|
|
||||||
"matches": matches
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const blueprintData = {
|
|
||||||
"materials": {
|
|
||||||
"oak_planks": 20,
|
|
||||||
"oak_door": 1,
|
|
||||||
"stone": 26,
|
|
||||||
},
|
|
||||||
"levels": [
|
|
||||||
{
|
|
||||||
"level": 0,
|
|
||||||
"coordinates": [142, -60, -179],
|
|
||||||
"placement":
|
|
||||||
[
|
|
||||||
["stone", "stone", "oak_door", "stone", "stone"],
|
|
||||||
["stone", "air", "air", "air", "stone"],
|
|
||||||
["stone", "air", "air", "air", "stone"],
|
|
||||||
["stone", "stone", "stone", "stone", "stone"]
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"level": 1,
|
|
||||||
"coordinates": [142, -59, -179],
|
|
||||||
"placement":
|
|
||||||
[
|
|
||||||
["stone", "stone", "oak_door", "stone", "stone"],
|
|
||||||
["stone", "air", "air", "air", "stone"],
|
|
||||||
["stone", "air", "air", "air", "stone"],
|
|
||||||
["stone", "stone", "stone", "stone", "stone"]
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"level": 2,
|
|
||||||
"coordinates": [142, -58, -179],
|
|
||||||
"placement":
|
|
||||||
[
|
|
||||||
["oak_planks", "oak_planks", "oak_planks", "oak_planks", "oak_planks"],
|
|
||||||
["oak_planks", "oak_planks", "oak_planks", "oak_planks", "oak_planks"],
|
|
||||||
["oak_planks", "oak_planks", "oak_planks", "oak_planks", "oak_planks"],
|
|
||||||
["oak_planks", "oak_planks", "oak_planks", "oak_planks", "oak_planks"]
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,147 +0,0 @@
|
||||||
import mineflayer from 'mineflayer';
|
|
||||||
import { Vec3 } from 'vec3';
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async function checkBuildingBlueprint(bot, blueprint) {
|
|
||||||
/**
|
|
||||||
* Checks if a Minecraft building matches a given blueprint using Mineflayer.
|
|
||||||
*
|
|
||||||
* @param {mineflayer.Bot} bot - The Mineflayer bot instance.
|
|
||||||
* @param {object} blueprint - The blueprint object.
|
|
||||||
* @returns {Promise<boolean>} - True if the building matches, false otherwise.
|
|
||||||
*/
|
|
||||||
|
|
||||||
const mismatches = [];
|
|
||||||
|
|
||||||
for (const levelData of blueprint.levels) {
|
|
||||||
const levelNum = levelData.level;
|
|
||||||
const startCoords = levelData.coordinates;
|
|
||||||
const placement = levelData.placement;
|
|
||||||
|
|
||||||
for (let zOffset = 0; zOffset < placement.length; zOffset++) {
|
|
||||||
const row = placement[zOffset];
|
|
||||||
for (let xOffset = 0; xOffset < row.length; xOffset++) {
|
|
||||||
const blockName = row[xOffset];
|
|
||||||
const expectedBlockId = getBlockIdFromName(bot, blockName);
|
|
||||||
|
|
||||||
if (expectedBlockId === undefined) {
|
|
||||||
console.warn(`Warning: Unknown block name '${blockName}' in blueprint. Skipping.`);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const x = startCoords[0] + xOffset;
|
|
||||||
const y = startCoords[1] + levelNum;
|
|
||||||
const z = startCoords[2] + zOffset;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const blockAtLocation = await bot.blockAt(new Vec3(x, y, z));
|
|
||||||
if (!blockAtLocation || blockAtLocation.type !== expectedBlockId) {
|
|
||||||
mismatches.push({
|
|
||||||
level: levelNum,
|
|
||||||
coordinates: [x, y, z],
|
|
||||||
expected: blockName,
|
|
||||||
actual: blockAtLocation ? bot.registry.blocks[blockAtLocation.type].name : 'air' // Assuming air if no block
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
console.error(`Error getting block at (${x}, ${y}, ${z}):`, err);
|
|
||||||
return false; // Stop checking if there's an issue getting blocks
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mismatches.length > 0) {
|
|
||||||
console.log("Building does not match the blueprint. Found the following mismatches:");
|
|
||||||
mismatches.forEach(mismatch => {
|
|
||||||
console.log(` Level ${mismatch.level}, Coordinates ${mismatch.coordinates.join(', ')}: Expected '${mismatch.expected}', Found '${mismatch.actual}'`);
|
|
||||||
});
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
console.log("Building matches the blueprint!");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function getBlockIdFromName(bot, blockName) {
|
|
||||||
/**
|
|
||||||
* Gets the numerical block ID from a string block name using the bot's registry.
|
|
||||||
* @param {mineflayer.Bot} bot - The Mineflayer bot instance.
|
|
||||||
* @param {string} blockName - The name of the block (case-insensitive).
|
|
||||||
* @returns {number|undefined} - The block ID, or undefined if not found.
|
|
||||||
*/
|
|
||||||
const blockInfo = bot.registry.blocksByName[blockName.toLowerCase().replace(/ /g, '_')];
|
|
||||||
return blockInfo ? blockInfo.id : undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Example usage (replace with your bot login and server details)
|
|
||||||
const blueprintData = {
|
|
||||||
"materials": {
|
|
||||||
"plank": {
|
|
||||||
"id": "oak_plank",
|
|
||||||
"number": 20
|
|
||||||
},
|
|
||||||
"door": {
|
|
||||||
"id": "oak_door",
|
|
||||||
"number": 1
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"levels": [
|
|
||||||
{
|
|
||||||
"level": 0,
|
|
||||||
"coordinates": [142, -60, -179],
|
|
||||||
"placement":
|
|
||||||
[
|
|
||||||
["stone", "stone", "oak_door", "stone", "stone"],
|
|
||||||
["stone", "air", "air", "air", "stone"],
|
|
||||||
["stone", "air", "air", "air", "stone"],
|
|
||||||
["stone", "stone", "stone", "stone", "stone"]
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"level": 1,
|
|
||||||
"coordinates": [142, -59, -179],
|
|
||||||
"placement":
|
|
||||||
[
|
|
||||||
["stone", "stone", "air", "stone", "stone"],
|
|
||||||
["stone", "air", "air", "air", "stone"],
|
|
||||||
["stone", "air", "air", "air", "stone"],
|
|
||||||
["stone", "stone", "stone", "stone", "stone"]
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"level": 2,
|
|
||||||
"coordinates": [142, -58, -179],
|
|
||||||
"placement":
|
|
||||||
[
|
|
||||||
["oak_plank", "oak_plank", "oak_plank", "oak_plank", "oak_plank"],
|
|
||||||
["oak_plank", "oak_plank", "oak_plank", "oak_plank", "oak_plank"],
|
|
||||||
["oak_plank", "oak_plank", "oak_plank", "oak_plank", "oak_plank"],
|
|
||||||
["oak_plank", "oak_plank", "oak_plank", "oak_plank", "oak_plank"]
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
};
|
|
||||||
|
|
||||||
const bot = mineflayer.createBot({
|
|
||||||
host: 'localhost', // Replace with your server IP or hostname
|
|
||||||
port: 55916, // Replace with your server port
|
|
||||||
username: 'andy', // Replace with your bot's username
|
|
||||||
// password: 'your_bot_password' // Only if the server has online-mode=true
|
|
||||||
});
|
|
||||||
|
|
||||||
bot.on('spawn', async () => {
|
|
||||||
console.log("Bot spawned. Starting blueprint check...");
|
|
||||||
const matchesBlueprint = await checkBuildingBlueprint(bot, blueprintData);
|
|
||||||
console.log(`Blueprint check result: ${matchesBlueprint}`);
|
|
||||||
bot.quit(); // Disconnect the bot after checking
|
|
||||||
});
|
|
||||||
|
|
||||||
bot.on('kicked', (reason, loggedIn) => {
|
|
||||||
console.log(`Bot kicked: ${reason}, loggedIn: ${loggedIn}`);
|
|
||||||
});
|
|
||||||
|
|
||||||
bot.on('error', err => {
|
|
||||||
console.log(`Bot error: ${err}`);
|
|
||||||
});
|
|
|
@ -1,821 +0,0 @@
|
||||||
import {materials} from "mineflayer-armor-manager/dist/data/armor.js";
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param m - length (x-axis)
|
|
||||||
* @param n - width (y-axis)
|
|
||||||
* @param p - depth (z-axis, how many layers)
|
|
||||||
* @param rooms
|
|
||||||
* @returns {any[][][]}
|
|
||||||
*/
|
|
||||||
function generateAbstractRooms(m, n, p, rooms = 5) {
|
|
||||||
const matrix = Array.from({ length: p }, () =>
|
|
||||||
Array.from({ length: m }, () =>
|
|
||||||
Array(n).fill('air')
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Mark entire outer border with 'stone'
|
|
||||||
for (let z = 0; z < p; z++) {
|
|
||||||
for (let x = 0; x < m; x++) {
|
|
||||||
for (let y = 0; y < n; y++) {
|
|
||||||
if (
|
|
||||||
z === 0 || z === p - 1 || // Top and bottom faces
|
|
||||||
x === 0 || x === m - 1 || // Front and back faces
|
|
||||||
y === 0 || y === n - 1 // Left and right faces
|
|
||||||
) {
|
|
||||||
matrix[z][x][y] = 'stone';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const usedSpaces = new Set();
|
|
||||||
|
|
||||||
// Loop that places rooms
|
|
||||||
for (let roomCount = 0; roomCount < rooms; roomCount++) {
|
|
||||||
const length = Math.max(4, Math.floor(Math.random() * 6) + 4);
|
|
||||||
const width = Math.max(4, Math.floor(Math.random() * 6) + 4);
|
|
||||||
const depth = Math.max(3, Math.floor(Math.random() * 6) + 4);
|
|
||||||
|
|
||||||
let roomPlaced = false;
|
|
||||||
|
|
||||||
for (let attempt = 0; attempt < 50; attempt++) {
|
|
||||||
const x = Math.floor(Math.random() * (m - length - 1)) + 1;
|
|
||||||
const y = Math.floor(Math.random() * (n - width - 1)) + 1;
|
|
||||||
const z = Math.floor(Math.random() * (p - depth - 1)) + 1;
|
|
||||||
|
|
||||||
// Check space availability, excluding room's own edges (so that walls/ceilings can be shared)
|
|
||||||
console.log(`Attempting room: ${length}x${width}x${depth}`);
|
|
||||||
|
|
||||||
const spaceAvailable = !Array.from({ length: depth }).some((_, di) =>
|
|
||||||
Array.from({ length: length }).some((_, dj) =>
|
|
||||||
Array.from({ length: width }).some((_, dk) =>
|
|
||||||
// Exclude room's own edges from check
|
|
||||||
(di !== 0 && di !== depth - 1 &&
|
|
||||||
dj !== 0 && dj !== length - 1 &&
|
|
||||||
dk !== 0 && dk !== width - 1) &&
|
|
||||||
usedSpaces.has(`${x + dj},${y + dk},${z + di}`)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (spaceAvailable) {
|
|
||||||
for (let di = 0; di < depth; di++) {
|
|
||||||
for (let dj = 0; dj < length; dj++) {
|
|
||||||
for (let dk = 0; dk < width; dk++) {
|
|
||||||
const spaceKey = `${x + dj},${y + dk},${z + di}`;
|
|
||||||
usedSpaces.add(spaceKey);
|
|
||||||
|
|
||||||
if (
|
|
||||||
z + di >= 0 && z + di < p &&
|
|
||||||
x + dj >= 0 && x + dj < m &&
|
|
||||||
y + dk >= 0 && y + dk < n
|
|
||||||
) {
|
|
||||||
// Mark only the outer edges of the room
|
|
||||||
if (di === 0 || di === depth - 1 ||
|
|
||||||
dj === 0 || dj === length - 1 ||
|
|
||||||
dk === 0 || dk === width - 1) {
|
|
||||||
matrix[z + di][x + dj][y + dk] = 'stone';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
roomPlaced = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!roomPlaced) {
|
|
||||||
console.warn(`Could not place room ${roomCount}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
blueprint = matrixToBlueprint(matrix, [200, -60, -100])
|
|
||||||
|
|
||||||
return blueprint;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Systematically builds the houses by placing them next to the already existing rooms. Still uses randomness for what gets placed next.
|
|
||||||
* @param m width of the 3D space
|
|
||||||
* @param n height of the 3D space
|
|
||||||
* @param p depth of the 3D space
|
|
||||||
* @param rooms Number of rooms to attempt to generate
|
|
||||||
* @param minRoomWidth
|
|
||||||
* @param minRoomLength
|
|
||||||
* @param minRoomDepth
|
|
||||||
* @param roomVariance How much the room size will vary
|
|
||||||
* @param wrapping material of wrapping (air, glass, etc...) -> default is air
|
|
||||||
* @param carpetStyle 0,1,2 increasingly more complex
|
|
||||||
* @param windowStyle 0,1,2 increasingly more complex
|
|
||||||
* @param complexity 0,1,2,3,4 for increasingly complex materials for room generation
|
|
||||||
* @returns a Blueprint object
|
|
||||||
*/
|
|
||||||
// todo: room material params, roof style
|
|
||||||
function proceduralGeneration(m = 20,
|
|
||||||
n = 20,
|
|
||||||
p = 20,
|
|
||||||
rooms = 8,
|
|
||||||
minRoomWidth = 5,
|
|
||||||
minRoomLength = 5,
|
|
||||||
minRoomDepth = 6,
|
|
||||||
roomVariance = 5,
|
|
||||||
wrapping = "air",
|
|
||||||
carpetStyle = 1,
|
|
||||||
windowStyle = 2,
|
|
||||||
complexity = 4) {
|
|
||||||
// Build 3D space
|
|
||||||
const matrix = Array.from({length: p}, () =>
|
|
||||||
Array.from({length: m}, () =>
|
|
||||||
Array(n).fill('air')
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
// set materials
|
|
||||||
let roomMaterials = ["stone", "terracotta", "quartz_block", "copper_block", "purpur_block"]
|
|
||||||
|
|
||||||
if (complexity < roomMaterials.length){
|
|
||||||
roomMaterials = roomMaterials.slice(0, complexity + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mark entire outer border with 'stone'
|
|
||||||
for (let z = 0; z < p; z++) {
|
|
||||||
for (let x = 0; x < m; x++) {
|
|
||||||
for (let y = 0; y < n; y++) {
|
|
||||||
if (
|
|
||||||
z === 0 || z === p - 1 || // Top and bottom faces
|
|
||||||
x === 0 || x === m - 1 || // Front and back faces
|
|
||||||
y === 0 || y === n - 1 // Left and right faces
|
|
||||||
) {
|
|
||||||
matrix[z][x][y] = 'stone';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Replace outer layer with wrap
|
|
||||||
for (let z = 0; z < p; z++) {
|
|
||||||
for (let x = 0; x < m; x++) {
|
|
||||||
for (let y = 0; y < n; y++) {
|
|
||||||
if (
|
|
||||||
(z === p - 1 || // Top face
|
|
||||||
x === 0 || x === m - 1 || // Front and back faces
|
|
||||||
y === 0 || y === n - 1) // Left and right faces
|
|
||||||
) {
|
|
||||||
matrix[z][x][y] = wrapping;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let placedRooms = 0;
|
|
||||||
let lastRoom = null;
|
|
||||||
|
|
||||||
// Direction probabilities (e.g., 'above': 40%, 'left': 15%, etc.)
|
|
||||||
const directionChances = [
|
|
||||||
{direction: 'above', chance: 0.15},
|
|
||||||
{direction: 'left', chance: 0.15},
|
|
||||||
{direction: 'right', chance: 0.15},
|
|
||||||
{direction: 'forward', chance: 0.15},
|
|
||||||
{direction: 'backward', chance: 0.15},
|
|
||||||
];
|
|
||||||
|
|
||||||
// Function to pick a random direction based on percentages
|
|
||||||
function getRandomDirection() {
|
|
||||||
const rand = Math.random();
|
|
||||||
let cumulative = 0;
|
|
||||||
|
|
||||||
for (const {direction, chance} of directionChances) {
|
|
||||||
cumulative += chance;
|
|
||||||
if (rand <= cumulative) return direction;
|
|
||||||
}
|
|
||||||
return directionChances[1].direction; // Fallback to the first direction
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ensures no rooms overlap except at edges
|
|
||||||
function isSpaceValid(newX, newY, newZ, newLength, newWidth, newDepth) {
|
|
||||||
for (let di = 0; di < newDepth; di++) {
|
|
||||||
for (let dj = 0; dj < newLength; dj++) {
|
|
||||||
for (let dk = 0; dk < newWidth; dk++) {
|
|
||||||
const x = newX + dj;
|
|
||||||
const y = newY + dk;
|
|
||||||
const z = newZ + di;
|
|
||||||
|
|
||||||
// Skip checking the outermost borders of the new room (these can overlap with stone)
|
|
||||||
if (dj === 0 || dj === newLength - 1 ||
|
|
||||||
dk === 0 || dk === newWidth - 1 ||
|
|
||||||
di === 0 || di === newDepth - 1) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// For non-border spaces, ensure they're air
|
|
||||||
if (matrix[z][x][y] !== 'air') {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function validateAndBuildBorder(matrix, newX, newY, newZ, newLength, newWidth, newDepth, m, n, p, material) {
|
|
||||||
// Allow rooms to use the matrix edges (note the <= instead of <)
|
|
||||||
if (
|
|
||||||
newX >= 0 && newX + newLength <= m &&
|
|
||||||
newY >= 0 && newY + newWidth <= n &&
|
|
||||||
newZ >= 0 && newZ + newDepth <= p &&
|
|
||||||
isSpaceValid(newX, newY, newZ, newLength, newWidth, newDepth)
|
|
||||||
) {
|
|
||||||
console.log(`Placing room at (${newX}, ${newY}, ${newZ}) with dimensions (${newLength}x${newWidth}x${newDepth})`);
|
|
||||||
for (let di = 0; di < newDepth; di++) {
|
|
||||||
for (let dj = 0; dj < newLength; dj++) {
|
|
||||||
for (let dk = 0; dk < newWidth; dk++) {
|
|
||||||
const x = newX + dj;
|
|
||||||
const y = newY + dk;
|
|
||||||
const z = newZ + di;
|
|
||||||
|
|
||||||
// If this is at a matrix border, don't modify it
|
|
||||||
if (z === 0){
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// if (x === 0 || x === m - 1 ||
|
|
||||||
// y === 0 || y === n - 1 ||
|
|
||||||
// z === 0 || z === p - 1) {
|
|
||||||
// continue;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// For non-border spaces, check if this is a floor that should be shared
|
|
||||||
//was: === 'stone'
|
|
||||||
if (di === 0 && matrix[z-1][x][y] !== 'air') {
|
|
||||||
// Skip creating floor if there's a ceiling below
|
|
||||||
matrix[z][x][y] = 'air';
|
|
||||||
} else if (di === 0 || di === newDepth - 1 ||
|
|
||||||
dj === 0 || dj === newLength - 1 ||
|
|
||||||
dk === 0 || dk === newWidth - 1) {
|
|
||||||
matrix[z][x][y] = material;
|
|
||||||
} else {
|
|
||||||
matrix[z][x][y] = 'air';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
function addDoor(matrix, x, y, z, material) {
|
|
||||||
matrix[z][x][y] = material;
|
|
||||||
|
|
||||||
// Place the lower half of the door
|
|
||||||
matrix[z + 1][x][y] = 'dark_oak_door[half=lower, hinge=left]';
|
|
||||||
|
|
||||||
// Place the upper half of the door
|
|
||||||
matrix[z + 2][x][y] = 'dark_oak_door[half=upper, hinge=left]';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Takes in a room and randomly converts some faces to be windows
|
|
||||||
function addWindowsAsSquares(matrix, x, y, z, newLength, newWidth, newDepth, material) {
|
|
||||||
// Matrix dimensions
|
|
||||||
const matrixDepth = matrix.length;
|
|
||||||
const matrixLength = matrix[0].length;
|
|
||||||
const matrixWidth = matrix[0][0].length;
|
|
||||||
const windowX = Math.ceil(minRoomWidth/2)
|
|
||||||
const windowY = Math.ceil(minRoomLength/2)
|
|
||||||
const windowZ = Math.ceil(minRoomDepth/2)
|
|
||||||
|
|
||||||
// Helper function to check if coordinates are within bounds
|
|
||||||
function isInBounds(z, x, y) {
|
|
||||||
return z >= 0 && z < matrixDepth &&
|
|
||||||
x >= 0 && x < matrixLength &&
|
|
||||||
y >= 0 && y < matrixWidth;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Front and back faces (z is constant)
|
|
||||||
if (Math.random() < 0.8) {
|
|
||||||
let centerX = x + Math.floor(newLength / 2 - windowX/2);
|
|
||||||
let centerY = y + Math.floor(newWidth / 2 - windowY/2);
|
|
||||||
|
|
||||||
for (let dx = 0; dx <= windowX; dx++) {
|
|
||||||
for (let dy = 0; dy <= windowY; dy++) {
|
|
||||||
let frontZ = z;
|
|
||||||
let backZ = z + newDepth - 1;
|
|
||||||
|
|
||||||
if (isInBounds(frontZ, centerX + dx, centerY + dy) &&
|
|
||||||
matrix[frontZ][centerX + dx][centerY + dy] === material) {
|
|
||||||
matrix[frontZ][centerX + dx][centerY + dy] = 'glass';
|
|
||||||
}
|
|
||||||
if (isInBounds(backZ, centerX + dx, centerY + dy) &&
|
|
||||||
matrix[backZ][centerX + dx][centerY + dy] === material) {
|
|
||||||
matrix[backZ][centerX + dx][centerY + dy] = 'glass';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Left and right faces (x is constant)
|
|
||||||
if (Math.random() < 0.8) {
|
|
||||||
let centerZ = z + Math.floor(newDepth / 2 - windowZ/2);
|
|
||||||
let centerY = y + Math.floor(newWidth / 2 - windowY/2);
|
|
||||||
|
|
||||||
for (let dz = 0; dz <= windowZ; dz++) {
|
|
||||||
for (let dy = 0; dy <= windowY; dy++) {
|
|
||||||
let leftX = x;
|
|
||||||
let rightX = x + newLength - 1;
|
|
||||||
|
|
||||||
if (isInBounds(centerZ + dz, leftX, centerY + dy) &&
|
|
||||||
matrix[centerZ + dz][leftX][centerY + dy] === material) {
|
|
||||||
matrix[centerZ + dz][leftX][centerY + dy] = 'glass';
|
|
||||||
}
|
|
||||||
if (isInBounds(centerZ + dz, rightX, centerY + dy) &&
|
|
||||||
matrix[centerZ + dz][rightX][centerY + dy] === material) {
|
|
||||||
matrix[centerZ + dz][rightX][centerY + dy] = 'glass';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Top and bottom faces (y is constant)
|
|
||||||
if (Math.random() < 0.8) {
|
|
||||||
let centerX = x + Math.floor(newLength / 2 - windowX/2);
|
|
||||||
let centerZ = z + Math.floor(newDepth / 2 - windowZ / 2);
|
|
||||||
|
|
||||||
for (let dx = 0; dx <= windowX; dx++) {
|
|
||||||
for (let dz = 0; dz <= windowZ; dz++) {
|
|
||||||
let bottomY = y;
|
|
||||||
let topY = y + newWidth - 1;
|
|
||||||
|
|
||||||
if (isInBounds(centerZ + dz, centerX + dx, bottomY) &&
|
|
||||||
matrix[centerZ + dz][centerX + dx][bottomY] === material) {
|
|
||||||
matrix[centerZ + dz][centerX + dx][bottomY] = 'glass';
|
|
||||||
}
|
|
||||||
if (isInBounds(centerZ + dz, centerX + dx, topY) &&
|
|
||||||
matrix[centerZ + dz][centerX + dx][topY] === material) {
|
|
||||||
matrix[centerZ + dz][centerX + dx][topY] = 'glass';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function addWindowsAsPlane(matrix, x, y, z, newLength, newWidth, newDepth, material) {
|
|
||||||
// Ensure the new dimensions are within bounds
|
|
||||||
const maxX = matrix[0].length;
|
|
||||||
const maxY = matrix[0][0].length;
|
|
||||||
const maxZ = matrix.length;
|
|
||||||
|
|
||||||
// Each face has a 30% chance of becoming a window
|
|
||||||
if (Math.random() < 0.8) {
|
|
||||||
for (let dx = 0; dx < newLength; dx++) {
|
|
||||||
for (let dy = 0; dy < newWidth; dy++) {
|
|
||||||
let frontZ = z;
|
|
||||||
let backZ = z + newDepth - 1;
|
|
||||||
|
|
||||||
// Check bounds before modifying the matrix
|
|
||||||
if (frontZ >= 0 && frontZ < maxZ && x + dx >= 0 && x + dx < maxX && y + dy >= 0 && y + dy < maxY) {
|
|
||||||
if (matrix[frontZ][x + dx][y + dy] === material) {
|
|
||||||
matrix[frontZ][x + dx][y + dy] = 'glass';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (backZ >= 0 && backZ < maxZ && x + dx >= 0 && x + dx < maxX && y + dy >= 0 && y + dy < maxY) {
|
|
||||||
if (matrix[backZ][x + dx][y + dy] === material) {
|
|
||||||
matrix[backZ][x + dx][y + dy] = 'glass';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Math.random() < 0.8) {
|
|
||||||
for (let dz = 0; dz < newDepth; dz++) {
|
|
||||||
for (let dy = 0; dy < newWidth; dy++) {
|
|
||||||
let leftX = x;
|
|
||||||
let rightX = x + newLength - 1;
|
|
||||||
|
|
||||||
// Check bounds before modifying the matrix
|
|
||||||
if (leftX >= 0 && leftX < maxX && z + dz >= 0 && z + dz < maxZ && y + dy >= 0 && y + dy < maxY) {
|
|
||||||
if (matrix[z + dz][leftX][y + dy] === material) {
|
|
||||||
matrix[z + dz][leftX][y + dy] = 'glass';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (rightX >= 0 && rightX < maxX && z + dz >= 0 && z + dz < maxZ && y + dy >= 0 && y + dy < maxY) {
|
|
||||||
if (matrix[z + dz][rightX][y + dy] === material) {
|
|
||||||
matrix[z + dz][rightX][y + dy] = 'glass';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// out of commission
|
|
||||||
function addStairs(matrix, x, y, z, direction) {
|
|
||||||
let dz = 0; // Change in Z direction
|
|
||||||
let dx = 0; // Change in X direction
|
|
||||||
let facing = '';
|
|
||||||
|
|
||||||
// Determine direction and facing
|
|
||||||
switch (direction) {
|
|
||||||
case 'north':
|
|
||||||
dz = -1;
|
|
||||||
facing = 'oak_stairs[facing=north]';
|
|
||||||
break;
|
|
||||||
case 'south':
|
|
||||||
dz = 1;
|
|
||||||
facing = 'oak_stairs[facing=south]';
|
|
||||||
break;
|
|
||||||
case 'east':
|
|
||||||
dx = 1;
|
|
||||||
facing = 'oak_stairs[facing=east]';
|
|
||||||
break;
|
|
||||||
case 'west':
|
|
||||||
dx = -1;
|
|
||||||
facing = 'oak_stairs[facing=west]';
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
console.error('Invalid stair direction');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Bore stair pattern downwards until we hit a floor or the matrix edge
|
|
||||||
let currentZ = z;
|
|
||||||
while (currentZ > 0 && matrix[currentZ - 1][x][y] === 'air') {
|
|
||||||
// Place stone as foundation
|
|
||||||
matrix[currentZ - 1][x][y] = 'stone';
|
|
||||||
|
|
||||||
// Place stair above the stone
|
|
||||||
matrix[currentZ][x][y] = facing;
|
|
||||||
|
|
||||||
// Move down diagonally
|
|
||||||
x += dx;
|
|
||||||
y += dz;
|
|
||||||
currentZ--;
|
|
||||||
|
|
||||||
// Check if we've hit the edge
|
|
||||||
if (x < 0 || x >= matrix[0].length || y < 0 || y >= matrix[0][0].length) break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function addCarpet(probability, matrix, newX, newY, newZ, newLength, newWidth, material) {
|
|
||||||
let colors = ["blue", "cyan", "light_blue", "lime"];
|
|
||||||
|
|
||||||
// Iterate through the dimensions of the room
|
|
||||||
for (let dx = 1; dx < newLength-1; dx++) {
|
|
||||||
for (let dy = 1; dy < newWidth-1; dy++) {
|
|
||||||
let x = newX + dx;
|
|
||||||
let y = newY + dy;
|
|
||||||
let z = newZ; // Start at floor level
|
|
||||||
|
|
||||||
// Check if there is floor (not air)
|
|
||||||
if (matrix[z][x][y] === material) {
|
|
||||||
// Consider a random probability of adding a carpet
|
|
||||||
if (Math.random() < probability) {
|
|
||||||
// Choose a random color for the carpet
|
|
||||||
let randomColor = colors[Math.floor(Math.random() * colors.length)];
|
|
||||||
// Add carpet one z position above the floor with a random color
|
|
||||||
matrix[z + 1][x][y] = `${randomColor}_carpet`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function addLadder(matrix, x, y, z) {
|
|
||||||
let currentZ = z+1;
|
|
||||||
|
|
||||||
// turn the floor into air where person would go up
|
|
||||||
matrix[currentZ][x+1][y] = 'air';
|
|
||||||
|
|
||||||
// Build the first 3 ladder segments from floor level downwards
|
|
||||||
for (let i = 0; i < 3; i++) {
|
|
||||||
matrix[currentZ][x][y] = 'ladder[facing=north]';
|
|
||||||
currentZ-=1
|
|
||||||
}
|
|
||||||
|
|
||||||
// Continue building ladder downwards until a floor is hit or we reach the bottom
|
|
||||||
while (currentZ >= 0 && matrix[currentZ][x][y] === 'air') {
|
|
||||||
// Place ladder
|
|
||||||
matrix[currentZ][x][y] = 'ladder[facing=north]';
|
|
||||||
|
|
||||||
// Move down
|
|
||||||
currentZ--;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function embellishments(carpet, windowStyle, matrix, newX, newY, newZ, newLength, newWidth, newDepth, material){
|
|
||||||
|
|
||||||
|
|
||||||
switch (windowStyle) {
|
|
||||||
case 0:
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
addWindowsAsSquares(matrix, newZ, newY, newZ, newLength, newWidth, newDepth, material)
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
addWindowsAsPlane(matrix, newZ, newY, newZ, newLength, newWidth, newDepth, material)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
switch (carpet) {
|
|
||||||
case 0:
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
addCarpet(0.3,matrix,newX, newY, newZ, newLength, newWidth, material);
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
addCarpet(0.7,matrix,newX, newY, newZ, newLength, newWidth, material)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Places rooms until we can't, or we place all
|
|
||||||
// attempts random configurations of rooms in random directions.
|
|
||||||
while (placedRooms < rooms) {
|
|
||||||
let roomPlaced = false;
|
|
||||||
|
|
||||||
for (let attempt = 0; attempt < 150; attempt++) {
|
|
||||||
|
|
||||||
const material = roomMaterials[Math.floor(Math.random() * roomMaterials.length)];
|
|
||||||
|
|
||||||
|
|
||||||
// dimensions of room
|
|
||||||
const newLength = Math.max(minRoomLength, Math.floor(Math.random() * roomVariance) + minRoomLength);
|
|
||||||
const newWidth = Math.max(minRoomWidth, Math.floor(Math.random() * roomVariance) + minRoomWidth);
|
|
||||||
const newDepth = Math.max(minRoomDepth, Math.floor(Math.random() * Math.floor(roomVariance/2) ) + minRoomDepth );
|
|
||||||
let newX, newY, newZ;
|
|
||||||
|
|
||||||
// first room is special
|
|
||||||
if (placedRooms === 0) {
|
|
||||||
// First room placement
|
|
||||||
newX = Math.floor(Math.random() * (m - newLength - 1)) + 1;
|
|
||||||
newY = Math.floor(Math.random() * (n - newWidth - 1)) + 1;
|
|
||||||
newZ = 0; // Ground floor
|
|
||||||
|
|
||||||
if (validateAndBuildBorder(matrix, newX, newY, newZ, newLength, newWidth, newDepth, m, n, p, material)) {
|
|
||||||
lastRoom = { x: newX, y: newY, z: newZ, length: newLength, width: newWidth, depth: newDepth };
|
|
||||||
roomPlaced = true;
|
|
||||||
placedRooms++;
|
|
||||||
|
|
||||||
// Add doors to all four sides
|
|
||||||
// Left side
|
|
||||||
addDoor(matrix, newX, newY + Math.floor(newWidth / 2), newZ, material);
|
|
||||||
// Right side
|
|
||||||
addDoor(matrix, newX + newLength - 1, newY + Math.floor(newWidth / 2), newZ, material);
|
|
||||||
// Front side
|
|
||||||
addDoor(matrix, newX + Math.floor(newLength / 2), newY, newZ, material);
|
|
||||||
// Back side
|
|
||||||
addDoor(matrix, newX + Math.floor(newLength / 2), newY + newWidth - 1, newZ, material);
|
|
||||||
|
|
||||||
addCarpet(0.7, matrix, newX, newY, newZ, newLength, newWidth)
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
const direction = getRandomDirection();
|
|
||||||
|
|
||||||
switch (direction) {
|
|
||||||
case 'above':
|
|
||||||
newX = lastRoom.x;
|
|
||||||
newY = lastRoom.y;
|
|
||||||
newZ = lastRoom.z + lastRoom.depth - 1;
|
|
||||||
if (validateAndBuildBorder(matrix, newX, newY, newZ, newLength, newWidth, newDepth, m, n, p, material)) {
|
|
||||||
|
|
||||||
embellishments(carpetStyle, windowStyle, matrix, newX, newY, newZ, newLength, newWidth, newDepth, material)
|
|
||||||
|
|
||||||
addLadder(matrix, lastRoom.x + Math.floor(lastRoom.length / 2),
|
|
||||||
lastRoom.y + Math.floor(lastRoom.width / 2),
|
|
||||||
newZ); // Adding the ladder
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
lastRoom = { x: newX, y: newY, z: newZ, length: newLength, width: newWidth, depth: newDepth };
|
|
||||||
roomPlaced = true;
|
|
||||||
placedRooms++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'left':
|
|
||||||
newX = lastRoom.x - newLength + 1;
|
|
||||||
newY = lastRoom.y;
|
|
||||||
newZ = lastRoom.z;
|
|
||||||
if (validateAndBuildBorder(matrix, newX, newY, newZ, newLength, newWidth, newDepth, m, n, p, material)) {
|
|
||||||
|
|
||||||
|
|
||||||
embellishments(carpetStyle, windowStyle, matrix, newX, newY, newZ, newLength, newWidth, newDepth, material)
|
|
||||||
|
|
||||||
|
|
||||||
addDoor(matrix, lastRoom.x, lastRoom.y + Math.floor(lastRoom.width / 2), lastRoom.z, material);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
lastRoom = { x: newX, y: newY, z: newZ, length: newLength, width: newWidth, depth: newDepth };
|
|
||||||
roomPlaced = true;
|
|
||||||
placedRooms++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'right':
|
|
||||||
newX = lastRoom.x + lastRoom.length - 1;
|
|
||||||
newY = lastRoom.y;
|
|
||||||
newZ = lastRoom.z;
|
|
||||||
if (validateAndBuildBorder(matrix, newX, newY, newZ, newLength, newWidth, newDepth, m, n, p, material)) {
|
|
||||||
|
|
||||||
embellishments(carpetStyle, windowStyle, matrix, newX, newY, newZ, newLength, newWidth, newDepth, material)
|
|
||||||
|
|
||||||
|
|
||||||
addDoor(matrix, lastRoom.x + lastRoom.length - 1,
|
|
||||||
lastRoom.y + Math.floor(lastRoom.width / 2),
|
|
||||||
lastRoom.z, material);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
lastRoom = { x: newX, y: newY, z: newZ, length: newLength, width: newWidth, depth: newDepth };
|
|
||||||
roomPlaced = true;
|
|
||||||
placedRooms++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'forward':
|
|
||||||
newX = lastRoom.x;
|
|
||||||
newY = lastRoom.y + lastRoom.width - 1;
|
|
||||||
newZ = lastRoom.z;
|
|
||||||
if (validateAndBuildBorder(matrix, newX, newY, newZ, newLength, newWidth, newDepth, m, n, p, material)) {
|
|
||||||
|
|
||||||
embellishments(carpetStyle, windowStyle, matrix, newX, newY, newZ, newLength, newWidth, newDepth, material)
|
|
||||||
|
|
||||||
|
|
||||||
addDoor(matrix, lastRoom.x + Math.floor(lastRoom.length / 2),
|
|
||||||
lastRoom.y + lastRoom.width - 1,
|
|
||||||
lastRoom.z, material);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
lastRoom = { x: newX, y: newY, z: newZ, length: newLength, width: newWidth, depth: newDepth };
|
|
||||||
roomPlaced = true;
|
|
||||||
placedRooms++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'backward':
|
|
||||||
newX = lastRoom.x;
|
|
||||||
newY = lastRoom.y - newWidth + 1;
|
|
||||||
newZ = lastRoom.z;
|
|
||||||
if (validateAndBuildBorder(matrix, newX, newY, newZ, newLength, newWidth, newDepth, m, n, p, material)) {
|
|
||||||
|
|
||||||
embellishments(carpetStyle, windowStyle, matrix, newX, newY, newZ, newLength, newWidth, newDepth, material)
|
|
||||||
|
|
||||||
|
|
||||||
addDoor(matrix, lastRoom.x + Math.floor(lastRoom.length / 2),
|
|
||||||
lastRoom.y,
|
|
||||||
lastRoom.z, material);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
lastRoom = { x: newX, y: newY, z: newZ, length: newLength, width: newWidth, depth: newDepth };
|
|
||||||
roomPlaced = true;
|
|
||||||
placedRooms++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (roomPlaced) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!roomPlaced) {
|
|
||||||
console.warn(`Could not place room ${placedRooms + 1}`);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return matrix
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts a 3D matrix into a Minecraft blueprint format
|
|
||||||
* @param {Array<Array<Array<string>>>} matrix - 3D matrix of block types
|
|
||||||
* @param {number[]} startCoord - Starting coordinates [x, y, z]
|
|
||||||
* @returns {Object} Blueprint object in Minecraft format
|
|
||||||
*/
|
|
||||||
function matrixToBlueprint(matrix, startCoord) {
|
|
||||||
// Validate inputs
|
|
||||||
if (!Array.isArray(matrix) || !Array.isArray(startCoord) || startCoord.length !== 3) {
|
|
||||||
throw new Error('Invalid input format');
|
|
||||||
}
|
|
||||||
|
|
||||||
const [startX, startY, startZ] = startCoord;
|
|
||||||
|
|
||||||
return {
|
|
||||||
levels: matrix.map((level, levelIndex) => ({
|
|
||||||
level: levelIndex,
|
|
||||||
coordinates: [
|
|
||||||
startX,
|
|
||||||
startY + levelIndex,
|
|
||||||
startZ
|
|
||||||
],
|
|
||||||
placement: level.map(row =>
|
|
||||||
// Ensure each block is a string, default to 'air' if undefined
|
|
||||||
row.map(block => block?.toString() || 'air')
|
|
||||||
)
|
|
||||||
}))
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* for cutesy output
|
|
||||||
* @param matrix
|
|
||||||
*/
|
|
||||||
function printMatrix(matrix) {
|
|
||||||
matrix.forEach((layer, layerIndex) => {
|
|
||||||
console.log(`Layer ${layerIndex}:`);
|
|
||||||
layer.forEach(row => {
|
|
||||||
console.log(
|
|
||||||
row.map(cell => {
|
|
||||||
switch (cell) {
|
|
||||||
case 'stone': return '█'; // Wall
|
|
||||||
case 'air': return '.'; // Open space
|
|
||||||
case 'dark_oak_door[half=upper, hinge=left]': return 'D';
|
|
||||||
case 'dark_oak_door[half=lower, hinge=left]': return 'D';
|
|
||||||
case 'oak_stairs[facing=north]': return 'S'; // Stairs
|
|
||||||
case 'oak_stairs[facing=east]': return 'S'; // Stairs
|
|
||||||
case 'oak_stairs[facing=south]': return 'S'; // Stairs
|
|
||||||
case 'oak_stairs[facing=west]': return 'S'; // Stairs
|
|
||||||
case 'glass': return 'W'
|
|
||||||
|
|
||||||
|
|
||||||
default: return '?'; // Unknown or unmarked space
|
|
||||||
}
|
|
||||||
}).join(' ')
|
|
||||||
);
|
|
||||||
});
|
|
||||||
console.log('---');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// main:
|
|
||||||
const resultMatrix = proceduralGeneration(20, 10, 20, 10, "air", 2, 2, 4);
|
|
||||||
printMatrix(resultMatrix)
|
|
||||||
|
|
||||||
let blueprint = matrixToBlueprint(resultMatrix,[122, -60, -178])
|
|
||||||
|
|
||||||
import mineflayer from "mineflayer";
|
|
||||||
import {autoBuild} from "./test_blueprint_layout.js";
|
|
||||||
|
|
||||||
const bot = mineflayer.createBot({
|
|
||||||
host: 'localhost', // Replace with your server IP or hostname
|
|
||||||
port: 55916, // Replace with your server port
|
|
||||||
username: 'andy', // Replace with your bot's username
|
|
||||||
// password: 'your_bot_password' // Only if the server has online-mode=true
|
|
||||||
});
|
|
||||||
|
|
||||||
bot.on('spawn', async () => {
|
|
||||||
// have andy build the blueprint automatically
|
|
||||||
const result = autoBuild(blueprint);
|
|
||||||
// const result = clearHouse(blueprint)
|
|
||||||
const commands = result.commands;
|
|
||||||
const nearbyPosition = result.nearbyPosition;
|
|
||||||
for (const command of commands) {
|
|
||||||
bot.chat(command);
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(commands.slice(-10));
|
|
||||||
bot.chat('I have built the house!');
|
|
||||||
// bot.chat('/tp @a ' + nearbyPosition.x + ' ' + nearbyPosition.y + ' ' + nearbyPosition.z+1);
|
|
||||||
|
|
||||||
// Print out the location nearby the blueprint
|
|
||||||
console.log(`tp ${nearbyPosition.x} ${nearbyPosition.y} ${nearbyPosition.z}`)
|
|
||||||
});
|
|
||||||
|
|
|
@ -1,14 +0,0 @@
|
||||||
import { resetConstructionWorld } from "../src/agent/tasks.js";
|
|
||||||
import mineflayer from 'mineflayer';
|
|
||||||
|
|
||||||
const bot = mineflayer.createBot({
|
|
||||||
host: 'localhost', // Replace with your server IP or hostname
|
|
||||||
port: 55916, // Replace with your server port
|
|
||||||
username: 'andy', // Replace with your bot's username
|
|
||||||
// password: 'your_bot_password' // Only if the server has online-mode=true
|
|
||||||
});
|
|
||||||
|
|
||||||
bot.on('spawn', async () => {
|
|
||||||
bot.chat("/tp andy izzycw");
|
|
||||||
resetConstructionWorld(bot);
|
|
||||||
});
|
|
Loading…
Add table
Reference in a new issue