fix: Entity viewer in REI

This commit is contained in:
Linnea Gräf
2024-12-31 17:13:16 +01:00
parent a892a5f90b
commit 7424fe2499
2 changed files with 20 additions and 20 deletions

View File

@@ -25,24 +25,19 @@ class EntityWidget(
override fun render(context: DrawContext, mouseX: Int, mouseY: Int, delta: Float) { override fun render(context: DrawContext, mouseX: Int, mouseY: Int, delta: Float) {
try { try {
context.matrices.push()
if (!hasErrored) { if (!hasErrored) {
context.matrices.translate(point.x.toDouble(), point.y.toDouble(), 0.0)
val xScale = size.width / defaultSize.width.toDouble()
val yScale = size.height / defaultSize.height.toDouble()
context.matrices.scale(xScale.toFloat(), yScale.toFloat(), 1.0F)
EntityRenderer.renderEntity( EntityRenderer.renderEntity(
entity!!, entity!!,
context, context,
0, 0, point.x, point.y,
(mouseX - point.x) * xScale, size.width, size.height,
(mouseY - point.y) * yScale) mouseX.toDouble(),
mouseY.toDouble())
} }
} catch (ex: Exception) { } catch (ex: Exception) {
ErrorUtil.softError("Failed to render constructed entity: $entity", ex) ErrorUtil.softError("Failed to render constructed entity: $entity", ex)
hasErrored = true hasErrored = true
} finally { } finally {
context.matrices.pop()
} }
if (hasErrored) { if (hasErrored) {
context.fill(point.x, point.y, point.x + size.width.toInt(), point.y + size.height.toInt(), 0xFFAA2222.toInt()) context.fill(point.x, point.y, point.x + size.width.toInt(), point.y + size.height.toInt(), 0xFFAA2222.toInt())

View File

@@ -112,10 +112,13 @@ object EntityRenderer {
posX: Int, posX: Int,
posY: Int, posY: Int,
// TODO: Add width, height properties here // TODO: Add width, height properties here
width: Double,
height: Double,
mouseX: Double, mouseX: Double,
mouseY: Double mouseY: Double,
entityScale: Double = (height - 10.0) / 2.0
) { ) {
var bottomOffset = 0.0F var bottomOffset = 0.0
var currentEntity = entity var currentEntity = entity
val maxSize = entity.iterate { it.firstPassenger as? LivingEntity } val maxSize = entity.iterate { it.firstPassenger as? LivingEntity }
.map { it.height } .map { it.height }
@@ -126,9 +129,9 @@ object EntityRenderer {
renderContext, renderContext,
posX, posX,
posY, posY,
posX + 50, (posX + width).toInt(),
posY + 80, (posY + height).toInt(),
minOf(2F / maxSize, 1F) * 30, minOf(2F / maxSize, 1F) * entityScale,
-bottomOffset, -bottomOffset,
mouseX, mouseX,
mouseY, mouseY,
@@ -147,8 +150,8 @@ object EntityRenderer {
y1: Int, y1: Int,
x2: Int, x2: Int,
y2: Int, y2: Int,
size: Float, size: Double,
bottomOffset: Float, bottomOffset: Double,
mouseX: Double, mouseX: Double,
mouseY: Double, mouseY: Double,
entity: LivingEntity entity: LivingEntity
@@ -156,8 +159,10 @@ object EntityRenderer {
context.enableScissorWithTranslation(x1.toFloat(), y1.toFloat(), x2.toFloat(), y2.toFloat()) context.enableScissorWithTranslation(x1.toFloat(), y1.toFloat(), x2.toFloat(), y2.toFloat())
val centerX = (x1 + x2) / 2f val centerX = (x1 + x2) / 2f
val centerY = (y1 + y2) / 2f val centerY = (y1 + y2) / 2f
val targetYaw = atan(((centerX - mouseX) / 40.0f)).toFloat() val hw = (x2 - x1) / 2
val targetPitch = atan(((centerY - mouseY) / 40.0f)).toFloat() val hh = (y2 - y1) / 2
val targetYaw = atan(((centerX - mouseX) / hw)).toFloat()
val targetPitch = atan(((centerY - mouseY) / hh)).toFloat()
val rotateToFaceTheFront = Quaternionf().rotateZ(Math.PI.toFloat()) val rotateToFaceTheFront = Quaternionf().rotateZ(Math.PI.toFloat())
val rotateToFaceTheCamera = Quaternionf().rotateX(targetPitch * 20.0f * (Math.PI.toFloat() / 180)) val rotateToFaceTheCamera = Quaternionf().rotateX(targetPitch * 20.0f * (Math.PI.toFloat() / 180))
rotateToFaceTheFront.mul(rotateToFaceTheCamera) rotateToFaceTheFront.mul(rotateToFaceTheCamera)
@@ -171,12 +176,12 @@ object EntityRenderer {
entity.pitch = -targetPitch * 20.0f entity.pitch = -targetPitch * 20.0f
entity.headYaw = entity.yaw entity.headYaw = entity.yaw
entity.prevHeadYaw = entity.yaw entity.prevHeadYaw = entity.yaw
val vector3f = Vector3f(0.0f, entity.height / 2.0f + bottomOffset, 0.0f) val vector3f = Vector3f(0.0f, (entity.height / 2.0f + bottomOffset).toFloat(), 0.0f)
InventoryScreen.drawEntity( InventoryScreen.drawEntity(
context, context,
centerX, centerX,
centerY, centerY,
size, size.toFloat(),
vector3f, vector3f,
rotateToFaceTheFront, rotateToFaceTheFront,
rotateToFaceTheCamera, rotateToFaceTheCamera,