PrismarineJS / prismarine-schematic

Read and write schematic of any minecraft version, provide them in a convenient and stable API
https://prismarine.js.org/prismarine-schematic/
MIT License
21 stars 8 forks source link

Does not conver block states #42

Open ATXLtheAxolotl opened 2 years ago

ATXLtheAxolotl commented 2 years ago

Versions

Detailed description of a problem

When using prismarine-schematic's .makeWithCommands('pe') function it generates a Promise, however this doesn't convert block states nor block names, this is a problem for me because I'm trying to actually run those commands in-game. As you can see I've attempted to fix it but with no success. I got the Java2Bedrock.json from here.

Your current code

        const schemFile = await fs.readFileSync(`./plugins/schematics/schematics/${data[1]}`)

        const schem = await Schematic.read(schemFile)
        const cmds:string[] = await schem.makeWithCommands(new Vec3(parseInt(data[2]),parseInt( data[3]), parseInt(data[4])), 'pe')
        await console.log(cmds)
        cmds.push(`tellraw @a {\"rawtext\":[{\"text\":\"§a§l§oSchematic has been loaded!\"}]}`)
        var d = await JSON.parse(await fs.readFileSync('./plugins/schematics/src/data/Java2Bedrock.json'))

        for(let i =0; i< cmds.length; i++) {
          if(cmds[i].includes("air")) continue
          //console.log()
          try {
            cmds[i] = d[`minecraft:${cmds[i].replace('/setblock','').replace(/[0-9]/g, '').replace(new RegExp(' ','g'),'')}`]
            console.log(cmds[i])
          }
          catch(e) {
            console.log(e)
          }

          //if(data[5] == 'true')  
          //console.log(d[i])
          //this.api.getCommandManager().executeCommand(cmds[i])
        }
      }

Expected behavior

.makeWithCommands('pe') to convert block states as well and not just block names.

Additional context

No other additional context.