Skip to content

Commit

Permalink
Allow two variations of syntax in fromString
Browse files Browse the repository at this point in the history
  • Loading branch information
Flonja committed Dec 31, 2023
1 parent 38e8e87 commit 9d5ac1b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,9 @@ function provider (registry, { Biome, version }) {
if (str.startsWith('minecraft:')) str = str.substring(10)
const name = str.split('[', 1)[0]
const propertiesStr = str.slice(name.length + 1, -1).split(',')
if (version.type === 'pc') {
if (!str.includes('["')) {
return Block.fromProperties(name, Object.fromEntries(propertiesStr.map(property => property.split('='))), biomeId)
} else if (version.type === 'bedrock') {
} else {
return Block.fromProperties(name, Object.fromEntries(propertiesStr.map(property => {
const [key, value] = property.split(':')
return [key.slice(1, -1), value.startsWith('"') ? value.slice(1, -1) : { true: 1, false: 0 }[value] ?? parseInt(value)]
Expand Down
1 change: 1 addition & 0 deletions test/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ describe('fromString', () => {
const versions = {
1.18: 'minecraft:candle[lit=true]',
'pe_1.18.0': 'minecraft:candle["lit":true]',
1.19: 'minecraft:candle["lit":true]',
'1.20': 'minecraft:candle[lit=true]'
}
for (const [version, str] of Object.entries(versions)) {
Expand Down

0 comments on commit 9d5ac1b

Please sign in to comment.