Files
assets
tools
pack.mcmeta
README.md
Code
5 153
tools/generate_ice_dagger_texture.py
from pathlib import Path
import struct
import zlib
SIZE = 64
TRANSPARENT = (0, 0, 0, 0)
def create_canvas():
return [[TRANSPARENT for _ in range(SIZE)] for _ in range(SIZE)]
def rectangle(canvas, left, top, right, bottom, color):
for y in range(max(0, top), min(SIZE, bottom + 1)):
for x in range(max(0, left), min(SIZE, right + 1)):
canvas[y][x] = color
def polygon(canvas, points, color):
min_x = max(0, min(x for x, _ in points))
max_x = min(SIZE - 1, max(x for x, _ in points))
min_y = max(0, min(y for _, y in points))
max_y = min(SIZE - 1, max(y for _, y in points))
for y in range(min_y, max_y + 1):
for x in range(min_x, max_x + 1):
inside = False
previous = points[-1]
for current in points:
x1, y1 = previous
x2, y2 = current
if (y1 > y) != (y2 > y):
crossing = (x2 - x1) * (y - y1) / (y2 - y1) + x1
if x < crossing:
inside = not inside
previous = current
if inside:
canvas[y][x] = color
def draw_texture():
canvas = create_canvas()
blade_shadow = (92, 172, 207, 155)
blade = (158, 229, 249, 205)
blade_light = (207, 248, 255, 235)
blade_blue = (74, 190, 238, 220)
core = (103, 232, 255, 255)
core_light = (194, 250, 255, 255)
frost_dark = (24, 55, 76, 255)
handle = (31, 43, 57, 255)
handle_light = (62, 81, 96, 255)
guard = (20, 33, 47, 255)
polygon(canvas, [(18, 45), (24, 37), (29, 32), (34, 25), (40, 17), (48, 7), (52, 4), (50, 13), (45, 23), (39, 31), (33, 39), (26, 47)], blade_shadow)
polygon(canvas, [(23, 42), (28, 34), (34, 28), (38, 20), (45, 12), (50, 7), (47, 17), (42, 25), (36, 34), (30, 43)], blade)
polygon(canvas, [(28, 37), (33, 29), (37, 22), (43, 15), (47, 11), (44, 21), (39, 29), (34, 37)], blade_light)
polygon(canvas, [(30, 40), (34, 31), (39, 25), (44, 18), (41, 28), (36, 36)], blade_blue)
polygon(canvas, [(27, 40), (31, 32), (36, 26), (40, 19), (43, 17), (39, 27), (34, 34), (31, 41)], core)
rectangle(canvas, 34, 28, 36, 34, core_light)
rectangle(canvas, 37, 23, 39, 27, core_light)
rectangle(canvas, 31, 34, 33, 38, (75, 210, 249, 255))
polygon(canvas, [(43, 16), (47, 10), (49, 8), (47, 17)], (231, 253, 255, 220))
polygon(canvas, [(37, 28), (40, 22), (42, 21), (40, 29)], (237, 254, 255, 180))
polygon(canvas, [(25, 42), (29, 37), (30, 41), (27, 45)], frost_dark)
rectangle(canvas, 41, 14, 42, 18, (255, 255, 255, 210))
rectangle(canvas, 35, 24, 36, 27, (255, 255, 255, 190))
polygon(canvas, [(12, 49), (17, 43), (24, 36), (29, 40), (22, 47), (17, 53)], guard)
rectangle(canvas, 15, 44, 25, 46, handle_light)
rectangle(canvas, 13, 47, 20, 49, (48, 69, 83, 255))
polygon(canvas, [(17, 48), (23, 41), (28, 44), (22, 52), (19, 56), (14, 53)], handle)
polygon(canvas, [(19, 49), (23, 45), (25, 46), (21, 52), (18, 54)], handle_light)
rectangle(canvas, 14, 52, 19, 55, frost_dark)
rectangle(canvas, 16, 55, 20, 57, handle)
polygon(canvas, [(13, 53), (17, 55), (20, 57), (18, 59), (13, 56), (11, 54)], guard)
rectangle(canvas, 12, 54, 15, 55, (84, 112, 126, 255))
return canvas
def write_png(path, canvas):
raw = b"".join(b"\x00" + bytes(channel for pixel in row for channel in pixel) for row in canvas)
def chunk(kind, data):
return struct.pack(">I", len(data)) + kind + data + struct.pack(">I", zlib.crc32(kind + data) & 0xFFFFFFFF)
png = b"\x89PNG\r\n\x1a\n"
png += chunk(b"IHDR", struct.pack(">IIBBBBB", SIZE, SIZE, 8, 6, 0, 0, 0))
png += chunk(b"IDAT", zlib.compress(raw, 9))
png += chunk(b"IEND", b"")
path.parent.mkdir(parents=True, exist_ok=True)
path.write_bytes(png)
if __name__ == "__main__":
output = Path(__file__).resolve().parents[1] / "assets/minecraft/textures/item/ice_dagger.png"
write_png(output, draw_texture())
print(f"Generated {output} ({SIZE}x{SIZE})")