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 a Loot Table, Spawn Rule & Crafting Recipe
  • 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
    • Troubleshooting Blocks
      help
  • Visuals
    • Block Culling
    • Block Models
      guide
    • Block Texture Animation
    • Block Texture Variation
    • Block Tinting
  • Tutorials
    • Applying Effects
      Scripts
    • Avoiding State Limit
    • Block Orientation
    • Fake Blocks
      Scripts
    • Intercardinal Orientation
      Scripts
    • Ore Loot Tables
      Scripts
    • Tool-Based Destruction
  • Vanilla Re-Creations
    • Custom Crops
      Scripts
    • Custom Glass
    • Custom Glazed Terracotta
    • Custom Heads
      Scripts
    • Custom Trapdoors
      Scripts
  • Documentation
    • Block Format History
    • Block Shapes
    • Block Sounds
    • Redstone Components
    • Vanilla Block Models
    • Vanilla Block Tags
Commands
  • General
    • Intro to Command Blocks
    • Functions
    • Block States
    • Coordinate System
    • Giving NBT Items
    • Scoreboard Operations
    • Understanding Selectors
  • Commands
    • Damage
    • Execute
    • Playanimation
    • Playsound
  • On Event Systems
    • On First World Load
    • 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
  • Techniques
    • Execute Logic Gates
    • Execute at Block Variant
    • MBE - Max's Block Entity
    • FMBE - A New Way to Create Display Entities
    • Item Drop Detection
    • Look Detection
    • Movement Detections
    • Orbital Camera
  • Useful Creations
    • Compass Display
    • Custom Crafter
    • 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
    • Convert Points Between Any Space (World, Entity, Bones)
    • Creating Boats
    • Detecting Other Entities
    • Disabling Team Damage
    • Dummy Entities
    • Entity Attacks
    • Entity Holds Item
    • Entity Movement
    • Entity Timers
    • Introduction to AOE Clouds
    • 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
    • Custom Armor
    • Custom Food
      Scripts
    • Custom Pottery Sherds
    • Custom Weapons
    • Equipment-Based Commands
    • Spawning Items
    • Throwable Items
  • 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
    • Modifying Server Forms
    • Preserve Title Texts
    • String to Number
  • 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
    • Block Placement Prevention
    • Custom Commands
    • GameTests
    • Script Core Features
    • Script Forms
    • Script Privileges
    • Script Requests API
  • 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

Intercardinal Orientation

intermediate
scripting
Intercardinal Orientation
  • Initial Block JSON
  • Defining the Direction State
  • Setting the Direction State
    • Calculating the Direction Value
    • Orientation Custom Component
  • Block Model
    • Cardinal Bone
    • Intercardinal Bones
  • Applying Block Rotation
    • Bone Visibility
    • Permutation Entries
  • Final Block JSON & Script
  • Result
    • Download Example Pack

FORMAT VERSION 1.26.0

This tutorial assumes a good understanding of blocks and scripting. Check out the blocks guide before starting.

This tutorial guides you through making a block that can face any of 16 intercardinal directions, like mob heads and signs, providing examples of a "mug" block with this type of block orientation.

Custom mug blocks placed in different directions on a table

Initial Block JSON ​

Before you implement intercardinal direction into your block, you'll need to create a JSON file for your block definition.

Here is the JSON we will be starting with for the "mug" block in this tutorial:

BP/blocks/mug.json
json
{
    "format_version": "1.26.0",
    "minecraft:block": {
        "description": {
            "identifier": "wiki:mug",
            "menu_category": {
                "category": "items"
            }
        },
        "components": {
            // Collision and selection boxes
            "minecraft:collision_box": {
                "origin": [-3, 0, -3],
                "size": [6, 8, 6]
            },
            "minecraft:selection_box": {
                "origin": [-3, 0, -3],
                "size": [6, 8, 6]
            },
            // Visuals
            "minecraft:destruction_particles": {
                "particle_count": 48
            },
            "minecraft:material_instances": {
                "*": { "texture": "wiki:mug" }
            }
        }
    }
}
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

As you can see, the block is currently missing geometry and permutations that would allow for orientation. Let's get that fixed!

Defining the Direction State ​

Since Minecraft doesn't expose a built-in intercardinal direction state for use with custom blocks, we'll have to make our own.

The state in this tutorial is based on the ground_sign_direction state used for the orientation of vanilla banners and signs, and will have the following values:

ValueDirection
0South
1South-southwest
2Southwest
3West-southwest
4West
5West-northwest
6Northwest
7North-northwest
8North
9North-northeast
10Northeast
11East-northeast
12East
13East-southeast
14Southeast
15South-southeast

As shown above, we'll need to define a block state that supports integer values from 0 to 15. In this tutorial, that state will be called wiki:intercardinal_direction. As always, make sure you change wiki to your own namespace!

minecraft:block > description
json
"states": {
    "wiki:intercardinal_direction": {
        "values": { "min": 0, "max": 15 }
    }
}
1
2
3
4
5

Setting the Direction State ​

Now we need a way to set the wiki:intercardinal_direction state to the correct value before the block is placed by a player.

For this, we can use scripts to calculate the direction value and update the block permutation being placed using the beforeOnPlayerPlace() event hook in a custom component.

Calculating the Direction Value ​

Here is the function that we will use to convert the player's rotation into an intercardinal direction from 0 to 15.

BP/scripts/intercardinalOrientation.js
js
/** @param {number} yRotation */
function getIntercardinalDirection(yRotation) {
    // Converts the Y rotation into a positive angle below 360
    yRotation %= 360;
    if (yRotation < 0) yRotation += 360;

    // Returns the Y rotation as an intercardinal direction below 16
    return Math.round(yRotation / 22.5) % 16;
}
1
2
3
4
5
6
7
8
9

Orientation Custom Component ​

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

BP/scripts/intercardinalOrientation.js
js
import { system } from "@minecraft/server";

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

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

        // 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 intercardinal direction value (0-15) from the player's Y rotation
        const direction = getIntercardinalDirection(yRotation);

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

// Register the custom component with the name "wiki:intercardinal_orientation".
system.beforeEvents.startup.subscribe(({ blockComponentRegistry }) => {
    blockComponentRegistry.registerCustomComponent(
        componentName,
        BlockIntercardinalOrientationComponent
    );
});
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

Notice that this custom component has an additional y_rotation_offset parameter? This parameter will allow us to orient the block with an offset to the player, just like the equivalent parameter in the placement direction block trait.

Without this parameter, the block would face the same direction as the player when placed, meaning the back of the block would face towards the player. By setting the parameter to 180, the front of the block (north face of the block model) will face towards the player when placed.

Let's apply the custom component to our block in its components:

BP/blocks/mug.json
json
"wiki:intercardinal_orientation": {
    "y_rotation_offset": 180 // Face towards the player
}
1
2
3

Block Model ​

Generally, the block transformation component is used to rotate blocks to match their direction, however this component only supports angles that are multiples of 90 degrees. To allow for the 22.5 degree intervals used for intercardinal rotation, your block's model will need a few extra bones.

There are four bones required for intercardinal orientation, each with different Y-axis rotations:

  • 0
  • 22.5
  • 45
  • 67.5

These rotations are in a clockwise direction when looking at the model from above.

Cardinal Bone ​

First, you need to create a bone with no rotation, where the front of the model faces north. In this tutorial, each bone will be named after its Y rotation, meaning this bone should have the name 0 as it has been rotated 0 degrees.

This is the bone that will be visible when the block is facing a cardinal direction (when wiki:intercardinal_direction is 0, 4, 8 or 12). At this stage, all cubes of your model must be direct children of this bone and cannot be contained in child bones.

Intercardinal Bones ​

Now you need to duplicate this bone three times with the remaining rotation values (22.5, 45 and 67.5). These duplicate bones are used when rotating the block to face an intercardinal direction.

TIP

You can duplicate bones in Blockbench by selecting the bone and pressing Ctrl + D.

Keep each bone's pivot point set to [0, 0, 0] so that its rotation is around the middle of the block.

For reference, here's how the final model looks for the "mug" block. Be warned, it isn't a pretty sight just yet!

Applying Block Rotation ​

Bone Visibility ​

Not all bones in your model should be visible, so we make use of the bone_visibility parameter in the geometry component to ensure that only the required bones are rendered.

Add the following component to your block:

minecraft:block > components
json
"minecraft:geometry": {
    "identifier": "geometry.mug", // Model created in previous step
    "bone_visibility": {
        "0": "math.mod(q.block_state('wiki:intercardinal_direction'), 4) == 0",
        "22.5": "math.mod(q.block_state('wiki:intercardinal_direction'), 4) == 1",
        "45": "math.mod(q.block_state('wiki:intercardinal_direction'), 4) == 2",
        "67.5": "math.mod(q.block_state('wiki:intercardinal_direction'), 4) == 3"
    }
}
1
2
3
4
5
6
7
8
9

Permutation Entries ​

Now, use the permutations array to define the rotation for the base cardinal rotations of the block by inserting the following into your block JSON (in the presented order):

minecraft:block
json
"permutations": [
    {
        "condition": "q.block_state('wiki:intercardinal_direction') >= 0",
        "components": {
            "minecraft:transformation": { "rotation": [0, 180, 0] }
        }
    },
    {
        "condition": "q.block_state('wiki:intercardinal_direction') >= 4",
        "components": {
            "minecraft:transformation": { "rotation": [0, 90, 0] }
        }
    },
    {
        "condition": "q.block_state('wiki:intercardinal_direction') >= 8",
        "components": {
            "minecraft:transformation": { "rotation": [0, 0, 0] }
        }
    },
    {
        "condition": "q.block_state('wiki:intercardinal_direction') >= 12",
        "components": {
            "minecraft:transformation": { "rotation": [0, -90, 0] }
        }
    }
]
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

Final Block JSON & Script ​

Your block JSON and script files after the above steps should look similar to those below:

Mug Example Block JSON
BP/blocks/mug.json
json
{
    "format_version": "1.26.0",
    "minecraft:block": {
        "description": {
            "identifier": "wiki:mug",
            "menu_category": {
                "category": "items"
            },
            "states": {
                "wiki:intercardinal_direction": {
                    "values": { "min": 0, "max": 15 }
                }
            }
        },
        "components": {
            // Sets the "wiki:intercardinal_direction" state to the correct value before the block is placed
            "wiki:intercardinal_orientation": {
                "y_rotation_offset": 180 // Face towards the player
            },
            // Collision and selection boxes
            "minecraft:collision_box": {
                "origin": [-3, 0, -3],
                "size": [6, 8, 6]
            },
            "minecraft:selection_box": {
                "origin": [-3, 0, -3],
                "size": [6, 8, 6]
            },
            // Visuals
            "minecraft:destruction_particles": {
                "particle_count": 48
            },
            "minecraft:geometry": {
                "identifier": "geometry.mug",
                "bone_visibility": {
                    "0": "math.mod(q.block_state('wiki:intercardinal_direction'), 4) == 0",
                    "22.5": "math.mod(q.block_state('wiki:intercardinal_direction'), 4) == 1",
                    "45": "math.mod(q.block_state('wiki:intercardinal_direction'), 4) == 2",
                    "67.5": "math.mod(q.block_state('wiki:intercardinal_direction'), 4) == 3"
                }
            },
            "minecraft:material_instances": {
                "*": { "texture": "wiki:mug" }
            }
        },
        "permutations": [
            {
                "condition": "q.block_state('wiki:intercardinal_direction') >= 0",
                "components": {
                    "minecraft:transformation": { "rotation": [0, 180, 0] }
                }
            },
            {
                "condition": "q.block_state('wiki:intercardinal_direction') >= 4",
                "components": {
                    "minecraft:transformation": { "rotation": [0, 90, 0] }
                }
            },
            {
                "condition": "q.block_state('wiki:intercardinal_direction') >= 8",
                "components": {
                    "minecraft:transformation": { "rotation": [0, 0, 0] }
                }
            },
            {
                "condition": "q.block_state('wiki:intercardinal_direction') >= 12",
                "components": {
                    "minecraft:transformation": { "rotation": [0, -90, 0] }
                }
            }
        ]
    }
}
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
Intercardinal Orientation Script
BP/scripts/intercardinalOrientation.js
js
import { system } from "@minecraft/server";

/** @param {number} yRotation */
function getIntercardinalDirection(yRotation) {
    // Converts the Y rotation into a positive angle below 360
    yRotation %= 360;
    if (yRotation < 0) yRotation += 360;

    // Returns the Y rotation as an intercardinal direction below 16
    return Math.round(yRotation / 22.5) % 16;
}

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

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

        // 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 intercardinal direction value (0-15) from the player's Y rotation
        const direction = getIntercardinalDirection(yRotation);

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

// Register the custom component with the name "wiki:intercardinal_orientation".
system.beforeEvents.startup.subscribe(({ blockComponentRegistry }) => {
    blockComponentRegistry.registerCustomComponent(
        componentName,
        BlockIntercardinalOrientationComponent
    );
});
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

Remember to import the script into your entry file!

BP/scripts/index.js
js
import "./intercardinalOrientation.js";
1

Result ​

What you have created:

  • A block model supporting intercardinal directions
  • A block with 16 supported direction state values
  • A custom component that can be used to set the direction state
Custom mug blocks in a square formation, each pointing towards the middle

Download Example Pack ​

Template pack made according to this tutorial, adding a "Mug" block into the "Items" tab of the creative menu.

Download MCADDON

Contributors

Edit Intercardinal Orientation 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