minerender 2.1.0-alpha.12 → 2.1.0-alpha.13
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 +8 -1
- package/dist/browser/index.d.ts +8 -1
- package/dist/browser/index.js +68 -17
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/index.mjs +68 -17
- package/dist/browser/index.mjs.map +1 -1
- package/dist/bundle.js +68 -17
- package/dist/bundle.js.map +1 -1
- package/dist/node/index.d.mts +8 -1
- package/dist/node/index.d.ts +8 -1
- package/dist/node/index.js +68 -17
- package/dist/node/index.js.map +1 -1
- package/dist/node/index.mjs +68 -17
- package/dist/node/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/node/index.d.mts
CHANGED
|
@@ -671,6 +671,11 @@ declare class AssetLoader {
|
|
|
671
671
|
static getAll<T extends MinecraftAsset>(key: AssetKey, parser: AssetParser | string): Promise<T[]>;
|
|
672
672
|
/** Returns the first defined result in source-priority order, without merging assets. */
|
|
673
673
|
static get<T extends MinecraftAsset>(key: AssetKey, parser: AssetParser | string): Promise<Maybe<T>>;
|
|
674
|
+
/** Tries each path within a source before considering lower-priority sources. */
|
|
675
|
+
static getFirst<T extends MinecraftAsset>(keys: readonly AssetKey[], parser: AssetParser | string): Promise<Maybe<{
|
|
676
|
+
key: AssetKey;
|
|
677
|
+
asset: T;
|
|
678
|
+
}>>;
|
|
674
679
|
}
|
|
675
680
|
|
|
676
681
|
interface BlockState extends MinecraftAsset {
|
|
@@ -696,7 +701,7 @@ interface MultipartCondition {
|
|
|
696
701
|
[key: string]: string;
|
|
697
702
|
}
|
|
698
703
|
|
|
699
|
-
declare const DEFAULT_ROOT = "https://assets.mcasset.cloud/1.
|
|
704
|
+
declare const DEFAULT_ROOT = "https://assets.mcasset.cloud/1.21.11";
|
|
700
705
|
declare const DEFAULT_NAMESPACE = "minecraft";
|
|
701
706
|
declare class Assets {
|
|
702
707
|
/**
|
|
@@ -761,6 +766,8 @@ declare class Models {
|
|
|
761
766
|
private static get PERSISTENT_CACHE();
|
|
762
767
|
static getItemList(): Promise<string[]>;
|
|
763
768
|
static loadAndMerge(key: AssetKey): Promise<Maybe<Model>>;
|
|
769
|
+
private static getItemModel;
|
|
770
|
+
private static defaultItemModel;
|
|
764
771
|
static getRaw(key: AssetKey): Promise<Maybe<Model>>;
|
|
765
772
|
static getMerged(key: AssetKey): Promise<Maybe<Model>>;
|
|
766
773
|
static get(key: AssetKey): Promise<Maybe<Model>>;
|
package/dist/node/index.d.ts
CHANGED
|
@@ -671,6 +671,11 @@ declare class AssetLoader {
|
|
|
671
671
|
static getAll<T extends MinecraftAsset>(key: AssetKey, parser: AssetParser | string): Promise<T[]>;
|
|
672
672
|
/** Returns the first defined result in source-priority order, without merging assets. */
|
|
673
673
|
static get<T extends MinecraftAsset>(key: AssetKey, parser: AssetParser | string): Promise<Maybe<T>>;
|
|
674
|
+
/** Tries each path within a source before considering lower-priority sources. */
|
|
675
|
+
static getFirst<T extends MinecraftAsset>(keys: readonly AssetKey[], parser: AssetParser | string): Promise<Maybe<{
|
|
676
|
+
key: AssetKey;
|
|
677
|
+
asset: T;
|
|
678
|
+
}>>;
|
|
674
679
|
}
|
|
675
680
|
|
|
676
681
|
interface BlockState extends MinecraftAsset {
|
|
@@ -696,7 +701,7 @@ interface MultipartCondition {
|
|
|
696
701
|
[key: string]: string;
|
|
697
702
|
}
|
|
698
703
|
|
|
699
|
-
declare const DEFAULT_ROOT = "https://assets.mcasset.cloud/1.
|
|
704
|
+
declare const DEFAULT_ROOT = "https://assets.mcasset.cloud/1.21.11";
|
|
700
705
|
declare const DEFAULT_NAMESPACE = "minecraft";
|
|
701
706
|
declare class Assets {
|
|
702
707
|
/**
|
|
@@ -761,6 +766,8 @@ declare class Models {
|
|
|
761
766
|
private static get PERSISTENT_CACHE();
|
|
762
767
|
static getItemList(): Promise<string[]>;
|
|
763
768
|
static loadAndMerge(key: AssetKey): Promise<Maybe<Model>>;
|
|
769
|
+
private static getItemModel;
|
|
770
|
+
private static defaultItemModel;
|
|
764
771
|
static getRaw(key: AssetKey): Promise<Maybe<Model>>;
|
|
765
772
|
static getMerged(key: AssetKey): Promise<Maybe<Model>>;
|
|
766
773
|
static get(key: AssetKey): Promise<Maybe<Model>>;
|
package/dist/node/index.js
CHANGED
|
@@ -1297,7 +1297,7 @@ var AssetKey = class _AssetKey extends BasicAssetKey {
|
|
|
1297
1297
|
}
|
|
1298
1298
|
toString() {
|
|
1299
1299
|
let a = [
|
|
1300
|
-
|
|
1300
|
+
this.root ?? AssetLoader.ROOT,
|
|
1301
1301
|
this.rootType ?? "__rootType__",
|
|
1302
1302
|
this.assetType ?? "__assetType__",
|
|
1303
1303
|
this.type ?? "__type__",
|
|
@@ -1347,6 +1347,7 @@ var ModelMerger = class {
|
|
|
1347
1347
|
}
|
|
1348
1348
|
const models = [];
|
|
1349
1349
|
const parentKey = AssetKey.parse("models", model.parent);
|
|
1350
|
+
parentKey.root = model.key?.root;
|
|
1350
1351
|
const parentModel = await Models.getRaw(parentKey);
|
|
1351
1352
|
if (parentModel) {
|
|
1352
1353
|
models.unshift(parentModel);
|
|
@@ -1376,26 +1377,58 @@ var Models = class _Models {
|
|
|
1376
1377
|
return this._persistentCache ??= PersistentCache.open("minerender-models");
|
|
1377
1378
|
}
|
|
1378
1379
|
static async getItemList() {
|
|
1379
|
-
const key = new AssetKey(
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
"
|
|
1383
|
-
"item",
|
|
1384
|
-
"assets",
|
|
1385
|
-
".json",
|
|
1386
|
-
DEFAULT_ROOT
|
|
1387
|
-
);
|
|
1388
|
-
return Caching.listAssetCache.get(key.serialize(), () => {
|
|
1389
|
-
return AssetLoader.get(key, "list" /* LIST */);
|
|
1380
|
+
const key = new AssetKey(DEFAULT_NAMESPACE, "_list", "items");
|
|
1381
|
+
const legacyKey = new AssetKey(DEFAULT_NAMESPACE, "_list", "models", "item");
|
|
1382
|
+
return Caching.listAssetCache.get(key.serialize(), async () => {
|
|
1383
|
+
return (await AssetLoader.getFirst([key, legacyKey], "list" /* LIST */))?.asset;
|
|
1390
1384
|
}).then((r) => r?.files ?? []);
|
|
1391
1385
|
}
|
|
1392
1386
|
static async loadAndMerge(key) {
|
|
1393
|
-
const model = await this.getRaw(key);
|
|
1387
|
+
const model = key.type === "item" ? await this.getItemModel(key) : await this.getRaw(key);
|
|
1394
1388
|
if (!model) {
|
|
1395
1389
|
return void 0;
|
|
1396
1390
|
}
|
|
1397
1391
|
return ModelMerger.mergeWithParents(model);
|
|
1398
1392
|
}
|
|
1393
|
+
static async getItemModel(key) {
|
|
1394
|
+
const itemKey = new AssetKey(key.namespace, key.path, "items", void 0, key.rootType, ".json", key.root);
|
|
1395
|
+
const model = await this.PERSISTENT_CACHE.getOrLoad(itemKey.serialize(), async () => {
|
|
1396
|
+
const result = await AssetLoader.getFirst([itemKey, key], "json" /* JSON */);
|
|
1397
|
+
if (!result) return void 0;
|
|
1398
|
+
if (result.key.assetType !== "items") return { ...result.asset, key };
|
|
1399
|
+
const reference = this.defaultItemModel(result.asset.model, key);
|
|
1400
|
+
const modelKey = AssetKey.parse("models", reference);
|
|
1401
|
+
modelKey.root = key.root;
|
|
1402
|
+
const model2 = await this.getRaw(modelKey);
|
|
1403
|
+
if (!model2) throw new Error(`Item ${key.toNamespacedString()} references missing model ${reference}`);
|
|
1404
|
+
return model2;
|
|
1405
|
+
});
|
|
1406
|
+
return model ? { ...model, key: Object.assign(new AssetKey("", ""), model.key) } : void 0;
|
|
1407
|
+
}
|
|
1408
|
+
// Item previews use the GUI context, false conditions, and zero numeric properties.
|
|
1409
|
+
static defaultItemModel(node, key) {
|
|
1410
|
+
if (!node || typeof node.type !== "string") {
|
|
1411
|
+
throw new Error(`Unsupported item model definition for ${key.toNamespacedString()}`);
|
|
1412
|
+
}
|
|
1413
|
+
switch (node.type.replace(/^minecraft:/, "")) {
|
|
1414
|
+
case "model":
|
|
1415
|
+
if (typeof node.model === "string" && node.model) return node.model;
|
|
1416
|
+
break;
|
|
1417
|
+
case "condition":
|
|
1418
|
+
return this.defaultItemModel(node.on_false, key);
|
|
1419
|
+
case "select": {
|
|
1420
|
+
const selected = node.property?.replace(/^minecraft:/, "") === "display_context" ? node.cases?.find((entry) => Array.isArray(entry.when) ? entry.when.includes("gui") : entry.when === "gui")?.model : void 0;
|
|
1421
|
+
return this.defaultItemModel(selected ?? node.fallback, key);
|
|
1422
|
+
}
|
|
1423
|
+
case "range_dispatch": {
|
|
1424
|
+
const selected = node.entries?.reduce((match, entry) => {
|
|
1425
|
+
return entry.threshold <= 0 && (!match || entry.threshold >= match.threshold) ? entry : match;
|
|
1426
|
+
}, void 0);
|
|
1427
|
+
return this.defaultItemModel(selected?.model ?? node.fallback, key);
|
|
1428
|
+
}
|
|
1429
|
+
}
|
|
1430
|
+
throw new Error(`Unsupported item model ${node?.type ?? "definition"} for ${key.toNamespacedString()}`);
|
|
1431
|
+
}
|
|
1399
1432
|
static async getRaw(key) {
|
|
1400
1433
|
if (!key.assetType) {
|
|
1401
1434
|
key.assetType = "models";
|
|
@@ -1502,7 +1535,7 @@ var DefaultBlockStates = class {
|
|
|
1502
1535
|
};
|
|
1503
1536
|
|
|
1504
1537
|
// src/assets/Assets.ts
|
|
1505
|
-
var DEFAULT_ROOT = "https://assets.mcasset.cloud/1.
|
|
1538
|
+
var DEFAULT_ROOT = "https://assets.mcasset.cloud/1.21.11";
|
|
1506
1539
|
var DEFAULT_NAMESPACE = "minecraft";
|
|
1507
1540
|
var Assets = class {
|
|
1508
1541
|
/**
|
|
@@ -1945,11 +1978,29 @@ var AssetLoader = class {
|
|
|
1945
1978
|
}
|
|
1946
1979
|
/** Returns the first defined result in source-priority order, without merging assets. */
|
|
1947
1980
|
static async get(key, parser) {
|
|
1981
|
+
const keys = [key];
|
|
1982
|
+
if (key.rootType === "data" && (key.assetType === "structure" || key.assetType === "structures")) {
|
|
1983
|
+
keys.push(new AssetKey(
|
|
1984
|
+
key.namespace,
|
|
1985
|
+
key.path,
|
|
1986
|
+
key.assetType === "structure" ? "structures" : "structure",
|
|
1987
|
+
key.type,
|
|
1988
|
+
key.rootType,
|
|
1989
|
+
key.extension,
|
|
1990
|
+
key.root
|
|
1991
|
+
));
|
|
1992
|
+
}
|
|
1993
|
+
return (await this.getFirst(keys, parser))?.asset;
|
|
1994
|
+
}
|
|
1995
|
+
/** Tries each path within a source before considering lower-priority sources. */
|
|
1996
|
+
static async getFirst(keys, parser) {
|
|
1948
1997
|
const sources = [...this._SOURCES];
|
|
1949
1998
|
for (const source of sources) {
|
|
1950
|
-
const
|
|
1951
|
-
|
|
1952
|
-
|
|
1999
|
+
for (const key of keys) {
|
|
2000
|
+
const result = await source.source.get(key, parser);
|
|
2001
|
+
if (result !== void 0) {
|
|
2002
|
+
return { key, asset: result };
|
|
2003
|
+
}
|
|
1953
2004
|
}
|
|
1954
2005
|
}
|
|
1955
2006
|
return void 0;
|