Спавн блоков на поверхности земли
import { world, system } from "@minecraft/server";
let active = false;
const block = "minecraft:gold_block";
const radius = 10;
const tag = "replace";
function checkMob() {
const mobs = world.getDimension("overworld").getEntities({ tags: [tag] });
return mobs.length > 0;
}
function placeBlocks() {
if (!checkMob()) {
active = false;
return;
}
const dimension = world.getDimension("overworld");
const players = world.getAllPlayers();
const mobs = dimension.getEntities({ tags: [tag] });
const targets = [...players, ...mobs];
for (const target of targets) {
const { x, z } = target.location;
const angle = Math.random() * Math.PI * 2;
const distance = Math.random() * radius;
const targetX = x + Math.cos(angle) * distance;
const targetZ = z + Math.sin(angle) * distance;
for (let y = 320; y >= -64; y--) {
const ground = dimension.getBlock({ x: targetX, y, z: targetZ });
if (ground?.typeId === "minecraft:grass_block" || ground?.typeId === "minecraft:dirt") {
const air = dimension.getBlock({ x: targetX, y: y + 1, z: targetZ });
if (air?.typeId === "minecraft:air") {
air.setType(block);
break;
}
}
}
}
}
system.runInterval(() => {
if (checkMob() && !active) {
active = true;
system.runInterval(placeBlocks, 1 * 20);
}
else if (!checkMob() && active) {
active = false;
}
}, 20);