Files
build_pack.py
manifest.json
README.md
Code
3 415
build_pack.py
from pathlib import Path
import base64
import binascii
import json
import math
import random
import struct
import zipfile
import zlib
ROOT = Path(__file__).resolve().parent
PACK = ROOT / "generated_pack"
OUTPUT = ROOT / "ENDR_YAZBAN_32x.mcpack"
MANIFEST = {
"format_version": 2,
"header": {
"name": "ENDR YAZBAN | Dark End PvP",
"description": "32x32 Dark End, Neon Purple and Diamond PvP Resource Pack optimized for Bedrock mobile.",
"uuid": "a4e1f1e0-4f50-4c4d-9fd3-2d8b0f4e9a11",
"version": [1, 0, 0],
"min_engine_version": [1, 20, 0]
},
"modules": [{
"type": "resources",
"uuid": "d7c2a5b9-6a70-4f81-b7f4-5c0a1e8d3f22",
"version": [1, 0, 0]
}],
"metadata": {
"authors": ["ENDR YAZBAN"],
"license": "Custom"
}
}
def rgba(r, g, b, a=255):
return (r, g, b, a)
def canvas(width=32, height=32, color=(0, 0, 0, 0)):
return [[color for _ in range(width)] for _ in range(height)]
def put(img, x, y, color):
if 0 <= y < len(img) and 0 <= x < len(img[0]):
img[y][x] = color
def rect(img, x1, y1, x2, y2, color):
for y in range(max(0, y1), min(len(img), y2 + 1)):
for x in range(max(0, x1), min(len(img[0]), x2 + 1)):
img[y][x] = color
def line(img, x1, y1, x2, y2, color, width=1):
dx = abs(x2 - x1)
dy = -abs(y2 - y1)
sx = 1 if x1 < x2 else -1
sy = 1 if y1 < y2 else -1
error = dx + dy
while True:
for ox in range(-width + 1, width):
for oy in range(-width + 1, width):
put(img, x1 + ox, y1 + oy, color)
if x1 == x2 and y1 == y2:
break
twice = 2 * error
if twice >= dy:
error += dy
x1 += sx
if twice <= dx:
error += dx
y1 += sy
def polygon(img, points, color):
min_y = max(0, min(y for _, y in points))
max_y = min(len(img) - 1, max(y for _, y in points))
for y in range(min_y, max_y + 1):
intersections = []
for index in range(len(points)):
x1, y1 = points[index]
x2, y2 = points[(index + 1) % len(points)]
if y1 == y2:
continue
if min(y1, y2) <= y < max(y1, y2):
intersections.append(x1 + (y - y1) * (x2 - x1) / (y2 - y1))
intersections.sort()
for index in range(0, len(intersections) - 1, 2):
for x in range(math.ceil(intersections[index]), math.floor(intersections[index + 1]) + 1):
put(img, x, y, color)
def write_png(path, img):
path.parent.mkdir(parents=True, exist_ok=True)
height = len(img)
raw = b"".join(b"\x00" + b"".join(bytes(pixel) for pixel in row) for row in img)
def chunk(name, data):
return (
struct.pack(">I", len(data)) +
name +
data +
struct.pack(">I", binascii.crc32(name + data) & 0xffffffff)
)
png = b"\x89PNG\r\n\x1a\n"
png += chunk(b"IHDR", struct.pack(">IIBBBBB", len(img[0]), height, 8, 6, 0, 0, 0))
png += chunk(b"IDAT", zlib.compress(raw, 9))
png += chunk(b"IEND", b"")
path.write_bytes(png)
def write_json(path, data):
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(json.dumps(data, indent=2, ensure_ascii=False) + "\n", encoding="utf-8")
def block_texture(base, accent, seed, crystal=False):
random.seed(seed)
img = canvas(32, 32, base)
for y in range(32):
for x in range(32):
if x in (0, 31) or y in (0, 31):
put(img, x, y, rgba(max(0, base[0] - 12), max(0, base[1] - 12), max(0, base[2] - 12)))
elif random.random() < 0.07:
shade = random.choice([-12, -7, 8])
put(img, x, y, rgba(max(0, base[0] + shade), max(0, base[1] + shade), max(0, base[2] + shade)))
if crystal:
for cx, cy in ((7, 9), (23, 7), (15, 23), (25, 25)):
for ox, oy in ((0, -2), (-1, -1), (0, -1), (1, -1), (-2, 0), (-1, 0), (0, 0), (1, 0), (2, 0), (-1, 1), (0, 1), (1, 1), (0, 2)):
put(img, cx + ox, cy + oy, accent)
put(img, cx, cy, rgba(220, 255, 255))
return img
def gem_texture(color, dark):
img = canvas()
polygon(img, [(16, 2), (25, 10), (22, 24), (16, 30), (9, 24), (6, 10)], dark)
polygon(img, [(16, 4), (22, 11), (19, 23), (16, 27), (12, 22), (10, 11)], color)
line(img, 12, 9, 16, 24, rgba(225, 255, 255), 1)
line(img, 16, 5, 16, 27, rgba(150, 255, 255), 1)
return img
def sword_texture(blade, energy):
img = canvas()
line(img, 6, 26, 25, 6, rgba(9, 7, 18), 5)
line(img, 7, 25, 25, 7, blade, 3)
line(img, 9, 23, 23, 9, energy, 1)
line(img, 4, 27, 12, 19, rgba(42, 20, 58), 2)
line(img, 3, 28, 9, 22, rgba(13, 10, 22), 2)
rect(img, 2, 28, 8, 30, rgba(8, 7, 14))
rect(img, 4, 27, 7, 28, rgba(107, 55, 120))
return img
def tool_texture(metal, energy):
img = canvas()
line(img, 7, 27, 25, 9, rgba(9, 7, 18), 3)
line(img, 8, 26, 24, 10, rgba(45, 23, 56), 2)
line(img, 9, 25, 23, 11, energy, 1)
polygon(img, [(4, 7), (9, 3), (17, 7), (14, 11), (8, 9)], metal)
line(img, 5, 6, 15, 8, energy, 1)
return img
def armor_texture(accent, seed):
random.seed(seed)
img = canvas(64, 32, rgba(8, 6, 16))
for y in range(32):
for x in range(64):
if random.random() < 0.12:
put(img, x, y, rgba(15, 10, 28))
for x in (3, 14, 25, 36, 47, 58):
line(img, x, 3, x + 4, 14, accent, 1)
line(img, 0, 18, 63, 18, rgba(52, 20, 75), 1)
line(img, 8, 27, 56, 27, accent, 1)
rect(img, 1, 1, 62, 2, rgba(18, 10, 31))
return img
def enderman_texture():
img = canvas(64, 64, rgba(8, 5, 14))
for y in range(64):
for x in range(64):
if (x * 17 + y * 13) % 29 == 0:
put(img, x, y, rgba(28, 12, 42))
rect(img, 16, 8, 47, 29, rgba(12, 7, 20))
rect(img, 20, 12, 43, 25, rgba(20, 8, 30))
rect(img, 23, 17, 29, 18, rgba(220, 65, 255))
rect(img, 34, 17, 40, 18, rgba(78, 245, 255))
rect(img, 24, 17, 28, 17, rgba(255, 150, 255))
rect(img, 35, 17, 39, 17, rgba(210, 255, 255))
line(img, 25, 30, 22, 61, rgba(13, 8, 22), 3)
line(img, 38, 30, 42, 61, rgba(13, 8, 22), 3)
return img
def sky_texture():
random.seed(9137)
img = canvas(128, 128, rgba(3, 2, 10))
for y in range(128):
shade = int((y / 128) * 9)
for x in range(128):
put(img, x, y, rgba(3 + shade // 3, 2, 10 + shade))
for _ in range(95):
x = random.randrange(128)
y = random.randrange(128)
color = random.choice([rgba(115, 50, 180), rgba(214, 75, 255), rgba(63, 213, 255)])
put(img, x, y, color)
if random.random() < 0.2:
put(img, min(127, x + 1), y, rgba(color[0] // 2, color[1] // 2, color[2] // 2))
for i in range(3):
line(img, 0, 35 + i * 25, 127, 22 + i * 25, rgba(35, 10, 58, 90), 1)