#how to spawn particle inside of a block

1 messages · Page 1 of 1 (latest)

stray pivot
#

Hey, I'd strongly advise not to run this command since it can fill your command queue really fast (since it does checks every x ticks).
The script below checks for alliums in a radius of 10 blocks around the player and then spawns the endrod particle at the center of that block and y + 1 so it's visible.

function createParticleEffects(player) {
    const dimension = world.getDimension("overworld");
    const playerLocation = player.location;

    // Round down the player's position to the nearest whole number
    const roundedX = Math.floor(playerLocation.x);
    const roundedY = Math.floor(playerLocation.y);
    const roundedZ = Math.floor(playerLocation.z);

    const radius = 10;

    for (let x = roundedX - radius; x <= roundedX + radius; x++) {
        for (let y = roundedY - radius; y <= roundedY + radius; y++) {
            for (let z = roundedZ - radius; z <= roundedZ + radius; z++) {
                const block = dimension.getBlock({ x, y, z });
                if (block && block.typeId === "minecraft:allium") {
                    dimension.runCommandAsync(`particle minecraft:endrod ${x} ${y + 1} ${z}`);
                }
            }
        }
    }
}

// Periodically update particle effects around players
system.runInterval(() => {
    const dimension = world.getDimension("overworld");
    const players = dimension.getPlayers();

    players.forEach(player => {
        createParticleEffects(player);
    });
}, 5); // Run every 5 ticks```
thorn plume
#

Is this a custom block? If so then you would use the onTick CustomBlockComponent