This repository was archived by the owner on Nov 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +16
-2
lines changed
main/kotlin/io/github/dockyardmc/world/block
test/kotlin/io/github/dockyard/tests/block Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -120,8 +120,14 @@ data class Block(
120120
121121 fun getBlockFromStateString (identifier : String ): Block {
122122 val blockIdentifier = identifier.split(" [" )[0 ]
123- val block = BlockRegistry [blockIdentifier]
124- val id = block.possibleStates[identifier] ? : throw IllegalArgumentException (" No matching state sequence found on ${block.identifier} " )
123+ val registryBlock = BlockRegistry [blockIdentifier]
124+
125+ // if no block state ids, no need to look up the block state ids map
126+ if (registryBlock.states.isEmpty()) {
127+ return registryBlock.toBlock()
128+ }
129+
130+ val id = registryBlock.possibleStates[identifier] ? : throw IllegalArgumentException (" No matching state sequence found on ${registryBlock.identifier} " )
125131 return getBlockByStateId(id)
126132 }
127133
Original file line number Diff line number Diff line change @@ -103,6 +103,14 @@ class BlockTest {
103103
104104 @Test
105105 fun testBlockStateParsing () {
106+ val matches = mutableMapOf<String , Int >(
107+ " minecraft:coarse_dirt" to 11
108+ )
109+
110+ matches.forEach { (identifier, blockStateId) ->
111+ assertEquals(blockStateId, Block .getBlockFromStateString(identifier).getProtocolId())
112+ }
113+
106114 val parsed = Block .parseBlockStateString(" minecraft:oak_slab[type=top]" )
107115
108116 assertEquals(" minecraft:oak_slab" , parsed.first)
You can’t perform that action at this time.
0 commit comments