construction task fixes

This commit is contained in:
Mehul Maheshwari 2025-03-20 14:07:00 -07:00
parent a61c6da134
commit 21dfa0a9d3
2 changed files with 63 additions and 49 deletions

4
.gitignore vendored
View file

@ -19,13 +19,9 @@ experiments/
andy_*.json andy_*.json
jill_*.json jill_*.json
src/models/logs/* src/models/logs/*
<<<<<<< HEAD
server_data/* server_data/*
server_data_*/* server_data_*/*
=======
server_data*
results/* results/*
>>>>>>> d70491e5974a973b96c47f0515c2722b82c9b253
tasks/construction_tasks/test_multiagent_construction_tasks.json tasks/construction_tasks/test_multiagent_construction_tasks.json
tasks/construction_tasks/train_multiagent_construction_tasks.json tasks/construction_tasks/train_multiagent_construction_tasks.json
tasks/construction_tasks/test/** tasks/construction_tasks/test/**

View file

@ -634,51 +634,46 @@ export function proceduralGeneration(m = 20,
} }
// out of commission //still a little buggy
function addStairs(matrix, x, y, z, direction) { function addStairs(matrix, x, y, z, length, width, material) {
let dz = 0; // Change in Z direction let currentZ = z;
let dx = 0; // Change in X direction let currentX = x + 1;
let facing = ''; let currentY = y + 1;
let direction = 0;
let stepCount = 0;
const maxSteps = length * width; // Safety limit
// Determine direction and facing while (currentZ >= 0 && currentX < x + length - 1 && currentY < y + width - 1 && stepCount < maxSteps) {
switch (direction) { // Place stair block
case 'north': matrix[currentZ][currentX][currentY] = material || 'stone';
dz = -1;
facing = 'oak_stairs[facing=north]'; // Clear 3 blocks above for headroom
break; for (let i = 1; i <= 3; i++) {
case 'south': if (currentZ + i < matrix.length) {
dz = 1; matrix[currentZ + i][currentX][currentY] = 'air';
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 // Move to next position based on direction
let currentZ = z; if (direction === 0) {
while (currentZ > 0 && matrix[currentZ - 1][x][y] === 'air') { currentX++;
// Place stone as foundation if (currentX >= x + length - 1) {
matrix[currentZ - 1][x][y] = 'stone'; currentX = x + length - 2;
direction = 1;
// Place stair above the stone } else {
matrix[currentZ][x][y] = facing;
// Move down diagonally
x += dx;
y += dz;
currentZ--; currentZ--;
}
} else {
currentY++;
if (currentY >= y + width - 1) {
currentY = y + width - 2;
direction = 0;
} else {
currentZ--;
}
}
// Check if we've hit the edge stepCount++;
if (x < 0 || x >= matrix[0].length || y < 0 || y >= matrix[0][0].length) break;
} }
} }
@ -817,9 +812,11 @@ export function proceduralGeneration(m = 20,
embellishments(carpetStyle, windowStyle, matrix, newX, newY, newZ, newLength, newWidth, newDepth, material) embellishments(carpetStyle, windowStyle, matrix, newX, newY, newZ, newLength, newWidth, newDepth, material)
addLadder(matrix, lastRoom.x + Math.floor(lastRoom.length / 2), // addLadder(matrix, lastRoom.x + Math.floor(lastRoom.length / 2),
lastRoom.y + Math.floor(lastRoom.width / 2), // lastRoom.y + Math.floor(lastRoom.width / 2),
newZ); // Adding the ladder // newZ); // Adding the ladder
addStairs(matrix, newX, newY, newZ, newLength, newWidth, material)
lastRoom = {x: newX, y: newY, z: newZ, length: newLength, width: newWidth, depth: newDepth}; lastRoom = {x: newX, y: newY, z: newZ, length: newLength, width: newWidth, depth: newDepth};
@ -998,3 +995,24 @@ function matrixToBlueprint(matrix, startCoord) {
}; };
} }
// testing code
// let blueprint = proceduralGeneration(10,10,20)
// const b = new Blueprint(blueprint)
// const result = b.autoBuild();
// const commands = result.commands;
// const nearbyPosition = result.nearbyPosition;
//
// import {initBot} from "../../utils/mcdata.js";
// let bot = initBot("andy");
//
//
// bot.on('spawn', async () => {
// console.log("nearby position", nearbyPosition);
// bot.chat(`/tp @andy ${nearbyPosition.x} ${nearbyPosition.y} ${nearbyPosition.z}`);
// for (const command of commands) {
// bot.chat(command);
// }
// });