Skip to main content

Rotation class

Namespace: DoriosCore · Package: DoriosCore/index.js

Rotation applies player-facing placement and wrench rotation to DoriosCore-compatible blocks.

import { Rotation } from "DoriosCore/index.js";

Definition

class Rotation

All members are static. Do not construct this class.

Supported block states

Block statesBehavior
utilitycraft:axisSix-direction placement with facing().
utilitycraft:axis and utilitycraft:rotationFull 24-orientation wrench behavior.
minecraft:facing_directionCycles the supported vanilla facing values.
minecraft:cardinal_directionCycles north, south, east, and west.

Methods

facing(player, block, perm)

Rotation.facing(player: Player, block: Block, perm: BlockPermutation): void

Manually places perm.type.id at block.location with utilitycraft:axis based on the strongest component of the player's view direction.

ParameterTypeDescription
playerPlayerPlayer whose view determines the axis and who receives the placement sound.
blockBlockPosition and dimension where the permutation is placed.
permBlockPermutationPermutation supplying the block identifier and tags.
View directionStored axis
Vertical component is strongestup or down
Z component is stronger than Xnorth or south
Otherwiseeast or west

Placement is scheduled with system.run(). On the following scheduled callback, energy-, item-, and fluid-tagged blocks emit dorios:updatePipes so UtilityCore can refresh the corresponding network. UtilityCore, not DoriosCore, owns those networks.

Machine.spawnEntity() uses this method when the machine configuration enables rotation.

handleRotation(block, blockFace)

Rotation.handleRotation(block: Block, blockFace: DirectionName | string): void

Rotates block according to its supported states.

ParameterTypeDescription
blockBlockBlock to rotate.
blockFaceDirectionName | stringFace clicked by the wrench interaction.

The method chooses the first compatible strategy:

  1. Blocks with utilitycraft:axis and utilitycraft:rotation use rotate_24().
  2. Blocks with minecraft:facing_direction advance to the next facing value.
  3. Blocks with minecraft:cardinal_direction advance to the next cardinal value.

When no supported state exists, the block is left unchanged.

rotate_24(block, blockFace)

Rotation.rotate_24(block: Block, blockFace: DirectionName | string): void

Applies the 24-orientation mapping for a block containing both UtilityCraft states.

  • Clicking the current axis or its opposite increments utilitycraft:rotation modulo 4.
  • Clicking another face looks up the next axis and rotation in DoriosCore's orientation map.
  • An unsupported mapping leaves the permutation unchanged.

Call handleRotation() from a normal wrench component so blocks with vanilla states remain supported too.

Example: wrench component

import * as DoriosLib from "DoriosLib/index.js";
import { Rotation } from "DoriosCore/index.js";

DoriosLib.registry.itemComponent("example:example_wrench", {
onUseOn(event) {
Rotation.handleRotation(event.block, event.blockFace);
},
});

Remarks

  • The block JSON must declare every state that the selected rotation method writes.
  • facing() places the block by command on a scheduled callback; do not immediately assume the original Block reference already contains the new permutation.
  • Use addon-owned interaction code to decide which item acts as a wrench. Do not modify DoriosCore.