#replacing and giving blocks

1 messages · Page 1 of 1 (latest)

torn cave
#

i’m trying to replace a certain area of blocks with air and then whatever blocks were replaced with air will be given or added to the players inventory

i haven’t been able to get a stable script of this working and i’m wondering if anyone is willing to help

wraith ridge
#
function destroyRegionToContainer(container: Container, dimension: Dimension, v1: Vector3, v2: Vector3): void {
    const startLocation = { x: Math.min(v1.x, v2.x ), y: Math.min(v1.y, v2.y ), z: Math.min(v1.z, v2.z ) };
    const endLocation = { x: Math.max(v1.x, v2.x ), y: Math.max(v1.y, v2.y ), z: Math.max(v1.z, v2.z ) };
    for (let x = startLocation.x; x <= endLocation.x; x++) {
        for (let y = startLocation.y; y <= endLocation.y; y++) {
            for (let z = startLocation.z; z <= endLocation.z; z++) {
                const block = dimension.getBlock({ x: x, y: y, z: z });
                if (block === undefined || block?.typeId === "minecraft:air") continue;
                const itemStack = block.getItemStack();
                if (itemStack === undefined) continue;
                container.addItem(itemStack);
                block.setPermutation(BlockPermutation.resolve("minecraft:air"));
            }
        }
    }
}
#

wait stable you guys dont have typeid

#
function destroyRegionToContainer(container: Container, dimension: Dimension, v1: Vector3, v2: Vector3): void {
    const startLocation = { x: Math.min(v1.x, v2.x ), y: Math.min(v1.y, v2.y ), z: Math.min(v1.z, v2.z ) };
    const endLocation = { x: Math.max(v1.x, v2.x ), y: Math.max(v1.y, v2.y ), z: Math.max(v1.z, v2.z ) };
    const permutation = BlockPermutation.resolve("minecraft:air");
    for (let x = startLocation.x; x <= endLocation.x; x++) {
        for (let y = startLocation.y; y <= endLocation.y; y++) {
            for (let z = startLocation.z; z <= endLocation.z; z++) {
                const block = dimension.getBlock({ x: x, y: y, z: z });
                if (block === undefined || block.permutation.matches("minecraft:air")) continue;
                const itemStack = block.getItemStack();
                if (itemStack === undefined) continue;
                container.addItem(itemStack);
                block.setPermutation(permutation);
            }
        }
    }
}
torn cave
wraith ridge
#

ah saw you stable so thought you meant stable ver