minerender 2.1.0-alpha.16 → 2.1.0-alpha.18
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 +9 -7
- package/dist/browser/index.d.ts +9 -7
- package/dist/browser/index.js +36 -62
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/index.mjs +36 -62
- package/dist/browser/index.mjs.map +1 -1
- package/dist/bundle.js +35 -61
- package/dist/bundle.js.map +1 -1
- package/dist/node/index.d.mts +9 -7
- package/dist/node/index.d.ts +9 -7
- package/dist/node/index.js +36 -62
- package/dist/node/index.js.map +1 -1
- package/dist/node/index.mjs +36 -62
- package/dist/node/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/browser/index.d.mts
CHANGED
|
@@ -173,6 +173,7 @@ declare class AssetKey extends BasicAssetKey {
|
|
|
173
173
|
rootType: "assets" | "data" | string;
|
|
174
174
|
extension: ".json" | ".png" | string;
|
|
175
175
|
root?: string | undefined;
|
|
176
|
+
readonly isAssetKey: true;
|
|
176
177
|
constructor(namespace: string, path: string, assetType?: AssetType | undefined, type?: string | undefined, rootType?: "assets" | "data" | string, extension?: ".json" | ".png" | string, root?: string | undefined);
|
|
177
178
|
static parse(assetType: AssetType, str: string, origin?: AssetKey): AssetKey;
|
|
178
179
|
toString(): string;
|
|
@@ -689,16 +690,17 @@ interface BlockStateVariant {
|
|
|
689
690
|
y?: number;
|
|
690
691
|
x?: number;
|
|
691
692
|
uvlock?: boolean;
|
|
693
|
+
weight?: number;
|
|
692
694
|
}
|
|
693
695
|
interface BlockStateMultipart {
|
|
694
|
-
when?: MultipartCondition
|
|
695
|
-
|
|
696
|
-
};
|
|
697
|
-
apply?: BlockStateVariant;
|
|
698
|
-
}
|
|
699
|
-
interface MultipartCondition {
|
|
700
|
-
[key: string]: string;
|
|
696
|
+
when?: MultipartCondition;
|
|
697
|
+
apply?: BlockStateVariant | BlockStateVariant[];
|
|
701
698
|
}
|
|
699
|
+
type MultipartCondition = Record<string, string> | {
|
|
700
|
+
OR: MultipartCondition[];
|
|
701
|
+
} | {
|
|
702
|
+
AND: MultipartCondition[];
|
|
703
|
+
};
|
|
702
704
|
|
|
703
705
|
declare const DEFAULT_ROOT = "https://assets.mcasset.cloud/1.21.11";
|
|
704
706
|
declare const DEFAULT_NAMESPACE = "minecraft";
|
package/dist/browser/index.d.ts
CHANGED
|
@@ -173,6 +173,7 @@ declare class AssetKey extends BasicAssetKey {
|
|
|
173
173
|
rootType: "assets" | "data" | string;
|
|
174
174
|
extension: ".json" | ".png" | string;
|
|
175
175
|
root?: string | undefined;
|
|
176
|
+
readonly isAssetKey: true;
|
|
176
177
|
constructor(namespace: string, path: string, assetType?: AssetType | undefined, type?: string | undefined, rootType?: "assets" | "data" | string, extension?: ".json" | ".png" | string, root?: string | undefined);
|
|
177
178
|
static parse(assetType: AssetType, str: string, origin?: AssetKey): AssetKey;
|
|
178
179
|
toString(): string;
|
|
@@ -689,16 +690,17 @@ interface BlockStateVariant {
|
|
|
689
690
|
y?: number;
|
|
690
691
|
x?: number;
|
|
691
692
|
uvlock?: boolean;
|
|
693
|
+
weight?: number;
|
|
692
694
|
}
|
|
693
695
|
interface BlockStateMultipart {
|
|
694
|
-
when?: MultipartCondition
|
|
695
|
-
|
|
696
|
-
};
|
|
697
|
-
apply?: BlockStateVariant;
|
|
698
|
-
}
|
|
699
|
-
interface MultipartCondition {
|
|
700
|
-
[key: string]: string;
|
|
696
|
+
when?: MultipartCondition;
|
|
697
|
+
apply?: BlockStateVariant | BlockStateVariant[];
|
|
701
698
|
}
|
|
699
|
+
type MultipartCondition = Record<string, string> | {
|
|
700
|
+
OR: MultipartCondition[];
|
|
701
|
+
} | {
|
|
702
|
+
AND: MultipartCondition[];
|
|
703
|
+
};
|
|
702
704
|
|
|
703
705
|
declare const DEFAULT_ROOT = "https://assets.mcasset.cloud/1.21.11";
|
|
704
706
|
declare const DEFAULT_NAMESPACE = "minecraft";
|
package/dist/browser/index.js
CHANGED
|
@@ -1279,6 +1279,7 @@ var AssetKey = class _AssetKey extends BasicAssetKey {
|
|
|
1279
1279
|
this.rootType = rootType;
|
|
1280
1280
|
this.extension = extension;
|
|
1281
1281
|
this.root = root;
|
|
1282
|
+
this.isAssetKey = true;
|
|
1282
1283
|
}
|
|
1283
1284
|
static parse(assetType, str, origin) {
|
|
1284
1285
|
let namespace = origin?.namespace || DEFAULT_NAMESPACE;
|
|
@@ -1294,7 +1295,10 @@ var AssetKey = class _AssetKey extends BasicAssetKey {
|
|
|
1294
1295
|
split.shift();
|
|
1295
1296
|
}
|
|
1296
1297
|
let path = split.join("/");
|
|
1297
|
-
|
|
1298
|
+
const extension = assetType === "textures" ? ".png" : origin?.extension ?? ".json";
|
|
1299
|
+
if (extension && path.endsWith(extension)) {
|
|
1300
|
+
path = path.slice(0, -extension.length);
|
|
1301
|
+
}
|
|
1298
1302
|
return new _AssetKey(namespace, path, assetType, type, "assets", extension, origin?.root);
|
|
1299
1303
|
}
|
|
1300
1304
|
toString() {
|
|
@@ -1324,10 +1328,10 @@ var AssetKey = class _AssetKey extends BasicAssetKey {
|
|
|
1324
1328
|
}
|
|
1325
1329
|
};
|
|
1326
1330
|
function isBasicAssetKey(obj) {
|
|
1327
|
-
return "
|
|
1331
|
+
return obj !== null && typeof obj === "object" && typeof obj.namespace === "string" && typeof obj.path === "string";
|
|
1328
1332
|
}
|
|
1329
1333
|
function isAssetKey(obj) {
|
|
1330
|
-
return isBasicAssetKey(obj) &&
|
|
1334
|
+
return isBasicAssetKey(obj) && obj.isAssetKey === true;
|
|
1331
1335
|
}
|
|
1332
1336
|
|
|
1333
1337
|
// src/model/ModelMerger.ts
|
|
@@ -4368,6 +4372,16 @@ function isModelObject(obj) {
|
|
|
4368
4372
|
var import_ts_deepmerge6 = __toESM(require_dist());
|
|
4369
4373
|
var import_three16 = require("three");
|
|
4370
4374
|
var p10 = prefix("BlockObject");
|
|
4375
|
+
function matchesCondition(condition, state) {
|
|
4376
|
+
return Object.entries(condition).every(([key, value]) => {
|
|
4377
|
+
if (Array.isArray(value)) {
|
|
4378
|
+
if (key === "OR") return value.some((child) => matchesCondition(child, state));
|
|
4379
|
+
if (key === "AND") return value.every((child) => matchesCondition(child, state));
|
|
4380
|
+
return false;
|
|
4381
|
+
}
|
|
4382
|
+
return typeof value === "string" && state[key] !== void 0 && value.split("|").includes(`${state[key]}`);
|
|
4383
|
+
});
|
|
4384
|
+
}
|
|
4371
4385
|
var _BlockObject = class _BlockObject extends SceneObject {
|
|
4372
4386
|
constructor(blockState, options) {
|
|
4373
4387
|
super(options);
|
|
@@ -4396,15 +4410,9 @@ var _BlockObject = class _BlockObject extends SceneObject {
|
|
|
4396
4410
|
if (this.blockState.variants) {
|
|
4397
4411
|
await this.setState(Object.keys(this.blockState.variants)[0]);
|
|
4398
4412
|
} else if (this.blockState.multipart) {
|
|
4399
|
-
|
|
4400
|
-
|
|
4401
|
-
|
|
4402
|
-
if (k) {
|
|
4403
|
-
await this.setState(k, part.when[k].split("|")[0]);
|
|
4404
|
-
break;
|
|
4405
|
-
}
|
|
4406
|
-
}
|
|
4407
|
-
}
|
|
4413
|
+
const condition = this.blockState.multipart.map((part) => part.when).find((when) => when !== void 0 && Object.values(when).every((value) => typeof value === "string"));
|
|
4414
|
+
const state = Object.fromEntries(Object.entries(condition ?? {}).map(([key, value]) => [key, value.split("|")[0]]));
|
|
4415
|
+
await this.setState(state);
|
|
4408
4416
|
}
|
|
4409
4417
|
}
|
|
4410
4418
|
} else {
|
|
@@ -4464,52 +4472,8 @@ var _BlockObject = class _BlockObject extends SceneObject {
|
|
|
4464
4472
|
console.debug(p10, "Missing apply for blockState part", part);
|
|
4465
4473
|
continue;
|
|
4466
4474
|
}
|
|
4467
|
-
if (!part.when) {
|
|
4475
|
+
if (!part.when || matchesCondition(part.when, state)) {
|
|
4468
4476
|
out.push(this.getSingleVariant(part.apply));
|
|
4469
|
-
} else {
|
|
4470
|
-
let matches = true;
|
|
4471
|
-
if ("OR" in part.when) {
|
|
4472
|
-
const or = part.when.OR;
|
|
4473
|
-
let anyMatch = false;
|
|
4474
|
-
for (let o of or) {
|
|
4475
|
-
for (let k in o) {
|
|
4476
|
-
const split = o[k].split("|");
|
|
4477
|
-
let m = false;
|
|
4478
|
-
for (let s of split) {
|
|
4479
|
-
if (`${state[k]}` === `${s}`) {
|
|
4480
|
-
m = true;
|
|
4481
|
-
break;
|
|
4482
|
-
}
|
|
4483
|
-
}
|
|
4484
|
-
if (m) {
|
|
4485
|
-
anyMatch = true;
|
|
4486
|
-
break;
|
|
4487
|
-
}
|
|
4488
|
-
}
|
|
4489
|
-
}
|
|
4490
|
-
if (!anyMatch) {
|
|
4491
|
-
matches = false;
|
|
4492
|
-
}
|
|
4493
|
-
} else {
|
|
4494
|
-
for (let k in part.when) {
|
|
4495
|
-
const split = part.when[k].split("|");
|
|
4496
|
-
let m = false;
|
|
4497
|
-
for (let s of split) {
|
|
4498
|
-
if (`${state[k]}` === `${s}`) {
|
|
4499
|
-
m = true;
|
|
4500
|
-
break;
|
|
4501
|
-
}
|
|
4502
|
-
}
|
|
4503
|
-
if (!m) {
|
|
4504
|
-
matches = false;
|
|
4505
|
-
break;
|
|
4506
|
-
}
|
|
4507
|
-
}
|
|
4508
|
-
}
|
|
4509
|
-
if (matches) {
|
|
4510
|
-
const variants = part.apply;
|
|
4511
|
-
out.push(this.getSingleVariant(variants));
|
|
4512
|
-
}
|
|
4513
4477
|
}
|
|
4514
4478
|
}
|
|
4515
4479
|
}
|
|
@@ -4539,11 +4503,21 @@ var _BlockObject = class _BlockObject extends SceneObject {
|
|
|
4539
4503
|
}
|
|
4540
4504
|
}
|
|
4541
4505
|
getSingleVariant(variants) {
|
|
4542
|
-
if (Array.isArray(variants))
|
|
4543
|
-
|
|
4544
|
-
|
|
4545
|
-
|
|
4546
|
-
|
|
4506
|
+
if (!Array.isArray(variants)) return variants;
|
|
4507
|
+
if (!variants.length) throw new MineRenderError("Blockstate variant arrays must not be empty");
|
|
4508
|
+
const total = variants.reduce((sum, variant) => {
|
|
4509
|
+
const weight = variant.weight ?? 1;
|
|
4510
|
+
if (!Number.isInteger(weight) || weight < 1) {
|
|
4511
|
+
throw new MineRenderError(`Invalid blockstate variant weight: ${weight}`);
|
|
4512
|
+
}
|
|
4513
|
+
return sum + weight;
|
|
4514
|
+
}, 0);
|
|
4515
|
+
let choice = Math.random() * total;
|
|
4516
|
+
for (const variant of variants) {
|
|
4517
|
+
choice -= variant.weight ?? 1;
|
|
4518
|
+
if (choice < 0) return variant;
|
|
4519
|
+
}
|
|
4520
|
+
return variants[variants.length - 1];
|
|
4547
4521
|
}
|
|
4548
4522
|
// @deprecated
|
|
4549
4523
|
async createAVariant(variants, instanceInfo) {
|