aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2025-10-13 21:09:29 +0200
committerLinnea Gräf <nea@nea.moe>2025-10-13 21:09:29 +0200
commit05160314e6899ece75779dbd2e5b691ed581c2b9 (patch)
tree1a510d4d8d3fe692b980a4762b3634874d5d7dc2
parent0d903f93d35410a81f7be073511487903ff49516 (diff)
downloadFirmament-05160314e6899ece75779dbd2e5b691ed581c2b9.tar.gz
Firmament-05160314e6899ece75779dbd2e5b691ed581c2b9.tar.bz2
Firmament-05160314e6899ece75779dbd2e5b691ed581c2b9.zip
feat: add debug mode to custom block texture areas
-rw-r--r--src/main/kotlin/Firmament.kt2
-rw-r--r--src/main/kotlin/commands/rome.kt9
-rw-r--r--src/main/kotlin/events/CommandEvent.kt1
-rw-r--r--src/main/kotlin/util/render/RenderInWorldContext.kt11
-rw-r--r--src/texturePacks/java/moe/nea/firmament/features/texturepack/CustomBlockTextures.kt13
-rw-r--r--src/texturePacks/java/moe/nea/firmament/features/texturepack/CustomBlockTexturesDebugger.kt132
6 files changed, 163 insertions, 5 deletions
diff --git a/src/main/kotlin/Firmament.kt b/src/main/kotlin/Firmament.kt
index 795619e..8e31848 100644
--- a/src/main/kotlin/Firmament.kt
+++ b/src/main/kotlin/Firmament.kt
@@ -124,7 +124,7 @@ object Firmament {
@Suppress("UNUSED_PARAMETER")
ctx: CommandRegistryAccess
) {
- registerFirmamentCommand(dispatcher)
+ registerFirmamentCommand(dispatcher, ctx)
CommandEvent.publish(CommandEvent(dispatcher, ctx, MC.networkHandler?.commandDispatcher))
}
diff --git a/src/main/kotlin/commands/rome.kt b/src/main/kotlin/commands/rome.kt
index affc860..97acf73 100644
--- a/src/main/kotlin/commands/rome.kt
+++ b/src/main/kotlin/commands/rome.kt
@@ -6,6 +6,7 @@ import com.mojang.brigadier.arguments.StringArgumentType.string
import io.ktor.client.statement.bodyAsText
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource
import kotlinx.coroutines.launch
+import net.minecraft.command.CommandRegistryAccess
import net.minecraft.nbt.NbtOps
import net.minecraft.text.Text
import net.minecraft.text.TextCodecs
@@ -45,7 +46,7 @@ import moe.nea.firmament.util.tr
import moe.nea.firmament.util.unformattedString
-fun firmamentCommand() = literal("firmament") {
+fun firmamentCommand(ctx: CommandRegistryAccess) = literal("firmament") {
thenLiteral("config") {
thenExecute {
AllConfigsGui.showAllGuis()
@@ -406,12 +407,12 @@ fun firmamentCommand() = literal("firmament") {
thenExecute {
AllConfigsGui.showAllGuis()
}
- CommandEvent.SubCommand.publish(CommandEvent.SubCommand(this@literal))
+ CommandEvent.SubCommand.publish(CommandEvent.SubCommand(this@literal, ctx))
}
-fun registerFirmamentCommand(dispatcher: CommandDispatcher<FabricClientCommandSource>) {
- val firmament = dispatcher.register(firmamentCommand())
+fun registerFirmamentCommand(dispatcher: CommandDispatcher<FabricClientCommandSource>, ctx: CommandRegistryAccess) {
+ val firmament = dispatcher.register(firmamentCommand(ctx))
dispatcher.register(literal("firm") {
redirect(firmament)
})
diff --git a/src/main/kotlin/events/CommandEvent.kt b/src/main/kotlin/events/CommandEvent.kt
index cc9cf45..63ed115 100644
--- a/src/main/kotlin/events/CommandEvent.kt
+++ b/src/main/kotlin/events/CommandEvent.kt
@@ -23,6 +23,7 @@ data class CommandEvent(
*/
data class SubCommand(
val builder: CaseInsensitiveLiteralCommandNode.Builder<DefaultSource>,
+ val commandRegistryAccess: CommandRegistryAccess,
) : FirmamentEvent() {
companion object : FirmamentEventBus<SubCommand>()
diff --git a/src/main/kotlin/util/render/RenderInWorldContext.kt b/src/main/kotlin/util/render/RenderInWorldContext.kt
index 12a061d..b1ba9d0 100644
--- a/src/main/kotlin/util/render/RenderInWorldContext.kt
+++ b/src/main/kotlin/util/render/RenderInWorldContext.kt
@@ -7,7 +7,9 @@ import util.render.CustomRenderLayers
import kotlin.math.pow
import net.minecraft.client.render.Camera
import net.minecraft.client.render.RenderLayer
+import net.minecraft.client.render.RenderLayers
import net.minecraft.client.render.RenderTickCounter
+import net.minecraft.client.render.TexturedRenderLayers
import net.minecraft.client.render.VertexConsumer
import net.minecraft.client.render.VertexConsumerProvider
import net.minecraft.client.texture.Sprite
@@ -15,6 +17,7 @@ import net.minecraft.client.util.math.MatrixStack
import net.minecraft.text.Text
import net.minecraft.util.Identifier
import net.minecraft.util.math.BlockPos
+import net.minecraft.util.math.Box
import net.minecraft.util.math.Vec3d
import moe.nea.firmament.events.WorldRenderLastEvent
import moe.nea.firmament.util.FirmFormatters
@@ -34,6 +37,14 @@ class RenderInWorldContext private constructor(
matrixStack.pop()
}
+ fun box(aabb: Box, color: Int) {
+ matrixStack.push()
+ matrixStack.translate(aabb.minX, aabb.minY, aabb.minZ)
+ matrixStack.scale(aabb.lengthX.toFloat(), aabb.lengthY.toFloat(), aabb.lengthZ.toFloat())
+ buildCube(matrixStack.peek().positionMatrix, vertexConsumers.getBuffer(CustomRenderLayers.COLORED_QUADS), color)
+ matrixStack.pop()
+ }
+
fun sharedVoxelSurface(blocks: Set<BlockPos>, color: Int) {
val m = BlockPos.Mutable()
val l = vertexConsumers.getBuffer(CustomRenderLayers.COLORED_QUADS)
diff --git a/src/texturePacks/java/moe/nea/firmament/features/texturepack/CustomBlockTextures.kt b/src/texturePacks/java/moe/nea/firmament/features/texturepack/CustomBlockTextures.kt
index 2d7a978..de64805 100644
--- a/src/texturePacks/java/moe/nea/firmament/features/texturepack/CustomBlockTextures.kt
+++ b/src/texturePacks/java/moe/nea/firmament/features/texturepack/CustomBlockTextures.kt
@@ -41,6 +41,7 @@ import net.minecraft.resource.SinglePreparationResourceReloader
import net.minecraft.state.StateManager
import net.minecraft.util.Identifier
import net.minecraft.util.math.BlockPos
+import net.minecraft.util.math.Box
import net.minecraft.util.profiler.Profiler
import net.minecraft.util.thread.AsyncHelper
import moe.nea.firmament.Firmament
@@ -48,6 +49,7 @@ import moe.nea.firmament.annotations.Subscribe
import moe.nea.firmament.events.EarlyResourceReloadEvent
import moe.nea.firmament.events.FinalizeResourceManagerEvent
import moe.nea.firmament.events.SkyblockServerUpdateEvent
+import moe.nea.firmament.features.debug.DebugLogger
import moe.nea.firmament.features.texturepack.CustomBlockTextures.createBakedModels
import moe.nea.firmament.features.texturepack.CustomGlobalTextures.logger
import moe.nea.firmament.util.ErrorUtil
@@ -161,6 +163,17 @@ object CustomBlockTextures {
(blockPos.y in realMin.y..realMax.y) &&
(blockPos.z in realMin.z..realMax.z)
}
+
+ fun toBox(): Box {
+ return Box(
+ realMin.x.toDouble(),
+ realMin.y.toDouble(),
+ realMin.z.toDouble(),
+ (realMax.x + 1).toDouble(),
+ (realMax.y + 1).toDouble(),
+ (realMax.z + 1).toDouble()
+ )
+ }
}
data class LocationReplacements(
diff --git a/src/texturePacks/java/moe/nea/firmament/features/texturepack/CustomBlockTexturesDebugger.kt b/src/texturePacks/java/moe/nea/firmament/features/texturepack/CustomBlockTexturesDebugger.kt
new file mode 100644
index 0000000..456b6fd
--- /dev/null
+++ b/src/texturePacks/java/moe/nea/firmament/features/texturepack/CustomBlockTexturesDebugger.kt
@@ -0,0 +1,132 @@
+package moe.nea.firmament.features.texturepack
+
+import com.mojang.brigadier.arguments.IntegerArgumentType
+import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager
+import net.minecraft.block.Block
+import net.minecraft.command.argument.BlockArgumentParser
+import net.minecraft.command.argument.BlockStateArgumentType
+import net.minecraft.util.math.Box
+import net.minecraft.util.math.Vec3d
+import moe.nea.firmament.annotations.Subscribe
+import moe.nea.firmament.commands.get
+import moe.nea.firmament.commands.thenArgument
+import moe.nea.firmament.commands.thenExecute
+import moe.nea.firmament.commands.thenLiteral
+import moe.nea.firmament.events.CommandEvent
+import moe.nea.firmament.events.WorldRenderLastEvent
+import moe.nea.firmament.features.debug.DeveloperFeatures
+import moe.nea.firmament.util.MC
+import moe.nea.firmament.util.render.RenderInWorldContext
+import moe.nea.firmament.util.tr
+
+object CustomBlockTexturesDebugger {
+ var debugMode: DebugMode = DebugMode.Never
+ var range = 30
+
+
+ @Subscribe
+ fun onRender(event: WorldRenderLastEvent) {
+ if (debugMode == DebugMode.Never) return
+ val replacements = CustomBlockTextures.currentIslandReplacements ?: return
+ RenderInWorldContext.renderInWorld(event) {
+ for ((block, repl) in replacements.lookup) {
+ if (!debugMode.shouldHighlight(block)) continue
+ for (i in repl) {
+ if (i.roughCheck != null)
+ tryRenderBox(i.roughCheck!!.toBox(), 0x50FF8050.toInt())
+ i.checks?.forEach { area ->
+ tryRenderBox(area.toBox(), 0x5050FF50.toInt())
+ }
+ }
+ }
+ }
+ }
+
+ fun RenderInWorldContext.tryRenderBox(box: Box, colour: Int) {
+ val player = MC.player?.pos ?: Vec3d.ZERO
+ if (box.center.distanceTo(player) < range + maxOf(
+ box.lengthZ, box.lengthX, box.lengthY
+ ) / 2 && !box.contains(player)
+ ) {
+ box(box, colour)
+ }
+ }
+
+
+ @Subscribe
+ fun onCommand(event: CommandEvent.SubCommand) {
+ event.subcommand(DeveloperFeatures.DEVELOPER_SUBCOMMAND) {
+ thenLiteral("debugcbt") {
+ thenLiteral("range") {
+ thenArgument("range", IntegerArgumentType.integer(0)) { rangeArg ->
+ thenExecute {
+ this@CustomBlockTexturesDebugger.range = get(rangeArg)
+ MC.sendChat(
+ tr(
+ "firmament.debugcbt.always",
+ "Only render areas within ${this@CustomBlockTexturesDebugger.range} blocks"
+ )
+ )
+ }
+ }
+ }
+ thenLiteral("all") {
+ thenExecute {
+ debugMode = DebugMode.Always
+ MC.sendChat(
+ tr(
+ "firmament.debugcbt.always",
+ "Showing debug outlines for all custom block textures"
+ )
+ )
+ }
+ }
+ thenArgument("block", BlockStateArgumentType.blockState(event.commandRegistryAccess)) { block ->
+ thenExecute {
+ val block = get(block).blockState.block
+ debugMode = DebugMode.ForBlock(block)
+ MC.sendChat(
+ tr(
+ "firmament.debugcbt.block",
+ "Showing debug outlines for all custom ${block.name} textures"
+ )
+ )
+ }
+ }
+ thenLiteral("never") {
+ thenExecute {
+ debugMode = DebugMode.Never
+ MC.sendChat(
+ tr(
+ "firmament.debugcbt.disabled",
+ "Disabled debug outlines for custom block textures"
+ )
+ )
+ }
+ }
+ }
+ }
+ }
+
+ sealed interface DebugMode {
+ fun shouldHighlight(block: Block): Boolean
+
+ data object Never : DebugMode {
+ override fun shouldHighlight(block: Block): Boolean {
+ return false
+ }
+ }
+
+ data class ForBlock(val block: Block) : DebugMode {
+ override fun shouldHighlight(block: Block): Boolean {
+ return block == this.block
+ }
+ }
+
+ data object Always : DebugMode {
+ override fun shouldHighlight(block: Block): Boolean {
+ return true
+ }
+ }
+ }
+}