Implement some logic for three rotation freedom of blocks, make holo sign have three rotation freedoms
This commit is contained in:
parent
e2791add3b
commit
192144cc27
@ -31,6 +31,11 @@ private fun initialTransform(it: BlockState, modelPath: String, builder: Configu
|
||||
builder.rotationX(it.primary.toXRotBlockstate())
|
||||
}
|
||||
|
||||
it.getValueNullable(BlockRotationFreedom.THREE.property)?.let {
|
||||
builder.rotationY(it.primary.toYRotBlockstate() + (it.secondary?.toYRotBlockstate() ?: 0))
|
||||
builder.rotationX(it.primary.toXRotBlockstate())
|
||||
}
|
||||
|
||||
it.getValueNullable(WorkerState.WORKER_STATE)?.let {
|
||||
modelPath += "_" + it.name.lowercase()
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package ru.dbotthepony.mc.otm.block
|
||||
|
||||
import net.minecraft.core.Direction
|
||||
import net.minecraft.world.item.context.BlockPlaceContext
|
||||
import net.minecraft.world.level.block.Block
|
||||
import net.minecraft.world.level.block.Rotation
|
||||
@ -20,16 +21,30 @@ abstract class RotatableMatteryBlock @JvmOverloads constructor(properties: Prope
|
||||
}
|
||||
|
||||
override fun getStateForPlacement(context: BlockPlaceContext): BlockState? {
|
||||
if (rotationFreedom() == BlockRotationFreedom.ONE) {
|
||||
return defaultBlockState().setValue(
|
||||
rotationProperty,
|
||||
return when (val freedom = rotationFreedom()) {
|
||||
BlockRotationFreedom.ONE -> defaultBlockState().setValue(
|
||||
freedom.property,
|
||||
BlockRotation.of(if (faceToPlayer(context)) context.horizontalDirection.opposite else context.horizontalDirection)
|
||||
)
|
||||
} else {
|
||||
return defaultBlockState().setValue(
|
||||
rotationProperty,
|
||||
|
||||
BlockRotationFreedom.TWO -> defaultBlockState().setValue(
|
||||
freedom.property,
|
||||
BlockRotation.of(if (faceToPlayer(context)) context.nearestLookingDirection.opposite else context.nearestLookingDirection)
|
||||
)
|
||||
|
||||
BlockRotationFreedom.THREE -> {
|
||||
val primary = if (faceToPlayer(context)) context.nearestLookingDirection.opposite else context.nearestLookingDirection
|
||||
var secondary = if (faceToPlayer(context)) context.horizontalDirection else context.horizontalDirection.opposite
|
||||
|
||||
if (primary == Direction.DOWN) {
|
||||
secondary = secondary.opposite
|
||||
}
|
||||
|
||||
defaultBlockState().setValue(
|
||||
freedom.property,
|
||||
BlockRotation.ofSafe(primary, secondary)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@ import ru.dbotthepony.mc.otm.shapes.BlockShapes
|
||||
|
||||
class HoloSignBlock : RotatableMatteryBlock(), EntityBlock {
|
||||
override fun rotationFreedom(): BlockRotationFreedom {
|
||||
return BlockRotationFreedom.TWO
|
||||
return BlockRotationFreedom.THREE
|
||||
}
|
||||
|
||||
override fun newBlockEntity(p_153215_: BlockPos, p_153216_: BlockState): BlockEntity {
|
||||
|
@ -15,6 +15,7 @@ import ru.dbotthepony.mc.otm.core.get
|
||||
import ru.dbotthepony.mc.otm.core.math.RGBAColor
|
||||
import ru.dbotthepony.mc.otm.core.math.facingTwo
|
||||
import ru.dbotthepony.mc.otm.core.math.rotateWithBlockFacing
|
||||
import ru.dbotthepony.mc.otm.core.math.rotationThree
|
||||
|
||||
class HoloSignRenderer(private val context: BlockEntityRendererProvider.Context) : BlockEntityRenderer<HoloSignBlockEntity> {
|
||||
override fun render(
|
||||
@ -29,7 +30,7 @@ class HoloSignRenderer(private val context: BlockEntityRendererProvider.Context)
|
||||
return
|
||||
|
||||
poseStack.pushPose()
|
||||
poseStack.rotateWithBlockFacing(tile.blockState.facingTwo)
|
||||
poseStack.rotateWithBlockFacing(tile.blockState.rotationThree)
|
||||
poseStack.translate(0.5f, 0.5f, 0.6f)
|
||||
poseStack.scale(0.01f, 0.01f, 0.01f)
|
||||
|
||||
|
@ -24,20 +24,21 @@ operator fun BlockPos.plus(other: BlockRotation): BlockPos {
|
||||
return this + other.normal
|
||||
}
|
||||
|
||||
/**
|
||||
* [secondary] clarifies about block's top facing direction, NOT bottom
|
||||
*/
|
||||
enum class BlockRotation(val primary: Direction, val secondary: Direction?) : StringRepresentable {
|
||||
DOWN(Direction.DOWN, null),
|
||||
UP(Direction.UP, null),
|
||||
DOWN(Direction.DOWN, Direction.NORTH),
|
||||
UP(Direction.UP, Direction.NORTH),
|
||||
NORTH(Direction.NORTH, null),
|
||||
SOUTH(Direction.SOUTH, null),
|
||||
WEST(Direction.WEST, null),
|
||||
EAST(Direction.EAST, null),
|
||||
|
||||
DOWN_NORTH(Direction.DOWN, Direction.NORTH),
|
||||
DOWN_SOUTH(Direction.DOWN, Direction.SOUTH),
|
||||
DOWN_WEST(Direction.DOWN, Direction.WEST),
|
||||
DOWN_EAST(Direction.DOWN, Direction.EAST),
|
||||
|
||||
UP_NORTH(Direction.UP, Direction.NORTH),
|
||||
UP_SOUTH(Direction.UP, Direction.SOUTH),
|
||||
UP_WEST(Direction.UP, Direction.WEST),
|
||||
UP_EAST(Direction.UP, Direction.EAST);
|
||||
@ -113,7 +114,6 @@ enum class BlockRotation(val primary: Direction, val secondary: Direction?) : St
|
||||
Direction.UP -> {
|
||||
when (secondary) {
|
||||
null -> UP
|
||||
Direction.NORTH -> UP_NORTH
|
||||
Direction.SOUTH -> UP_SOUTH
|
||||
Direction.WEST -> UP_WEST
|
||||
Direction.EAST -> UP_EAST
|
||||
@ -124,7 +124,6 @@ enum class BlockRotation(val primary: Direction, val secondary: Direction?) : St
|
||||
Direction.DOWN -> {
|
||||
when (secondary) {
|
||||
null -> DOWN
|
||||
Direction.NORTH -> DOWN_NORTH
|
||||
Direction.SOUTH -> DOWN_SOUTH
|
||||
Direction.WEST -> DOWN_WEST
|
||||
Direction.EAST -> DOWN_EAST
|
||||
@ -133,5 +132,33 @@ enum class BlockRotation(val primary: Direction, val secondary: Direction?) : St
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun ofSafe(primary: Direction, secondary: Direction?): BlockRotation {
|
||||
return when (primary) {
|
||||
Direction.NORTH -> NORTH
|
||||
Direction.SOUTH -> SOUTH
|
||||
Direction.WEST -> WEST
|
||||
Direction.EAST -> EAST
|
||||
|
||||
Direction.UP -> {
|
||||
when (secondary) {
|
||||
Direction.SOUTH -> UP_SOUTH
|
||||
Direction.WEST -> UP_WEST
|
||||
Direction.EAST -> UP_EAST
|
||||
else -> UP
|
||||
}
|
||||
}
|
||||
|
||||
Direction.DOWN -> {
|
||||
when (secondary) {
|
||||
Direction.SOUTH -> DOWN_SOUTH
|
||||
Direction.WEST -> DOWN_WEST
|
||||
Direction.EAST -> DOWN_EAST
|
||||
else -> DOWN
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -35,11 +35,9 @@ enum class BlockRotationFreedom(vararg values: BlockRotation) {
|
||||
BlockRotation.SOUTH,
|
||||
BlockRotation.WEST,
|
||||
BlockRotation.EAST,
|
||||
BlockRotation.DOWN_NORTH,
|
||||
BlockRotation.DOWN_SOUTH,
|
||||
BlockRotation.DOWN_WEST,
|
||||
BlockRotation.DOWN_EAST,
|
||||
BlockRotation.UP_NORTH,
|
||||
BlockRotation.UP_SOUTH,
|
||||
BlockRotation.UP_WEST,
|
||||
BlockRotation.UP_EAST,
|
||||
|
@ -647,6 +647,10 @@ fun PoseStack.rotateWithBlockFacing(rotation: Direction, clarifyingAxis: Directi
|
||||
return this
|
||||
}
|
||||
|
||||
fun PoseStack.rotateWithBlockFacing(rotation: BlockRotation): PoseStack {
|
||||
return rotateWithBlockFacing(rotation = rotation.primary, clarifyingAxis = rotation.secondary)
|
||||
}
|
||||
|
||||
fun PoseStack.rotateYDegrees(rotation: Float): PoseStack {
|
||||
mulPose(Quaternionf(AxisAngle4f(toRadians(rotation), 0f, 1f, 0f)))
|
||||
return this
|
||||
|
Loading…
Reference in New Issue
Block a user