rotateWithBlockFacing

This commit is contained in:
DBotThePony 2023-01-24 12:09:37 +07:00
parent 48bda405cd
commit 7dffa61bae
Signed by: DBot
GPG Key ID: DCC23B5715498507
2 changed files with 90 additions and 5 deletions

View File

@ -4,14 +4,16 @@ import com.mojang.blaze3d.vertex.PoseStack
import net.minecraft.client.renderer.MultiBufferSource
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider
import net.minecraft.core.Direction
import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock
import ru.dbotthepony.mc.otm.block.entity.decorative.HoloSignBlockEntity
import ru.dbotthepony.mc.otm.client.font
import ru.dbotthepony.mc.otm.client.render.DynamicBufferSource
import ru.dbotthepony.mc.otm.client.render.TextAlign
import ru.dbotthepony.mc.otm.client.render.drawAligned
import ru.dbotthepony.mc.otm.core.get
import ru.dbotthepony.mc.otm.core.math.RGBAColor
import ru.dbotthepony.mc.otm.core.math.rotateX
import ru.dbotthepony.mc.otm.core.math.rotateY
import ru.dbotthepony.mc.otm.core.math.rotateWithBlockFacing
class HoloSignRenderer(private val context: BlockEntityRendererProvider.Context) : BlockEntityRenderer<HoloSignBlockEntity> {
override fun render(
@ -23,9 +25,8 @@ class HoloSignRenderer(private val context: BlockEntityRendererProvider.Context)
p_112312_: Int
) {
poseStack.pushPose()
poseStack.translate(0.5f, 0.5f, -0.1f)
poseStack.rotateX(Math.PI.toFloat())
poseStack.rotateY(Math.PI.toFloat())
poseStack.rotateWithBlockFacing(tile.blockState[RotatableMatteryBlock.FACING_FULL], clarifyingAxis = Direction.SOUTH)
poseStack.translate(0.0f, 0.0f, -0.1f)
poseStack.scale(0.01f, 0.01f, 0.01f)
val sorse = DynamicBufferSource.WORLD

View File

@ -561,6 +561,90 @@ fun PoseStack.rotateZ(rotation: Float): PoseStack {
return this
}
const val PIf = 3.1415927f
/**
* aligns 0,0 with top left point of block corner when looking directly at it,
* and swaps Y to +Y when going down and -Y when going up
*/
fun PoseStack.rotateWithBlockFacing(rotation: Direction, clarifyingAxis: Direction? = null): PoseStack {
when (rotation) {
Direction.NORTH -> {
rotateX(PIf)
rotateY(PIf)
translate(-1f, -1f, 0f)
}
Direction.EAST -> {
rotateX(PIf)
rotateY(PIf / -2f)
translate(-1f, -1f, -1f)
}
Direction.WEST -> {
rotateX(PIf)
rotateY(PIf / 2f)
translate(0f, -1f, 0f)
}
Direction.UP -> {
rotateX(PIf / 2f)
translate(0f, 0f, -1f)
if (clarifyingAxis != null) {
when (clarifyingAxis) {
Direction.NORTH -> {}
Direction.SOUTH -> {
rotateZ(PIf)
translate(-1f, -1f, 0f)
}
Direction.WEST -> {
rotateZ(PIf / -2f)
translate(-1f, 0f, 0f)
}
Direction.EAST -> {
rotateZ(PIf / 2f)
translate(0f, -1f, 0f)
}
else -> {}
}
}
}
Direction.DOWN -> {
rotateY(PIf)
rotateX(PIf / -2f)
translate(-1f, 0f, 0f)
if (clarifyingAxis != null) {
when (clarifyingAxis) {
Direction.NORTH -> {}
Direction.SOUTH -> {
rotateZ(PIf)
translate(-1f, -1f, 0f)
}
Direction.WEST -> {
rotateZ(PIf / 2f)
translate(0f, -1f, 0f)
}
Direction.EAST -> {
rotateZ(PIf / -2f)
translate(-1f, 0f, 0f)
}
else -> {}
}
}
}
Direction.SOUTH -> {
rotateX(PIf)
translate(0f, -1f, -1f)
}
}
return this
}
fun PoseStack.rotateYDegrees(rotation: Float): PoseStack {
mulPose(Quaternionf(AxisAngle4f(toRadians(rotation), 0f, 1f, 0f)))
return this