house and door fixes

This commit is contained in:
Kolby Nottingham 2024-04-09 23:38:59 -07:00
parent 83b5f56acc
commit 0d31185704
5 changed files with 111 additions and 51 deletions

View file

@ -0,0 +1,38 @@
{
"name": "hole",
"offset": -2,
"blocks": [
[
["", "", "", "", ""],
["", "dirt", "dirt", "dirt", ""],
["", "dirt", "dirt", "dirt", ""],
["", "dirt", "dirt", "dirt", ""],
["", "", "dirt", "", ""],
["", "", "dirt", "", ""]
],
[
["dirt", "dirt", "dirt", "dirt", "dirt"],
["dirt", "chest", "bed", "air", "dirt"],
["dirt", "air", "bed", "air", "dirt"],
["dirt", "air", "air", "air", "dirt"],
["dirt", "dirt", "door", "dirt", "dirt"],
["dirt", "dirt", "air", "dirt", "dirt"]
],
[
["dirt", "dirt", "dirt", "dirt", "dirt"],
["dirt", "air", "air", "air", "dirt"],
["dirt", "torch", "air", "air", "dirt"],
["dirt", "air", "air", "air", "dirt"],
["dirt", "dirt", "door", "dirt", "dirt"],
["air", "air", "air", "air", "air"]
],
[
["air", "air", "air", "air", "air"],
["dirt", "dirt", "dirt", "dirt", "dirt"],
["dirt", "dirt", "dirt", "dirt", "dirt"],
["dirt", "dirt", "dirt", "dirt", "dirt"],
["air", "air", "air", "air", "air"],
["air", "air", "air", "air", "air"]
]
]
}

View file

@ -0,0 +1,42 @@
{
"name": "shelter",
"offset": -1,
"blocks": [
[
["", "", "", "", ""],
["", "planks", "planks", "planks", ""],
["", "planks", "planks", "planks", ""],
["", "planks", "planks", "planks", ""],
["", "planks", "planks", "planks", ""],
["", "", "planks", "", ""],
["", "", "", "", ""]
],
[
["log", "planks", "planks", "planks", "log"],
["planks", "chest", "bed", "air", "planks"],
["planks", "air", "bed", "air", "planks"],
["planks", "air", "air", "air", "planks"],
["planks", "air", "air", "air", "planks"],
["log", "planks", "door", "planks", "log"],
["", "air", "air", "air", ""]
],
[
["log", "planks", "planks", "planks", "log"],
["planks", "torch", "air", "torch", "planks"],
["planks", "air", "air", "air", "planks"],
["planks", "air", "air", "air", "planks"],
["planks", "torch", "air", "torch", "planks"],
["log", "planks", "door", "planks", "log"],
["", "air", "air", "air", ""]
],
[
["air", "air", "air", "air", "air"],
["air", "planks", "planks", "planks", "air"],
["planks", "planks", "planks", "planks", "planks"],
["planks", "planks", "planks", "planks", "planks"],
["air", "planks", "planks", "planks", "air"],
["air", "air", "air", "air", "air"],
["", "air", "air", "air", ""]
]
]
}

View file

@ -1,43 +0,0 @@
{
"name": "shelter",
"offset": -1,
"placement": [
[1, 1, 1],
[1, 2, 1],
[1, 3, 1],
[2, 3, 1],
[3, 1, 1],
[3, 2, 1],
[3, 3, 1]
],
"blocks": [
[
["dirt", "dirt", "dirt", "dirt", "dirt"],
["dirt", "dirt", "dirt", "dirt", "dirt"],
["dirt", "dirt", "dirt", "dirt", "dirt"],
["dirt", "dirt", "dirt", "dirt", "dirt"],
["dirt", "dirt", "dirt", "dirt", "dirt"]
],
[
["dirt", "dirt", "dirt", "dirt", "dirt"],
["dirt", "chest", "air", "bed", "dirt"],
["dirt", "air", "air", "bed", "dirt"],
["dirt", "air", "air", "air", "dirt"],
["dirt", "dirt", "door", "dirt", "dirt"]
],
[
["dirt", "dirt", "dirt", "dirt", "dirt"],
["dirt", "air", "air", "air", "dirt"],
["dirt", "air", "air", "air", "dirt"],
["dirt", "air", "air", "air", "dirt"],
["dirt", "dirt", "door", "dirt", "dirt"]
],
[
["air", "air", "air", "air", "air"],
["dirt", "dirt", "dirt", "dirt", "dirt"],
["dirt", "dirt", "dirt", "dirt", "dirt"],
["dirt", "dirt", "dirt", "dirt", "dirt"],
["air", "air", "air", "air", "air"]
]
]
}

View file

@ -50,9 +50,25 @@ export class NPCContoller {
}
}
for (let name in this.constructions) {
let sizez = this.constructions[name].blocks[0].length;
let sizex = this.constructions[name].blocks[0][0].length;
let max_size = Math.max(sizex, sizez);
for (let y = 0; y < this.constructions[name].blocks.length; y++) {
for (let z = 0; z < max_size; z++) {
if (z >= this.constructions[name].blocks[y].length)
this.constructions[name].blocks[y].push([]);
for (let x = 0; x < max_size; x++) {
if (x >= this.constructions[name].blocks[y][z].length)
this.constructions[name].blocks[y][z].push('');
}
}
}
}
this.agent.bot.on('idle', async () => {
// Wait a while for inputs before acting independently
await new Promise((resolve) => setTimeout(resolve, 2000));
await new Promise((resolve) => setTimeout(resolve, 5000));
if (!this.agent.isIdle()) return;
// Persue goal
@ -65,15 +81,19 @@ export class NPCContoller {
async executeNext() {
if (!this.agent.isIdle()) return;
await this.agent.coder.execute(async () => {
await skills.moveAway(this.agent.bot, 2);
});
if (this.agent.bot.time.timeOfDay < 12000) {
if (this.agent.bot.time.timeOfDay < 13000) {
// Exit any buildings
let building = this.currentBuilding();
if (building) {
if (building == this.data.home) {
let door_pos = this.getBuildingDoor(building);
if (door_pos) {
await this.agent.coder.execute(async () => {
await skills.useDoor(this.agent.bot, door_pos);
await skills.moveAway(this.agent.bot, 2); // If the bot is too close to the building it will try to enter again
});
}
}
@ -96,6 +116,9 @@ export class NPCContoller {
await skills.goToBed(this.agent.bot);
});
}
if (this.agent.isIdle())
this.agent.bot.emit('idle');
}
async executeGoal() {
@ -142,9 +165,6 @@ export class NPCContoller {
if (res.acted) break;
}
}
if (this.agent.isIdle())
this.agent.bot.emit('idle');
}
currentBuilding() {
@ -186,10 +206,11 @@ export class NPCContoller {
if (door_x !== null) break;
}
if (door_x === null) return null;
let sizex = this.constructions[name].blocks[0][0].length;
let sizez = this.constructions[name].blocks[0].length;
let orientation = this.data.built[name].orientation;
let orientation = 4 - this.data.built[name].orientation; // this conversion is opposite
if (orientation == 4) orientation = 0;
[door_x, door_z] = rotateXZ(door_x, door_z, orientation, sizex, sizez);
door_y += this.constructions[name].offset;

View file

@ -77,6 +77,8 @@ export function blockSatisfied(target_name, block) {
return block.name.endsWith(target_name);
} else if (target_name == 'bed') {
return block.name.endsWith('bed');
} else if (target_name == 'torch') {
return block.name.includes('torch');
}
return block.name == target_name;
}