@@ -24,6 +24,9 @@ import com.lambda.module.tag.ModuleTag
2424import com.lambda.util.BlockUtils.blockState
2525import com.lambda.util.Communication.info
2626import com.lambda.util.KeyCode
27+ import net.minecraft.block.BlockState
28+ import net.minecraft.state.property.Properties
29+ import net.minecraft.state.property.Property
2730import net.minecraft.util.hit.BlockHitResult
2831
2932object 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