Skip to content

Commit 3595d23

Browse files
Fix player heads (#70)
* Fix player heads * Fix skull translations
1 parent 807083f commit 3595d23

File tree

574 files changed

+1534
-8861
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

574 files changed

+1534
-8861
lines changed

PyMCTranslate/build_number.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
375
1+
377
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import uuid
2+
3+
from amulet_nbt import CompoundTag, ListTag, IntTag, StringTag
4+
5+
6+
def convert_uuid(tag: CompoundTag):
7+
id_tag = tag.pop("Id", None)
8+
if isinstance(id_tag, StringTag):
9+
try:
10+
uuid_ = uuid.UUID(id_tag.py_str)
11+
except ValueError:
12+
pass
13+
else:
14+
uuid_int = uuid_.int
15+
tag["Id"] = ListTag(
16+
[
17+
IntTag((uuid_int >> 96) & 0xFFFFFFFF),
18+
IntTag((uuid_int >> 64) & 0xFFFFFFFF),
19+
IntTag((uuid_int >> 32) & 0xFFFFFFFF),
20+
IntTag(uuid_int & 0xFFFFFFFF),
21+
]
22+
)
23+
24+
25+
def convert_properties(tag: CompoundTag):
26+
properties_tag = tag.get("properties")
27+
if isinstance(properties_tag, ListTag):
28+
new_properties_tag = CompoundTag()
29+
for prop_tag in properties_tag:
30+
if isinstance(prop_tag, CompoundTag):
31+
name = prop_tag.get("name")
32+
value = prop_tag.get("value")
33+
signature = prop_tag.get("signature")
34+
if isinstance(name, StringTag) and isinstance(value, StringTag):
35+
new_prop_tag = CompoundTag({"Value": value})
36+
if isinstance(signature, StringTag):
37+
new_prop_tag["Signature"] = signature
38+
new_properties_tag.setdefault(name.py_str, ListTag()).append(
39+
new_prop_tag
40+
)
41+
tag["Properties"] = new_properties_tag
42+
43+
44+
def downgrade_name(tag: CompoundTag):
45+
name_tag = tag.pop("name", None)
46+
if isinstance(name_tag, StringTag):
47+
tag["Name"] = name_tag
48+
49+
50+
def main(nbt):
51+
if isinstance(nbt, CompoundTag):
52+
utags = nbt.get("utags")
53+
if isinstance(utags, CompoundTag):
54+
owner_j116 = utags.get("owner_j116")
55+
if isinstance(owner_j116, CompoundTag):
56+
return [
57+
[
58+
"",
59+
"compound",
60+
[],
61+
"SkullOwner",
62+
owner_j116,
63+
]
64+
]
65+
owner_j1205 = utags.get("owner_j1205")
66+
if isinstance(owner_j1205, CompoundTag):
67+
convert_properties(owner_j1205)
68+
downgrade_name(owner_j1205)
69+
return [
70+
[
71+
"",
72+
"compound",
73+
[],
74+
"SkullOwner",
75+
owner_j1205,
76+
]
77+
]
78+
owner_j19 = utags.get("owner_j19")
79+
if isinstance(owner_j19, CompoundTag):
80+
convert_uuid(owner_j19)
81+
return [
82+
[
83+
"",
84+
"compound",
85+
[],
86+
"SkullOwner",
87+
owner_j19,
88+
]
89+
]
90+
91+
return []
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import uuid
2+
3+
from amulet_nbt import CompoundTag, ListTag, IntTag, StringTag
4+
5+
6+
def convert_uuid(tag: CompoundTag):
7+
id_tag = tag.pop("Id", None)
8+
if isinstance(id_tag, StringTag):
9+
try:
10+
uuid_ = uuid.UUID(id_tag.py_str)
11+
except ValueError:
12+
pass
13+
else:
14+
uuid_int = uuid_.int
15+
tag["Id"] = ListTag(
16+
[
17+
IntTag((uuid_int >> 96) & 0xFFFFFFFF),
18+
IntTag((uuid_int >> 64) & 0xFFFFFFFF),
19+
IntTag((uuid_int >> 32) & 0xFFFFFFFF),
20+
IntTag(uuid_int & 0xFFFFFFFF),
21+
]
22+
)
23+
24+
25+
def convert_properties(tag: CompoundTag):
26+
properties_tag = tag.get("Properties")
27+
if isinstance(properties_tag, CompoundTag):
28+
new_properties_tag = ListTag()
29+
for prop_name, prop_tags in properties_tag.items():
30+
if isinstance(prop_tags, ListTag):
31+
for prop_tag in prop_tags:
32+
if isinstance(prop_tag, CompoundTag):
33+
value = prop_tag.get("Value")
34+
signature = prop_tag.get("Signature")
35+
if isinstance(value, StringTag):
36+
new_prop_tag = CompoundTag(
37+
{"name": StringTag(prop_name), "value": value}
38+
)
39+
if isinstance(signature, StringTag):
40+
new_prop_tag["signature"] = signature
41+
new_properties_tag.append(new_prop_tag)
42+
if new_properties_tag:
43+
tag["properties"] = new_properties_tag
44+
45+
46+
def upgrade_name(tag: CompoundTag):
47+
name_tag = tag.pop("Name", None)
48+
if isinstance(name_tag, StringTag):
49+
tag["name"] = name_tag
50+
51+
52+
def main(nbt):
53+
if isinstance(nbt, CompoundTag):
54+
utags = nbt.get("utags")
55+
if isinstance(utags, CompoundTag):
56+
owner_j1205 = utags.get("owner_j1205")
57+
if isinstance(owner_j1205, CompoundTag):
58+
return [
59+
[
60+
"",
61+
"compound",
62+
[],
63+
"profile",
64+
owner_j1205,
65+
]
66+
]
67+
owner_j116 = utags.get("owner_j116")
68+
if isinstance(owner_j116, CompoundTag):
69+
convert_properties(owner_j116)
70+
upgrade_name(owner_j116)
71+
return [
72+
[
73+
"",
74+
"compound",
75+
[],
76+
"profile",
77+
owner_j116,
78+
]
79+
]
80+
owner_j19 = utags.get("owner_j19")
81+
if isinstance(owner_j19, CompoundTag):
82+
convert_uuid(owner_j19)
83+
convert_properties(owner_j19)
84+
upgrade_name(owner_j19)
85+
return [
86+
[
87+
"",
88+
"compound",
89+
[],
90+
"profile",
91+
owner_j19,
92+
]
93+
]
94+
95+
return []
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import uuid
2+
3+
from amulet_nbt import CompoundTag, ListTag, IntTag, StringTag
4+
5+
6+
def convert_uuid(tag: CompoundTag):
7+
id_tag = tag.pop("Id", None)
8+
if (
9+
isinstance(id_tag, ListTag)
10+
and id_tag.list_data_type == IntTag.tag_id
11+
and len(id_tag) == 4
12+
):
13+
tag["Id"] = StringTag(
14+
str(
15+
uuid.UUID(
16+
int=((id_tag[0] & 0xFFFFFFFF) << 96)
17+
| ((id_tag[1] & 0xFFFFFFFF) << 64)
18+
| ((id_tag[2] & 0xFFFFFFFF) << 32)
19+
| (id_tag[3] & 0xFFFFFFFF)
20+
)
21+
)
22+
)
23+
24+
25+
def convert_properties(tag: CompoundTag):
26+
properties_tag = tag.get("properties")
27+
if isinstance(properties_tag, ListTag):
28+
new_properties_tag = CompoundTag()
29+
for prop_tag in properties_tag:
30+
if isinstance(prop_tag, CompoundTag):
31+
name = prop_tag.get("name")
32+
value = prop_tag.get("value")
33+
signature = prop_tag.get("signature")
34+
if isinstance(name, StringTag) and isinstance(value, StringTag):
35+
new_prop_tag = CompoundTag({"Value": value})
36+
if isinstance(signature, StringTag):
37+
new_prop_tag["Signature"] = signature
38+
new_properties_tag.setdefault(name.py_str, ListTag()).append(
39+
new_prop_tag
40+
)
41+
tag["Properties"] = new_properties_tag
42+
43+
44+
def downgrade_name(tag: CompoundTag):
45+
name_tag = tag.pop("name", None)
46+
if isinstance(name_tag, StringTag):
47+
tag["Name"] = name_tag
48+
49+
50+
def main(nbt):
51+
if isinstance(nbt, CompoundTag):
52+
utags = nbt.get("utags")
53+
if isinstance(utags, CompoundTag):
54+
owner_j19 = utags.get("owner_j19")
55+
if isinstance(owner_j19, CompoundTag):
56+
return [
57+
[
58+
"",
59+
"compound",
60+
[],
61+
"Owner",
62+
owner_j19,
63+
]
64+
]
65+
owner_j116 = utags.get("owner_j116")
66+
if isinstance(owner_j116, CompoundTag):
67+
# convert list[int, 4] to uuid
68+
convert_uuid(owner_j116)
69+
return [
70+
[
71+
"",
72+
"compound",
73+
[],
74+
"Owner",
75+
owner_j116,
76+
]
77+
]
78+
owner_j1205 = utags.get("owner_j1205")
79+
if isinstance(owner_j1205, CompoundTag):
80+
convert_uuid(owner_j1205)
81+
convert_properties(owner_j1205)
82+
downgrade_name(owner_j1205)
83+
return [
84+
[
85+
"",
86+
"compound",
87+
[],
88+
"Owner",
89+
owner_j1205,
90+
]
91+
]
92+
93+
return []

0 commit comments

Comments
 (0)