for my personal project I need to edit every the bytes of every section in a chunk that is stored in a .mca file. I can already generate the bytes that I need for the blocks. The only problem I have is that I can't understand how to edit these type of files very easily in java.
Asked
Active
Viewed 244 times
1 Answers
0
Here is an example using this Java NBT library, it provides instructions on including to your project in the README. Hope this helps!
byte[][][] generatedBytes = new byte[16][256][16];
MCAFile mcaFile = new MCAFile(0, 0);
Chunk chunk = Chunk.newChunk();
// Generate bytes to be put into chunk, here we just generate some stripes
for (int y=0; y < 256; y++) {
for (int z = 0; z < 16; z++) {
for (int x = 0; x < 16; x++) {
generatedBytes[x][y][z] = (byte) (x % 3);
}
}
}
// Write our generated bytes to a chunk
for (int y=0; y < 256; y++) {
for (int z = 0; z < 16; z++) {
for (int x = 0; x < 16; x++) {
CompoundTag blockTag = new CompoundTag();
String blockType = "minecraft:air";
switch (generatedBytes[x][y][z]) {
case 1:
blockType = "minecraft:stone";
break;
case 2:
blockType = "minecraft:grass_block";
break;
default:
break;
}
blockTag.putString("Name", blockType);
chunk.setBlockStateAt(x, y, z, blockTag, false);
}
}
}
mcaFile.setChunk(0, 0, chunk);
MCAUtil.write(mcaFile, "r.0.0.mca");

Kmschr
- 84
- 6