-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathResourcePackBuilder.py
47 lines (34 loc) · 1.18 KB
/
ResourcePackBuilder.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
import zipfile
import json
from io import BytesIO
from PIL import Image
# Create a simple image with Pillow
class ResourcePackBuilder:
def __init__(self, mcMeta):
self.packData = {}
if mcMeta != None:
packMeta = json.dumps(mcMeta, indent=4)
self.addFile("pack.mcmeta", str(packMeta))
def addFile(self, filePath, file):
self.packData[filePath] = file
def delFile(self, filePath):
del self.packData[filePath]
def writePack(self, packPath):
with zipfile.ZipFile(packPath, 'w') as zipf:
for filePath, file in self.packData.items():
zipf.writestr(filePath, file)
if __name__ == "__main__":
image = Image.new('RGB', (100, 100), color = 'blue')
image_name = 'image.png'
image_bytes = BytesIO()
image.save(image_bytes, format='PNG')
image_bytes.seek(0)
mcMeta = {
"pack": {
"description": "Test",
"pack_format": 0
}
}
maker = ResourcePackBuilder("furry_paintings", "../pack.png" , mcMeta)
maker.addFile(f'/assets/minecraft/textures/painting/{image_name}', image_bytes.read())
maker.writePack("./furry_paintings.zip")