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/bundle.js CHANGED
@@ -66946,7 +66946,11 @@ return ${compiler2.callType("value", tagType)}
66946
66946
 
66947
66947
  if (SHADE) {
66948
66948
 
66949
- vec3 N = vec3( modelMatrix * instanceMatrix * vec4(normal, 0.0) );
66949
+ #ifdef USE_INSTANCING
66950
+ vec3 N = vec3( modelMatrix * instanceMatrix * vec4(normal, 0.0) );
66951
+ #else
66952
+ vec3 N = vec3( modelMatrix * vec4(normal, 0.0) );
66953
+ #endif
66950
66954
 
66951
66955
  float yLight = (1.0+N.y) * 0.5;
66952
66956
  light = yLight * (1.0-AMBIENT) + N.x*N.x * XFAC + N.z*N.z * ZFAC + AMBIENT;
@@ -79969,6 +79973,16 @@ return ${compiler2.callType("value", tagType)}
79969
79973
  // src/model/block/scene/BlockObject.ts
79970
79974
  var import_ts_deepmerge6 = __toESM(require_dist());
79971
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
+ }
79972
79986
  var _BlockObject = class _BlockObject extends SceneObject {
79973
79987
  constructor(blockState, options) {
79974
79988
  super(options);
@@ -79997,15 +80011,9 @@ return ${compiler2.callType("value", tagType)}
79997
80011
  if (this.blockState.variants) {
79998
80012
  await this.setState(Object.keys(this.blockState.variants)[0]);
79999
80013
  } else if (this.blockState.multipart) {
80000
- for (let part of this.blockState.multipart) {
80001
- if (part.when && !("OR" in part.when)) {
80002
- const k4 = Object.keys(part.when)[0];
80003
- if (k4) {
80004
- await this.setState(k4, part.when[k4].split("|")[0]);
80005
- break;
80006
- }
80007
- }
80008
- }
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);
80009
80017
  }
80010
80018
  }
80011
80019
  } else {
@@ -80065,52 +80073,8 @@ return ${compiler2.callType("value", tagType)}
80065
80073
  console.debug(p13, "Missing apply for blockState part", part);
80066
80074
  continue;
80067
80075
  }
80068
- if (!part.when) {
80076
+ if (!part.when || matchesCondition(part.when, state)) {
80069
80077
  out.push(this.getSingleVariant(part.apply));
80070
- } else {
80071
- let matches = true;
80072
- if ("OR" in part.when) {
80073
- const or = part.when.OR;
80074
- let anyMatch = false;
80075
- for (let o4 of or) {
80076
- for (let k4 in o4) {
80077
- const split = o4[k4].split("|");
80078
- let m4 = false;
80079
- for (let s4 of split) {
80080
- if (`${state[k4]}` === `${s4}`) {
80081
- m4 = true;
80082
- break;
80083
- }
80084
- }
80085
- if (m4) {
80086
- anyMatch = true;
80087
- break;
80088
- }
80089
- }
80090
- }
80091
- if (!anyMatch) {
80092
- matches = false;
80093
- }
80094
- } else {
80095
- for (let k4 in part.when) {
80096
- const split = part.when[k4].split("|");
80097
- let m4 = false;
80098
- for (let s4 of split) {
80099
- if (`${state[k4]}` === `${s4}`) {
80100
- m4 = true;
80101
- break;
80102
- }
80103
- }
80104
- if (!m4) {
80105
- matches = false;
80106
- break;
80107
- }
80108
- }
80109
- }
80110
- if (matches) {
80111
- const variants = part.apply;
80112
- out.push(this.getSingleVariant(variants));
80113
- }
80114
80078
  }
80115
80079
  }
80116
80080
  }
@@ -80140,11 +80104,21 @@ return ${compiler2.callType("value", tagType)}
80140
80104
  }
80141
80105
  }
80142
80106
  getSingleVariant(variants) {
80143
- if (Array.isArray(variants)) {
80144
- return variants[0];
80145
- } else {
80146
- return variants;
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;
80147
80120
  }
80121
+ return variants[variants.length - 1];
80148
80122
  }
80149
80123
  // @deprecated
80150
80124
  async createAVariant(variants, instanceInfo) {