-
Notifications
You must be signed in to change notification settings - Fork 1
/
LevelDatNbt.py
156 lines (141 loc) · 5.48 KB
/
LevelDatNbt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
from io import BytesIO
from nbtlib import File, schema, CompoundSchema
from nbtlib.tag import (
Byte,
Int,
Long,
Float,
String,
List,
read_numeric,
write_numeric,
INT,
)
# fmt: off
# fmt: on
class BedrockLevelFile(File, CompoundSchema):
BedrockLevelData = schema("BedrockLevelData", {
"CenterMapsToOrigin": Byte,
"Difficulty": Int,
"FlatWorldLayers": String,
"ForceGameType": Byte,
"GameType": Int,
"Generator": Int,
"InventoryVersion": String,
"LANBroadcast": Byte,
"LastPlayed": Long,
"LevelName": String,
"LimitedWorldOriginX": Int,
"LimitedWorldOriginY": Int,
"LimitedWorldOriginZ": Int,
"MultiplayerGame": Byte,
"NetherScale": Int,
"NetworkVersion": Int,
"Platform": Int,
"PlatformBroadcast": Byte,
"PlatformBroadcastMode": Int,
"RandomSeed": Long,
"SpawnX": Int,
"SpawnY": Int,
"SpawnZ": Int,
"StorageVersion": Int,
"Time": Long,
"XBLBroadcast": Byte,
"XBLBroadcastIntent": Byte,
"XBLBroadcastMode": Int,
"abilities": schema("Abilities", {
"attackmobs": Byte,
"attackplayers": Byte,
"buildandmine": Byte,
"doorsandswitches": Byte,
"flySpeed": Float,
"flying": Byte,
"instabuild": Byte,
"invulnerable": Byte,
"lightning": Byte,
"mayfly": Byte,
"op": Byte,
"opencontainers": Byte,
"permissionsLevel": Int,
"playerPermissionsLevel": Int,
"teleport": Byte,
"walkSpeed": Float,
}),
"bonusChestEnabled": Byte,
"bonusChestSpawned": Byte,
"commandblockoutput": Byte,
"commandsEnabled": Byte,
"currentTick": Long,
"dodaylightcycle": Byte,
"doentitydrops": Byte,
"dofiretick": Byte,
"domobloot": Byte,
"domobspawning": Byte,
"dotiledrops": Byte,
"doweathercycle": Byte,
"drowningdamage": Byte,
"eduLevel": Byte,
"educationFeaturesEnabled": Byte,
"experimentalgameplay": Byte,
"falldamage": Byte,
"firedamage": Byte,
"hasBeenLoadedInCreative": Byte,
"hasLockedBehaviorPack": Byte,
"hasLockedResourcePack": Byte,
"immutableWorld": Byte,
"isFromLockedTemplate": Byte,
"keepinventory": Byte,
"lastOpenedWithVersion": List[Int],
"lightningLevel": Float,
"lightningTime": Int,
"maxcommandchainlength": Int,
"mobgriefing": Byte,
"naturalregeneration": Byte,
"prid": String,
"pvp": Byte,
"rainLevel": Float,
"rainTime": Int,
"sendcommandfeedback": Byte,
"serverChunkTickRange": Int,
"showcoordinates": Byte,
"spawnMobs": Byte,
"startWithMapEnabled": Byte,
"texturePacksRequired": Byte,
"tntexplodes": Byte,
"worldStartCount": Long,
})
schema = {"": BedrockLevelData}
def __init__(
self, level_data=None, version=8, *, gzipped=False, byteorder="little"
):
super().__init__({"": level_data or {}}, gzipped=gzipped, byteorder=byteorder)
self.version = version
@classmethod
def parse(cls, buff, byteorder="little"):
version = read_numeric(INT, buff, byteorder)
_length = read_numeric(INT, buff, byteorder)
self = super().parse(buff, byteorder)
self.version = version
return self
def write(self, buff, byteorder="little"):
tmp = BytesIO()
super().write(tmp, byteorder)
tmp.seek(0)
data = tmp.read()
write_numeric(INT, self.version, buff, byteorder)
write_numeric(INT, len(data), buff, byteorder)
buff.write(data)
@classmethod
def from_buffer(cls, buff, byteorder="little"):
return super().from_buffer(buff, byteorder)
@classmethod
def load(cls, filename, gzipped=False, byteorder="little"):
return super().load(filename, gzipped, byteorder)
def __enter__(self):
return self.root
if __name__=='__main__':
folder="C:\\Users\\camer\\Desktop\\world\\"
with BedrockLevelFile.load("C:\\Users\\camer\\Desktop\\world\\"+'level.dat') as level_data:
print(level_data['LevelName'])
for key in level_data:
print(key)