aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/com
diff options
context:
space:
mode:
authoringlettronald <inglettronald@gmail.com>2023-07-03 20:48:53 -0500
committeringlettronald <inglettronald@gmail.com>2023-07-03 20:48:53 -0500
commit6d75d450d54a6dbdc6072148d32a6221c44af400 (patch)
treeb10dcae9df6e2eccca6c855ddb8ec5251951a05e /src/main/kotlin/com
parent58b0f74fd9747002f734a025862b64f236534bd1 (diff)
downloadDulkirMod-Fabric-6d75d450d54a6dbdc6072148d32a6221c44af400.tar.gz
DulkirMod-Fabric-6d75d450d54a6dbdc6072148d32a6221c44af400.tar.bz2
DulkirMod-Fabric-6d75d450d54a6dbdc6072148d32a6221c44af400.zip
wip
Diffstat (limited to 'src/main/kotlin/com')
-rw-r--r--src/main/kotlin/com/dulkirfabric/Registrations.kt2
-rw-r--r--src/main/kotlin/com/dulkirfabric/features/RenderBoxTest.kt26
-rw-r--r--src/main/kotlin/com/dulkirfabric/features/RenderTest.kt22
-rw-r--r--src/main/kotlin/com/dulkirfabric/util/WorldRenderUtils.kt78
4 files changed, 76 insertions, 52 deletions
diff --git a/src/main/kotlin/com/dulkirfabric/Registrations.kt b/src/main/kotlin/com/dulkirfabric/Registrations.kt
index 59ba213..0bb39e2 100644
--- a/src/main/kotlin/com/dulkirfabric/Registrations.kt
+++ b/src/main/kotlin/com/dulkirfabric/Registrations.kt
@@ -51,7 +51,7 @@ object Registrations {
fun registerEventListeners() {
EVENT_BUS.subscribe(DulkirModFabric)
EVENT_BUS.subscribe(KeyShortCutImpl)
- EVENT_BUS.subscribe(RenderBoxTest)
+ EVENT_BUS.subscribe(RenderTest)
EVENT_BUS.subscribe(TooltipImpl)
EVENT_BUS.subscribe(CustomBlockOutline)
EVENT_BUS.subscribe(AbiPhoneDND)
diff --git a/src/main/kotlin/com/dulkirfabric/features/RenderBoxTest.kt b/src/main/kotlin/com/dulkirfabric/features/RenderBoxTest.kt
deleted file mode 100644
index ea05247..0000000
--- a/src/main/kotlin/com/dulkirfabric/features/RenderBoxTest.kt
+++ /dev/null
@@ -1,26 +0,0 @@
-package com.dulkirfabric.features
-
-import com.dulkirfabric.events.WorldRenderLastEvent
-import com.dulkirfabric.util.WorldRenderUtils
-import meteordevelopment.orbit.EventHandler
-import net.minecraft.text.Text
-import net.minecraft.util.math.Box
-import net.minecraft.util.math.Vec3d
-import java.awt.Color
-
-object RenderBoxTest {
-
- @EventHandler
- fun onRender(event: WorldRenderLastEvent) {
-
- WorldRenderUtils.drawBox(
- event.context, Box(-183.0, 78.0, -465.0, -182.0, 79.0, -464.0),
- Color(255, 100, 150, 255), 10f, false
- )
-
- WorldRenderUtils.renderTextWithDistance(Text.literal("Hello worldgpqy"), event.context, event.context.consumers()!!,
- Vec3d(2.0, 0.0, 0.0), false,
- depthTest = false
- )
- }
-} \ No newline at end of file
diff --git a/src/main/kotlin/com/dulkirfabric/features/RenderTest.kt b/src/main/kotlin/com/dulkirfabric/features/RenderTest.kt
new file mode 100644
index 0000000..7def54c
--- /dev/null
+++ b/src/main/kotlin/com/dulkirfabric/features/RenderTest.kt
@@ -0,0 +1,22 @@
+package com.dulkirfabric.features
+
+import com.dulkirfabric.events.WorldRenderLastEvent
+import com.dulkirfabric.util.WorldRenderUtils
+import meteordevelopment.orbit.EventHandler
+import net.minecraft.text.Style
+import net.minecraft.text.Text
+import net.minecraft.util.math.Vec3d
+import java.awt.Color
+
+object RenderTest {
+
+ @EventHandler
+ fun onRender(event: WorldRenderLastEvent) {
+
+ WorldRenderUtils.renderWaypoint(
+ Text.literal("Home Base").setStyle(Style.EMPTY.withColor(Color(255, 100, 150, 255).rgb)), event.context, event.context.consumers()!!,
+ Vec3d(-183.5, 79.0, -465.5), false,
+ depthTest = false
+ )
+ }
+} \ No newline at end of file
diff --git a/src/main/kotlin/com/dulkirfabric/util/WorldRenderUtils.kt b/src/main/kotlin/com/dulkirfabric/util/WorldRenderUtils.kt
index 89648c5..41c28e3 100644
--- a/src/main/kotlin/com/dulkirfabric/util/WorldRenderUtils.kt
+++ b/src/main/kotlin/com/dulkirfabric/util/WorldRenderUtils.kt
@@ -15,10 +15,28 @@ import org.joml.Vector3f
import java.awt.Color
import kotlin.math.max
import kotlin.math.pow
+import kotlin.math.sqrt
object WorldRenderUtils {
+ var NO_DEPTH_LAYER: RenderLayer = RenderLayer.of(
+ "clientcommands_no_depth",
+ VertexFormats.LINES,
+ VertexFormat.DrawMode.LINES,
+ 256,
+ true,
+ true,
+ RenderLayer.MultiPhaseParameters.builder()
+ .program(RenderLayer.LINES_PROGRAM)
+ .writeMaskState(RenderLayer.COLOR_MASK)
+ .cull(RenderLayer.DISABLE_CULLING)
+ .depthTest(RenderLayer.ALWAYS_DEPTH_TEST)
+ .layering(RenderLayer.VIEW_OFFSET_Z_LAYERING)
+ .lineWidth(LineWidth(OptionalDouble.of(2.0)))
+ .build(true)
+ )
+
private fun line(
matrix: MatrixStack.Entry, buffer: BufferBuilder,
x1: Number, y1: Number, z1: Number,
@@ -202,12 +220,13 @@ object WorldRenderUtils {
matrices.pop()
}
- fun renderText(string: Text,
- context: WorldRenderContext,
- vertexConsumer: VertexConsumerProvider,
- pos: Vec3d,
- shadow: Boolean = true,
- depthTest: Boolean = true,
+ fun renderText(
+ string: Text,
+ context: WorldRenderContext,
+ vertexConsumer: VertexConsumerProvider,
+ pos: Vec3d,
+ shadow: Boolean = true,
+ depthTest: Boolean = true,
)
{
val d: Double = pos.distanceTo(MinecraftClient.getInstance().player?.pos)
@@ -230,32 +249,44 @@ object WorldRenderUtils {
matrices.pop()
}
- fun renderTextWithDistance(string: Text,
- context: WorldRenderContext,
- vertexConsumer: VertexConsumerProvider,
- pos: Vec3d,
- shadow: Boolean = true,
- depthTest: Boolean = true,
+ fun renderWaypoint(
+ string: Text,
+ context: WorldRenderContext,
+ vertexConsumer: VertexConsumerProvider,
+ pos: Vec3d,
+ shadow: Boolean = true,
+ depthTest: Boolean = true,
)
{
val d: Double = pos.distanceTo(MinecraftClient.getInstance().player?.pos)
val matrices = context.matrixStack()
matrices.push()
- matrices.translate(pos.x - context.camera().pos.x,
- pos.y - context.camera().pos.y,
- pos.z - context.camera().pos.z)
+ val magnitude = sqrt((pos.x - context.camera().pos.x).pow(2) +
+ (pos.y - context.camera().pos.y).pow(2) +
+ (pos.z - context.camera().pos.z).pow(2))
+ if (magnitude < 20) {
+ matrices.translate(
+ pos.x - context.camera().pos.x,
+ pos.y - context.camera().pos.y,
+ pos.z - context.camera().pos.z
+ )
+ } else {
+ matrices.translate(
+ (pos.x - context.camera().pos.x) / magnitude * 20,
+ (pos.y - context.camera().pos.y) / magnitude * 20,
+ (pos.z - context.camera().pos.z) / magnitude * 20
+ )
+ }
matrices.multiply(context.camera().rotation)
val scale = max(d.toFloat() / 7f, 1f)
- matrices.scale(-.025f * scale, -.025f * scale, 1.0f)
+ if (magnitude < 20) {
+ matrices.scale(-.025f * scale, -.025f * scale, 1.0f)
+ } else {
+ matrices.scale(-.025f * 20 / 7f, -.025f * 20 / 7f, 1.0f)
+ }
val matrix4f = matrices.peek().positionMatrix
val textRenderer = MinecraftClient.getInstance().textRenderer
val j: Int = (.25 * 255.0f).toInt() shl 24
- if (!depthTest) {
- RenderSystem.disableDepthTest()
- RenderSystem.depthMask(false)
- } else {
- RenderSystem.enableDepthTest()
- }
textRenderer.draw(
string, -textRenderer.getWidth(string).toFloat() / 2, 0f, 0xFFFFFF, shadow, matrix4f, vertexConsumer,
if (depthTest) TextRenderer.TextLayerType.NORMAL else TextRenderer.TextLayerType.SEE_THROUGH,
@@ -268,9 +299,6 @@ object WorldRenderUtils {
if (depthTest) TextRenderer.TextLayerType.NORMAL else TextRenderer.TextLayerType.SEE_THROUGH,
j, LightmapTextureManager.MAX_LIGHT_COORDINATE
)
- RenderSystem.depthMask(true)
- RenderSystem.enableDepthTest()
matrices.pop()
}
-
} \ No newline at end of file