Comments (7)
I'm not familiar with the region code, though I have been meaning to do some code cleanup for a while. It may be a good opportunity to revisit this code.
from nbt.
I just pushed some test code to branch write-nbt-todo in my own repository. @Fenixin, @twoolie, (and any other listeners) could you do me a favour? Run the examples/region_util.py
script on all your saved files.
I.e.:
git remote add macfreek https://github.com/macfreek/NBT.git
git checkout macfreek/write-nbt-todo
examples/region_util.py ~/Library/Application\ Support/minecraft/saves/*/region/*.mc*
(or wherever your saved files are located; I'm obviously using a Mac)
I'm interested in all notes about the size of the chunk versus the number of allocated sectors.
E.g.:
chunk 21,12 is 4096 bytes (4+1+4091) and requires 1 sectors, but 2 sectors are allocated
chunk 31,30 is 8192 bytes (4+1+8187) and requires 2 sectors, but 3 sectors are allocated
chunk 11,21 is 4096 bytes (4+1+4091) and requires 1 sectors, but 2 sectors are allocated
chunk 15,15 is 4094 bytes (4+1+4089) and requires 1 sector(s), and indeed 1 sector(s) is/are allocated
chunk 4,3 is 4095 bytes (4+1+4090) and requires 1 sector(s), and indeed 1 sector(s) is/are allocated
chunk 8,24 is 4096 bytes (4+1+4091) and requires 1 sectors, but 2 sectors are allocated
As expected, a chunk of 4090 bytes (thus reported "length" value in the chunk block header of 4091, and a block of 4095 bytes) uses 1 sector. And a chunk of 4092 bytes (thus reported "length" value in the chunk block header of 4093, and a block size of 4097) uses 2 sectors. No surprises there.
However, a chunk of 4091 bytes (thus reported "length" value in the chunk block header of 4092, and a block of 4096 bytes) uses 2 sectors, while I would have expected 1 sector.
Am I missing something here (is there a compulsory \0 byte at the end of each compressed chunk perhaps?) Or is there a off-by-one error in the Minecraft code? Or is there a bug in my code somewhere?
Note that I see this behaviour consistently for region files written by Minecraft and at least WorldDowloader (a mod that stores chunks received from a server)
from nbt.
Just added 52 unit tests for region.py 9aeb394. The good news is: 18 tests already succeed, and it is fairly easy to increase that to 29. The bed new is: the remain 23 unit tests are harder to fix.
from nbt.
Question: if there is a corrupt chunk in a region file, it is now almost arbitrary what kind of exception is raised: nbt.region.ChunkDataError, nbt.nbt.MalformedFileError, or zlib.error.
There are 3 types or errors here:
- unknown compression
- decompression error in zlib or gzip
- data format error in nbt.nbt.NBTFile
I'm almost inclined to turn this into: nbt.region.UnkownCompression, native zlib/gzip exception, and nbt.nbt.MalformedDataError. (with ChunkDataError an alias of UnkownCompression, and MalformedFileError an alias of MalformedDataError for backward compatibility).
An alternative to the native zlib/gzip exceptions is to catch these exception and reraise them as a nbt.region.CompressionError. I personally like that, since most users don't care what's exactly wrong while decompression, just that the chunk is corrupt. However, the process of catching an exception and reraising as something different seems very uncommon in Python. (The Ruby solution would be to open the zlib.error and gzip.error classes and make subclasses of CompressionError, but I don't think this is possible or recommended in Python).
Suggestions?
from nbt.
Review completed.
Rewrite completed. See #68.
from nbt.
I'm sorry I didn't show up before, I was more or less out for a month and after that I've been catching up with everything slowly.
It seems this thread is pretty outdated now and that lot's of changes have been done, so I guess I'm pretty late to answer/do anything. Anyway, anything I can do/answer right now?
from nbt.
Hi Fenixin, welcome back! :)
Have a look at #69 and see if the changes are useful to you, in particular if the backward compatible changes are OK.
from nbt.
Related Issues (20)
- get_region should limit the number of open files
- ImportError in Python 3.10: cannot import name 'MutableMapping' from 'collections' HOT 9
- [Question, Potential Bug Report]: _render_buffer recursion when trying to modify region files in entities folder HOT 1
- [Question] How to get block data from blockstates
- (Question) Trying to modify region binary to replace stuff in minecraft world using blockdata
- KeyError: Tag Level does not exist when using Minecraft 1.18.1 worlds. HOT 3
- Can someone add support for 1.18 world height. Chunk section range should support -4 to 19, not 0 to 15. Thanks!
- Error while creating data: "struct.error: int too large to convert" HOT 1
- Unable to set value for Compound HOT 1
- Writing a compound tag to a file HOT 1
- 'TAG_End' is not defined HOT 3
- Using the map example with a 1.8 world renders nothing but black. HOT 2
- Can't save .mca HOT 2
- Get uncompressed NBT data to variable
- SNBT parser in/out
- Use of TAG_Int_Array unclear/undocumented HOT 2
- `Sample_World.tar.gz` missing? HOT 1
- Continuous integration setup HOT 1
- Policy on compatibility with old Minecraft versions HOT 2
- Opening servers.dat.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nbt.