aboutsummaryrefslogtreecommitdiff
path: root/src/texturePacks/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/texturePacks/java')
-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
2 files changed, 145 insertions, 0 deletions
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
+ }
+ }
+ }
+}