Open Didericis opened 8 years ago
Try this:
var mcaData = fs.readFileSync('r.0.1.mca', 'binary')
I had the same problem until I realized Node was reading my file as the wrong encoding.
D'Oh, right! Thanks!
Still having trouble with this library, though. I'm not able to get anything other than null from the getChunk(x, y)
function. I've tried it with the r.0.1.mca file included in this repo and two of my own, all of which I know have data in them, but it doesn't matter. Also, it should have been returning true for a lot of those region.outOfBounds(x, y)
calls I was making, but it's not.
Here's the code I'm using:
var mcRegion = require('minecraft-region');
var fs = require('fs');
var mcaData = fs.readFileSync('r.0.1.mca', 'binary');
var region = mcRegion(mcaData);
for (var x=-100; x<100; x++) {
for (var y=-100; y<100; y++) {
if (region.outOfBounds(x, y)){
console.log(x + ', ' + y);
} else if (region.getChunk(x, y)){
console.log(region.getChunk(x, y));
}
}
}
I've made minor changes to the code that makes it work for me with Node. They're in the pull request #5. I hope they help with your experiments.
@fidian I ran into this issue today as well. I can confirm that your changes work in node 0.10.41, 0.12.9, and 5.4.1. However, in the sample code, when I load the region, I have to include the region coordinate. For example, I have to change var region = mcRegion(mcData)
to var region = mcRegion(mcData, 0, 0)
where 0,0
should reflect the region coordinate from the mca file name.
I'm trying to view and manipulate mca data in node.js. I'd like to use the
getChunk(x, y)
method, but it's been giving me trouble. Here some test code I used to see if I could read chunks. It's a modified version of the test.js file in the repo.Here's the output I'm getting:
I'm using node v0.12.2. Also tried with node v0.10.40 and got the same error. The only other thing I tried was changing line 5 in index.js from
to
That gave me the following output:
Any help would be much appreciated.