Files
generate_pack.py
Code
1 359
generate_pack.py
from pathlib import Path
import json
import struct
import zipfile
import zlib
PACK_NAME = "MRHET768GAMERZ_1K"
OUTPUT = Path(PACK_NAME)
ZIP_PATH = Path(f"{PACK_NAME}.zip")
BLACK = (8, 8, 12, 255)
PANEL = (18, 18, 24, 255)
RED = (220, 24, 42, 255)
BRIGHT_RED = (255, 54, 66, 255)
WHITE = (240, 240, 244, 255)
DARK = (55, 12, 20, 255)
FONT = {
"A": ("010", "101", "111", "101", "101"), "B": ("110", "101", "110", "101", "110"),
"C": ("011", "100", "100", "100", "011"), "D": ("110", "101", "101", "101", "110"),
"E": ("111", "100", "110", "100", "111"), "F": ("111", "100", "110", "100", "100"),
"G": ("011", "100", "101", "101", "011"), "H": ("101", "101", "111", "101", "101"),
"I": ("111", "010", "010", "010", "111"), "J": ("001", "001", "001", "101", "010"),
"K": ("101", "101", "110", "101", "101"), "L": ("100", "100", "100", "100", "111"),
"M": ("101", "111", "111", "101", "101"), "N": ("101", "111", "111", "111", "101"),
"O": ("010", "101", "101", "101", "010"), "P": ("110", "101", "110", "100", "100"),
"Q": ("010", "101", "101", "111", "011"), "R": ("110", "101", "110", "101", "101"),
"S": ("011", "100", "010", "001", "110"), "T": ("111", "010", "010", "010", "010"),
"U": ("101", "101", "101", "101", "111"), "V": ("101", "101", "101", "101", "010"),
"W": ("101", "101", "111", "111", "101"), "X": ("101", "101", "010", "101", "101"),
"Y": ("101", "101", "010", "010", "010"), "Z": ("111", "001", "010", "100", "111"),
"0": ("111", "101", "101", "101", "111"), "1": ("010", "110", "010", "010", "111"),
"2": ("110", "001", "010", "100", "111"), "3": ("110", "001", "010", "001", "110"),
"4": ("101", "101", "111", "001", "001"), "5": ("111", "100", "110", "001", "110"),
"6": ("011", "100", "110", "101", "010"), "7": ("111", "001", "010", "010", "010"),
"8": ("010", "101", "010", "101", "010"), "9": ("010", "101", "011", "001", "110"),
"-": ("000", "000", "111", "000", "000"), ".": ("000", "000", "000", "000", "010"),
}
def image(width, height, color=(0, 0, 0, 0)):
return [list(color) * width for _ in range(height)]
def set_pixel(img, x, y, color):
if 0 <= x < len(img[0]) and 0 <= y < len(img):
start = x * 4
img[y][start:start + 4] = color
def rect(img, x, y, width, height, color):
for py in range(max(0, y), min(len(img), y + height)):
for px in range(max(0, x), min(len(img[0]) // 4, x + width)):
set_pixel(img, px, py, color)
def outline(img, x, y, width, height, color):
rect(img, x, y, width, 1, color)
rect(img, x, y + height - 1, width, 1, color)
rect(img, x, y, 1, height, color)
rect(img, x + width - 1, y, 1, height, color)
def line(img, x0, y0, x1, y1, color):
dx, dy = abs(x1 - x0), abs(y1 - y0)
sx, sy = (1 if x0 < x1 else -1), (1 if y0 < y1 else -1)
error = dx - dy
while True:
set_pixel(img, x0, y0, color)
if x0 == x1 and y0 == y1:
break
doubled = error * 2
if doubled > -dy:
error -= dy
x0 += sx
if doubled < dx:
error += dx
y0 += sy
def draw_text(img, x, y, value, color, scale=1, spacing=1):
cursor = x
for char in value.upper():
glyph = FONT.get(char)
if glyph:
for gy, row in enumerate(glyph):
for gx, pixel in enumerate(row):
if pixel == "1":
rect(img, cursor + gx * scale, y + gy * scale, scale, scale, color)
cursor += (4 * scale if glyph else 3 * scale) + spacing
def write_png(path, img):
height, width = len(img), len(img[0]) // 4
raw = b"".join(b"\x00" + bytes(row) for row in img)
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"
+ chunk(b"IHDR", struct.pack(">IIBBBBB", width, height, 8, 6, 0, 0, 0))
+ chunk(b"IDAT", zlib.compress(raw, 9))
+ chunk(b"IEND", b""))
path.parent.mkdir(parents=True, exist_ok=True)
path.write_bytes(png)
def save_texture(relative_path, img):
write_png(OUTPUT / "assets/minecraft/textures" / relative_path, img)
def make_icon():
img = image(128, 128, BLACK)
rect(img, 5, 5, 118, 118, (15, 15, 20, 255))
outline(img, 4, 4, 120, 120, RED)
outline(img, 8, 8, 112, 112, (105, 18, 30, 255))
for offset in range(0, 128, 16):
set_pixel(img, offset, 2, BRIGHT_RED)
set_pixel(img, 127 - offset, 125, BRIGHT_RED)
draw_text(img, 28, 26, "1K", WHITE, 8, 2)
rect(img, 20, 91, 88, 2, RED)
draw_text(img, 25, 101, "MRHET768", WHITE, 2, 1)
return img
def make_inventory():
img = image(176, 166, PANEL)
rect(img, 2, 2, 172, 162, (12, 12, 17, 255))
outline(img, 1, 1, 174, 164, RED)
outline(img, 3, 3, 170, 160, (75, 20, 29, 255))
rect(img, 5, 5, 166, 14, (26, 15, 20, 255))
draw_text(img, 8, 9, "MRHET 1K", WHITE)
rect(img, 6, 23, 164, 1, DARK)
for x, y, columns, rows in ((7, 41, 2, 2), (79, 19, 2, 2), (7, 67, 9, 3), (7, 125, 9, 1)):
for row in range(rows):
for column in range(columns):
sx, sy = x + column * 18, y + row * 18
rect(img, sx, sy, 18, 18, (6, 6, 9, 255))
outline(img, sx, sy, 18, 18, (52, 48, 54, 255))
set_pixel(img, sx + 1, sy + 1, (85, 24, 33, 255))
return img
def make_hotbar():
img = image(182, 22, (0, 0, 0, 0))
rect(img, 0, 0, 182, 22, (12, 12, 17, 220))
outline(img, 0, 0, 182, 22, (86, 28, 39, 255))
for slot in range(9):
x = 2 + slot * 20
rect(img, x, 2, 18, 18, (22, 21, 25, 255))
outline(img, x, 2, 18, 18, (43, 40, 46, 255))
return img
def make_selection():
img = image(24, 24)
outline(img, 0, 0, 24, 24, WHITE)
outline(img, 1, 1, 22, 22, BRIGHT_RED)
return img
def make_crosshair():
img = image(15, 15)
for y in range(2, 13):
for x in range(2, 13):
if (x in (6, 7, 8) or y in (6, 7, 8)) and not (5 <= x <= 9 and 5 <= y <= 9):
set_pixel(img, x, y, (0, 0, 0, 210))
for x, y in ((7, 5), (5, 7), (9, 7), (7, 9)):
set_pixel(img, x, y, BRIGHT_RED)
return img
def make_heart(fill):
img = image(9, 9)
shape = ("01100110", "11111111", "11111111", "11111111", "01111110", "00111100", "00011000")
for y, row in enumerate(shape):
for x, value in enumerate(row):
if value == "1":
set_pixel(img, x, y + 1, fill if y > 0 else BRIGHT_RED)
return img
def make_bar(width, height, filled):
img = image(width, height, (0, 0, 0, 0))
rect(img, 0, 0, width, height, (17, 16, 19, 255))
if filled:
for x in range(width):
color = BRIGHT_RED if x < width * 0.65 else RED
rect(img, x, 1, 1, max(1, height - 2), color)
outline(img, 0, 0, width, height, (80, 74, 78, 255))
return img
def make_particle():
img = image(8, 8)
pixels = ((3, 0), (2, 1), (3, 1), (4, 1), (1, 2), (2, 2), (3, 2), (4, 2), (5, 2),
(1, 3), (2, 3), (3, 3), (4, 3), (5, 3), (2, 4), (3, 4), (4, 4), (3, 5))
for x, y in pixels:
set_pixel(img, x, y, WHITE if (x, y) in ((3, 2), (3, 3)) else BRIGHT_RED)