diff options
author | Linnea Gräf <nea@nea.moe> | 2024-12-31 17:13:16 +0100 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-12-31 17:13:16 +0100 |
commit | 7424fe24993c3697a51c28b4a861c9c9174d8181 (patch) | |
tree | 0dfc8d4ee6cd57024039ae7cd4c6f31247925d28 /src | |
parent | a892a5f90b87b530331a7652dd4eb5bc07bf1c03 (diff) | |
download | Firmament-7424fe24993c3697a51c28b4a861c9c9174d8181.tar.gz Firmament-7424fe24993c3697a51c28b4a861c9c9174d8181.tar.bz2 Firmament-7424fe24993c3697a51c28b4a861c9c9174d8181.zip |
fix: Entity viewer in REI
Diffstat (limited to 'src')
-rw-r--r-- | src/compat/rei/java/moe/nea/firmament/compat/rei/EntityWidget.kt | 13 | ||||
-rw-r--r-- | src/main/kotlin/gui/entity/EntityRenderer.kt | 27 |
2 files changed, 20 insertions, 20 deletions
diff --git a/src/compat/rei/java/moe/nea/firmament/compat/rei/EntityWidget.kt b/src/compat/rei/java/moe/nea/firmament/compat/rei/EntityWidget.kt index 2b9e4bf..1097654 100644 --- a/src/compat/rei/java/moe/nea/firmament/compat/rei/EntityWidget.kt +++ b/src/compat/rei/java/moe/nea/firmament/compat/rei/EntityWidget.kt @@ -25,24 +25,19 @@ class EntityWidget( override fun render(context: DrawContext, mouseX: Int, mouseY: Int, delta: Float) { try { - context.matrices.push() 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( entity!!, context, - 0, 0, - (mouseX - point.x) * xScale, - (mouseY - point.y) * yScale) + point.x, point.y, + size.width, size.height, + mouseX.toDouble(), + mouseY.toDouble()) } } catch (ex: Exception) { ErrorUtil.softError("Failed to render constructed entity: $entity", ex) hasErrored = true } finally { - context.matrices.pop() } if (hasErrored) { context.fill(point.x, point.y, point.x + size.width.toInt(), point.y + size.height.toInt(), 0xFFAA2222.toInt()) diff --git a/src/main/kotlin/gui/entity/EntityRenderer.kt b/src/main/kotlin/gui/entity/EntityRenderer.kt index 9a09fc6..fd7a0c4 100644 --- a/src/main/kotlin/gui/entity/EntityRenderer.kt +++ b/src/main/kotlin/gui/entity/EntityRenderer.kt @@ -112,10 +112,13 @@ object EntityRenderer { posX: Int, posY: Int, // TODO: Add width, height properties here + width: Double, + height: 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 val maxSize = entity.iterate { it.firstPassenger as? LivingEntity } .map { it.height } @@ -126,9 +129,9 @@ object EntityRenderer { renderContext, posX, posY, - posX + 50, - posY + 80, - minOf(2F / maxSize, 1F) * 30, + (posX + width).toInt(), + (posY + height).toInt(), + minOf(2F / maxSize, 1F) * entityScale, -bottomOffset, mouseX, mouseY, @@ -147,8 +150,8 @@ object EntityRenderer { y1: Int, x2: Int, y2: Int, - size: Float, - bottomOffset: Float, + size: Double, + bottomOffset: Double, mouseX: Double, mouseY: Double, entity: LivingEntity @@ -156,8 +159,10 @@ object EntityRenderer { context.enableScissorWithTranslation(x1.toFloat(), y1.toFloat(), x2.toFloat(), y2.toFloat()) val centerX = (x1 + x2) / 2f val centerY = (y1 + y2) / 2f - val targetYaw = atan(((centerX - mouseX) / 40.0f)).toFloat() - val targetPitch = atan(((centerY - mouseY) / 40.0f)).toFloat() + val hw = (x2 - x1) / 2 + 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 rotateToFaceTheCamera = Quaternionf().rotateX(targetPitch * 20.0f * (Math.PI.toFloat() / 180)) rotateToFaceTheFront.mul(rotateToFaceTheCamera) @@ -171,12 +176,12 @@ object EntityRenderer { entity.pitch = -targetPitch * 20.0f entity.headYaw = 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( context, centerX, centerY, - size, + size.toFloat(), vector3f, rotateToFaceTheFront, rotateToFaceTheCamera, |