rotateWithBlockFacing
This commit is contained in:
parent
48bda405cd
commit
7dffa61bae
@ -4,14 +4,16 @@ import com.mojang.blaze3d.vertex.PoseStack
|
|||||||
import net.minecraft.client.renderer.MultiBufferSource
|
import net.minecraft.client.renderer.MultiBufferSource
|
||||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer
|
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer
|
||||||
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider
|
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.block.entity.decorative.HoloSignBlockEntity
|
||||||
import ru.dbotthepony.mc.otm.client.font
|
import ru.dbotthepony.mc.otm.client.font
|
||||||
import ru.dbotthepony.mc.otm.client.render.DynamicBufferSource
|
import ru.dbotthepony.mc.otm.client.render.DynamicBufferSource
|
||||||
import ru.dbotthepony.mc.otm.client.render.TextAlign
|
import ru.dbotthepony.mc.otm.client.render.TextAlign
|
||||||
import ru.dbotthepony.mc.otm.client.render.drawAligned
|
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.RGBAColor
|
||||||
import ru.dbotthepony.mc.otm.core.math.rotateX
|
import ru.dbotthepony.mc.otm.core.math.rotateWithBlockFacing
|
||||||
import ru.dbotthepony.mc.otm.core.math.rotateY
|
|
||||||
|
|
||||||
class HoloSignRenderer(private val context: BlockEntityRendererProvider.Context) : BlockEntityRenderer<HoloSignBlockEntity> {
|
class HoloSignRenderer(private val context: BlockEntityRendererProvider.Context) : BlockEntityRenderer<HoloSignBlockEntity> {
|
||||||
override fun render(
|
override fun render(
|
||||||
@ -23,9 +25,8 @@ class HoloSignRenderer(private val context: BlockEntityRendererProvider.Context)
|
|||||||
p_112312_: Int
|
p_112312_: Int
|
||||||
) {
|
) {
|
||||||
poseStack.pushPose()
|
poseStack.pushPose()
|
||||||
poseStack.translate(0.5f, 0.5f, -0.1f)
|
poseStack.rotateWithBlockFacing(tile.blockState[RotatableMatteryBlock.FACING_FULL], clarifyingAxis = Direction.SOUTH)
|
||||||
poseStack.rotateX(Math.PI.toFloat())
|
poseStack.translate(0.0f, 0.0f, -0.1f)
|
||||||
poseStack.rotateY(Math.PI.toFloat())
|
|
||||||
poseStack.scale(0.01f, 0.01f, 0.01f)
|
poseStack.scale(0.01f, 0.01f, 0.01f)
|
||||||
|
|
||||||
val sorse = DynamicBufferSource.WORLD
|
val sorse = DynamicBufferSource.WORLD
|
||||||
|
@ -561,6 +561,90 @@ fun PoseStack.rotateZ(rotation: Float): PoseStack {
|
|||||||
return this
|
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 {
|
fun PoseStack.rotateYDegrees(rotation: Float): PoseStack {
|
||||||
mulPose(Quaternionf(AxisAngle4f(toRadians(rotation), 0f, 1f, 0f)))
|
mulPose(Quaternionf(AxisAngle4f(toRadians(rotation), 0f, 1f, 0f)))
|
||||||
return this
|
return this
|
||||||
|
Loading…
Reference in New Issue
Block a user