Skip to content

Commit

Permalink
only render the text labels closer than 16 blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexdoru committed Nov 28, 2024
1 parent 4b44984 commit eed6ed5
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,12 @@ object VisualiserOverlayRender extends WorldOverlayRenderer {
VisualisationModes.P2P
)

override def doRender(partialTicks: Float): Unit = {
override def doRender(
partialTicks: Float,
viewX: Double,
viewY: Double,
viewZ: Double
): Unit = {
val stack = Client.player.inventory.getCurrentItem
if (
!(stack != null && stack.getItem == ItemVisualiser && stack.hasTagCompound) || !stack.getTagCompound
Expand Down Expand Up @@ -277,13 +282,20 @@ object VisualiserOverlayRender extends WorldOverlayRenderer {

if (mode == VisualisationModes.FULL) {
for (link <- currentLinks.links if link.channels > 0) {
OverlayRenderHandler.renderFloatingText(
link.channels.toString,
(link.node1.x + link.node2.x) / 2d + 0.5d,
(link.node1.y + link.node2.y) / 2d + 0.5d,
(link.node1.z + link.node2.z) / 2d + 0.5d,
0xffffff
)
val linkX = (link.node1.x + link.node2.x) / 2d + 0.5d
val linkY = (link.node1.y + link.node2.y) / 2d + 0.5d
val linkZ = (link.node1.z + link.node2.z) / 2d + 0.5d
val distSq =
(viewX - linkX) * (viewX - linkX) + (viewY - linkY) * (viewY - linkY) + (viewZ - linkZ) * (viewZ - linkZ)
if (distSq < 256d) { // 16 blocks
OverlayRenderHandler.renderFloatingText(
link.channels.toString,
linkX,
linkY,
linkZ,
0xffffff
)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ import net.minecraft.util.MovingObjectPosition
import org.lwjgl.opengl.GL11

object WirelessOverlayRender extends WorldOverlayRenderer {
override def doRender(partialTicks: Float): Unit = {
override def doRender(
partialTicks: Float,
viewX: Double,
viewY: Double,
viewZ: Double
): Unit = {
val mop = Client.minecraft.objectMouseOver
if (
mop != null && mop.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK
Expand Down
27 changes: 17 additions & 10 deletions src/main/scala/net/bdew/ae2stuff/misc/OverlayRenderHandler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,20 @@ package net.bdew.ae2stuff.misc
import cpw.mods.fml.common.eventhandler.SubscribeEvent
import net.bdew.ae2stuff.AE2Stuff
import net.bdew.lib.Client
import net.minecraft.client.Minecraft
import net.minecraft.client.renderer.Tessellator
import net.minecraft.client.renderer.entity.RenderManager
import net.minecraftforge.client.event.RenderWorldLastEvent
import net.minecraftforge.common.MinecraftForge
import org.lwjgl.opengl.GL11

trait WorldOverlayRenderer {
def doRender(partialTicks: Float): Unit
def doRender(
partialTicks: Float,
viewX: Double,
viewY: Double,
viewZ: Double
): Unit
}

object OverlayRenderHandler {
Expand All @@ -30,17 +36,17 @@ object OverlayRenderHandler {

@SubscribeEvent
def onRenderWorldLastEvent(ev: RenderWorldLastEvent): Unit = {
val p = Client.player
val dx = p.lastTickPosX + (p.posX - p.lastTickPosX) * ev.partialTicks
val dy = p.lastTickPosY + (p.posY - p.lastTickPosY) * ev.partialTicks
val dz = p.lastTickPosZ + (p.posZ - p.lastTickPosZ) * ev.partialTicks
val p = Minecraft.getMinecraft.renderViewEntity
val viewX = p.lastTickPosX + (p.posX - p.lastTickPosX) * ev.partialTicks
val viewY = p.lastTickPosY + (p.posY - p.lastTickPosY) * ev.partialTicks
val viewZ = p.lastTickPosZ + (p.posZ - p.lastTickPosZ) * ev.partialTicks

GL11.glPushMatrix()
GL11.glTranslated(-dx, -dy, -dz)
GL11.glTranslated(-viewX, -viewY, -viewZ)

for (renderer <- renderers) {
try {
renderer.doRender(ev.partialTicks)
renderer.doRender(ev.partialTicks, viewX, viewY, viewZ)
} catch {
case t: Throwable =>
AE2Stuff.logErrorException(
Expand Down Expand Up @@ -83,7 +89,8 @@ object OverlayRenderHandler {

GL11.glDisable(GL11.GL_TEXTURE_2D)
tessellator.startDrawingQuads()
val stringMiddle = fontRenderer.getStringWidth(text) / 2
val textWidth = fontRenderer.getStringWidth(text)
val stringMiddle = textWidth / 2
tessellator.setColorRGBA_F(0.0f, 0.0f, 0.0f, 0.5f)
tessellator.addVertex(-stringMiddle - 1, -1 + yOffset, 0.0d)
tessellator.addVertex(-stringMiddle - 1, 8 + yOffset, 0.0d)
Expand All @@ -94,15 +101,15 @@ object OverlayRenderHandler {
GL11.glColor4f(1f, 1f, 1f, 0.5f)
fontRenderer.drawString(
text,
-fontRenderer.getStringWidth(text) / 2,
-textWidth / 2,
yOffset,
color
)
GL11.glEnable(GL11.GL_DEPTH_TEST)
GL11.glDepthMask(true)
fontRenderer.drawString(
text,
-fontRenderer.getStringWidth(text) / 2,
-textWidth / 2,
yOffset,
color
)
Expand Down

0 comments on commit eed6ed5

Please sign in to comment.