minerender 2.1.0-alpha.82 → 2.1.0-alpha.83
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/index.d.mts +53 -5
- package/dist/browser/index.d.ts +53 -5
- package/dist/browser/index.js +142 -6
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/index.mjs +142 -6
- package/dist/browser/index.mjs.map +1 -1
- package/dist/bundle.js +145 -6
- package/dist/bundle.js.map +1 -1
- package/dist/node/index.d.mts +53 -5
- package/dist/node/index.d.ts +53 -5
- package/dist/node/index.js +146 -6
- package/dist/node/index.js.map +1 -1
- package/dist/node/index.mjs +144 -6
- package/dist/node/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/browser/index.mjs
CHANGED
|
@@ -260,7 +260,8 @@ var init_Caching = __esm({
|
|
|
260
260
|
this.entityTextureCache,
|
|
261
261
|
this.entityAnimationCache,
|
|
262
262
|
this.blockEntityIndexCache,
|
|
263
|
-
this.fontCache
|
|
263
|
+
this.fontCache,
|
|
264
|
+
this.bannerPatternCache
|
|
264
265
|
];
|
|
265
266
|
}
|
|
266
267
|
/** Invalidates in-memory entries so later lookups reload them. Persisted entries are retained. */
|
|
@@ -309,6 +310,7 @@ var init_Caching = __esm({
|
|
|
309
310
|
_Caching.entityAnimationCache = _Caching.createAssetCache();
|
|
310
311
|
_Caching.blockEntityIndexCache = _Caching.createAssetCache();
|
|
311
312
|
_Caching.fontCache = _Caching.createAssetCache();
|
|
313
|
+
_Caching.bannerPatternCache = _Caching.createAssetCache();
|
|
312
314
|
Caching = _Caching;
|
|
313
315
|
}
|
|
314
316
|
});
|
|
@@ -941,6 +943,7 @@ var init_Materials = __esm({
|
|
|
941
943
|
material.depthWrite = false;
|
|
942
944
|
break;
|
|
943
945
|
case "eyes":
|
|
946
|
+
case "no_outline":
|
|
944
947
|
material.transparent = true;
|
|
945
948
|
material.alphaTest = 0;
|
|
946
949
|
material.depthWrite = false;
|
|
@@ -1529,6 +1532,79 @@ var init_AssetParsers = __esm({
|
|
|
1529
1532
|
}
|
|
1530
1533
|
});
|
|
1531
1534
|
|
|
1535
|
+
// src/assets/BannerPatterns.ts
|
|
1536
|
+
var DYE_COLORS, BannerPatterns;
|
|
1537
|
+
var init_BannerPatterns = __esm({
|
|
1538
|
+
"src/assets/BannerPatterns.ts"() {
|
|
1539
|
+
init_AssetKey();
|
|
1540
|
+
init_AssetLoader();
|
|
1541
|
+
init_AssetParsers();
|
|
1542
|
+
init_Caching();
|
|
1543
|
+
DYE_COLORS = Object.freeze({
|
|
1544
|
+
white: 16383998,
|
|
1545
|
+
orange: 16351261,
|
|
1546
|
+
magenta: 13061821,
|
|
1547
|
+
light_blue: 3847130,
|
|
1548
|
+
yellow: 16701501,
|
|
1549
|
+
lime: 8439583,
|
|
1550
|
+
pink: 15961002,
|
|
1551
|
+
gray: 4673362,
|
|
1552
|
+
light_gray: 10329495,
|
|
1553
|
+
cyan: 1481884,
|
|
1554
|
+
purple: 8991416,
|
|
1555
|
+
blue: 3949738,
|
|
1556
|
+
brown: 8606770,
|
|
1557
|
+
green: 6192150,
|
|
1558
|
+
red: 11546150,
|
|
1559
|
+
black: 1908001
|
|
1560
|
+
});
|
|
1561
|
+
BannerPatterns = class {
|
|
1562
|
+
/** Lists namespaced pattern IDs from the selected namespace's data directory. */
|
|
1563
|
+
static async getList(namespace = "minecraft", root) {
|
|
1564
|
+
const collect = async (path) => {
|
|
1565
|
+
const prefix2 = path ? `${path}/` : "";
|
|
1566
|
+
const key = new AssetKey(namespace, `${prefix2}_list`, "banner_pattern", void 0, "data", ".json", root);
|
|
1567
|
+
const list2 = await Caching.listAssetCache.get(key.serialize(), () => AssetLoader.get(key, "list" /* LIST */));
|
|
1568
|
+
if (!list2) return [];
|
|
1569
|
+
const files = list2.files.filter((file) => file.endsWith(".json") && file !== "_list.json").map((file) => `${namespace}:${prefix2}${file.slice(0, -5)}`);
|
|
1570
|
+
const children = await Promise.all(list2.directories.map((directory) => collect(`${prefix2}${directory}`)));
|
|
1571
|
+
return [...files, ...children.flat()];
|
|
1572
|
+
};
|
|
1573
|
+
return collect("");
|
|
1574
|
+
}
|
|
1575
|
+
/** Returns the named dye's sRGB value, rejecting unknown colors. */
|
|
1576
|
+
static getColor(color2) {
|
|
1577
|
+
if (typeof color2 !== "string" || !Object.prototype.hasOwnProperty.call(DYE_COLORS, color2)) throw new Error(`Unsupported dye color ${color2}`);
|
|
1578
|
+
return DYE_COLORS[color2];
|
|
1579
|
+
}
|
|
1580
|
+
/** Resolves the first 16 layers of a `banner_patterns` component, preserving their order. */
|
|
1581
|
+
static async getLayers(value, target, root) {
|
|
1582
|
+
if (value === void 0) return [];
|
|
1583
|
+
if (!Array.isArray(value)) throw new Error("banner_patterns must be an array");
|
|
1584
|
+
return Promise.all(value.slice(0, 16).map(async (layer) => {
|
|
1585
|
+
if (!layer || typeof layer !== "object" || Array.isArray(layer)) throw new Error("Each banner pattern requires a pattern and dye color");
|
|
1586
|
+
const color2 = this.getColor(layer.color);
|
|
1587
|
+
let pattern2 = layer.pattern;
|
|
1588
|
+
if (typeof pattern2 === "string") {
|
|
1589
|
+
const id = this.identifier(pattern2);
|
|
1590
|
+
const key = new AssetKey(id.namespace, id.getFullPath(), "banner_pattern", void 0, "data", ".json", root);
|
|
1591
|
+
pattern2 = await Caching.bannerPatternCache.get(key.serialize(), () => AssetLoader.get(key, "json" /* JSON */));
|
|
1592
|
+
if (!pattern2) throw new Error(`Missing banner pattern ${layer.pattern}`);
|
|
1593
|
+
}
|
|
1594
|
+
if (!pattern2 || typeof pattern2 !== "object" || Array.isArray(pattern2) || typeof pattern2.translation_key !== "string") throw new Error("Banner patterns require asset_id and translation_key");
|
|
1595
|
+
const asset2 = this.identifier(pattern2.asset_id);
|
|
1596
|
+
return { color: color2, texture: new AssetKey(asset2.namespace, `${target}/${asset2.getFullPath()}`, "textures", "entity", "assets", ".png", root) };
|
|
1597
|
+
}));
|
|
1598
|
+
}
|
|
1599
|
+
static identifier(value) {
|
|
1600
|
+
if (typeof value !== "string" || !/^(?:[a-z0-9_.-]+:)?[a-z0-9_./-]+$/.test(value)) throw new Error(`Invalid banner-pattern identifier ${value}`);
|
|
1601
|
+
const [namespace, path] = value.includes(":") ? value.split(":") : ["minecraft", value];
|
|
1602
|
+
return new AssetKey(namespace, path);
|
|
1603
|
+
}
|
|
1604
|
+
};
|
|
1605
|
+
}
|
|
1606
|
+
});
|
|
1607
|
+
|
|
1532
1608
|
// src/assets/Models.ts
|
|
1533
1609
|
var Models;
|
|
1534
1610
|
var init_Models = __esm({
|
|
@@ -1541,6 +1617,7 @@ var init_Models = __esm({
|
|
|
1541
1617
|
init_AssetKey();
|
|
1542
1618
|
init_AssetParsers();
|
|
1543
1619
|
init_DisplayPosition();
|
|
1620
|
+
init_BannerPatterns();
|
|
1544
1621
|
Models = class _Models {
|
|
1545
1622
|
// opened lazily: touching the store at import time would hit IndexedDB/disk just for loading
|
|
1546
1623
|
// the library, and would require an EnvProvider before any entry has had a chance to register
|
|
@@ -1730,6 +1807,13 @@ var init_Models = __esm({
|
|
|
1730
1807
|
if (!node.base || !node.model || typeof node.model !== "object") break;
|
|
1731
1808
|
const special = node.model;
|
|
1732
1809
|
switch (special.type) {
|
|
1810
|
+
case "banner":
|
|
1811
|
+
case "minecraft:banner":
|
|
1812
|
+
if (typeof special.color === "string" && Object.prototype.hasOwnProperty.call(DYE_COLORS, special.color)) return { model: node.base, special };
|
|
1813
|
+
break;
|
|
1814
|
+
case "shield":
|
|
1815
|
+
case "minecraft:shield":
|
|
1816
|
+
return { model: node.base, special };
|
|
1733
1817
|
case "shulker_box":
|
|
1734
1818
|
case "minecraft:shulker_box":
|
|
1735
1819
|
if (typeof special.texture === "string" && special.texture && (special.openness === void 0 || typeof special.openness === "number" && Number.isFinite(special.openness)) && (special.orientation === void 0 || ["down", "up", "north", "south", "west", "east"].includes(special.orientation))) {
|
|
@@ -5440,9 +5524,11 @@ var init_SpecialItems = __esm({
|
|
|
5440
5524
|
"src/model/SpecialItems.ts"() {
|
|
5441
5525
|
init_AssetKey();
|
|
5442
5526
|
init_Entities();
|
|
5527
|
+
init_BannerPatterns();
|
|
5528
|
+
init_ModelTextures();
|
|
5443
5529
|
SpecialItems = class {
|
|
5444
5530
|
/** Resolves the static entity parts drawn by a special item renderer, in model units. */
|
|
5445
|
-
static async getParts(special, root) {
|
|
5531
|
+
static async getParts(special, root, components = {}) {
|
|
5446
5532
|
const texture = (id, directory) => {
|
|
5447
5533
|
const key = AssetKey.parse("textures", id);
|
|
5448
5534
|
return new AssetKey(
|
|
@@ -5455,13 +5541,60 @@ var init_SpecialItems = __esm({
|
|
|
5455
5541
|
root
|
|
5456
5542
|
);
|
|
5457
5543
|
};
|
|
5458
|
-
const load = async (id, textureKey, transform, rotations = {}) => {
|
|
5544
|
+
const load = async (id, textureKey, transform, rotations = {}, layers = ["main"]) => {
|
|
5459
5545
|
const key = new AssetKey("minecraft", id, void 0, void 0, "entity-models", ".json", root);
|
|
5460
|
-
const model = await Entities.getEntity(key, textureKey, { layer:
|
|
5546
|
+
const model = await Entities.getEntity(key, textureKey, layers.length === 1 ? { layer: layers[0] } : {
|
|
5547
|
+
layers,
|
|
5548
|
+
textures: textureKey ? Object.fromEntries(layers.map((name) => [name, textureKey])) : void 0
|
|
5549
|
+
});
|
|
5461
5550
|
if (!model) throw new Error(`Missing entity model minecraft:${id} for special item ${special.type}`);
|
|
5462
5551
|
return { model, transform, rotations };
|
|
5463
5552
|
};
|
|
5464
5553
|
switch (special.type) {
|
|
5554
|
+
case "minecraft:banner":
|
|
5555
|
+
case "banner":
|
|
5556
|
+
case "minecraft:shield":
|
|
5557
|
+
case "shield": {
|
|
5558
|
+
const banner = special.type === "banner" || special.type === "minecraft:banner";
|
|
5559
|
+
const color2 = banner ? BannerPatterns.getColor(special.color) : components["minecraft:base_color"] === void 0 ? void 0 : BannerPatterns.getColor(components["minecraft:base_color"]);
|
|
5560
|
+
const patterns = await BannerPatterns.getLayers(components["minecraft:banner_patterns"], banner ? "banner" : "shield", root);
|
|
5561
|
+
const patterned = banner || color2 !== void 0 || patterns.length > 0;
|
|
5562
|
+
const baseTexture = texture(banner ? "banner_base" : patterned ? "shield_base" : "shield_base_nopattern", "");
|
|
5563
|
+
const transform = banner ? new Matrix48().makeTranslation(8, 0, 8).multiply(new Matrix48().makeScale(2 / 3, -2 / 3, -2 / 3)) : new Matrix48().makeScale(1, -1, -1);
|
|
5564
|
+
const part = await load(banner ? "standing_banner" : "shield", baseTexture, transform, {}, banner ? ["main", "flag"] : ["main"]);
|
|
5565
|
+
const layers = Object.fromEntries(Object.entries(part.model.layers ?? { main: part.model }).map(([name, layer]) => [name, { ...layer, render: "solid" }]));
|
|
5566
|
+
let overlay2;
|
|
5567
|
+
if (banner) {
|
|
5568
|
+
const flagLayer = layers.flag;
|
|
5569
|
+
const flag = flagLayer?.layer.root.children.flag;
|
|
5570
|
+
if (!flag) throw new Error("Banner entity model is missing its flag layer");
|
|
5571
|
+
overlay2 = { ...flagLayer.layer, root: { ...flagLayer.layer.root, children: {
|
|
5572
|
+
...flagLayer.layer.root.children,
|
|
5573
|
+
flag: { ...flag, pose: { ...flag.pose, rotation: [-25e-4 * Math.PI, flag.pose.rotation[1], flag.pose.rotation[2]] } }
|
|
5574
|
+
} } };
|
|
5575
|
+
layers.flag = { ...flagLayer, layer: overlay2 };
|
|
5576
|
+
} else {
|
|
5577
|
+
const main = layers.main.layer;
|
|
5578
|
+
const plate = main.root.children.plate;
|
|
5579
|
+
if (!plate) throw new Error("Shield entity model is missing its plate");
|
|
5580
|
+
overlay2 = { ...main, root: { ...main.root, cubes: [], children: { plate } } };
|
|
5581
|
+
}
|
|
5582
|
+
const tints = {};
|
|
5583
|
+
if (patterned) {
|
|
5584
|
+
const draws = [{ texture: texture(`${banner ? "banner" : "shield"}/base`, ""), color: color2 ?? DYE_COLORS.white }, ...patterns];
|
|
5585
|
+
draws.forEach((draw, index) => {
|
|
5586
|
+
const name = index === 0 ? "pattern_base" : `pattern_${index - 1}`;
|
|
5587
|
+
layers[name] = { key: draw.texture, texture: draw.texture, layer: overlay2, render: "no_outline", tint: name };
|
|
5588
|
+
tints[name] = draw.color;
|
|
5589
|
+
});
|
|
5590
|
+
}
|
|
5591
|
+
await Promise.all([...new Map(Object.values(layers).map((layer) => [layer.texture.serialize(), layer.texture])).values()].map(async (key) => {
|
|
5592
|
+
if (!await ModelTextures.preload(key)) throw new Error(`Missing special item texture ${key.toNamespacedString()}`);
|
|
5593
|
+
}));
|
|
5594
|
+
part.model = { ...part.model, ...layers.main, layers };
|
|
5595
|
+
part.tints = tints;
|
|
5596
|
+
return [part];
|
|
5597
|
+
}
|
|
5465
5598
|
case "minecraft:chest":
|
|
5466
5599
|
case "chest": {
|
|
5467
5600
|
const angle = -(special.openness ?? 0) * Math.PI / 2;
|
|
@@ -5756,12 +5889,12 @@ var init_ModelObject = __esm({
|
|
|
5756
5889
|
this.options.tints = await ItemTints.get(this.originalModel, this.options.tints);
|
|
5757
5890
|
const special = this.originalModel.special;
|
|
5758
5891
|
if (special) {
|
|
5759
|
-
const parts2 = await SpecialItems.getParts(special, this.originalModel.key?.root);
|
|
5892
|
+
const parts2 = await SpecialItems.getParts(special, this.originalModel.key?.root, this.originalModel.components);
|
|
5760
5893
|
const transform = this.options.displayPosition ? DisplayTransforms.getMatrix(this.originalModel.display, this.options.displayPosition) : new Matrix49();
|
|
5761
5894
|
transform.multiply(new Matrix49().makeTranslation(-8, -8, -8));
|
|
5762
5895
|
try {
|
|
5763
5896
|
for (const part of parts2) {
|
|
5764
|
-
const object3 = new EntityObject(part.model, { flip: false, wireframe: this.options.wireframe });
|
|
5897
|
+
const object3 = new EntityObject(part.model, { flip: false, wireframe: this.options.wireframe, tints: part.tints });
|
|
5765
5898
|
object3.matrix.copy(transform).multiply(part.transform);
|
|
5766
5899
|
object3.matrixWorldNeedsUpdate = true;
|
|
5767
5900
|
object3.matrixAutoUpdate = false;
|
|
@@ -6385,6 +6518,7 @@ function shutdown() {
|
|
|
6385
6518
|
init_AssetKey();
|
|
6386
6519
|
init_AssetLoader();
|
|
6387
6520
|
init_Assets();
|
|
6521
|
+
init_BannerPatterns();
|
|
6388
6522
|
|
|
6389
6523
|
// src/assets/BlockEntities.ts
|
|
6390
6524
|
init_AssetKey();
|
|
@@ -16797,6 +16931,7 @@ export {
|
|
|
16797
16931
|
Axis,
|
|
16798
16932
|
BUILTIN_ENTITY,
|
|
16799
16933
|
BUILTIN_GENERATED,
|
|
16934
|
+
BannerPatterns,
|
|
16800
16935
|
BasicAssetKey,
|
|
16801
16936
|
BatchedExecutor,
|
|
16802
16937
|
BlockEntities,
|
|
@@ -16821,6 +16956,7 @@ export {
|
|
|
16821
16956
|
DEFAULT_ROOT,
|
|
16822
16957
|
DEFAULT_UV,
|
|
16823
16958
|
DISPLAY_POSITIONS,
|
|
16959
|
+
DYE_COLORS,
|
|
16824
16960
|
DefaultBlockStates,
|
|
16825
16961
|
DisplayPosition,
|
|
16826
16962
|
DisplayTransforms,
|