Add block color generation tools for Minecraft 1.13

This commit is contained in:
Matthias Schiffer 2018-07-22 16:54:00 +02:00
parent f3d65febf3
commit 73a072c2ca
Signed by: neocturne
GPG key ID: 16EF3F64CB201D9C
3 changed files with 1392 additions and 0 deletions

1308
resource/blocks.json Normal file

File diff suppressed because it is too large Load diff

58
resource/extract.py Executable file
View file

@ -0,0 +1,58 @@
#!/usr/bin/env python3
import json
import os
import sys
from PIL import Image
if len(sys.argv) != 4:
sys.exit('Usage: extract.py <blocks.json> <asset directory> <colors.json>')
def mean_color(texture):
path = os.path.join(sys.argv[2], texture + '.png')
im = Image.open(path)
data = im.convert('RGBA').getdata()
a = sum([a for (r, g, b, a) in data])
if a == 0:
return None
r = sum([r * a for (r, g, b, a) in data])
g = sum([g * a for (r, g, b, a) in data])
b = sum([b * a for (r, g, b, a) in data])
return {
'r': r / a,
'g': g / a,
'b': b / a,
}
with open(sys.argv[1]) as f:
blocks = json.load(f)
output = {}
for name, info in blocks.items():
id = 'minecraft:' + name
output[id] = {
'color': {'r': 0, 'g': 0, 'b': 0},
'opaque': False,
'green': False,
'blue': False,
}
if info is None:
continue
color = mean_color(info.get('texture', name))
if color:
output[id]['color'] = color
output[id]['opaque'] = True
output[id]['green'] = info.get('green', False)
output[id]['blue'] = info.get('blue', False)
with open(sys.argv[3], 'w') as f:
json.dump(output, f)

26
resource/generate.py Executable file
View file

@ -0,0 +1,26 @@
#!/usr/bin/env python3
import json
import os
import sys
if len(sys.argv) != 3:
sys.exit('Usage: extract.py <colors.json> <BlockType.inc>')
with open(sys.argv[1]) as f:
colors = json.load(f)
output = {}
with open(sys.argv[2], 'w') as f:
for name, info in colors.items():
print('{"%s", {%s, %s, %s, {%u, %u, %u}}},' % (
name,
['false', 'true'][info['opaque']],
['false', 'true'][info['green']],
['false', 'true'][info['blue']],
info['color']['r'],
info['color']['g'],
info['color']['b'],
), file=f)