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/bundle.js
CHANGED
|
@@ -79973,6 +79973,16 @@ return ${compiler2.callType("value", tagType)}
|
|
|
79973
79973
|
// src/model/block/scene/BlockObject.ts
|
|
79974
79974
|
var import_ts_deepmerge6 = __toESM(require_dist());
|
|
79975
79975
|
var p13 = prefix("BlockObject");
|
|
79976
|
+
function matchesCondition(condition, state) {
|
|
79977
|
+
return Object.entries(condition).every(([key, value]) => {
|
|
79978
|
+
if (Array.isArray(value)) {
|
|
79979
|
+
if (key === "OR") return value.some((child) => matchesCondition(child, state));
|
|
79980
|
+
if (key === "AND") return value.every((child) => matchesCondition(child, state));
|
|
79981
|
+
return false;
|
|
79982
|
+
}
|
|
79983
|
+
return typeof value === "string" && state[key] !== void 0 && value.split("|").includes(`${state[key]}`);
|
|
79984
|
+
});
|
|
79985
|
+
}
|
|
79976
79986
|
var _BlockObject = class _BlockObject extends SceneObject {
|
|
79977
79987
|
constructor(blockState, options) {
|
|
79978
79988
|
super(options);
|
|
@@ -80001,15 +80011,9 @@ return ${compiler2.callType("value", tagType)}
|
|
|
80001
80011
|
if (this.blockState.variants) {
|
|
80002
80012
|
await this.setState(Object.keys(this.blockState.variants)[0]);
|
|
80003
80013
|
} else if (this.blockState.multipart) {
|
|
80004
|
-
|
|
80005
|
-
|
|
80006
|
-
|
|
80007
|
-
if (k4) {
|
|
80008
|
-
await this.setState(k4, part.when[k4].split("|")[0]);
|
|
80009
|
-
break;
|
|
80010
|
-
}
|
|
80011
|
-
}
|
|
80012
|
-
}
|
|
80014
|
+
const condition = this.blockState.multipart.map((part) => part.when).find((when) => when !== void 0 && Object.values(when).every((value) => typeof value === "string"));
|
|
80015
|
+
const state = Object.fromEntries(Object.entries(condition ?? {}).map(([key, value]) => [key, value.split("|")[0]]));
|
|
80016
|
+
await this.setState(state);
|
|
80013
80017
|
}
|
|
80014
80018
|
}
|
|
80015
80019
|
} else {
|
|
@@ -80069,52 +80073,8 @@ return ${compiler2.callType("value", tagType)}
|
|
|
80069
80073
|
console.debug(p13, "Missing apply for blockState part", part);
|
|
80070
80074
|
continue;
|
|
80071
80075
|
}
|
|
80072
|
-
if (!part.when) {
|
|
80076
|
+
if (!part.when || matchesCondition(part.when, state)) {
|
|
80073
80077
|
out.push(this.getSingleVariant(part.apply));
|
|
80074
|
-
} else {
|
|
80075
|
-
let matches = true;
|
|
80076
|
-
if ("OR" in part.when) {
|
|
80077
|
-
const or = part.when.OR;
|
|
80078
|
-
let anyMatch = false;
|
|
80079
|
-
for (let o4 of or) {
|
|
80080
|
-
for (let k4 in o4) {
|
|
80081
|
-
const split = o4[k4].split("|");
|
|
80082
|
-
let m4 = false;
|
|
80083
|
-
for (let s4 of split) {
|
|
80084
|
-
if (`${state[k4]}` === `${s4}`) {
|
|
80085
|
-
m4 = true;
|
|
80086
|
-
break;
|
|
80087
|
-
}
|
|
80088
|
-
}
|
|
80089
|
-
if (m4) {
|
|
80090
|
-
anyMatch = true;
|
|
80091
|
-
break;
|
|
80092
|
-
}
|
|
80093
|
-
}
|
|
80094
|
-
}
|
|
80095
|
-
if (!anyMatch) {
|
|
80096
|
-
matches = false;
|
|
80097
|
-
}
|
|
80098
|
-
} else {
|
|
80099
|
-
for (let k4 in part.when) {
|
|
80100
|
-
const split = part.when[k4].split("|");
|
|
80101
|
-
let m4 = false;
|
|
80102
|
-
for (let s4 of split) {
|
|
80103
|
-
if (`${state[k4]}` === `${s4}`) {
|
|
80104
|
-
m4 = true;
|
|
80105
|
-
break;
|
|
80106
|
-
}
|
|
80107
|
-
}
|
|
80108
|
-
if (!m4) {
|
|
80109
|
-
matches = false;
|
|
80110
|
-
break;
|
|
80111
|
-
}
|
|
80112
|
-
}
|
|
80113
|
-
}
|
|
80114
|
-
if (matches) {
|
|
80115
|
-
const variants = part.apply;
|
|
80116
|
-
out.push(this.getSingleVariant(variants));
|
|
80117
|
-
}
|
|
80118
80078
|
}
|
|
80119
80079
|
}
|
|
80120
80080
|
}
|
|
@@ -80144,11 +80104,21 @@ return ${compiler2.callType("value", tagType)}
|
|
|
80144
80104
|
}
|
|
80145
80105
|
}
|
|
80146
80106
|
getSingleVariant(variants) {
|
|
80147
|
-
if (Array.isArray(variants))
|
|
80148
|
-
|
|
80149
|
-
|
|
80150
|
-
|
|
80107
|
+
if (!Array.isArray(variants)) return variants;
|
|
80108
|
+
if (!variants.length) throw new MineRenderError("Blockstate variant arrays must not be empty");
|
|
80109
|
+
const total = variants.reduce((sum, variant) => {
|
|
80110
|
+
const weight = variant.weight ?? 1;
|
|
80111
|
+
if (!Number.isInteger(weight) || weight < 1) {
|
|
80112
|
+
throw new MineRenderError(`Invalid blockstate variant weight: ${weight}`);
|
|
80113
|
+
}
|
|
80114
|
+
return sum + weight;
|
|
80115
|
+
}, 0);
|
|
80116
|
+
let choice = Math.random() * total;
|
|
80117
|
+
for (const variant of variants) {
|
|
80118
|
+
choice -= variant.weight ?? 1;
|
|
80119
|
+
if (choice < 0) return variant;
|
|
80151
80120
|
}
|
|
80121
|
+
return variants[variants.length - 1];
|
|
80152
80122
|
}
|
|
80153
80123
|
// @deprecated
|
|
80154
80124
|
async createAVariant(variants, instanceInfo) {
|