Bedrock Wiki
  • Discord
  • Contribute
  • bedrock.dev
  • MS Learn
Beginner's Guide
  • Guide
    • 1. Introduction
      guide
    • 2. Add-Ons Explained
    • 3. Software & Preparation
    • 4. Project Setup
    • 5. Create a Custom Item
    • 6. Create a Custom Entity
    • 7. Blockbench: Modeling, Texturing & Animating
    • 8. Adding Loot Tables, Spawn Rules & Crafting Recipes
  • Extra
    • a. Understanding JSON
    • b. Download Example Packs
    • c. Troubleshooting
      help
    • d. Advanced Manifest
    • e. Format Versions
    • f. Project Setup Android
Animation Controllers
  • Intro to Animation Controllers
    guide
  • Entity Commands
  • AFK Detector
  • Death Commands
  • Molang into Scoreboard
  • Respawn Commands
Blocks
  • General
    • Intro to Blocks
      guide
    • Block Components
    • Block Tags
    • Block States
    • Block Traits
    • Block Permutations
    • Block Events
      Scripts
    • Block Event Migration
      help
    • Blocks as Items
    • Multi-Blocks
    • Troubleshooting Blocks
      help
  • Sound & Visuals
    • Intro to Block Visuals
      guide
    • Block Culling
    • Block Models
      guide
    • Block Sounds
    • Block Texture Animation
    • Block Texture Variation
    • Block Tinting
    • N-Way Rotation
      guide
  • Tutorials
    • Applying Effects
      Scripts
    • Avoiding State Limit
    • Block Orientation
    • Fake Blocks
      Scripts
    • Ore Loot Tables
      Scripts
    • Tool-Based Destruction
  • Vanilla Re-Creations
    • Custom Crops
      Scripts
    • Custom Fences
    • Custom Glass
    • Custom Glazed Terracotta
    • Custom Heads
    • Custom Trapdoors
      Scripts
  • Documentation
    • Block Co-Location
    • Block Format History
    • Block Shapes
    • Redstone Components
    • Vanilla Block Models
    • Vanilla Block Sounds
    • Vanilla Block Tags
    • Vanilla Voxel Shapes
Commands
  • General
    • Intro to Command Blocks
    • Understanding Selectors
    • Functions
      guide
    • Block States
    • Coordinate System
    • Giving NBT Items
    • Scoreboard Operations
  • Commands
    • Damage
    • Execute
    • Playanimation
    • Playsound
  • On Event Systems
    • On First World Load
      function
    • On Player First Join
    • On Player Join
    • On Player Leave
    • On Player Death
    • On Player Respawn
  • Scoreboard Systems
    • Entity Counter
    • Scoreboard Timers
    • Comparing And Retrieving Scores
  • Detection Systems
    • Look Detection
    • Item Drop Detection
    • Movement Detections
    • Rain Detection
  • Techniques
    • Execute Logic Gates
      concept
    • Execute at Block Variant
    • Execution Forking
      concept
    • Binary in Commands
      concept
    • MBE - Max's Block Entity
    • FMBE - A New Way to Create Display Entities
    • Dynamic Displays
    • Orbital Camera
  • Useful Creations
    • Sphere Command
    • Compass Display
    • Custom Crafting
    • Multiplayer Position Rearrangement
      function
Concepts
  • contents.json
  • Molang
  • Namespaces
  • Overwriting Assets
  • Shaders
  • Sounds
  • Subpacks
  • Texture Atlases
  • textures_list.json
Documentation
  • Advanced Molang
  • File Types
  • Fog IDs
  • Material Configuration Description
  • Molang Queries
  • Pack Folder Structure
  • Shared Constructs
  • Sound Definitions
  • Vanilla Materials
Entities
  • General
    • Intro to Entities BP
      guide
    • Intro to Entities RP
      guide
    • Troubleshooting Entities
      help
    • Entity Events
    • Entity Properties
    • NPC Dialogue
    • Render Controllers
    • Spawn Rules
  • Tutorials
    • Area Effect Clouds
    • Coordinate Space Conversion
    • Creating Boats
    • Detecting Other Entities
    • Disabling Team Damage
    • Dummy Entities
    • Entity Attacks
    • Entity Movement
    • Entity Timers
    • Holding Items
    • Invulnerable Entities
    • Look at Entity
    • Riding Flying Entities
    • Sleeping Entities
    • Solid Entities
    • Spawning Tamed Entities
      Scripts
    • Village Mechanic
  • Documentation
    • Dummy Components
    • Non-Mob Runtime Identifiers
    • Projectiles
    • Runtime Identifiers
    • Vanilla Usage Components
    • Vanilla Usage Spawn Rules
Items
  • General
    • Intro to Items
      guide
    • Item Components
    • Item Tags
    • Item Events
      Scripts
    • Item Event Migration
      help
    • Item Catalog
    • Troubleshooting Items
      help
  • Tutorials
    • Equipment-Based Commands
    • Spawning Items
    • Throwable Items
  • Vanilla Re-Creations
    • Custom Armor
    • Custom Food
      Scripts
    • Custom Pottery Sherds
    • Custom Weapons
  • Documentation
    • Enchantments
    • Attachables
    • Item Format History
    • Numerical Item IDs
    • Vanilla Item Groups
    • Vanilla Item Tags
    • Vanilla Usage Components
JSON UI
  • General
    • Intro to JSON UI
      guide
    • Best Practices
      guide
  • Tutorials
    • Adding HUD Elements
    • Aseprite Animations
    • Buttons and Toggles
    • Dynamic Content Generation
    • Modifying Server Forms
    • Preserve Title Texts
    • Type Conversion
  • Documentation
    • JSON UI Documentation
Loot, Recipes & Trading
  • General
    • Trading Behavior
  • Documentation
    • Loot Tables
    • Trade Tables
    • Recipes
    • Item Functions
  • Tutorials
    • Randomized Structure Loot
Meta
  • Add-On Performance
  • Style Guide
  • Useful Links
  • Using Schemas
  • Version Control
  • Q&A
    • Blocks and Items Q&A 2024/08/30
    • Deferred Technical Preview Q&A 2024/02/23
    • GameTest Q&A 2021/08/06
    • Scripting and Editor Q&A 2023/09/22
    • World Generation Q&A 2024/11/15
NBT
  • General
    • .mcstructure
  • Tutorials
    • Enabling Experiments by Editing NBT
    • Extending Structure Limits
  • NBT in Depth
    • About NBT (Named Binary Tag)
    • NBT Libraries
    • Reading NBT Example
Particles
  • General
    • Intro to Particles
      guide
  • Tutorials
    • Disabling Particles
  • Documentation
    • Vanilla Particles
Scripting
  • General
    • Intro to Scripting
    • What is Script API?
    • API Modules
  • Tutorials
    • Script Core Features
    • Block Placement Prevention
    • Custom Commands
    • GameTests
    • Script Privileges
    • Script Requests API
    • Server Forms
  • Documentation
    • Engine Environment
    • Script Resources
    • Script Watchdog
    • Troubleshooting JavaScript
    • TypeScript
Servers
  • Software
    • Bedrock Server Software
  • Protocols
    • Bedrock Protocol
    • NetherNet Protocol
    • RakNet Protocol
Text & Localization
  • General
    • Intro to Text & Localization
    • Raw Text
    • Splashes
  • Emojis & Symbols
    • Fonts
    • Intro to Emojis
    • Custom Emojis
    • Input Keys
Visuals
  • General
    • Introduction to Entity Visuals
      guide
    • Bedrock Modeling
    • Custom Death Animations
    • Effects in Animations
    • Material Creations
    • Materials
    • Math-Based Animations
    • Skin Packs
  • Tutorials
    • Entity Texture Animation
    • Glowing Entity Texture
    • Hurt Animations
    • Leash Position
    • Player Geometry
    • Remove Entity Shadows
    • Retexturing Spawn Eggs
  • Ideas
    • Structure Presentation
World Generation
  • General
    • Intro to World Generation
      guide
    • Biomes
      guide
    • Feature Types
    • Jigsaw Structures
  • Tutorials
    • Block Conditions for Features
    • Generating Custom Ores
    • Generating Custom Structures
    • Generating Patches
    • Heightmap Noise
  • Documentation
    • Biome Tags

N-Way Rotation

guide
intermediate
N-Way Rotation
  • How It Works
  • Existing Applications
    • Cardinal Direction
    • Sixteen-Way Rotation
  • Custom N-Way Rotation States
    • Custom State
    • Custom Component
      • Component JSON Format
      • Component Script
    • Final Block JSON & Script
Download Example
Download as ZIP Download as MCADDON

VISUAL ONLY

Unlike rotation from the transformation component, features such as collision box and selection box will not be affected by N-way rotation as this system only targets block geometry. This is because N-way rotation may not be axis-aligned which would cause issues for these components.

ROOT ONLY

N-way rotation can only be defined in the root components object of the block, so cannot be specified per permutation.

MULTI-BLOCKS

N-way rotation is not supported by multi-blocks and attempts to use it will cause the block JSON to be invalid.

How It Works ​

N-way rotation allows the geometry of a block to be rotated by linking a block state with each rotation axis. The game will then automatically associate an angle of rotation to each block state value, equally spacing rotations across the full 360°, starting from south.

Here, N refers to the number of discrete angles that the block can face on a given axis, determined by the number of valid values listed for the associated block state. For example, the state below has 3 valid values (0, 1 and 2), meaning it could be used to apply 3-way rotation to the block geometry.

Note: You will need to implement a way to set the value of any custom states you make, see the custom N-way rotation states section. Alternatively, there are vanilla states provided by block traits (such as minecraft:sixteen_way_rotation) which will have their values set automatically when the block is placed.

📝 BP/blocks/three_way_arrow.json
minecraft:block
json
"description": {
    "identifier": "wiki:three_way_arrow",
    "menu_category": {
        "category": "construction"
    },
    "states": {
        "wiki:three_way_rotation": [0, 1, 2]
    }
}
1
2
3
4
5
6
7
8
9

In the block's geometry component, we need to define the n_way_visual_rotation parameter. Here, the y axis has been set to the name of the block state it should rotate based on, as that is the axis that the rotation should affect. Other keys (x and z) can also be defined here if you would like those axes to have N-way rotation too.

📝 BP/blocks/three_way_arrow.json
minecraft:blockcomponents
json
"minecraft:geometry": {
    "identifier": "geometry.wiki_arrow",
    "n_way_visual_rotation": {
        "y": "wiki:three_way_rotation"
    }
}
1
2
3
4
5
6

Now that we have N-way rotation set up, let's see how it looks in-game!

The first state value (0 in this case) will always be associated with a rotation of 0° from south. Assuming your block model faces north, the block will face south when placed with this state value and when displayed in the UI.

The angle of rotation increases by 360N degrees in a clockwise direction for each subsequent state value.

The different permutations of our arrow block with 3-way rotation have their associated angles annotated below. The following screenshots were taken from above while facing north.

wiki:three_way_rotation = 0
wiki:three_way_rotation = 1
wiki:three_way_rotation = 2

Existing Applications ​

Cardinal Direction ​

Traditionally, blocks with cardinal orientation would have their rotation applied via the minecraft:transformation component, with each state value (e.g. "west") manually assigned a rotation angle using the permutations array.

However, for blocks where only the geometry needs to be rotated (such as carved pumpkins which have the same collision and selection boxes regardless of direction), N-way rotation provides a much easier interface for applying cardinal direction by automatically applying different angles of rotation based on the minecraft:cardinal_direction state.

Example block with cardinal direction applied via N-way rotation
📝 BP/blocks/cardinal_arrow.json
json
{
    "format_version": "1.26.40",
    "minecraft:block": {
        "description": {
            "identifier": "wiki:cardinal_arrow",
            "menu_category": {
                "category": "construction"
            },
            "traits": {
                "minecraft:placement_direction": {
                    "enabled_states": ["minecraft:cardinal_direction"],
                    "y_rotation_offset": 180 // Face towards the player
                }
            }
        },
        "components": {
            // Visuals
            "minecraft:geometry": {
                "identifier": "geometry.wiki_arrow",
                "n_way_visual_rotation": {
                    "y": "minecraft:cardinal_direction"
                }
            },
            "minecraft:material_instances": {
                "*": {
                    "texture": "wiki:arrow",
                    "render_method": "alpha_test"
                }
            },
            // Collision and selection boxes
            // Remember that these will not rotate with the geometry so it's best to keep them symmetrical
            "minecraft:collision_box": {
                "origin": [-7, 0, -7],
                "size": [14, 1, 14]
            },
            "minecraft:selection_box": {
                "origin": [-7, 0, -7],
                "size": [14, 1, 14]
            }
        }
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

Sixteen-Way Rotation ​

Some vanilla blocks including banners, mob heads and signs can be placed at 16 discrete rotations, allowing for more precise orientation.

The minecraft:placement_direction block trait provides a minecraft:sixteen_way_direction state that can be used to enable this type of orientation.

Example block with 16-way rotation
📝 BP/blocks/sixteen_way_arrow.json
json
{
    "format_version": "1.26.40",
    "minecraft:block": {
        "description": {
            "identifier": "wiki:sixteen_way_arrow",
            "menu_category": {
                "category": "construction"
            },
            "traits": {
                "minecraft:placement_direction": {
                    "enabled_states": ["minecraft:sixteen_way_rotation"],
                    "y_rotation_offset": 180 // Face towards the player
                }
            }
        },
        "components": {
            // Visuals
            "minecraft:geometry": {
                "identifier": "geometry.wiki_arrow",
                "n_way_visual_rotation": {
                    "y": "minecraft:sixteen_way_rotation"
                }
            },
            "minecraft:material_instances": {
                "*": {
                    "texture": "wiki:arrow",
                    "render_method": "alpha_test"
                }
            },
            // Collision and selection boxes
            // Remember that these will not rotate with the geometry so it's best to keep them symmetrical
            "minecraft:collision_box": {
                "origin": [-7, 0, -7],
                "size": [14, 1, 14]
            },
            "minecraft:selection_box": {
                "origin": [-7, 0, -7],
                "size": [14, 1, 14]
            }
        }
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

Custom N-Way Rotation States ​

scripting

While Minecraft provides a placement direction state for 4-way rotation via minecraft:cardinal_direction and 16-way rotation via minecraft:sixteen_way_rotation, if you'd like your block to have a different N, you'll have to implement your own logic for setting the custom rotation state when placed.

In this section, you will be provided with a custom component that will adapt to the number of values that your rotation state has. We will be modifying the example arrow block from the start of this page so that its wiki:three_way_rotation state is set upon being placed by the player.

Custom State ​

Rather than using a block trait to enable a built-in block state, you'll need to define your own state.

STATE VALUE LIMIT

Keep in mind that a single block state can have a maximum of 16 values, meaning 16-way rotation is as precise as your block can get by using this system!

📝 BP/blocks/three_way_arrow.json
minecraft:blockdescription
json
"states": {
    "wiki:three_way_rotation": [0, 1, 2]
}
1
2
3

INTEGER RANGE FORMAT

For larger value ranges, it's a good idea to use the integer range format when defining your custom state so that you don't have to manually list each value. Here's an example for 8-way rotation:

minecraft:blockdescription
json
"states": {
    "wiki:eight_way_rotation": {
        "values": { "min": 0, "max": 7 }
    }
}
1
2
3
4
5

Custom Component ​

Component JSON Format ​

This custom component is needed to set the value of the wiki:three_way_rotation state when the block is placed. We will do this using the beforeOnPlayerPlace() event hook.

First, let's outline the format of our custom component in the block JSON file. We're going to give it two parameters:

  • rotation_state — String
    • The name of the state that is being used for N-way rotation.
    • This is needed for the script registering the custom component to know which state to set and how many values it has.
    • For our example, this parameter will be set to "wiki:three_way_rotation".
  • y_rotation_offset — Integer (optional)
    • An angle added to the player's Y rotation before calculating the value of the rotation state.
    • This is equivalent to the same parameter found in the minecraft:placement_direction trait.
    • Since we want the block to face towards the player when placed (rather than in the same direction as the player), we will set it to 180 degrees.
📝 BP/blocks/three_way_arrow.json
minecraft:blockcomponents
json
"wiki:n_way_rotation": {
    "rotation_state": "wiki:three_way_rotation",
    "y_rotation_offset": 180 // Face towards the player
}
1
2
3
4

Component Script ​

Here is the function that we will use to convert the player's Y rotation into a value between 0 and n-1 (where n is the number of state values).

📝 BP/scripts/nWayRotation.js
js
/**
 * @param {number} n
 * @param {number} rotation
 */
function getNWayRotation(n, rotation) {
    // Angle between different state values
    const rotationInterval = 360 / n;

    // Converts the rotation into a positive angle below 360
    rotation %= 360;
    if (rotation < 0) rotation += 360;

    // Returns the rotation as a value that is less than n
    return Math.round(rotation / rotationInterval) % n;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

Now let's create a custom component that uses the getNWayRotation() function to set the block to the correct rotation permutation.

📝 BP/scripts/nWayRotation.js
js
import { BlockStates, system } from "@minecraft/server";

// Make sure you change "wiki" to your own namespace!
const componentName = "wiki:n_way_rotation";

/** @type {import("@minecraft/server").BlockCustomComponent} */
const BlockNWayRotationComponent = {
    beforeOnPlayerPlace(event, { params }) {
        const { player } = event;
        if (!player) return;

        // Get the number of rotation state values
        const rotationState = params.rotation_state;
        const n = BlockStates.get(rotationState).validValues.length;

        // Get the "y_rotation_offset" value defined in the block JSON (default to 0) and add it to the player's Y rotation
        const yRotationOffset = params.y_rotation_offset ?? 0;
        const yRotation = player.getRotation().y + yRotationOffset;

        // Get the rotation state value from the player's Y rotation
        const value = getNWayRotation(n, yRotation);

        // Update the block permutation being placed
        event.permutationToPlace = event.permutationToPlace.withState(rotationState, value);
    },
};

// Register the custom component with the name "wiki:n_way_rotation"
system.beforeEvents.startup.subscribe(({ blockComponentRegistry }) => {
    blockComponentRegistry.registerCustomComponent(componentName, BlockNWayRotationComponent);
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

Remember to import the script into your entry file and set up scripts in BP/manifest.json if you haven't already!

📝 BP/scripts/index.js
js
import './nWayRotation.js';
1

Final Block JSON & Script ​

Example Arrow Block JSON
📝 BP/blocks/three_way_arrow.json
json
{
    "format_version": "1.26.40",
    "minecraft:block": {
        "description": {
            "identifier": "wiki:three_way_arrow",
            "menu_category": {
                "category": "construction"
            },
            "states": {
                "wiki:three_way_rotation": [0, 1, 2]
            }
        },
        "components": {
            // Custom component used to set the rotation state
            "wiki:n_way_rotation": {
                "rotation_state": "wiki:three_way_rotation",
                "y_rotation_offset": 180 // Face towards the player
            },
            // Visuals
            "minecraft:geometry": {
                "identifier": "geometry.wiki_arrow",
                "n_way_visual_rotation": {
                    "y": "wiki:three_way_rotation"
                }
            },
            "minecraft:material_instances": {
                "*": {
                    "texture": "wiki:arrow",
                    "render_method": "alpha_test"
                }
            },
            // Collision and selection boxes
            // Remember that these will not rotate with the geometry so it's best to keep them symmetrical
            "minecraft:collision_box": {
                "origin": [-7, 0, -7],
                "size": [14, 1, 14]
            },
            "minecraft:selection_box": {
                "origin": [-7, 0, -7],
                "size": [14, 1, 14]
            }
        }
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
N-Way Rotation Component Script
📝 BP/scripts/nWayRotation.js
js
import { BlockStates, system } from "@minecraft/server";

// Make sure you change "wiki" to your own namespace!
const componentName = "wiki:n_way_rotation";

/** @type {import("@minecraft/server").BlockCustomComponent} */
const BlockNWayRotationComponent = {
    beforeOnPlayerPlace(event, { params }) {
        const { player } = event;
        if (!player) return;

        // Get the number of rotation state values
        const rotationState = params.rotation_state;
        const n = BlockStates.get(rotationState).validValues.length;

        // Get the "y_rotation_offset" value defined in the block JSON (default to 0) and add it to the player's Y rotation
        const yRotationOffset = params.y_rotation_offset ?? 0;
        const yRotation = player.getRotation().y + yRotationOffset;

        // Get the rotation state value from the player's Y rotation
        const value = getNWayRotation(n, yRotation);

        // Update the block permutation being placed
        event.permutationToPlace = event.permutationToPlace.withState(rotationState, value);
    },
};

// Register the custom component with the name "wiki:n_way_rotation"
system.beforeEvents.startup.subscribe(({ blockComponentRegistry }) => {
    blockComponentRegistry.registerCustomComponent(componentName, BlockNWayRotationComponent);
});

/**
 * @param {number} n
 * @param {number} rotation
 */
function getNWayRotation(n, rotation) {
    // Angle between different state values
    const rotationInterval = 360 / n;

    // Converts the rotation into a positive angle below 360
    rotation %= 360;
    if (rotation < 0) rotation += 360;

    // Returns the rotation as a value that is less than n
    return Math.round(rotation / rotationInterval) % n;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47

Contributors

Edit N-Way Rotation on GitHub

Text and image content on this page is licensed under the Creative Commons Attribution 4.0 International License

Code samples on this page are licensed under the MIT License

Bedrock Wiki by Bedrock OSS

"Minecraft" is a trademark of Mojang AB.

Bedrock OSS, Bedrock Wiki and bedrock.dev are not affiliated in any way with Microsoft or Mojang AB.

  • Privacy Policy
  • Join our Discord
  • Learn how to Contribute
  • Visit our Repository