minerender 2.1.0-alpha.16 → 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 +29 -59
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/index.mjs +29 -59
- package/dist/browser/index.mjs.map +1 -1
- package/dist/bundle.js +28 -58
- 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 +29 -59
- package/dist/node/index.js.map +1 -1
- package/dist/node/index.mjs +29 -59
- package/dist/node/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/browser/index.mjs
CHANGED
|
@@ -4222,6 +4222,16 @@ function isModelObject(obj) {
|
|
|
4222
4222
|
var import_ts_deepmerge6 = __toESM(require_dist());
|
|
4223
4223
|
import { Euler as Euler3, Matrix4 as Matrix46, Vector3 as Vector36 } from "three";
|
|
4224
4224
|
var p10 = prefix("BlockObject");
|
|
4225
|
+
function matchesCondition(condition, state) {
|
|
4226
|
+
return Object.entries(condition).every(([key, value]) => {
|
|
4227
|
+
if (Array.isArray(value)) {
|
|
4228
|
+
if (key === "OR") return value.some((child) => matchesCondition(child, state));
|
|
4229
|
+
if (key === "AND") return value.every((child) => matchesCondition(child, state));
|
|
4230
|
+
return false;
|
|
4231
|
+
}
|
|
4232
|
+
return typeof value === "string" && state[key] !== void 0 && value.split("|").includes(`${state[key]}`);
|
|
4233
|
+
});
|
|
4234
|
+
}
|
|
4225
4235
|
var _BlockObject = class _BlockObject extends SceneObject {
|
|
4226
4236
|
constructor(blockState, options) {
|
|
4227
4237
|
super(options);
|
|
@@ -4250,15 +4260,9 @@ var _BlockObject = class _BlockObject extends SceneObject {
|
|
|
4250
4260
|
if (this.blockState.variants) {
|
|
4251
4261
|
await this.setState(Object.keys(this.blockState.variants)[0]);
|
|
4252
4262
|
} else if (this.blockState.multipart) {
|
|
4253
|
-
|
|
4254
|
-
|
|
4255
|
-
|
|
4256
|
-
if (k) {
|
|
4257
|
-
await this.setState(k, part.when[k].split("|")[0]);
|
|
4258
|
-
break;
|
|
4259
|
-
}
|
|
4260
|
-
}
|
|
4261
|
-
}
|
|
4263
|
+
const condition = this.blockState.multipart.map((part) => part.when).find((when) => when !== void 0 && Object.values(when).every((value) => typeof value === "string"));
|
|
4264
|
+
const state = Object.fromEntries(Object.entries(condition ?? {}).map(([key, value]) => [key, value.split("|")[0]]));
|
|
4265
|
+
await this.setState(state);
|
|
4262
4266
|
}
|
|
4263
4267
|
}
|
|
4264
4268
|
} else {
|
|
@@ -4318,52 +4322,8 @@ var _BlockObject = class _BlockObject extends SceneObject {
|
|
|
4318
4322
|
console.debug(p10, "Missing apply for blockState part", part);
|
|
4319
4323
|
continue;
|
|
4320
4324
|
}
|
|
4321
|
-
if (!part.when) {
|
|
4325
|
+
if (!part.when || matchesCondition(part.when, state)) {
|
|
4322
4326
|
out.push(this.getSingleVariant(part.apply));
|
|
4323
|
-
} else {
|
|
4324
|
-
let matches = true;
|
|
4325
|
-
if ("OR" in part.when) {
|
|
4326
|
-
const or = part.when.OR;
|
|
4327
|
-
let anyMatch = false;
|
|
4328
|
-
for (let o of or) {
|
|
4329
|
-
for (let k in o) {
|
|
4330
|
-
const split = o[k].split("|");
|
|
4331
|
-
let m = false;
|
|
4332
|
-
for (let s of split) {
|
|
4333
|
-
if (`${state[k]}` === `${s}`) {
|
|
4334
|
-
m = true;
|
|
4335
|
-
break;
|
|
4336
|
-
}
|
|
4337
|
-
}
|
|
4338
|
-
if (m) {
|
|
4339
|
-
anyMatch = true;
|
|
4340
|
-
break;
|
|
4341
|
-
}
|
|
4342
|
-
}
|
|
4343
|
-
}
|
|
4344
|
-
if (!anyMatch) {
|
|
4345
|
-
matches = false;
|
|
4346
|
-
}
|
|
4347
|
-
} else {
|
|
4348
|
-
for (let k in part.when) {
|
|
4349
|
-
const split = part.when[k].split("|");
|
|
4350
|
-
let m = false;
|
|
4351
|
-
for (let s of split) {
|
|
4352
|
-
if (`${state[k]}` === `${s}`) {
|
|
4353
|
-
m = true;
|
|
4354
|
-
break;
|
|
4355
|
-
}
|
|
4356
|
-
}
|
|
4357
|
-
if (!m) {
|
|
4358
|
-
matches = false;
|
|
4359
|
-
break;
|
|
4360
|
-
}
|
|
4361
|
-
}
|
|
4362
|
-
}
|
|
4363
|
-
if (matches) {
|
|
4364
|
-
const variants = part.apply;
|
|
4365
|
-
out.push(this.getSingleVariant(variants));
|
|
4366
|
-
}
|
|
4367
4327
|
}
|
|
4368
4328
|
}
|
|
4369
4329
|
}
|
|
@@ -4393,11 +4353,21 @@ var _BlockObject = class _BlockObject extends SceneObject {
|
|
|
4393
4353
|
}
|
|
4394
4354
|
}
|
|
4395
4355
|
getSingleVariant(variants) {
|
|
4396
|
-
if (Array.isArray(variants))
|
|
4397
|
-
|
|
4398
|
-
|
|
4399
|
-
|
|
4400
|
-
|
|
4356
|
+
if (!Array.isArray(variants)) return variants;
|
|
4357
|
+
if (!variants.length) throw new MineRenderError("Blockstate variant arrays must not be empty");
|
|
4358
|
+
const total = variants.reduce((sum, variant) => {
|
|
4359
|
+
const weight = variant.weight ?? 1;
|
|
4360
|
+
if (!Number.isInteger(weight) || weight < 1) {
|
|
4361
|
+
throw new MineRenderError(`Invalid blockstate variant weight: ${weight}`);
|
|
4362
|
+
}
|
|
4363
|
+
return sum + weight;
|
|
4364
|
+
}, 0);
|
|
4365
|
+
let choice = Math.random() * total;
|
|
4366
|
+
for (const variant of variants) {
|
|
4367
|
+
choice -= variant.weight ?? 1;
|
|
4368
|
+
if (choice < 0) return variant;
|
|
4369
|
+
}
|
|
4370
|
+
return variants[variants.length - 1];
|
|
4401
4371
|
}
|
|
4402
4372
|
// @deprecated
|
|
4403
4373
|
async createAVariant(variants, instanceInfo) {
|