minerender 2.1.0-alpha.15 → 2.1.0-alpha.17
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 -7
- package/dist/browser/index.d.ts +8 -7
- package/dist/browser/index.js +34 -60
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/index.mjs +34 -60
- package/dist/browser/index.mjs.map +1 -1
- package/dist/bundle.js +33 -59
- package/dist/bundle.js.map +1 -1
- package/dist/node/index.d.mts +8 -7
- package/dist/node/index.d.ts +8 -7
- package/dist/node/index.js +34 -60
- package/dist/node/index.js.map +1 -1
- package/dist/node/index.mjs +34 -60
- package/dist/node/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/node/index.d.mts
CHANGED
|
@@ -690,16 +690,17 @@ interface BlockStateVariant {
|
|
|
690
690
|
y?: number;
|
|
691
691
|
x?: number;
|
|
692
692
|
uvlock?: boolean;
|
|
693
|
+
weight?: number;
|
|
693
694
|
}
|
|
694
695
|
interface BlockStateMultipart {
|
|
695
|
-
when?: MultipartCondition
|
|
696
|
-
|
|
697
|
-
};
|
|
698
|
-
apply?: BlockStateVariant;
|
|
699
|
-
}
|
|
700
|
-
interface MultipartCondition {
|
|
701
|
-
[key: string]: string;
|
|
696
|
+
when?: MultipartCondition;
|
|
697
|
+
apply?: BlockStateVariant | BlockStateVariant[];
|
|
702
698
|
}
|
|
699
|
+
type MultipartCondition = Record<string, string> | {
|
|
700
|
+
OR: MultipartCondition[];
|
|
701
|
+
} | {
|
|
702
|
+
AND: MultipartCondition[];
|
|
703
|
+
};
|
|
703
704
|
|
|
704
705
|
declare const DEFAULT_ROOT = "https://assets.mcasset.cloud/1.21.11";
|
|
705
706
|
declare const DEFAULT_NAMESPACE = "minecraft";
|
package/dist/node/index.d.ts
CHANGED
|
@@ -690,16 +690,17 @@ interface BlockStateVariant {
|
|
|
690
690
|
y?: number;
|
|
691
691
|
x?: number;
|
|
692
692
|
uvlock?: boolean;
|
|
693
|
+
weight?: number;
|
|
693
694
|
}
|
|
694
695
|
interface BlockStateMultipart {
|
|
695
|
-
when?: MultipartCondition
|
|
696
|
-
|
|
697
|
-
};
|
|
698
|
-
apply?: BlockStateVariant;
|
|
699
|
-
}
|
|
700
|
-
interface MultipartCondition {
|
|
701
|
-
[key: string]: string;
|
|
696
|
+
when?: MultipartCondition;
|
|
697
|
+
apply?: BlockStateVariant | BlockStateVariant[];
|
|
702
698
|
}
|
|
699
|
+
type MultipartCondition = Record<string, string> | {
|
|
700
|
+
OR: MultipartCondition[];
|
|
701
|
+
} | {
|
|
702
|
+
AND: MultipartCondition[];
|
|
703
|
+
};
|
|
703
704
|
|
|
704
705
|
declare const DEFAULT_ROOT = "https://assets.mcasset.cloud/1.21.11";
|
|
705
706
|
declare const DEFAULT_NAMESPACE = "minecraft";
|
package/dist/node/index.js
CHANGED
|
@@ -1112,7 +1112,11 @@ var Materials = class _Materials {
|
|
|
1112
1112
|
|
|
1113
1113
|
if (SHADE) {
|
|
1114
1114
|
|
|
1115
|
-
|
|
1115
|
+
#ifdef USE_INSTANCING
|
|
1116
|
+
vec3 N = vec3( modelMatrix * instanceMatrix * vec4(normal, 0.0) );
|
|
1117
|
+
#else
|
|
1118
|
+
vec3 N = vec3( modelMatrix * vec4(normal, 0.0) );
|
|
1119
|
+
#endif
|
|
1116
1120
|
|
|
1117
1121
|
float yLight = (1.0+N.y) * 0.5;
|
|
1118
1122
|
light = yLight * (1.0-AMBIENT) + N.x*N.x * XFAC + N.z*N.z * ZFAC + AMBIENT;
|
|
@@ -4405,6 +4409,16 @@ function isModelObject(obj) {
|
|
|
4405
4409
|
var import_ts_deepmerge6 = __toESM(require_dist());
|
|
4406
4410
|
var import_three16 = require("three");
|
|
4407
4411
|
var p10 = prefix("BlockObject");
|
|
4412
|
+
function matchesCondition(condition, state) {
|
|
4413
|
+
return Object.entries(condition).every(([key, value]) => {
|
|
4414
|
+
if (Array.isArray(value)) {
|
|
4415
|
+
if (key === "OR") return value.some((child) => matchesCondition(child, state));
|
|
4416
|
+
if (key === "AND") return value.every((child) => matchesCondition(child, state));
|
|
4417
|
+
return false;
|
|
4418
|
+
}
|
|
4419
|
+
return typeof value === "string" && state[key] !== void 0 && value.split("|").includes(`${state[key]}`);
|
|
4420
|
+
});
|
|
4421
|
+
}
|
|
4408
4422
|
var BlockObject = class _BlockObject extends SceneObject {
|
|
4409
4423
|
constructor(blockState, options) {
|
|
4410
4424
|
super(options);
|
|
@@ -4438,15 +4452,9 @@ var BlockObject = class _BlockObject extends SceneObject {
|
|
|
4438
4452
|
if (this.blockState.variants) {
|
|
4439
4453
|
await this.setState(Object.keys(this.blockState.variants)[0]);
|
|
4440
4454
|
} else if (this.blockState.multipart) {
|
|
4441
|
-
|
|
4442
|
-
|
|
4443
|
-
|
|
4444
|
-
if (k) {
|
|
4445
|
-
await this.setState(k, part.when[k].split("|")[0]);
|
|
4446
|
-
break;
|
|
4447
|
-
}
|
|
4448
|
-
}
|
|
4449
|
-
}
|
|
4455
|
+
const condition = this.blockState.multipart.map((part) => part.when).find((when) => when !== void 0 && Object.values(when).every((value) => typeof value === "string"));
|
|
4456
|
+
const state = Object.fromEntries(Object.entries(condition ?? {}).map(([key, value]) => [key, value.split("|")[0]]));
|
|
4457
|
+
await this.setState(state);
|
|
4450
4458
|
}
|
|
4451
4459
|
}
|
|
4452
4460
|
} else {
|
|
@@ -4506,52 +4514,8 @@ var BlockObject = class _BlockObject extends SceneObject {
|
|
|
4506
4514
|
console.debug(p10, "Missing apply for blockState part", part);
|
|
4507
4515
|
continue;
|
|
4508
4516
|
}
|
|
4509
|
-
if (!part.when) {
|
|
4517
|
+
if (!part.when || matchesCondition(part.when, state)) {
|
|
4510
4518
|
out.push(this.getSingleVariant(part.apply));
|
|
4511
|
-
} else {
|
|
4512
|
-
let matches = true;
|
|
4513
|
-
if ("OR" in part.when) {
|
|
4514
|
-
const or = part.when.OR;
|
|
4515
|
-
let anyMatch = false;
|
|
4516
|
-
for (let o of or) {
|
|
4517
|
-
for (let k in o) {
|
|
4518
|
-
const split = o[k].split("|");
|
|
4519
|
-
let m = false;
|
|
4520
|
-
for (let s of split) {
|
|
4521
|
-
if (`${state[k]}` === `${s}`) {
|
|
4522
|
-
m = true;
|
|
4523
|
-
break;
|
|
4524
|
-
}
|
|
4525
|
-
}
|
|
4526
|
-
if (m) {
|
|
4527
|
-
anyMatch = true;
|
|
4528
|
-
break;
|
|
4529
|
-
}
|
|
4530
|
-
}
|
|
4531
|
-
}
|
|
4532
|
-
if (!anyMatch) {
|
|
4533
|
-
matches = false;
|
|
4534
|
-
}
|
|
4535
|
-
} else {
|
|
4536
|
-
for (let k in part.when) {
|
|
4537
|
-
const split = part.when[k].split("|");
|
|
4538
|
-
let m = false;
|
|
4539
|
-
for (let s of split) {
|
|
4540
|
-
if (`${state[k]}` === `${s}`) {
|
|
4541
|
-
m = true;
|
|
4542
|
-
break;
|
|
4543
|
-
}
|
|
4544
|
-
}
|
|
4545
|
-
if (!m) {
|
|
4546
|
-
matches = false;
|
|
4547
|
-
break;
|
|
4548
|
-
}
|
|
4549
|
-
}
|
|
4550
|
-
}
|
|
4551
|
-
if (matches) {
|
|
4552
|
-
const variants = part.apply;
|
|
4553
|
-
out.push(this.getSingleVariant(variants));
|
|
4554
|
-
}
|
|
4555
4519
|
}
|
|
4556
4520
|
}
|
|
4557
4521
|
}
|
|
@@ -4581,11 +4545,21 @@ var BlockObject = class _BlockObject extends SceneObject {
|
|
|
4581
4545
|
}
|
|
4582
4546
|
}
|
|
4583
4547
|
getSingleVariant(variants) {
|
|
4584
|
-
if (Array.isArray(variants))
|
|
4585
|
-
|
|
4586
|
-
|
|
4587
|
-
|
|
4588
|
-
|
|
4548
|
+
if (!Array.isArray(variants)) return variants;
|
|
4549
|
+
if (!variants.length) throw new MineRenderError("Blockstate variant arrays must not be empty");
|
|
4550
|
+
const total = variants.reduce((sum, variant) => {
|
|
4551
|
+
const weight = variant.weight ?? 1;
|
|
4552
|
+
if (!Number.isInteger(weight) || weight < 1) {
|
|
4553
|
+
throw new MineRenderError(`Invalid blockstate variant weight: ${weight}`);
|
|
4554
|
+
}
|
|
4555
|
+
return sum + weight;
|
|
4556
|
+
}, 0);
|
|
4557
|
+
let choice = Math.random() * total;
|
|
4558
|
+
for (const variant of variants) {
|
|
4559
|
+
choice -= variant.weight ?? 1;
|
|
4560
|
+
if (choice < 0) return variant;
|
|
4561
|
+
}
|
|
4562
|
+
return variants[variants.length - 1];
|
|
4589
4563
|
}
|
|
4590
4564
|
// @deprecated
|
|
4591
4565
|
async createAVariant(variants, instanceInfo) {
|