I seem to have an issue with ticking areas.
I create one and try to set blocks in the area I set but it just doesn’t want to load the area of the ticking area.
Making the ticking area my self seems to fix the issue and everything then works fine but I need this automated
import { world, system } from "@minecraft/server";
const CHUNK_SIZE = 16;
const MAX_TICKING_AREA_CHUNKS = 100;
const BLOCKS_PER_TICK = 2500;
function calculateTickingAreas(start, end) {
const areas = [];
const chunkStartX = Math.floor(start.x / CHUNK_SIZE);
const chunkStartZ = Math.floor(start.z / CHUNK_SIZE);
const chunkEndX = Math.floor(end.x / CHUNK_SIZE);
const chunkEndZ = Math.floor(end.z / CHUNK_SIZE);
const areaChunkSize = Math.floor(Math.sqrt(MAX_TICKING_AREA_CHUNKS));
for (let chunkX = chunkStartX; chunkX <= chunkEndX; chunkX += areaChunkSize) {
for (let chunkZ = chunkStartZ; chunkZ <= chunkEndZ; chunkZ += areaChunkSize) {
const areaStart = {
x: chunkX * CHUNK_SIZE,
y: start.y,
z: chunkZ * CHUNK_SIZE,
};
const areaEnd = {
x: Math.min((chunkX + areaChunkSize - 1) * CHUNK_SIZE + (CHUNK_SIZE - 1), end.x),
y: end.y,
z: Math.min((chunkZ + areaChunkSize - 1) * CHUNK_SIZE + (CHUNK_SIZE - 1), end.z),
};
areas.push({ start: areaStart, end: areaEnd });
}
}
return areas;
}
function* fillAreaBlocks(dimension, start, end, blockType) {
const blocks = [];
let blockCount = 0;
const totalBlocks = (end.x - start.x + 1) * (end.y - start.y + 1) * (end.z - start.z + 1);
for (let x = start.x; x <= end.x; x++) {
for (let y = start.y; y <= end.y; y++) {
for (let z = start.z; z <= end.z; z++) {
blocks.push({ x, y, z });
blockCount++;
if (blocks.length >= BLOCKS_PER_TICK || blockCount === totalBlocks) {
for (const block of blocks) {
dimension.setBlockType(block, blockType);
}
blocks.length = 0;
yield;
}
}
}
}
}
function fillArea(start, end, blockType = "minecraft:stone") {
const dimension = world.getDimension("overworld");
const tickingAreas = calculateTickingAreas(start, end);
try {
tickingAreas.forEach(({ start, end }, index) => {
console.warn("created ticking");
const player = Array.from(world.getPlayers())[0];
if (player) {
player.runCommandAsync(
`tickingarea add ${start.x} ${start.y} ${start.z} ${end.x} ${end.y} ${end.z} temp_${index} false`
).catch(error => console.error(`Failed to create ticking area: ${error}`));
}
});
} catch (error) {
console.error("Failed to create ticking areas:", error);
return;
}
system.runJob(fillAreaBlocks(dimension, start, end, blockType));
system.runTimeout(() => {
try {
tickingAreas.forEach((_, index) => {
dimension.runCommandAsync(`tickingarea remove temp_${index}`);
});
} catch (error) {
console.error("Failed to remove ticking areas:", error);
}
}, ((end.x - start.x + 1) * (end.y - start.y + 1) * (end.z - start.z + 1)) / BLOCKS_PER_TICK);
}
fillArea({ x: 2500, y: 64, z: 2500 }, { x: 2600, y: 94, z: 2600 });```
If anyone has a solution it would be appreciated