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/bundle.js
CHANGED
|
@@ -67157,6 +67157,7 @@ return ${compiler2.callType("value", tagType)}
|
|
|
67157
67157
|
this.rootType = rootType;
|
|
67158
67158
|
this.extension = extension;
|
|
67159
67159
|
this.root = root;
|
|
67160
|
+
this.isAssetKey = true;
|
|
67160
67161
|
}
|
|
67161
67162
|
static parse(assetType, str, origin) {
|
|
67162
67163
|
let namespace = origin?.namespace || DEFAULT_NAMESPACE;
|
|
@@ -67172,7 +67173,10 @@ return ${compiler2.callType("value", tagType)}
|
|
|
67172
67173
|
split.shift();
|
|
67173
67174
|
}
|
|
67174
67175
|
let path = split.join("/");
|
|
67175
|
-
|
|
67176
|
+
const extension = assetType === "textures" ? ".png" : origin?.extension ?? ".json";
|
|
67177
|
+
if (extension && path.endsWith(extension)) {
|
|
67178
|
+
path = path.slice(0, -extension.length);
|
|
67179
|
+
}
|
|
67176
67180
|
return new _AssetKey(namespace, path, assetType, type, "assets", extension, origin?.root);
|
|
67177
67181
|
}
|
|
67178
67182
|
toString() {
|
|
@@ -67202,10 +67206,10 @@ return ${compiler2.callType("value", tagType)}
|
|
|
67202
67206
|
}
|
|
67203
67207
|
};
|
|
67204
67208
|
function isBasicAssetKey(obj) {
|
|
67205
|
-
return "
|
|
67209
|
+
return obj !== null && typeof obj === "object" && typeof obj.namespace === "string" && typeof obj.path === "string";
|
|
67206
67210
|
}
|
|
67207
67211
|
function isAssetKey(obj) {
|
|
67208
|
-
return isBasicAssetKey(obj) &&
|
|
67212
|
+
return isBasicAssetKey(obj) && obj.isAssetKey === true;
|
|
67209
67213
|
}
|
|
67210
67214
|
|
|
67211
67215
|
// src/model/ModelMerger.ts
|
|
@@ -79973,6 +79977,16 @@ return ${compiler2.callType("value", tagType)}
|
|
|
79973
79977
|
// src/model/block/scene/BlockObject.ts
|
|
79974
79978
|
var import_ts_deepmerge6 = __toESM(require_dist());
|
|
79975
79979
|
var p13 = prefix("BlockObject");
|
|
79980
|
+
function matchesCondition(condition, state) {
|
|
79981
|
+
return Object.entries(condition).every(([key, value]) => {
|
|
79982
|
+
if (Array.isArray(value)) {
|
|
79983
|
+
if (key === "OR") return value.some((child) => matchesCondition(child, state));
|
|
79984
|
+
if (key === "AND") return value.every((child) => matchesCondition(child, state));
|
|
79985
|
+
return false;
|
|
79986
|
+
}
|
|
79987
|
+
return typeof value === "string" && state[key] !== void 0 && value.split("|").includes(`${state[key]}`);
|
|
79988
|
+
});
|
|
79989
|
+
}
|
|
79976
79990
|
var _BlockObject = class _BlockObject extends SceneObject {
|
|
79977
79991
|
constructor(blockState, options) {
|
|
79978
79992
|
super(options);
|
|
@@ -80001,15 +80015,9 @@ return ${compiler2.callType("value", tagType)}
|
|
|
80001
80015
|
if (this.blockState.variants) {
|
|
80002
80016
|
await this.setState(Object.keys(this.blockState.variants)[0]);
|
|
80003
80017
|
} 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
|
-
}
|
|
80018
|
+
const condition = this.blockState.multipart.map((part) => part.when).find((when) => when !== void 0 && Object.values(when).every((value) => typeof value === "string"));
|
|
80019
|
+
const state = Object.fromEntries(Object.entries(condition ?? {}).map(([key, value]) => [key, value.split("|")[0]]));
|
|
80020
|
+
await this.setState(state);
|
|
80013
80021
|
}
|
|
80014
80022
|
}
|
|
80015
80023
|
} else {
|
|
@@ -80069,52 +80077,8 @@ return ${compiler2.callType("value", tagType)}
|
|
|
80069
80077
|
console.debug(p13, "Missing apply for blockState part", part);
|
|
80070
80078
|
continue;
|
|
80071
80079
|
}
|
|
80072
|
-
if (!part.when) {
|
|
80080
|
+
if (!part.when || matchesCondition(part.when, state)) {
|
|
80073
80081
|
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
80082
|
}
|
|
80119
80083
|
}
|
|
80120
80084
|
}
|
|
@@ -80144,11 +80108,21 @@ return ${compiler2.callType("value", tagType)}
|
|
|
80144
80108
|
}
|
|
80145
80109
|
}
|
|
80146
80110
|
getSingleVariant(variants) {
|
|
80147
|
-
if (Array.isArray(variants))
|
|
80148
|
-
|
|
80149
|
-
|
|
80150
|
-
|
|
80111
|
+
if (!Array.isArray(variants)) return variants;
|
|
80112
|
+
if (!variants.length) throw new MineRenderError("Blockstate variant arrays must not be empty");
|
|
80113
|
+
const total = variants.reduce((sum, variant) => {
|
|
80114
|
+
const weight = variant.weight ?? 1;
|
|
80115
|
+
if (!Number.isInteger(weight) || weight < 1) {
|
|
80116
|
+
throw new MineRenderError(`Invalid blockstate variant weight: ${weight}`);
|
|
80117
|
+
}
|
|
80118
|
+
return sum + weight;
|
|
80119
|
+
}, 0);
|
|
80120
|
+
let choice = Math.random() * total;
|
|
80121
|
+
for (const variant of variants) {
|
|
80122
|
+
choice -= variant.weight ?? 1;
|
|
80123
|
+
if (choice < 0) return variant;
|
|
80151
80124
|
}
|
|
80125
|
+
return variants[variants.length - 1];
|
|
80152
80126
|
}
|
|
80153
80127
|
// @deprecated
|
|
80154
80128
|
async createAVariant(variants, instanceInfo) {
|