diff --git a/li/cil/oc/Config.scala b/li/cil/oc/Config.scala index e3d7e6821..9919d4452 100644 --- a/li/cil/oc/Config.scala +++ b/li/cil/oc/Config.scala @@ -32,7 +32,7 @@ object Config { var timeout = 3.0 var maxScreenTextRenderDistance = 10.0 - var screenTextFadeStartDistance = 4.0 + var screenTextFadeStartDistance = 8.0 // ----------------------------------------------------------------------- // diff --git a/li/cil/oc/client/renderer/tileentity/ScreenRenderer.scala b/li/cil/oc/client/renderer/tileentity/ScreenRenderer.scala index a39ecd3d7..d0e1e2dc3 100644 --- a/li/cil/oc/client/renderer/tileentity/ScreenRenderer.scala +++ b/li/cil/oc/client/renderer/tileentity/ScreenRenderer.scala @@ -16,11 +16,11 @@ import net.minecraftforge.common.ForgeDirection import org.lwjgl.opengl.{GLContext, GL14, GL11} object ScreenRenderer extends TileEntitySpecialRenderer with Callable[Int] with RemovalListener[TileEntity, Int] with ITickHandler { - private val maxRenderDistanceSq = (Config.maxScreenTextRenderDistance * Config.maxScreenTextRenderDistance).toFloat + private val maxRenderDistanceSq = Config.maxScreenTextRenderDistance * Config.maxScreenTextRenderDistance - private val fadeDistanceSq = (Config.screenTextFadeStartDistance * Config.screenTextFadeStartDistance).toFloat + private val fadeDistanceSq = Config.screenTextFadeStartDistance * Config.screenTextFadeStartDistance - private val fadeRatio = 1f / (maxRenderDistanceSq - fadeDistanceSq) + private val fadeRatio = 1.0 / (maxRenderDistanceSq - fadeDistanceSq) private val canFade = GLContext.getCapabilities.OpenGL14 @@ -43,9 +43,8 @@ object ScreenRenderer extends TileEntitySpecialRenderer with Callable[Int] with if (!screen.isOrigin) return - val player = Minecraft.getMinecraft.thePlayer - val playerDistance = player.getDistanceSq(t.xCoord + 0.5, t.yCoord + 0.5, t.zCoord + 0.5).toFloat - if (playerDistance > maxRenderDistanceSq) + val distance = playerDistanceSq() + if (distance > maxRenderDistanceSq) return // Crude check whether screen text can be seen by the local player based @@ -63,9 +62,9 @@ object ScreenRenderer extends TileEntitySpecialRenderer with Callable[Int] with GL11.glTranslated(x + 0.5, y + 0.5, z + 0.5) - if (canFade && playerDistance > fadeDistanceSq) { - val fade = 1f min ((playerDistance - fadeDistanceSq) * fadeRatio) - GL14.glBlendColor(0, 0, 0, 1 - fade) + if (canFade && distance > fadeDistanceSq) { + val fade = 1.0 min ((distance - fadeDistanceSq) * fadeRatio) + GL14.glBlendColor(0, 0, 0, 1 - fade.toFloat) GL11.glBlendFunc(GL11.GL_CONSTANT_ALPHA, GL11.GL_ONE) } @@ -128,6 +127,45 @@ object ScreenRenderer extends TileEntitySpecialRenderer with Callable[Int] with GL11.glEndList() } + private def playerDistanceSq() = { + val player = Minecraft.getMinecraft.thePlayer + val rect = screen.getRenderBoundingBox + + val px = player.posX + val py = player.posY + val pz = player.posZ + + val ex = rect.maxX - rect.minX + val ey = rect.maxY - rect.minY + val ez = rect.maxZ - rect.minZ + val cx = rect.minX + ex * 0.5 + val cy = rect.minY + ey * 0.5 + val cz = rect.minZ + ez * 0.5 + val dx = px - cx + val dy = py - cy + val dz = pz - cz + + (if (dx < -ex) { + val d = dx + ex; d * d + } + else if (dx > ex) { + val d = dx - ex; d * d + } + else 0) + (if (dy < -ey) { + val d = dy + ey; d * d + } + else if (dy > ey) { + val d = dy - ey; d * d + } + else 0) + (if (dz < -ez) { + val d = dz + ez; d * d + } + else if (dz > ez) { + val d = dz - ez; d * d + } + else 0) + } + // ----------------------------------------------------------------------- // // Cache // ----------------------------------------------------------------------- // diff --git a/li/cil/oc/common/tileentity/Screen.scala b/li/cil/oc/common/tileentity/Screen.scala index 82cde14fe..43fa70474 100644 --- a/li/cil/oc/common/tileentity/Screen.scala +++ b/li/cil/oc/common/tileentity/Screen.scala @@ -161,7 +161,10 @@ class Screen extends Rotatable with component.Screen.Environment with Receiver { val ox = xCoord + (if (sx < 0) 1 else 0) val oy = yCoord + (if (sy < 0) 1 else 0) val oz = zCoord + (if (sz < 0) 1 else 0) - AxisAlignedBB.getAABBPool.getAABB(ox, oy, oz, ox + sx, oy + sy, oz + sz) + val b = AxisAlignedBB.getAABBPool.getAABB(ox, oy, oz, ox + sx, oy + sy, oz + sz) + b.setBounds(b.minX min b.maxX, b.minY min b.maxY, b.minZ min b.maxZ, + b.minX max b.maxX, b.minY max b.maxY, b.minZ max b.maxZ) + b } // ----------------------------------------------------------------------- //