Skip to content

3. Block NBT

LLytho edited this page Jul 25, 2023 · 5 revisions

Block NBT

Modifying the NBT data of a block is simple.
In this example, one of the PonderJS tutorial structures is being used: ponderjs:block_entity_tutorial.

// for 1.18 pls use: onEvent("ponder.registry", event => { ... })
Ponder.registry((event) => {
    event
        .create("minecraft:paper")
        .scene("block_entity_nbt", "Set NBT for blocks", "ponderjs:block_entity_tutorial", (scene, util) => {
            scene.showStructure();
            scene.scaleSceneView(0.9);
            scene.setSceneOffsetY(-1);
            scene.idle(20);

            /**
             * "nbt" contains the NBT data of the block entity. In our example we are
             * using a banner which has "Patterns" as an array of NBT data.
             * 
             * For other block entities, the NBT data will be differently and you have
             * lookup yourself the NBT data of the block. Either through the minecraft
             * wiki or by using "/kubejs hand" when holding the block entity as item, as
             * some block entities will store their data inside the item after break. 
             */
            scene.world.modifyTileNBT([2, 3, 3], (nbt) => {
                
                nbt.Patterns = [
                    {
                        Color: 0,
                        Pattern: "pig",
                    },
                ];
            });

            scene.world.modifyTileNBT([3, 3, 2], (nbt) => {
                nbt.Patterns = [
                    {
                        Color: 0,
                        Pattern: "cre",
                    },
                ];
            });
        });
});

Preview of the result:

Clone this wiki locally