#How to get the id of a block at set coordinates?

1 messages · Page 1 of 1 (latest)

past turtle
#

In my current script I'm trying to detect the type.id of the block located at the newLocation variable coordinates. How would I go about checking? I know using detectable.includes() is required, but what do I need to add to the parameters of it to detect the block at the newLocation coordinates?

Here's my script so far:

``import { world, system, Block } from "@minecraft/server";

world.afterEvents.entityHitBlock.subscribe(e => {

const player = e.damagingEntity;
const block = e.hitBlock;
const bFace = e.blockFace;

const bLocation = block.location;
const startX = bLocation.x;
const startY = bLocation.y;
const startZ = bLocation.z;

const detectable = [
    "minecraft:diamond_ore"
];

function checkBlocks() {

    if (detectable.includes(block.type.id)) {

        console.log(`${block.type.id} detected`);
        return;
    }

    for (let i = 1; i <= 20; i++) {

        let newLocation;
        switch (bFace) {

            case "North":

                newLocation = { x: startX, y: startY, z: startZ - i };
                break;

            case "East":

                newLocation = { x: startX - i, y: startY, z: startZ };
                break;

            case "South":

                newLocation = { x: startX, y: startY, z: startZ + i };
                break;

            case "West":

                newLocation = { x: startX + i, y: startY, z: startZ };
                break;

            case "Up":

                newLocation = { x: startX, y: startY - i, z: startZ };
                break;

            case "Down":

                newLocation = { x: startX, y: startY + i, z: startZ };
                break;

            default: break;
        }
    }
}

})``

worthy hound
# past turtle In my current script I'm trying to detect the ``type.id`` of the block located a...
import { world, system, Block } from "@minecraft/server";

world.afterEvents.entityHitBlock.subscribe(e => {

    const player = e.damagingEntity;
    const block = e.hitBlock;
    const bFace = e.blockFace;
    comst dim = block.dimension;

    const bLocation = block.location;
    const startX = bLocation.x;
    const startY = bLocation.y;
    const startZ = bLocation.z;

    const detectable = [
        "minecraft:diamond_ore"
    ];

    function checkBlocks() {

        if (detectable.includes(block.type.id)) {

            console.log(`${block.type.id} detected`);
            return;
        }
        
        const locs = [];
        for (let i = 1; i <= 20; i++) {

            switch (bFace) {

                case "North":

                    locs.push({ x: startX, y: startY, z: startZ - i });
                    break;

                case "East":

                    locs.push({ x: startX - i, y: startY, z: startZ });
                    break;

                case "South":

                    locs.push({ x: startX, y: startY, z: startZ + i });
                    break;

                case "West":

                    locs.push({ x: startX + i, y: startY, z: startZ });
                    break;

                case "Up":

                    locs.push({ x: startX, y: startY - i, z: startZ });
                    break;

                case "Down":

                    locs.push({ x: startX, y: startY + i, z: startZ });
                    break;

                default: break;
            }
        }
        console.warn(locs.map(l => [dim.getBlock(l).typeId, l]))
    }
})```