Left image: if the block is placed by feature_rules
Right image: if the block is placed by the player
This is the script I use, allows blocks to rotate randomly. I have tried it with setblock command it works fine. But, this doesn't work if the block is placed by feature_rules.
import { world } from "@minecraft/server";
/** @type {import("@minecraft/server").BlockCustomComponent} */
const ItemRotationBlockComponent = {
onPlace(event) {
const rotation = Math.floor(Math.random() * 4);
const block = event.block
block.setPermutation(block.permutation.withState('dave:rotation', rotation))
},
};
world.beforeEvents.worldInitialize.subscribe(({ blockComponentRegistry }) => {
blockComponentRegistry.registerCustomComponent("dave:block_random_rotation", ItemRotationBlockComponent);
});