diff options
author | ingle <inglettronald@gmail.com> | 2022-10-15 11:18:19 -0500 |
---|---|---|
committer | ingle <inglettronald@gmail.com> | 2022-10-15 11:18:19 -0500 |
commit | d2eb0ada9182f9cd507cd32b74cb72f62355acaa (patch) | |
tree | 5f9378e9f066f62b777bc7e8c308f7c9ac1f9b7c /src/main/kotlin/dulkirmod/utils | |
parent | bb0a6799a67e3bed3f78948b2dc5711c668e1c4f (diff) | |
download | DulkirMod-d2eb0ada9182f9cd507cd32b74cb72f62355acaa.tar.gz DulkirMod-d2eb0ada9182f9cd507cd32b74cb72f62355acaa.tar.bz2 DulkirMod-d2eb0ada9182f9cd507cd32b74cb72f62355acaa.zip |
+ moar bestiary stuff and added WorldRenderUtils
Diffstat (limited to 'src/main/kotlin/dulkirmod/utils')
-rw-r--r-- | src/main/kotlin/dulkirmod/utils/TablistUtils.kt | 38 | ||||
-rw-r--r-- | src/main/kotlin/dulkirmod/utils/WorldRenderUtils.kt | 71 |
2 files changed, 109 insertions, 0 deletions
diff --git a/src/main/kotlin/dulkirmod/utils/TablistUtils.kt b/src/main/kotlin/dulkirmod/utils/TablistUtils.kt new file mode 100644 index 0000000..57cb289 --- /dev/null +++ b/src/main/kotlin/dulkirmod/utils/TablistUtils.kt @@ -0,0 +1,38 @@ +package dulkirmod.utils + +import com.google.common.collect.ComparisonChain +import com.google.common.collect.Ordering +import dulkirmod.DulkirMod.Companion.mc +import net.minecraft.client.network.NetworkPlayerInfo +import net.minecraft.world.WorldSettings + +val NetworkPlayerInfo.text: String + get() = mc.ingameGUI.tabList.getPlayerName(this) + +// STOLEN FROM SKYTILS mmm yes +object TabListUtils { + private val playerInfoOrdering = object : Ordering<NetworkPlayerInfo>() { + override fun compare(p_compare_1_: NetworkPlayerInfo?, p_compare_2_: NetworkPlayerInfo?): Int { + val scorePlayerTeam = p_compare_1_?.playerTeam + val scorePlayerTeam1 = p_compare_2_?.playerTeam + if (p_compare_1_ != null) { + if (p_compare_2_ != null) { + return ComparisonChain.start().compareTrueFirst( + p_compare_1_.gameType != WorldSettings.GameType.SPECTATOR, + p_compare_2_.gameType != WorldSettings.GameType.SPECTATOR + ).compare( + if (scorePlayerTeam != null) scorePlayerTeam.registeredName else "", + if (scorePlayerTeam1 != null) scorePlayerTeam1.registeredName else "" + ).compare(p_compare_1_.gameProfile.name, p_compare_2_.gameProfile.name).result() + } + return 0 + } + return -1 + } + } + var tabEntries: List<Pair<NetworkPlayerInfo, String>> = emptyList() + fun fetchTabEntires(): List<NetworkPlayerInfo> = + if (mc.thePlayer == null) emptyList() else playerInfoOrdering.sortedCopy( + mc.thePlayer.sendQueue.playerInfoMap + ) +}
\ No newline at end of file diff --git a/src/main/kotlin/dulkirmod/utils/WorldRenderUtils.kt b/src/main/kotlin/dulkirmod/utils/WorldRenderUtils.kt new file mode 100644 index 0000000..b214555 --- /dev/null +++ b/src/main/kotlin/dulkirmod/utils/WorldRenderUtils.kt @@ -0,0 +1,71 @@ +package dulkirmod.utils + +import dulkirmod.DulkirMod.Companion.mc +import net.minecraft.client.renderer.GlStateManager +import net.minecraft.client.renderer.GlStateManager.disableTexture2D +import net.minecraft.client.renderer.GlStateManager.enableTexture2D +import net.minecraft.client.renderer.Tessellator +import net.minecraft.client.renderer.vertex.DefaultVertexFormats +import net.minecraft.util.Vec3 +import org.lwjgl.opengl.GL11 + + +class WorldRenderUtils { + + companion object { + fun render(location: Vec3, text: String, depthTest: Boolean = true, scale: Float = 1f, shadow: Boolean = false, renderBlackBox: Boolean = true) { + if (!depthTest) { + GL11.glDisable(GL11.GL_DEPTH_TEST) + GL11.glDepthMask(false) + } + GlStateManager.pushMatrix() + GlStateManager.enableBlend() + GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0) + GlStateManager.translate( + location.xCoord - mc.renderManager.viewerPosX, + location.yCoord - mc.renderManager.viewerPosY, + location.zCoord - mc.renderManager.viewerPosZ + ) + GlStateManager.color(1f, 1f, 1f, 0.5f) + GlStateManager.rotate(-mc.renderManager.playerViewY, 0.0f, 1.0f, 0.0f) + GlStateManager.rotate(mc.renderManager.playerViewX, 1.0f, 0.0f, 0.0f) + GlStateManager.scale(-scale / 25, -scale / 25, scale / 25) + + if (renderBlackBox) { + val j = mc.fontRendererObj.getStringWidth(text) / 2 + disableTexture2D() + val worldRenderer = Tessellator.getInstance().worldRenderer + worldRenderer.begin(7, DefaultVertexFormats.POSITION_COLOR) + worldRenderer.pos((-j - 1).toDouble(), (-1).toDouble(), 0.0).color(0.0f, 0.0f, 0.0f, 0.25f).endVertex() + worldRenderer.pos((-j - 1).toDouble(), 8.toDouble(), 0.0).color(0.0f, 0.0f, 0.0f, 0.25f).endVertex() + worldRenderer.pos((j + 1).toDouble(), 8.toDouble(), 0.0).color(0.0f, 0.0f, 0.0f, 0.25f).endVertex() + worldRenderer.pos((j + 1).toDouble(), (-1).toDouble(), 0.0).color(0.0f, 0.0f, 0.0f, 0.25f).endVertex() + Tessellator.getInstance().draw() + enableTexture2D() + } + + if (shadow) { + mc.fontRendererObj.drawStringWithShadow( + text, + -mc.fontRendererObj.getStringWidth(text) / 2f, + 0f, + 0 + ) + } else { + mc.fontRendererObj.drawString( + text, + -mc.fontRendererObj.getStringWidth(text) / 2, + 0, + 0 + ) + } + GlStateManager.color(1f, 1f, 1f) + GlStateManager.disableBlend() + GlStateManager.popMatrix() + if (!depthTest) { + GL11.glEnable(GL11.GL_DEPTH_TEST) + GL11.glDepthMask(true) + } + } + } +}
\ No newline at end of file |