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/browser/index.d.mts
CHANGED
|
@@ -670,6 +670,11 @@ declare class AssetLoader {
|
|
|
670
670
|
static getAll<T extends MinecraftAsset>(key: AssetKey, parser: AssetParser | string): Promise<T[]>;
|
|
671
671
|
/** Returns the first defined result in source-priority order, without merging assets. */
|
|
672
672
|
static get<T extends MinecraftAsset>(key: AssetKey, parser: AssetParser | string): Promise<Maybe<T>>;
|
|
673
|
+
/** Tries each path within a source before considering lower-priority sources. */
|
|
674
|
+
static getFirst<T extends MinecraftAsset>(keys: readonly AssetKey[], parser: AssetParser | string): Promise<Maybe<{
|
|
675
|
+
key: AssetKey;
|
|
676
|
+
asset: T;
|
|
677
|
+
}>>;
|
|
673
678
|
}
|
|
674
679
|
|
|
675
680
|
interface BlockState extends MinecraftAsset {
|
|
@@ -695,7 +700,7 @@ interface MultipartCondition {
|
|
|
695
700
|
[key: string]: string;
|
|
696
701
|
}
|
|
697
702
|
|
|
698
|
-
declare const DEFAULT_ROOT = "https://assets.mcasset.cloud/1.
|
|
703
|
+
declare const DEFAULT_ROOT = "https://assets.mcasset.cloud/1.21.11";
|
|
699
704
|
declare const DEFAULT_NAMESPACE = "minecraft";
|
|
700
705
|
declare class Assets {
|
|
701
706
|
/**
|
|
@@ -760,6 +765,8 @@ declare class Models {
|
|
|
760
765
|
private static get PERSISTENT_CACHE();
|
|
761
766
|
static getItemList(): Promise<string[]>;
|
|
762
767
|
static loadAndMerge(key: AssetKey): Promise<Maybe<Model>>;
|
|
768
|
+
private static getItemModel;
|
|
769
|
+
private static defaultItemModel;
|
|
763
770
|
static getRaw(key: AssetKey): Promise<Maybe<Model>>;
|
|
764
771
|
static getMerged(key: AssetKey): Promise<Maybe<Model>>;
|
|
765
772
|
static get(key: AssetKey): Promise<Maybe<Model>>;
|
package/dist/browser/index.d.ts
CHANGED
|
@@ -670,6 +670,11 @@ declare class AssetLoader {
|
|
|
670
670
|
static getAll<T extends MinecraftAsset>(key: AssetKey, parser: AssetParser | string): Promise<T[]>;
|
|
671
671
|
/** Returns the first defined result in source-priority order, without merging assets. */
|
|
672
672
|
static get<T extends MinecraftAsset>(key: AssetKey, parser: AssetParser | string): Promise<Maybe<T>>;
|
|
673
|
+
/** Tries each path within a source before considering lower-priority sources. */
|
|
674
|
+
static getFirst<T extends MinecraftAsset>(keys: readonly AssetKey[], parser: AssetParser | string): Promise<Maybe<{
|
|
675
|
+
key: AssetKey;
|
|
676
|
+
asset: T;
|
|
677
|
+
}>>;
|
|
673
678
|
}
|
|
674
679
|
|
|
675
680
|
interface BlockState extends MinecraftAsset {
|
|
@@ -695,7 +700,7 @@ interface MultipartCondition {
|
|
|
695
700
|
[key: string]: string;
|
|
696
701
|
}
|
|
697
702
|
|
|
698
|
-
declare const DEFAULT_ROOT = "https://assets.mcasset.cloud/1.
|
|
703
|
+
declare const DEFAULT_ROOT = "https://assets.mcasset.cloud/1.21.11";
|
|
699
704
|
declare const DEFAULT_NAMESPACE = "minecraft";
|
|
700
705
|
declare class Assets {
|
|
701
706
|
/**
|
|
@@ -760,6 +765,8 @@ declare class Models {
|
|
|
760
765
|
private static get PERSISTENT_CACHE();
|
|
761
766
|
static getItemList(): Promise<string[]>;
|
|
762
767
|
static loadAndMerge(key: AssetKey): Promise<Maybe<Model>>;
|
|
768
|
+
private static getItemModel;
|
|
769
|
+
private static defaultItemModel;
|
|
763
770
|
static getRaw(key: AssetKey): Promise<Maybe<Model>>;
|
|
764
771
|
static getMerged(key: AssetKey): Promise<Maybe<Model>>;
|
|
765
772
|
static get(key: AssetKey): Promise<Maybe<Model>>;
|
package/dist/browser/index.js
CHANGED
|
@@ -1295,7 +1295,7 @@ var AssetKey = class _AssetKey extends BasicAssetKey {
|
|
|
1295
1295
|
}
|
|
1296
1296
|
toString() {
|
|
1297
1297
|
let a = [
|
|
1298
|
-
|
|
1298
|
+
this.root ?? AssetLoader.ROOT,
|
|
1299
1299
|
this.rootType ?? "__rootType__",
|
|
1300
1300
|
this.assetType ?? "__assetType__",
|
|
1301
1301
|
this.type ?? "__type__",
|
|
@@ -1345,6 +1345,7 @@ var ModelMerger = class {
|
|
|
1345
1345
|
}
|
|
1346
1346
|
const models = [];
|
|
1347
1347
|
const parentKey = AssetKey.parse("models", model.parent);
|
|
1348
|
+
parentKey.root = model.key?.root;
|
|
1348
1349
|
const parentModel = await Models.getRaw(parentKey);
|
|
1349
1350
|
if (parentModel) {
|
|
1350
1351
|
models.unshift(parentModel);
|
|
@@ -1374,26 +1375,58 @@ var Models = class _Models {
|
|
|
1374
1375
|
return this._persistentCache ?? (this._persistentCache = PersistentCache.open("minerender-models"));
|
|
1375
1376
|
}
|
|
1376
1377
|
static async getItemList() {
|
|
1377
|
-
const key = new AssetKey(
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
"
|
|
1381
|
-
"item",
|
|
1382
|
-
"assets",
|
|
1383
|
-
".json",
|
|
1384
|
-
DEFAULT_ROOT
|
|
1385
|
-
);
|
|
1386
|
-
return Caching.listAssetCache.get(key.serialize(), () => {
|
|
1387
|
-
return AssetLoader.get(key, "list" /* LIST */);
|
|
1378
|
+
const key = new AssetKey(DEFAULT_NAMESPACE, "_list", "items");
|
|
1379
|
+
const legacyKey = new AssetKey(DEFAULT_NAMESPACE, "_list", "models", "item");
|
|
1380
|
+
return Caching.listAssetCache.get(key.serialize(), async () => {
|
|
1381
|
+
return (await AssetLoader.getFirst([key, legacyKey], "list" /* LIST */))?.asset;
|
|
1388
1382
|
}).then((r) => r?.files ?? []);
|
|
1389
1383
|
}
|
|
1390
1384
|
static async loadAndMerge(key) {
|
|
1391
|
-
const model = await this.getRaw(key);
|
|
1385
|
+
const model = key.type === "item" ? await this.getItemModel(key) : await this.getRaw(key);
|
|
1392
1386
|
if (!model) {
|
|
1393
1387
|
return void 0;
|
|
1394
1388
|
}
|
|
1395
1389
|
return ModelMerger.mergeWithParents(model);
|
|
1396
1390
|
}
|
|
1391
|
+
static async getItemModel(key) {
|
|
1392
|
+
const itemKey = new AssetKey(key.namespace, key.path, "items", void 0, key.rootType, ".json", key.root);
|
|
1393
|
+
const model = await this.PERSISTENT_CACHE.getOrLoad(itemKey.serialize(), async () => {
|
|
1394
|
+
const result = await AssetLoader.getFirst([itemKey, key], "json" /* JSON */);
|
|
1395
|
+
if (!result) return void 0;
|
|
1396
|
+
if (result.key.assetType !== "items") return { ...result.asset, key };
|
|
1397
|
+
const reference = this.defaultItemModel(result.asset.model, key);
|
|
1398
|
+
const modelKey = AssetKey.parse("models", reference);
|
|
1399
|
+
modelKey.root = key.root;
|
|
1400
|
+
const model2 = await this.getRaw(modelKey);
|
|
1401
|
+
if (!model2) throw new Error(`Item ${key.toNamespacedString()} references missing model ${reference}`);
|
|
1402
|
+
return model2;
|
|
1403
|
+
});
|
|
1404
|
+
return model ? { ...model, key: Object.assign(new AssetKey("", ""), model.key) } : void 0;
|
|
1405
|
+
}
|
|
1406
|
+
// Item previews use the GUI context, false conditions, and zero numeric properties.
|
|
1407
|
+
static defaultItemModel(node, key) {
|
|
1408
|
+
if (!node || typeof node.type !== "string") {
|
|
1409
|
+
throw new Error(`Unsupported item model definition for ${key.toNamespacedString()}`);
|
|
1410
|
+
}
|
|
1411
|
+
switch (node.type.replace(/^minecraft:/, "")) {
|
|
1412
|
+
case "model":
|
|
1413
|
+
if (typeof node.model === "string" && node.model) return node.model;
|
|
1414
|
+
break;
|
|
1415
|
+
case "condition":
|
|
1416
|
+
return this.defaultItemModel(node.on_false, key);
|
|
1417
|
+
case "select": {
|
|
1418
|
+
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;
|
|
1419
|
+
return this.defaultItemModel(selected ?? node.fallback, key);
|
|
1420
|
+
}
|
|
1421
|
+
case "range_dispatch": {
|
|
1422
|
+
const selected = node.entries?.reduce((match, entry) => {
|
|
1423
|
+
return entry.threshold <= 0 && (!match || entry.threshold >= match.threshold) ? entry : match;
|
|
1424
|
+
}, void 0);
|
|
1425
|
+
return this.defaultItemModel(selected?.model ?? node.fallback, key);
|
|
1426
|
+
}
|
|
1427
|
+
}
|
|
1428
|
+
throw new Error(`Unsupported item model ${node?.type ?? "definition"} for ${key.toNamespacedString()}`);
|
|
1429
|
+
}
|
|
1397
1430
|
static async getRaw(key) {
|
|
1398
1431
|
if (!key.assetType) {
|
|
1399
1432
|
key.assetType = "models";
|
|
@@ -1500,7 +1533,7 @@ var DefaultBlockStates = class {
|
|
|
1500
1533
|
};
|
|
1501
1534
|
|
|
1502
1535
|
// src/assets/Assets.ts
|
|
1503
|
-
var DEFAULT_ROOT = "https://assets.mcasset.cloud/1.
|
|
1536
|
+
var DEFAULT_ROOT = "https://assets.mcasset.cloud/1.21.11";
|
|
1504
1537
|
var DEFAULT_NAMESPACE = "minecraft";
|
|
1505
1538
|
var Assets = class {
|
|
1506
1539
|
/**
|
|
@@ -1918,11 +1951,29 @@ var _AssetLoader = class _AssetLoader {
|
|
|
1918
1951
|
}
|
|
1919
1952
|
/** Returns the first defined result in source-priority order, without merging assets. */
|
|
1920
1953
|
static async get(key, parser) {
|
|
1954
|
+
const keys = [key];
|
|
1955
|
+
if (key.rootType === "data" && (key.assetType === "structure" || key.assetType === "structures")) {
|
|
1956
|
+
keys.push(new AssetKey(
|
|
1957
|
+
key.namespace,
|
|
1958
|
+
key.path,
|
|
1959
|
+
key.assetType === "structure" ? "structures" : "structure",
|
|
1960
|
+
key.type,
|
|
1961
|
+
key.rootType,
|
|
1962
|
+
key.extension,
|
|
1963
|
+
key.root
|
|
1964
|
+
));
|
|
1965
|
+
}
|
|
1966
|
+
return (await this.getFirst(keys, parser))?.asset;
|
|
1967
|
+
}
|
|
1968
|
+
/** Tries each path within a source before considering lower-priority sources. */
|
|
1969
|
+
static async getFirst(keys, parser) {
|
|
1921
1970
|
const sources = [...this._SOURCES];
|
|
1922
1971
|
for (const source of sources) {
|
|
1923
|
-
const
|
|
1924
|
-
|
|
1925
|
-
|
|
1972
|
+
for (const key of keys) {
|
|
1973
|
+
const result = await source.source.get(key, parser);
|
|
1974
|
+
if (result !== void 0) {
|
|
1975
|
+
return { key, asset: result };
|
|
1976
|
+
}
|
|
1926
1977
|
}
|
|
1927
1978
|
}
|
|
1928
1979
|
return void 0;
|