Skip to content

2. Set, Replace, Modify Blocks

LLytho edited this page Jul 25, 2023 · 4 revisions

Set, Replace & Modify Blocks

Modifying the blocks of a scene is very straightforward.
Take a look at this snippet for examples:

// for 1.18 pls use: onEvent("ponder.registry", event => { ... })
Ponder.registry((event) => {
    event.create("minecraft:stone").scene("set_replace_modify_tutorial", "Set, Replace, Modify.", (scene, util) => {
        scene.showStructure();

        /**
         * The last argument is for spawning particles.
         * true if yes, false if no
         */
        scene.world.setBlocks([0, 1, 0, 4, 1, 4], "minecraft:brick_slab", true);
        scene.world.setBlock([0, 1, 1], "minecraft:stone_slab", false);

        scene.world.modifyBlocks([2, 1, 2, 2, 1, 3], (curState) => curState.with("type", "double"), true);
        scene.world.modifyBlock([0, 1, 4], (curState) => curState.with("type", "top"), true);

        /**
         * Or directly return a new block state.
         */
        scene.world.modifyBlock([0, 1, 3], () => Block.id("minecraft:jungle_slab").with("type", "top"), true);

        scene.world.replaceBlocks([3, 1, 0, 4, 1, 4], "minecraft:oak_slab", false);
    });
});
Clone this wiki locally