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/node/index.mjs
CHANGED
|
@@ -1126,6 +1126,7 @@ var AssetKey = class _AssetKey extends BasicAssetKey {
|
|
|
1126
1126
|
this.rootType = rootType;
|
|
1127
1127
|
this.extension = extension;
|
|
1128
1128
|
this.root = root;
|
|
1129
|
+
this.isAssetKey = true;
|
|
1129
1130
|
}
|
|
1130
1131
|
static parse(assetType, str, origin) {
|
|
1131
1132
|
let namespace = origin?.namespace || DEFAULT_NAMESPACE;
|
|
@@ -1141,7 +1142,10 @@ var AssetKey = class _AssetKey extends BasicAssetKey {
|
|
|
1141
1142
|
split.shift();
|
|
1142
1143
|
}
|
|
1143
1144
|
let path = split.join("/");
|
|
1144
|
-
|
|
1145
|
+
const extension = assetType === "textures" ? ".png" : origin?.extension ?? ".json";
|
|
1146
|
+
if (extension && path.endsWith(extension)) {
|
|
1147
|
+
path = path.slice(0, -extension.length);
|
|
1148
|
+
}
|
|
1145
1149
|
return new _AssetKey(namespace, path, assetType, type, "assets", extension, origin?.root);
|
|
1146
1150
|
}
|
|
1147
1151
|
toString() {
|
|
@@ -1171,10 +1175,10 @@ var AssetKey = class _AssetKey extends BasicAssetKey {
|
|
|
1171
1175
|
}
|
|
1172
1176
|
};
|
|
1173
1177
|
function isBasicAssetKey(obj) {
|
|
1174
|
-
return "
|
|
1178
|
+
return obj !== null && typeof obj === "object" && typeof obj.namespace === "string" && typeof obj.path === "string";
|
|
1175
1179
|
}
|
|
1176
1180
|
function isAssetKey(obj) {
|
|
1177
|
-
return isBasicAssetKey(obj) &&
|
|
1181
|
+
return isBasicAssetKey(obj) && obj.isAssetKey === true;
|
|
1178
1182
|
}
|
|
1179
1183
|
|
|
1180
1184
|
// src/model/ModelMerger.ts
|
|
@@ -4264,6 +4268,16 @@ function isModelObject(obj) {
|
|
|
4264
4268
|
var import_ts_deepmerge6 = __toESM(require_dist());
|
|
4265
4269
|
import { Euler as Euler3, Matrix4 as Matrix46, Vector3 as Vector36 } from "three";
|
|
4266
4270
|
var p10 = prefix("BlockObject");
|
|
4271
|
+
function matchesCondition(condition, state) {
|
|
4272
|
+
return Object.entries(condition).every(([key, value]) => {
|
|
4273
|
+
if (Array.isArray(value)) {
|
|
4274
|
+
if (key === "OR") return value.some((child) => matchesCondition(child, state));
|
|
4275
|
+
if (key === "AND") return value.every((child) => matchesCondition(child, state));
|
|
4276
|
+
return false;
|
|
4277
|
+
}
|
|
4278
|
+
return typeof value === "string" && state[key] !== void 0 && value.split("|").includes(`${state[key]}`);
|
|
4279
|
+
});
|
|
4280
|
+
}
|
|
4267
4281
|
var BlockObject = class _BlockObject extends SceneObject {
|
|
4268
4282
|
constructor(blockState, options) {
|
|
4269
4283
|
super(options);
|
|
@@ -4297,15 +4311,9 @@ var BlockObject = class _BlockObject extends SceneObject {
|
|
|
4297
4311
|
if (this.blockState.variants) {
|
|
4298
4312
|
await this.setState(Object.keys(this.blockState.variants)[0]);
|
|
4299
4313
|
} else if (this.blockState.multipart) {
|
|
4300
|
-
|
|
4301
|
-
|
|
4302
|
-
|
|
4303
|
-
if (k) {
|
|
4304
|
-
await this.setState(k, part.when[k].split("|")[0]);
|
|
4305
|
-
break;
|
|
4306
|
-
}
|
|
4307
|
-
}
|
|
4308
|
-
}
|
|
4314
|
+
const condition = this.blockState.multipart.map((part) => part.when).find((when) => when !== void 0 && Object.values(when).every((value) => typeof value === "string"));
|
|
4315
|
+
const state = Object.fromEntries(Object.entries(condition ?? {}).map(([key, value]) => [key, value.split("|")[0]]));
|
|
4316
|
+
await this.setState(state);
|
|
4309
4317
|
}
|
|
4310
4318
|
}
|
|
4311
4319
|
} else {
|
|
@@ -4365,52 +4373,8 @@ var BlockObject = class _BlockObject extends SceneObject {
|
|
|
4365
4373
|
console.debug(p10, "Missing apply for blockState part", part);
|
|
4366
4374
|
continue;
|
|
4367
4375
|
}
|
|
4368
|
-
if (!part.when) {
|
|
4376
|
+
if (!part.when || matchesCondition(part.when, state)) {
|
|
4369
4377
|
out.push(this.getSingleVariant(part.apply));
|
|
4370
|
-
} else {
|
|
4371
|
-
let matches = true;
|
|
4372
|
-
if ("OR" in part.when) {
|
|
4373
|
-
const or = part.when.OR;
|
|
4374
|
-
let anyMatch = false;
|
|
4375
|
-
for (let o of or) {
|
|
4376
|
-
for (let k in o) {
|
|
4377
|
-
const split = o[k].split("|");
|
|
4378
|
-
let m = false;
|
|
4379
|
-
for (let s of split) {
|
|
4380
|
-
if (`${state[k]}` === `${s}`) {
|
|
4381
|
-
m = true;
|
|
4382
|
-
break;
|
|
4383
|
-
}
|
|
4384
|
-
}
|
|
4385
|
-
if (m) {
|
|
4386
|
-
anyMatch = true;
|
|
4387
|
-
break;
|
|
4388
|
-
}
|
|
4389
|
-
}
|
|
4390
|
-
}
|
|
4391
|
-
if (!anyMatch) {
|
|
4392
|
-
matches = false;
|
|
4393
|
-
}
|
|
4394
|
-
} else {
|
|
4395
|
-
for (let k in part.when) {
|
|
4396
|
-
const split = part.when[k].split("|");
|
|
4397
|
-
let m = false;
|
|
4398
|
-
for (let s of split) {
|
|
4399
|
-
if (`${state[k]}` === `${s}`) {
|
|
4400
|
-
m = true;
|
|
4401
|
-
break;
|
|
4402
|
-
}
|
|
4403
|
-
}
|
|
4404
|
-
if (!m) {
|
|
4405
|
-
matches = false;
|
|
4406
|
-
break;
|
|
4407
|
-
}
|
|
4408
|
-
}
|
|
4409
|
-
}
|
|
4410
|
-
if (matches) {
|
|
4411
|
-
const variants = part.apply;
|
|
4412
|
-
out.push(this.getSingleVariant(variants));
|
|
4413
|
-
}
|
|
4414
4378
|
}
|
|
4415
4379
|
}
|
|
4416
4380
|
}
|
|
@@ -4440,11 +4404,21 @@ var BlockObject = class _BlockObject extends SceneObject {
|
|
|
4440
4404
|
}
|
|
4441
4405
|
}
|
|
4442
4406
|
getSingleVariant(variants) {
|
|
4443
|
-
if (Array.isArray(variants))
|
|
4444
|
-
|
|
4445
|
-
|
|
4446
|
-
|
|
4447
|
-
|
|
4407
|
+
if (!Array.isArray(variants)) return variants;
|
|
4408
|
+
if (!variants.length) throw new MineRenderError("Blockstate variant arrays must not be empty");
|
|
4409
|
+
const total = variants.reduce((sum, variant) => {
|
|
4410
|
+
const weight = variant.weight ?? 1;
|
|
4411
|
+
if (!Number.isInteger(weight) || weight < 1) {
|
|
4412
|
+
throw new MineRenderError(`Invalid blockstate variant weight: ${weight}`);
|
|
4413
|
+
}
|
|
4414
|
+
return sum + weight;
|
|
4415
|
+
}, 0);
|
|
4416
|
+
let choice = Math.random() * total;
|
|
4417
|
+
for (const variant of variants) {
|
|
4418
|
+
choice -= variant.weight ?? 1;
|
|
4419
|
+
if (choice < 0) return variant;
|
|
4420
|
+
}
|
|
4421
|
+
return variants[variants.length - 1];
|
|
4448
4422
|
}
|
|
4449
4423
|
// @deprecated
|
|
4450
4424
|
async createAVariant(variants, instanceInfo) {
|