aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/com/dulkirfabric
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-05-09 22:12:27 +0200
committerLinnea Gräf <nea@nea.moe>2024-05-09 22:12:27 +0200
commitdce5a156849a3ba1b09e28dbfc153fc14a7f7b2c (patch)
treeb51bffce829a14ed1bdccb581acec2dd1838540e /src/main/kotlin/com/dulkirfabric
parent9d2b7bec68f98228acf913f029f0383e4dcff3d7 (diff)
downloadDulkirMod-Fabric-master.tar.gz
DulkirMod-Fabric-master.tar.bz2
DulkirMod-Fabric-master.zip
Port to 1.20.6HEADmaster
Diffstat (limited to 'src/main/kotlin/com/dulkirfabric')
-rw-r--r--src/main/kotlin/com/dulkirfabric/Registrations.kt7
-rw-r--r--src/main/kotlin/com/dulkirfabric/events/WorldRenderLastEvent.kt3
-rw-r--r--src/main/kotlin/com/dulkirfabric/features/AotvHighlight.kt13
-rw-r--r--src/main/kotlin/com/dulkirfabric/features/BrokenHyp.kt9
-rw-r--r--src/main/kotlin/com/dulkirfabric/features/CooldownDisplays.kt5
-rw-r--r--src/main/kotlin/com/dulkirfabric/util/Utils.kt3
-rw-r--r--src/main/kotlin/com/dulkirfabric/util/render/WorldRenderUtils.kt27
7 files changed, 39 insertions, 28 deletions
diff --git a/src/main/kotlin/com/dulkirfabric/Registrations.kt b/src/main/kotlin/com/dulkirfabric/Registrations.kt
index 355abb8..f47182b 100644
--- a/src/main/kotlin/com/dulkirfabric/Registrations.kt
+++ b/src/main/kotlin/com/dulkirfabric/Registrations.kt
@@ -126,7 +126,12 @@ object Registrations {
ModifyCommandEvent(command).also { it.post() }.command
}
- WorldRenderEvents.END.register { context -> WorldRenderLastEvent(context).post() }
+ WorldRenderEvents.END.register { context ->
+ WorldRenderLastEvent(
+ context,
+ context.matrixStack()!! // Not null assertion is safe here since this is late enough in rendering
+ ).post()
+ }
ScreenEvents.BEFORE_INIT.register(
ScreenEvents.BeforeInit { client, screen, scaledWidth, scaledHeight ->
diff --git a/src/main/kotlin/com/dulkirfabric/events/WorldRenderLastEvent.kt b/src/main/kotlin/com/dulkirfabric/events/WorldRenderLastEvent.kt
index 11b7714..e91c2f3 100644
--- a/src/main/kotlin/com/dulkirfabric/events/WorldRenderLastEvent.kt
+++ b/src/main/kotlin/com/dulkirfabric/events/WorldRenderLastEvent.kt
@@ -2,6 +2,7 @@ package com.dulkirfabric.events
import com.dulkirfabric.events.base.Event
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext
+import net.minecraft.client.util.math.MatrixStack
data class
-WorldRenderLastEvent(val context: WorldRenderContext): Event()
+WorldRenderLastEvent(val context: WorldRenderContext, val matrixStack: MatrixStack): Event()
diff --git a/src/main/kotlin/com/dulkirfabric/features/AotvHighlight.kt b/src/main/kotlin/com/dulkirfabric/features/AotvHighlight.kt
index 5cce244..5b1a81d 100644
--- a/src/main/kotlin/com/dulkirfabric/features/AotvHighlight.kt
+++ b/src/main/kotlin/com/dulkirfabric/features/AotvHighlight.kt
@@ -10,7 +10,9 @@ import com.dulkirfabric.util.render.WorldRenderUtils
import meteordevelopment.orbit.EventHandler
import net.minecraft.client.MinecraftClient
import net.minecraft.client.util.InputUtil
+import net.minecraft.component.DataComponentTypes
import net.minecraft.entity.Entity
+import net.minecraft.nbt.NbtString
import net.minecraft.util.hit.BlockHitResult
import net.minecraft.util.hit.HitResult
import net.minecraft.util.math.BlockPos
@@ -29,14 +31,9 @@ object AotvHighlight {
fun getHeldItemID(): String {
val stack = mc.player?.mainHandStack ?: return ""
- val tag = stack.nbt ?: return ""
- val id = tag.getCompound("ExtraAttributes").get("id") ?: return ""
- return id.toString().trim('"')
- }
-
- @EventHandler
- fun onLong(event: LongUpdateEvent) {
- //println(heldItemID)
+ val tag = stack.get(DataComponentTypes.CUSTOM_DATA)?.nbt ?: return ""
+ val id = tag.get("id") as? NbtString ?: return ""
+ return id.asString()
}
@EventHandler
diff --git a/src/main/kotlin/com/dulkirfabric/features/BrokenHyp.kt b/src/main/kotlin/com/dulkirfabric/features/BrokenHyp.kt
index 85c1f7b..713a9d1 100644
--- a/src/main/kotlin/com/dulkirfabric/features/BrokenHyp.kt
+++ b/src/main/kotlin/com/dulkirfabric/features/BrokenHyp.kt
@@ -6,6 +6,7 @@ import com.dulkirfabric.events.LongUpdateEvent
import com.dulkirfabric.util.TablistUtils
import com.dulkirfabric.util.render.HudRenderUtil
import meteordevelopment.orbit.EventHandler
+import net.minecraft.component.DataComponentTypes
import net.minecraft.item.ItemStack
import net.minecraft.text.Style
import net.minecraft.text.Text
@@ -29,11 +30,11 @@ object BrokenHyp {
val stack: ItemStack = mc.player?.mainHandStack ?: return
// get info about held item
- val tag = stack.nbt ?: return
- id = tag.getCompound("ExtraAttributes")?.getString("id") ?: ""
+ val tag = stack.get(DataComponentTypes.CUSTOM_DATA)?.nbt ?: return
+ id = tag.getString("id") ?: ""
- kill = tag.getCompound("ExtraAttributes")?.getInt("stats_book") ?: -1
- championXp = tag.getCompound("ExtraAttributes")?.getDouble("champion_combat_xp") ?: -1.0
+ kill = tag.getInt("stats_book") ?: -1
+ championXp = tag.getDouble("champion_combat_xp") ?: -1.0
// check if a wither blade, then check if same id
if (!(id matches "(HYPERION|ASTRAEA|SCYLLA|VALKYRIE)".toRegex())) {
diff --git a/src/main/kotlin/com/dulkirfabric/features/CooldownDisplays.kt b/src/main/kotlin/com/dulkirfabric/features/CooldownDisplays.kt
index 0476d51..e562a2e 100644
--- a/src/main/kotlin/com/dulkirfabric/features/CooldownDisplays.kt
+++ b/src/main/kotlin/com/dulkirfabric/features/CooldownDisplays.kt
@@ -8,6 +8,7 @@ import com.dulkirfabric.util.TrackedCooldown
import com.dulkirfabric.util.Utils
import meteordevelopment.orbit.EventHandler
import net.minecraft.client.sound.Sound
+import net.minecraft.component.DataComponentTypes
import net.minecraft.item.ItemStack
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable
import kotlin.math.round
@@ -89,8 +90,8 @@ object CooldownDisplays {
}
private fun fetchCooldownItem(stack: ItemStack): TrackedCooldown? {
- val tag = stack.nbt ?: return null
- val id = tag.getCompound("ExtraAttributes").get("id") ?: return null
+ val tag = stack.get(DataComponentTypes.CUSTOM_DATA)?.nbt ?: return null
+ val id = tag.get("id") ?: return null
val idStr = id.toString().trim('"')
trackedCooldowns.forEach {
if (idStr matches it.value.itemID)
diff --git a/src/main/kotlin/com/dulkirfabric/util/Utils.kt b/src/main/kotlin/com/dulkirfabric/util/Utils.kt
index 342dc48..e6342cb 100644
--- a/src/main/kotlin/com/dulkirfabric/util/Utils.kt
+++ b/src/main/kotlin/com/dulkirfabric/util/Utils.kt
@@ -6,6 +6,7 @@ import com.dulkirfabric.events.WorldLoadEvent
import com.dulkirfabric.events.chat.ChatEvents
import meteordevelopment.orbit.EventHandler
import net.minecraft.block.entity.SkullBlockEntity
+import net.minecraft.component.DataComponentTypes
import net.minecraft.entity.Entity
import net.minecraft.item.ItemStack
import net.minecraft.nbt.NbtHelper
@@ -72,7 +73,7 @@ object Utils {
}
fun getSkullTexture(itemStack: ItemStack): String? {
- return itemStack.getSubNbt(SkullBlockEntity.SKULL_OWNER_KEY)?.let(NbtHelper::toGameProfile)?.properties?.get(
+ return itemStack.get(DataComponentTypes.PROFILE)?.properties?.get(
"textures")?.first()?.value
}
} \ No newline at end of file
diff --git a/src/main/kotlin/com/dulkirfabric/util/render/WorldRenderUtils.kt b/src/main/kotlin/com/dulkirfabric/util/render/WorldRenderUtils.kt
index d779c23..d1cdab1 100644
--- a/src/main/kotlin/com/dulkirfabric/util/render/WorldRenderUtils.kt
+++ b/src/main/kotlin/com/dulkirfabric/util/render/WorldRenderUtils.kt
@@ -41,10 +41,10 @@ object WorldRenderUtils {
private fun line(matrix: MatrixStack.Entry, buffer: BufferBuilder, from: Vector3f, to: Vector3f) {
val normal = to.sub(from, Vector3f()).mul(-1F)
- buffer.vertex(matrix.positionMatrix, from.x, from.y, from.z)
- .normal(matrix.normalMatrix, normal.x, normal.y, normal.z).next()
- buffer.vertex(matrix.positionMatrix, to.x, to.y, to.z)
- .normal(matrix.normalMatrix, normal.x, normal.y, normal.z)
+ buffer.vertex(matrix, from.x, from.y, from.z)
+ .normal(matrix, normal.x, normal.y, normal.z).next()
+ buffer.vertex(matrix, to.x, to.y, to.z)
+ .normal(matrix, normal.x, normal.y, normal.z)
.next()
}
@@ -60,7 +60,7 @@ object WorldRenderUtils {
thickness: Float,
depthTest: Boolean = true
) {
- val matrices = context.matrixStack()
+ val matrices = context.assertHasMatrixStack() ?: return
matrices.push()
val prevShader = RenderSystem.getShader()
RenderSystem.setShader(GameRenderer::getRenderTypeLinesProgram)
@@ -114,12 +114,17 @@ object WorldRenderUtils {
matrices.pop()
}
+ fun WorldRenderContext.assertHasMatrixStack(): MatrixStack? {
+ assert(matrixStack() != null)
+ return matrixStack()
+ }
+
/**
* This draw line function is intended to be used for drawing very few lines, as it's not the most efficient.
* For drawing many lines in a series, save them to an array and use the drawLineArray function.
*/
fun drawLine(context: WorldRenderContext, startPos: Vec3d, endPos: Vec3d, color: Color, thickness: Float, depthTest: Boolean = true) {
- val matrices = context.matrixStack()
+ val matrices = context.assertHasMatrixStack() ?: return
matrices.push()
val prevShader = RenderSystem.getShader()
RenderSystem.setShader(GameRenderer::getRenderTypeLinesProgram)
@@ -162,7 +167,7 @@ object WorldRenderUtils {
* drawLine function being called many times in series.
*/
fun drawLineArray(context: WorldRenderContext, posArr: List<Vec3d>, color: Color, thickness: Float, depthTest: Boolean = true) {
- val matrices = context.matrixStack()
+ val matrices = context.assertHasMatrixStack() ?: return
matrices.push()
val prevShader = RenderSystem.getShader()
RenderSystem.setShader(GameRenderer::getRenderTypeLinesProgram)
@@ -217,6 +222,7 @@ object WorldRenderUtils {
depthTest: Boolean = true,
scale: Float = 1f
) {
+ val matrices = context.assertHasMatrixStack() ?: return
if (!depthTest) {
RenderSystem.disableDepthTest()
}
@@ -224,8 +230,7 @@ object WorldRenderUtils {
RenderSystem.defaultBlendFunc()
RenderSystem.disableCull()
- val vertexConsumer = context.worldRenderer().bufferBuilders.entityVertexConsumers
- val matrices = context.matrixStack()
+ val vertexConsumer = context.worldRenderer().bufferBuilders.entityVertexConsumers
matrices.push()
matrices.translate(
pos.x - context.camera().pos.x,
@@ -277,13 +282,13 @@ object WorldRenderUtils {
pos: Vec3d,
)
{
+ val matrices = context.assertHasMatrixStack() ?: return
RenderSystem.disableDepthTest()
RenderSystem.enableBlend()
RenderSystem.defaultBlendFunc()
RenderSystem.disableCull()
val d: Double = pos.distanceTo(MinecraftClient.getInstance().player?.pos)
val distText = Text.literal(d.toInt().toString() + "m").setStyle(Style.EMPTY.withColor(Formatting.YELLOW))
- val matrices = context.matrixStack()
val vertexConsumer = context.worldRenderer().bufferBuilders.entityVertexConsumers
matrices.push()
val magnitude = sqrt((pos.x - context.camera().pos.x).pow(2) +
@@ -365,6 +370,7 @@ object WorldRenderUtils {
color: Color,
depthTest: Boolean
) {
+ val matrices = context.assertHasMatrixStack() ?: return
if (!depthTest) {
RenderSystem.disableDepthTest()
//RenderSystem.depthMask(false)
@@ -375,7 +381,6 @@ object WorldRenderUtils {
RenderSystem.enableBlend()
RenderSystem.defaultBlendFunc()
- val matrices = context.matrixStack()
val tes = Tessellator.getInstance()
tes.buffer.begin(VertexFormat.DrawMode.TRIANGLE_STRIP, VertexFormats.POSITION_COLOR)
matrices.push()