Skip to content

Commit 3feb026

Browse files
committed
simple module for printing every property coupled with every state implementing said property in the game to a .txt file
1 parent 2c65434 commit 3feb026

File tree

2 files changed

+84
-3
lines changed

2 files changed

+84
-3
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright 2025 Lambda
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.lambda.module.modules.debug
19+
20+
import com.lambda.module.Module
21+
import com.lambda.module.tag.ModuleTag
22+
import com.lambda.util.FolderRegister
23+
import com.lambda.util.extension.resolveFile
24+
import net.minecraft.block.Block
25+
import net.minecraft.block.Blocks
26+
27+
object PropertyPrinter : Module(
28+
"PropertyPrinter",
29+
"Prints all properties coupled with all the states that use them into a text file",
30+
setOf(ModuleTag.DEBUG)
31+
) {
32+
init {
33+
onEnable {
34+
val file = FolderRegister.lambda.resolve("property-print").resolveFile("property-print.txt")
35+
file.parentFile.mkdirs()
36+
file.writeText("")
37+
StateInfo.propertyFields.forEach properties@ { property ->
38+
file.appendText("${property.value.name}\n")
39+
Blocks::class.java.declaredFields.forEach blocks@ { field ->
40+
field.isAccessible = true
41+
val block = field.get(null)
42+
if (!Block::class.java.isAssignableFrom(block::class.java)) return@blocks
43+
if ((block as Block).defaultState.properties.contains(property.key)) {
44+
file.appendText(" $block\n")
45+
}
46+
}
47+
file.appendText("\n\n\n\n\n")
48+
}
49+
disable()
50+
}
51+
}
52+
}

common/src/main/kotlin/com/lambda/module/modules/debug/StateInfo.kt

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ import com.lambda.module.tag.ModuleTag
2424
import com.lambda.util.BlockUtils.blockState
2525
import com.lambda.util.Communication.info
2626
import com.lambda.util.KeyCode
27+
import net.minecraft.block.BlockState
28+
import net.minecraft.state.property.Properties
29+
import net.minecraft.state.property.Property
2730
import net.minecraft.util.hit.BlockHitResult
2831

2932
object StateInfo : Module(
@@ -33,16 +36,42 @@ object StateInfo : Module(
3336
) {
3437
private val printBind by setting("Print", KeyCode.UNBOUND, "The bind used to print the info to chat")
3538

39+
val propertyFields = Properties::class.java.declaredFields
40+
.filter { Property::class.java.isAssignableFrom(it.type) }
41+
.associateBy { it.get(null) as Property<*> }
42+
3643
init {
3744
listen<KeyboardEvent.Press> { event ->
3845
if (!event.isPressed) return@listen
3946
if (event.keyCode != printBind.keyCode) return@listen
4047
val crosshair = mc.crosshairTarget ?: return@listen
4148
if (crosshair !is BlockHitResult) return@listen
49+
info(blockState(crosshair.blockPos).betterToString())
50+
}
51+
}
52+
53+
private fun BlockState.betterToString(): String {
54+
val stringBuilder = StringBuilder()
55+
stringBuilder.append(this.owner.toString() + "\n")
56+
57+
if (entries.isNotEmpty()) {
58+
stringBuilder.append(" [\n")
4259

43-
val targetBlock = blockState(crosshair.blockPos)
44-
val text = "$targetBlock"
45-
info(text)
60+
stringBuilder.append(
61+
entries.entries.joinToString("\n") { (property, value) ->
62+
val fieldName = propertyFields[property]?.name ?: property.toString()
63+
" $fieldName = ${nameValue(property, value)}"
64+
}
65+
)
66+
67+
stringBuilder.append("\n ]")
4668
}
69+
70+
return stringBuilder.toString()
71+
}
72+
73+
@Suppress("UNCHECKED_CAST")
74+
private fun <T : Comparable<T>?> nameValue(property: Property<T>, value: Comparable<*>): String {
75+
return property.name(value as T)
4776
}
4877
}

0 commit comments

Comments
 (0)