Package commoble.bagofyurting.api

# Class RotationUtil

java.lang.Object
commoble.bagofyurting.api.RotationUtil

public class RotationUtil extends Object

## Field Summary

Fields
Modifier and Type
Field
Description
`static net.minecraft.core.Direction`
`BASE_DIRECTION`
SOUTH is chosen because it's the 0-indexed direction for Direction's array of the four horizontal directions

## Constructor Summary

Constructors
Constructor
Description
`RotationUtil()`

## Method Summary

Modifier and Type
Method
Description
`static net.minecraft.world.level.block.Rotation`
`getHorizontalDifferenceRotation​(net.minecraft.core.Direction from, net.minecraft.core.Direction to)`
Returns a rotation value needed to rotate from one horizontal direction to another.
`static net.minecraft.world.level.block.Rotation`
`getTransformRotation​(net.minecraft.core.Direction orientation)`
Get the rotation Bag of Yurting uses to serialize data consistently given the horizontal facing of the player when they use the bag to store blocks in the back
`static net.minecraft.world.level.block.Rotation`
`getUntransformRotation​(net.minecraft.core.Direction orientation)`
Get the rotation Bag of Yurting uses to deserialize data consistently given the horizontal facing of the player when they use the bag to unload blocks into the Level
`static net.minecraft.core.BlockPos`
`transformBlockPos​(net.minecraft.world.level.block.Rotation rotation, net.minecraft.core.BlockPos pos, net.minecraft.core.BlockPos origin)`
First, we take the offset of the block pos relative to the origin of the yurt Second, we rotate this offset around the origin's y-axis The rotation is the difference angle between the player's orientation and some constant direction The difference when we unload the yurt is reversed from the difference when we load the yurt (b-a instead of a-b) The result is that when we unload, the rotation of the yurt relative to the player is preserved some examples: player facing south both times -- no rotation player facing west both times -- first rotate 90 degrees, then -90 degrees -- no rotation player facing south first, then west first -- no rotation -- block offsets are original positions second -- rotate from SOUTH to WEST = +90 degrees a block that was originally south of the player will now be west of the player a block that was originally in front of the player will still be in front of the player player facing west first, then east first -- rotate from west to south -- -90 degrees second -- rotate from south to east -- -90 degrees all blocks will be rotated 180 degrees around the player
`static net.minecraft.core.BlockPos`
`untransformBlockPos​(net.minecraft.world.level.block.Rotation unrotation, net.minecraft.core.BlockPos offset, net.minecraft.core.BlockPos origin)`
Undoes the transformBlockPos function, converting a (relative) offset to an (absolute) origin to an absolute position in Levelspace (applying the given rotation before transforming)

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### BASE_DIRECTION

public static final net.minecraft.core.Direction BASE_DIRECTION
SOUTH is chosen because it's the 0-indexed direction for Direction's array of the four horizontal directions

## Constructor Details

### RotationUtil

public RotationUtil()

## Method Details

### getTransformRotation

public static net.minecraft.world.level.block.Rotation getTransformRotation​(net.minecraft.core.Direction orientation)
Get the rotation Bag of Yurting uses to serialize data consistently given the horizontal facing of the player when they use the bag to store blocks in the back

Parameters:
  `orientation` - The facing of the player at the time of yurting-blocks-into-bag. Must be a horizontal direction.
Returns:
  The rotation used to transform positions when serializing them

### getUntransformRotation

public static net.minecraft.world.level.block.Rotation getUntransformRotation​(net.minecraft.core.Direction orientation)
Get the rotation Bag of Yurting uses to deserialize data consistently given the horizontal facing of the player when they use the bag to unload blocks into the Level

Parameters:
  `orientation` - The facing of the player at the time of unloading-blocks-from-back. Must be a horizontal direction.
Returns:
  The rotation used to untransform positions when deserializing them

### getHorizontalDifferenceRotation

public static net.minecraft.world.level.block.Rotation getHorizontalDifferenceRotation​(net.minecraft.core.Direction from, net.minecraft.core.Direction to)
Returns a rotation value needed to rotate from one horizontal direction to another. // horizontal indices are South, West, North, East (from 0 to 3 respectively) // degrees of each Rotation enum value is enum index * 90 (clockwise)

Parameters:
  `from` - Starting direction
  `to` - Ending direction
Returns:
  Rotation needed to rotate from from to to

### transformBlockPos

public static net.minecraft.core.BlockPos transformBlockPos​(net.minecraft.world.level.block.Rotation rotation, net.minecraft.core.BlockPos pos, net.minecraft.core.BlockPos origin)
First, we take the offset of the block pos relative to the origin of the yurt Second, we rotate this offset around the origin's y-axis The rotation is the difference angle between the player's orientation and some constant direction The difference when we unload the yurt is reversed from the difference when we load the yurt (b-a instead of a-b) The result is that when we unload, the rotation of the yurt relative to the player is preserved some examples: player facing south both times -- no rotation player facing west both times -- first rotate 90 degrees, then -90 degrees -- no rotation player facing south first, then west first -- no rotation -- block offsets are original positions second -- rotate from SOUTH to WEST = +90 degrees a block that was originally south of the player will now be west of the player a block that was originally in front of the player will still be in front of the player player facing west first, then east first -- rotate from west to south -- -90 degrees second -- rotate from south to east -- -90 degrees all blocks will be rotated 180 degrees around the player

Parameters:
  `rotation` - the rotation we use to transform the block
  `pos` - The position (in absolute Levelspace) we want to transform to a rotated offset to the origin
  `origin` - the origin to rotate pos around (usually the position a bag of yurting was used on)
Returns:
  pos as a rotated relative offset to the origin pos (pos is translated first and then rotated)

### untransformBlockPos

public static net.minecraft.core.BlockPos untransformBlockPos​(net.minecraft.world.level.block.Rotation unrotation, net.minecraft.core.BlockPos offset, net.minecraft.core.BlockPos origin)
Undoes the transformBlockPos function, converting a (relative) offset to an (absolute) origin to an absolute position in Levelspace (applying the given rotation before transforming)

Parameters:
  `unrotation` - The rotation to apply to the offset
  `offset` - The relative offset to the origin pos
  `origin` - The absolute position we're rotating offset around
Returns:
  A position in absolute Levelspace, consisting of the offset rotated around the origin by the specified rotation