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

Writing and then Reading donesn't work in 1.12 #39

Open autowert66 opened 3 years ago

autowert66 commented 3 years ago

Versions

Detailed description of a problem

If I try to use const schem2 = Schematic.read(await schem1.write()) the schem2 is not the same than schem1.

Your current code

const mineflayer = require("mineflayer");
const { Schematic } = require("prismarine-schematic");
const { Vec3 } = require("vec3");
// Connect to the server (in 1.12.2)
const bot = mineflayer.createBot({
  host: "example.org",
  username: "email@example.org",
  password: "p@ssw0rd",
  version: "1.12.2",
});
bot.once("spawn", async () => {
  await bot.waitForChunksToLoad();
  // Make the first Schematic
  const schem1 = await Schematic.copy(
    bot.world,
    new Vec3(bot.entity.position.x - 100, 0, bot.entity.position.z - 100),
    new Vec3(bot.entity.position.x + 100, 255, bot.entity.position.z + 100),
    new Vec3(0, 0, 0),
    "1.12.2"
  );
  // write and read the data
  const schem1Data = await schem1.write();
  const schem2 = await Schematic.read(schem1Data, "1.12.2");
  // should be the same, but isn't
  console.log(JSON.stringify(schem1.palette));
  console.log(JSON.stringify(schem2.palette));
});

Expected behavior

Both console outputs should be the same!

Current behavior

[0,112,21,16,17,19,256,208,240,224,1168,48,896,176,336,192,784,151,150,146,145,156,147,148,149,155,497,153,158,144,186,64,178,182,180,188,592,154,157,768,832,868,866,190,640,2802,2810,867,1545,32,1312,608,272,152,611,288,616,1550,3745,2467,273,81,3090,419,427,277,2469,869,416,2341,424,928,3553,2085,2338,3521,2466,2322,3697,3713,3729,2464,1074,1079,3097,1544,3096,2149,2150,290,2326,281,2339,2321,2474,1504,884,885,886,887,888,889,890,891,892,893,894,895,1118,1505,2477,1117,1092]
[0,112,null,null,null,16,256,208,240,224,1168,48,896,null,336,192,784,null,null,null,null,null,null,null,null,null,496,null,null,null,null,64,null,null,null,null,592,null,null,768,832,null,null,176,640,null,2800,null,null,32,1312,null,null,144,null,null,608,null,3744,null,null,80,null,null,null,null,null,864,null,null,416,928,3552,2080,null,3520,null,null,3696,3712,3728,null,null,1072,null,1536,3088,null,2144,288,null,272,2336,2320,null,null,null,null,null,null,null,null,null,null,null,null,null,880,null,1504,2464,1104,1088]

Additional context

As a workaround, you can use const schem2 = Schematic.fromJSON(schem1.toJSON());. To use this, you have to update your package.json to use the git version:

// Change
    "prismarine-schematic": "^1.2.1",
// to 
    "prismarine-schematic": "git+https://github.com/PrismarineJS/prismarine-schematic.git",

Then you need to run npm install again.


sertonix commented 2 years ago

The problem is that 1.12.2 does not have states and therefor the schematic can't be converted to the sponge schematic format. The specifications don't handle the old system. Your workaround seems to be the only and best way to copy the schematic.