Files
tools
XYPHER_RED_16X_PvP
Code
3 492
tools/generate_pack.py
from pathlib import Path
import json
import math
import struct
import zlib
ROOT = Path(__file__).resolve().parents[1]
PACK = ROOT / "XYPHER_RED_16X_PvP"
HEADER_UUID = "3f71e7b2-6e5f-4d03-9bd1-cb9f94b9e46e"
MODULE_UUID = "d7b4dc9c-fd43-4df7-a1b6-c0d9cfcc42a7"
TRANSPARENT = (0, 0, 0, 0)
RED = (220, 28, 45, 255)
BRIGHT_RED = (255, 58, 70, 255)
DARK_RED = (112, 12, 24, 255)
DEEP_RED = (72, 8, 18, 255)
WHITE = (255, 245, 245, 255)
BLACK = (24, 12, 16, 255)
GREEN = (73, 175, 64, 255)
LIGHT_GREEN = (108, 210, 72, 255)
DARK_GREEN = (36, 112, 42, 255)
DIRT = (126, 79, 46, 255)
DARK_DIRT = (91, 53, 34, 255)
GOLD = (255, 190, 32, 255)
DARK_GOLD = (181, 109, 18, 255)
BLUE = (34, 139, 204, 255)
LIGHT_BLUE = (68, 190, 235, 255)
ORANGE = (244, 109, 24, 255)
LIGHT_ORANGE = (255, 190, 51, 255)
GRAY = (151, 158, 171, 255)
DARK_GRAY = (70, 76, 91, 255)
BROWN = (116, 66, 38, 255)
def new_image(color=TRANSPARENT):
return [[color for _ in range(16)] for _ in range(16)]
def set_pixel(image, x, y, color):
if 0 <= x < 16 and 0 <= y < 16:
image[y][x] = color
def rectangle(image, x1, y1, x2, y2, color):
for y in range(y1, y2 + 1):
for x in range(x1, x2 + 1):
set_pixel(image, x, y, color)
def line(image, x1, y1, x2, y2, color, width=1):
steps = max(abs(x2 - x1), abs(y2 - y1), 1)
for index in range(steps + 1):
ratio = index / steps
x = round(x1 + (x2 - x1) * ratio)
y = round(y1 + (y2 - y1) * ratio)
for offset_x in range(-width + 1, width):
for offset_y in range(-width + 1, width):
set_pixel(image, x + offset_x, y + offset_y, color)
def circle(image, center_x, center_y, radius, color):
for y in range(16):
for x in range(16):
distance = math.sqrt((x - center_x) ** 2 + (y - center_y) ** 2)
if distance <= radius:
set_pixel(image, x, y, color)
def save_png(path, image):
path.parent.mkdir(parents=True, exist_ok=True)
raw = bytearray()
for row in image:
raw.append(0)
for red, green, blue, alpha in row:
raw.extend((red, green, blue, alpha))
def chunk(name, data):
return (
struct.pack(">I", len(data))
+ name
+ data
+ struct.pack(">I", zlib.crc32(name + data) & 0xFFFFFFFF)
)
png = b"\x89PNG\r\n\x1a\n"
png += chunk(b"IHDR", struct.pack(">IIBBBBB", 16, 16, 8, 6, 0, 0, 0))
png += chunk(b"IDAT", zlib.compress(bytes(raw), 9))
png += chunk(b"IEND", b"")
path.write_bytes(png)
def sword(base, accent, handle=BROWN):
image = new_image()
line(image, 3, 13, 12, 4, DARK_GRAY, 2)
line(image, 4, 12, 12, 4, base, 1)
line(image, 7, 9, 11, 5, accent, 1)
line(image, 2, 14, 5, 11, handle, 1)
line(image, 3, 13, 6, 10, DARK_GOLD, 1)
line(image, 4, 10, 8, 10, GOLD, 1)
set_pixel(image, 12, 3, WHITE)
return image
def golden_apple():
image = new_image()
rectangle(image, 6, 1, 9, 2, DARK_GREEN)
rectangle(image, 5, 3, 10, 4, GOLD)
rectangle(image, 3, 5, 12, 10, GOLD)
rectangle(image, 5, 11, 10, 12, DARK_GOLD)
rectangle(image, 6, 4, 8, 7, LIGHT_ORANGE)
rectangle(image, 4, 6, 5, 8, LIGHT_ORANGE)
rectangle(image, 9, 5, 11, 8, DARK_GOLD)
set_pixel(image, 8, 1, BROWN)
return image
def ender_pearl():
image = new_image()
circle(image, 8, 8, 6, DEEP_RED)
circle(image, 8, 8, 5, DARK_RED)
circle(image, 7, 7, 4, RED)
rectangle(image, 5, 4, 7, 5, BRIGHT_RED)
rectangle(image, 4, 6, 5, 8, BRIGHT_RED)
set_pixel(image, 10, 10, DARK_RED)
return image
def potion():
image = new_image()
rectangle(image, 6, 1, 9, 3, GRAY)
rectangle(image, 5, 4, 10, 5, DARK_GRAY)
rectangle(image, 4, 6, 11, 12, DARK_RED)
rectangle(image, 5, 6, 10, 10, RED)
rectangle(image, 6, 6, 8, 8, BRIGHT_RED)
rectangle(image, 5, 12, 10, 13, DEEP_RED)
return image
def bow():
image = new_image()
line(image, 4, 2, 2, 8, BROWN, 2)
line(image, 2, 8, 4, 14, BROWN, 2)
line(image, 5, 3, 5, 13, WHITE, 1)
line(image, 5, 8, 13, 8, RED, 1)
line(image, 11, 7, 13, 8, GOLD, 1)
line(image, 11, 9, 13, 8, GOLD, 1)
return image
def fishing_rod():
image = new_image()
line(image, 2, 13, 10, 3, BROWN, 1)
line(image, 3, 14, 5, 12, DARK_GOLD, 2)
line(image, 10, 3, 13, 3, GRAY, 1)
line(image, 13, 3, 13, 8, WHITE, 1)
line(image, 13, 8, 11, 10, WHITE, 1)
circle(image, 11, 11, 2, BRIGHT_RED)
set_pixel(image, 11, 11, RED)
return image
def cobweb():
image = new_image()
for offset in range(-16, 32, 4):
line(image, 0, offset, 15, offset + 15, RED, 1)
line(image, 15, offset, 0, offset + 15, DARK_RED, 1)
for value in (2, 6, 10, 14):
line(image, 0, value, 15, value, BRIGHT_RED, 1)
line(image, value, 0, value, 15, RED, 1)
return image
def grass_top():
image = new_image(GREEN)
for y in range(16):
for x in range(16):
if (x * 5 + y * 3) % 11 == 0:
set_pixel(image, x, y, LIGHT_GREEN)
elif (x * 7 + y) % 17 == 0:
set_pixel(image, x, y, DARK_GREEN)
return image
def grass_side():
image = new_image(DIRT)
rectangle(image, 0, 0, 15, 3, GREEN)
rectangle(image, 0, 0, 15, 1, LIGHT_GREEN)
for y in range(4, 16):
for x in range(16):
if (x * 3 + y * 5) % 13 == 0:
set_pixel(image, x, y, DARK_DIRT)
for x in range(0, 16, 4):
set_pixel(image, x, 2, DARK_GREEN)
return image
def water():
image = new_image(BLUE)