Comments (8)
https://minecraft.gamepedia.com/NBT_format
TAG_String : TAG_Short's payload length, then a UTF-8 string with size length.
from nbtlib.
are you able to parse this?
https://www.dropbox.com/s/dx2y14eg9gc7dxd/6a9c66bb-46dd-4e55-aefc-d1f48fabfa4a.dat?dl=0
from nbtlib.
As @ch-yx pointed out, nbt strings are supposed to be utf-8 encoded. Using iso-8859-1 doesn't fix the problem as it only silences the error by arbitrarily mapping bytes to characters from a completely different encoding.
I looked at the file you provided and there are books with 50 pages of random characters in your player's inventory. These books seem to have been generated by a clientside mod, and while the java code doesn't appear to have a problem with the resulting bytes, they're definitely not valid utf-8 encoded strings.
The books generated by the mod seem to enable an item duplication glitch in Minecraft, but result in non spec-compliant nbt files. I don't think I can do anything about this.
from nbtlib.
I am making my script to detect players who are using such books to dupe on the server. If using ISO-8859-1 isn't the correct solution then what do you suggest for others who come across this issue?
Should I report this as a bug to mojang?
from nbtlib.
raise an exception with raw bytes when cannot be decoded by utf-8?🤔
from nbtlib.
Hmm yeah I think the first thing to do would be to report it on the bug tracker. For your script, I guess that you could detect if someone has a glitched book by catching the UnicodeDecodeError
when reading a player's dat file.
def has_book(player_dat):
try:
nbtlib.load(player_dat)
except UnicodeDecodeError:
return True
else:
return False
It's not particularly pretty but it could do the job.
from nbtlib.
I don't think there's a need for a custom exception here, as you can already get the raw bytes that couldn't be decoded through the UnicodeDecodeError
.
try:
nbtlib.load('6a9c66bb-46dd-4e55-aefc-d1f48fabfa4a.dat')
except UnicodeDecodeError as exc:
print(exc.object)
print(exc.start, exc.end)
https://docs.python.org/3/library/exceptions.html#UnicodeError
But yeah that could be useful in your script as well 👍
from nbtlib.
Thanks for the suggestions and hopefully it will help others who come across this same issue :)
from nbtlib.
Related Issues (20)
- servers.dat issues. HOT 1
- Root creates an spurious Compound that is not in actual NBT data HOT 19
- `Path` cannot add or init integers, only strings and other Paths HOT 2
- Preserve type on List.copy() and slicing HOT 5
- Improve `read_numeric()` to vastly increase `parse()` performance for all tags HOT 4
- Array tags are immutable views, not editable ndarrays HOT 9
- `File` is not writing the trailing End tag HOT 4
- `nbtlib 2.0` HOT 16
- Add `Path.from_parts()` or similar to allow tuple constructor like `pathlib.Path` HOT 8
- Investigate schema improvements/autocast HOT 7
- How to add a server in servers.dat? HOT 2
- Iterate NBT HOT 4
- Can't read FTB Quests NBT HOT 2
- How to get JSON info as intuitively as CLI? HOT 1
- if just have one value in list ,i got error HOT 2
- Use modified utf-8 for encoding and decoding strings HOT 2
- nbtlib.Long can not set 64bytes value HOT 1
- a minor issue of index of list.
- How to use/initialize nbtlib.ByteArray? HOT 1
- Jython compatibility
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 nbtlib.