Skip to content

Commit

Permalink
Added eggs & other resource pack stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Noxitu committed Feb 4, 2024
1 parent 4a686ae commit b5e8b47
Show file tree
Hide file tree
Showing 25 changed files with 330 additions and 5 deletions.
Binary file added Components/Resource/Dungeon Logs/do2/_skull.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions Components/Resource/Dungeon Logs/do2/dungeon_logs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from pathlib import Path
from noxpack import json

BRILLIANCE_PATH = Path(__file__).resolve().parents[5] / "trackedout/Brilliance/Brilliance Resourcepack/assets"

def paper_list():
path = "do2/textures/item/artifacts"
glob = (BRILLIANCE_PATH / path).glob("*.png")
return ["skull"] + [path.stem for path in glob]


def _create_model(name):
@json(path=f"do2/models/item/dungeon_log/paper_{name}")
def _():
return {
"parent": "item/generated",
"textures": {
"layer0": f"do2:item/dungeon_log/paper_{name}",
}
}

for name in paper_list():
_create_model(name)
23 changes: 23 additions & 0 deletions Components/Resource/Dungeon Logs/do2/paper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from noxpack import json
from .dungeon_logs import paper_list


@json(path="minecraft/models/item/paper")
def _():
overrides = []

for idx, name in enumerate(paper_list()):
overrides.append(
{
"predicate": {"custom_model_data": idx + 1},
"model": f"do2:item/dungeon_log/paper_{name}",
}
)

return {
"parent": "item/generated",
"textures": {
"layer0": "item/paper",
},
"overrides": overrides,
}
73 changes: 73 additions & 0 deletions Components/Resource/Dungeon Logs/do2/textures.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
from pathlib import Path

import matplotlib.pyplot as plt
import numpy as np
import cv2

from noxpack import png
from .dungeon_logs import paper_list


BRILLIANCE_PATH = Path(__file__).resolve().parents[5] / "trackedout/Brilliance/Brilliance Resourcepack/assets"
MINECRAFT_PATH = Path(__file__).resolve().parents[6] / "Minecraft/Data/Versions/1.20.1/assets"
SELF = Path(__file__).resolve().parent


def imread(name):
if name == "do2:item/paper":
name = name.replace("do2:", "minecraft:")
root = MINECRAFT_PATH
else:
root = BRILLIANCE_PATH

image = plt.imread((root / name.replace(":", "/textures/")).with_suffix(".png"))
image = (255 * image).astype("u1")

if name == "do2:item/artifacts/tntslab":
assert image.shape == (64, 256, 4), f"Invalid shape: {image.shape}"
image = image[:, 128:][:, :64]
image[32:] = 0

return image


PAPER = imread("do2:item/paper")


def _create_texture(name):
@png(name=f"item/dungeon_log/paper_{name}")
def _():
if name == "skull":
icon = plt.imread(SELF / "_skull.png")
icon = 255 * icon
icon = (icon - 20) * 255 / (175 - 20)
icon = icon.clip(0, 255).astype("u1")
icon = np.concatenate([icon, 255 - icon[..., 0:1]], axis=-1)
else:
icon = imread(f"do2:item/artifacts/{name}")

size = 48
k2 = size / 128
x1, x2, y1, y2 = -16, 48, -24, 56
k1 = icon.shape[0] / 32
paper = cv2.resize(PAPER, (size, size), interpolation=cv2.INTER_NEAREST)
P = cv2.getPerspectiveTransform(
k1 * np.array([x1, y1, x2, y1, x2, y2, x1, y2]).astype('f4').reshape(4, 1, 2),
k2 * np.array([80, 14.7, 125, 59.8, 54.3, 111.7, 8.6, 64.7]).astype('f4').reshape(4, 1, 2),
)
# icon2 = cv2.warpPerspective(icon, P, (size, size), flags=cv2.INTER_NEAREST)
icon2 = cv2.warpPerspective(icon, P, (size, size), flags=cv2.INTER_CUBIC)
canvas = paper.copy()

a1 = icon2[..., -1].astype('f4') / 255
a2 = (1 - a1) * canvas[..., -1].astype('f4') / 255
a = a1 + a2
a = a.clip(0.001, None)

canvas = icon2 * (a1 / a)[..., np.newaxis] + canvas * (a2 / a)[..., np.newaxis]
canvas[..., -1] = 255 * a
canvas = canvas.clip(0, 255).astype("u1")
return canvas

for name in paper_list():
_create_texture(name)
75 changes: 75 additions & 0 deletions Components/Resource/Font Icons/do2/textures/font_icons.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
from pathlib import Path

import matplotlib.pyplot as plt
import numpy as np

from noxpack import png


BRILLIANCE_PATH = Path(__file__).resolve().parents[6] / "trackedout/Brilliance/Brilliance Resourcepack/assets"
MINECRAFT_PATH = Path(__file__).resolve().parents[7] / "Minecraft/Data/Versions/1.20.1/assets"


def image_list(path):
glob = (BRILLIANCE_PATH / path.replace(":", "/textures/")).glob("*.png")
return [path.stem for path in glob]


def imread(name):
if name == "do2:item/sweet_berries":
name = name.replace("do2:", "minecraft:")
root = MINECRAFT_PATH
else:
root = BRILLIANCE_PATH

image = plt.imread((root / name.replace(":", "/textures/")).with_suffix(".png"))
image = (255 * image).astype("u1")

if name == "do2:item/artifacts/tntslab":
assert image.shape == (64, 256, 4), f"Invalid shape: {image.shape}"
image = image[:, 128:][:, :64]
image[32:] = 0

return image


def png_array(call):
@png(name=call.__name__)
def _():
names = []

for item in call():
if isinstance(item, str):
names.append(item)
elif isinstance(item, tuple) and len(item) == 2 and isinstance(item[1], list):
prefix, item = item
names.extend(prefix + name for name in item)
else:
names.extend(item)

textures = [
imread(f"do2:item/{name}") for name in names
]

for texture in textures:
texture[-1, -1] = (60, 60, 60, 1)

return np.concatenate(textures, axis=1)


@png_array
def icons16():
yield "do_coin", "do_crown", "do_ember", "do_tome"
yield "sweet_berries"

@png_array
def icons32():
artifacts = image_list("do2:/item/artifacts")
artifacts = [a for a in artifacts if a != "tntslab"]
print(f":: Got {len(artifacts)} artifacts.")
yield "artifacts/", artifacts

@png_array
def icons64():
yield "keys/", ["do_key1_64", "do_key4_64", "do_key6_64", "toolbox", "do_key3_64"]
yield "artifacts/tntslab"
43 changes: 43 additions & 0 deletions Components/Resource/Font Icons/minecraft/font/default.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from noxpack import json
import numpy as np


def _space(code, size):
return {
"type": "bitmap",
"file": "do2:gui/empty.png",
"ascent": -65535,
"height": size - (1 if size > 0 else 2),
"chars": [chr(code)],
}


def _bitmap(name, ascent, height, chars):
return {
"type": "bitmap",
"file": f"{name}.png",
"ascent": ascent,
"height": height,
"chars": [chars],
}

@json
def _():
space_left = []
space_right = []

implemented = list(range(1, 33)) + [64, 128, 255]
space_left = [_space(0xEB00 + size, -size) for size in implemented]
space_right = [_space(0xEA00 + size, size) for size in implemented]

artifacts = "".join(chr(0xe100 + i) for i in range(1, 30))

return {
"providers": [
_bitmap("do2:font_icons/icons16", 16, 16, "\ue001\ue002\ue003\ue004\ue023"),
_bitmap("do2:font_icons/icons32", 16, 16, artifacts),
_bitmap("do2:font_icons/icons64", 16, 16, "\ue011\ue012\ue013\ue021\ue022\ue11e"),
*space_left,
*space_right,
]
}
25 changes: 25 additions & 0 deletions Components/Resource/More Eggs/do2/models/item/eggs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from pathlib import Path

from noxpack import json


TEXTURES = Path(__file__).parents[2] / "textures/item/eggs"

def _create_egg(name):
@json(name=name)
def _():
return {
"parent": "custom:item/egg/gold",
"textures": {
"2": f"do2:item/eggs/{name}",
"particle": f"do2:item/eggs/{name}"
}
}


for name in TEXTURES.glob("*.png"):
name = name.stem
if name.startswith("_"):
continue

_create_egg(name)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions Components/Resource/More Eggs/minecraft/models/item/pumpkin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from noxpack import json
import data


@json
def _():
overrides = []

for name, model in data.CUSTOM_MODIFICATIONS.MORE_EGGS.MODELS.items():
overrides.append(
{
"predicate": {"custom_model_data": model},
"model": f"do2:item/eggs/{name}",
}
)

return {
"parent": "minecraft:block/pumpkin",
"overrides": overrides,
}
24 changes: 24 additions & 0 deletions Configs/Dev-Server.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[
{
"type": "datapack",
"name": "Dev Server Datapack",
"description": "DO2 Experimental Datapack",
"components": [
"-Deck Validation",
"-Ethereal Cards",
"-GUI",
"-Run Summary",
"-Training"
]
},
{
"type": "resource_pack",
"name": "Dev Server Resource Pack",
"description": "DO2 Experimental Datapack",
"components": [
"-Ethereal Cards",
"Font Icons",
"GUI"
]
}
]
16 changes: 12 additions & 4 deletions Configs/Dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,27 @@
{
"type": "datapack",
"name": "Dev Datapack",
"description": "Combined Pack for Development",
"description": "Dev Datapack",
"components": [
"-Deck Validation",
"-Audio",
"-Config",
"Deck Validation",
"-Ethereal Cards",
"GUI"
"-GUI",
"-Run Summary",
"-Training",
"-Warden Anger"
]
},
{
"type": "resource_pack",
"name": "Dev Resource Pack",
"description": "Combined Pack for Development",
"description": "Dev Resource Pack",
"components": [
"-Dungeon Logs",
"More Eggs",
"-Ethereal Cards",
"-Font Icons",
"-GUI"
]
}
Expand Down
7 changes: 7 additions & 0 deletions Pack Builder/src/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
def text_button(text, color, scoreboard, trigger, hint):
return f"""{{
"color": "{color}",
"text": "[{text}]",
"clickEvent": {{"action": "run_command", "value": "/trigger {scoreboard} set {trigger}"}},
"hoverEvent": {{"action": "show_text", "contents": "{hint}"}}
}}"""
6 changes: 5 additions & 1 deletion Pack Builder/src/noxitu_pack_builder/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ def _():
for py_path in component_root.rglob("*.py"):
if any(part.startswith("_") for part in py_path.parts):
continue
_import(py_path, component_root)
try:
_import(py_path, component_root)
except Exception:
print("\033[31m::\033[m Failed: ", py_path)
raise

noxitu_pack_builder.output_file.save_outputs(output_root, root=content_root)

Expand Down

0 comments on commit b5e8b47

Please sign in to comment.