Skip to content

Commit 52fda55

Browse files
authored
Allow two variations of syntax in fromString (#96)
* Allow two variations of syntax in fromString * Added comments to show differences between the variations
1 parent 38e8e87 commit 52fda55

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

index.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,12 @@ function provider (registry, { Biome, version }) {
248248
if (str.startsWith('minecraft:')) str = str.substring(10)
249249
const name = str.split('[', 1)[0]
250250
const propertiesStr = str.slice(name.length + 1, -1).split(',')
251-
if (version.type === 'pc') {
251+
if (!str.includes('["')) {
252+
// Example state: `minecraft:candle[lit=true]` -> candle, {lit: "true"}
252253
return Block.fromProperties(name, Object.fromEntries(propertiesStr.map(property => property.split('='))), biomeId)
253-
} else if (version.type === 'bedrock') {
254+
} else {
255+
// Kept for backwards compatibility
256+
// Example state: `minecraft:candle["lit":true]` -> candle, {lit: 1}
254257
return Block.fromProperties(name, Object.fromEntries(propertiesStr.map(property => {
255258
const [key, value] = property.split(':')
256259
return [key.slice(1, -1), value.startsWith('"') ? value.slice(1, -1) : { true: 1, false: 0 }[value] ?? parseInt(value)]

test/basic.test.js

+1
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ describe('fromString', () => {
168168
const versions = {
169169
1.18: 'minecraft:candle[lit=true]',
170170
'pe_1.18.0': 'minecraft:candle["lit":true]',
171+
1.19: 'minecraft:candle["lit":true]',
171172
'1.20': 'minecraft:candle[lit=true]'
172173
}
173174
for (const [version, str] of Object.entries(versions)) {

0 commit comments

Comments
 (0)