Skip to content
This repository was archived by the owner on Nov 28, 2025. It is now read-only.

Commit 11893bc

Browse files
committed
fix incorrect block state string parsing
1 parent c65b20e commit 11893bc

File tree

2 files changed

+16
-2
lines changed
  • src
    • main/kotlin/io/github/dockyardmc/world/block
    • test/kotlin/io/github/dockyard/tests/block

2 files changed

+16
-2
lines changed

src/main/kotlin/io/github/dockyardmc/world/block/Block.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff 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

src/test/kotlin/io/github/dockyard/tests/block/BlockTest.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff 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)

0 commit comments

Comments
 (0)