minecraft-renderer 0.1.51 → 0.1.53

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.
@@ -28808,7 +28808,7 @@ void main() {
28808
28808
  vec4 texColor = texture2D(texture, gl_PointCoord);
28809
28809
  gl_FragColor = vColor * texColor;
28810
28810
  }
28811
- `,jr={textureSize:128,gravity:new K(0,-.005,0),friction:.998,defaultParticleSize:300,maxActiveFireworks:5},Jp=i=>{let t=i*3;return{x:t,y:t+1,z:t+2}},Kp=i=>{let t=i*4;return{r:t,g:t+1,b:t+2,a:t+3}},pu=(i=0,e=0)=>Math.floor(Math.random()*(i+1-e))+e,wqe=(i,e,t,n)=>{i.save();let r=i.createRadialGradient(e,e,0,e,e,e);r.addColorStop(0,"rgba(255,255,255,1.0)"),r.addColorStop(.5,"rgba(255,255,255,0.5)"),r.addColorStop(1,"rgba(255,255,255,0)"),i.fillStyle=r,i.fillRect(0,0,t,n),i.restore()},xqe=()=>{let i=jr.textureSize,e=zr(i,i),t=e.getContext("2d"),n=i/2;wqe(t,n,e.width,e.height);let r=new Gt(e);return r.needsUpdate=!0,r},Eqe=(i,e,t,n,r=jr.defaultParticleSize)=>{let s=new it,a=[],o=[],l=[],c=[],u=[],f=Math.random()>.3?"single":"multiple",m=pu(100,20)*.01,v=()=>pu(100,1)*.01,y="red",_=Math.random();_>.66?y="red":_>.33?y="green":y="blue";for(let g=0;g<i;g++){let x=new K(0,0,0);if(a.push(x.x,x.y,x.z),o.push(e[g].x,e[g].y,e[g].z),t==="seed"){let w=e[g].y**2*.04;g===0&&(w*=1.1),c.push(w),u.push(w*.017),l.push(1,1,1,1)}else if(t==="trail"){let w=Math.random()*.1+.1;c.push(w),u.push(w*.017),l.push(1,1,1,1)}else{let w=pu(r,10)*.001;if(c.push(w),u.push(w*.017),f==="multiple")l.push(v(),v(),v(),1);else switch(y){case"red":l.push(m,.1,.1,1);break;case"green":l.push(.1,m,.1,1);break;case"blue":l.push(.1,.1,m,1);break}}}s.setAttribute("position",new qe(a,3)),s.setAttribute("velocity",new qe(o,3)),s.setAttribute("color",new qe(l,4)),s.setAttribute("adjustSize",new qe(c,1)),s.setAttribute("mass",new qe(u,1));let b=new Pf({uniforms:{size:{value:jr.textureSize},texture:{value:n}},transparent:!0,depthWrite:!1,blending:Li,vertexShader:bqe,fragmentShader:_qe});return new tr(s,b)},Zp=class{particleNum;timerStartFading;mesh;constructor(e,t,n,r,s){this.particleNum=e,this.timerStartFading=10,this.mesh=Eqe(e,t,n,r,s)}update(e){this.timerStartFading>0&&(this.timerStartFading-=.3);let t=this.mesh.geometry.attributes.position,n=this.mesh.geometry.attributes.velocity,r=this.mesh.geometry.attributes.color,s=this.mesh.geometry.attributes.mass,a=()=>Math.random()>.5?.98:.96,o=l=>Math.random()>.5?0:(1-l)*.1;for(let l=0;l<this.particleNum;l++){let{x:c,y:u,z:f}=Jp(l);n.array[u]+=e.y-s.array[l],n.array[c]*=jr.friction,n.array[f]*=jr.friction,n.array[u]*=jr.friction,t.array[c]+=n.array[c],t.array[u]+=n.array[u],t.array[f]+=n.array[f];let{a:m}=Kp(l);this.timerStartFading<=0&&(r.array[m]*=a()-o(r.array[m]),r.array[m]<.001&&(r.array[m]=0))}t.needsUpdate=!0,n.needsUpdate=!0,r.needsUpdate=!0}disposeAll(){this.mesh.geometry.dispose(),this.mesh.material.dispose()}},uR=class extends Zp{constructor(e,t,n){super(e,t,"seed",n)}update(e){let t=this.mesh.geometry.attributes.position,n=this.mesh.geometry.attributes.velocity,r=this.mesh.geometry.attributes.color,s=this.mesh.geometry.attributes.mass,a=()=>Math.random()>.3?.99:.96,o=f=>Math.random()>.3?0:(1-f)*.1,l=()=>Math.random()>.5?.05:-.05,c=()=>Math.random()>.1,u=jr.friction*.98;for(let f=0;f<this.particleNum;f++){let{x:m,y:v,z:y}=Jp(f);n.array[v]+=e.y-s.array[f],n.array[m]*=u,n.array[y]*=u,n.array[v]*=u,t.array[m]+=n.array[m],t.array[v]+=n.array[v],t.array[y]+=n.array[y],c()&&(t.array[m]+=l()),c()&&(t.array[y]+=l());let{a:_}=Kp(f);r.array[_]*=a()-o(r.array[_]),r.array[_]<.001&&(r.array[_]=0)}t.needsUpdate=!0,n.needsUpdate=!0,r.needsUpdate=!0}},fR=class extends Zp{constructor(e,t,n){super(e,t,"trail",n)}update(e){let t=this.mesh.geometry.attributes.position,n=this.mesh.geometry.attributes.velocity,r=this.mesh.geometry.attributes.color,s=this.mesh.geometry.attributes.mass,a=()=>Math.random()>.3?.98:.95,o=()=>Math.random()>.5?.05:-.05,l=()=>Math.random()>.2;for(let c=0;c<this.particleNum;c++){let{x:u,y:f,z:m}=Jp(c);n.array[f]+=e.y-s.array[c],n.array[u]*=jr.friction,n.array[m]*=jr.friction,n.array[f]*=jr.friction,t.array[u]+=n.array[u],t.array[f]+=n.array[f],t.array[m]+=n.array[m],l()&&(t.array[u]+=o()),l()&&(t.array[m]+=o());let{a:v}=Kp(c);r.array[v]*=a(),r.array[v]<.001&&(r.array[v]=0)}t.needsUpdate=!0,n.needsUpdate=!0,r.needsUpdate=!0}},Qp=class{meshGroup;isExplode;petalsNum;life;seed;flowerSizeRate;flower;texture;particleSize;constructor(e,t=jr.defaultParticleSize,n){this.meshGroup=new ot,this.isExplode=!1,this.texture=e,this.particleSize=t;let r=400,s=150;this.petalsNum=pu(r,s),this.life=150,this.seed=this.getSeed(n),this.meshGroup.add(this.seed.mesh),this.flowerSizeRate=yt.mapLinear(this.petalsNum,s,r,.4,.7)}getSeed(e){let n=[];for(let s=0;s<40;s++){let o=s===0?Math.random()*2.5+.9:Math.random()*2+.4,l=0;n.push(new K(0,o,l))}let r=new uR(40,n,this.texture);if(e)r.mesh.position.set(0,0,0);else{let s=Math.random()*80-40,a=-50,o=Math.random()*80-40;r.mesh.position.set(s,a,o)}return r}explode(e){this.isExplode=!0,this.flower=this.getFlower(e),this.meshGroup.add(this.flower.mesh),this.meshGroup.remove(this.seed.mesh),this.seed.disposeAll()}getFlower(e){let t=this.petalsNum,n=[],r;if(Math.random()>.5)for(let o=0;o<t;o++){r=pu(120,60)*.01;let l=yt.degToRad(Math.random()*180),c=yt.degToRad(Math.random()*360),u=Math.sin(l)*Math.cos(c)*r,f=Math.sin(l)*Math.sin(c)*r,m=Math.cos(l)*r,v=new K(u,f,m);v.multiplyScalar(this.flowerSizeRate),n.push(v)}else{let o=180/t,l=360*(Math.random()*20+1)/t,c=l,u=l;r=pu(120,60)*.01;for(let f=0;f<t;f++){let m=Math.sin(yt.degToRad(o*f)),v=Math.cos(yt.degToRad(o*f))*r,y=Math.cos(yt.degToRad(c*f))*m*r,_=Math.sin(yt.degToRad(u*f))*m*r,b=new K(y,_,v);b.multiplyScalar(this.flowerSizeRate),n.push(b)}}let a=new Zp(t,n,"default",this.texture,this.particleSize);return a.mesh.position.set(e.x,e.y,e.z),a}update(e){this.isExplode?(this.flower.update(e),this.life>0&&(this.life-=1)):this.drawTail()}drawTail(){this.seed.update(jr.gravity);let e=this.seed.mesh.geometry.attributes.position,t=this.seed.mesh.geometry.attributes.velocity,n=0;for(let f=0,m=t.array.length;f<m;f++){let v=t.array[f];f%3===1&&v>0&&n++}if(!(n===0))return;let{x:s,y:a,z:o}=this.seed.mesh.position,l=new K(s,a,o),c=0,u;for(let f=0,m=e.array.length;f<m;f++){let v=e.array[f];f%3===1&&v>c&&(c=v,u=new K(e.array[f-1],v,e.array[f+2]))}u&&(l.add(u),this.explode(l))}},Z1=class extends Qp{tailMeshGroup;tails;constructor(e,t=jr.defaultParticleSize,n){super(e,t,n);let r=150,s=100;this.petalsNum=pu(r,s),this.flowerSizeRate=yt.mapLinear(this.petalsNum,s,r,.4,.7),this.tailMeshGroup=new ot,this.tails=[]}explode(e){this.isExplode=!0,this.flower=this.getFlower(e),this.tails=this.getTail(),this.meshGroup.add(this.flower.mesh),this.meshGroup.add(this.tailMeshGroup)}getTail(){let e=[],n=this.flower.mesh.geometry.attributes.color;for(let r=0;r<this.petalsNum;r++){let s=[];for(let E=0;E<20;E++)s.push(new K(0,0,0));let a=new fR(20,s,this.texture),{r:o,g:l,b:c,a:u}=Kp(r),f=n.array[o],m=n.array[l],v=n.array[c],y=n.array[u],_=a.mesh.geometry.attributes.position,b=a.mesh.geometry.attributes.color;for(let E=0;E<_.count;E++){let A=Kp(E);b.array[A.r]=f,b.array[A.g]=m,b.array[A.b]=v,b.array[A.a]=y}let{x:g,y:x,z:w}=this.flower.mesh.position;a.mesh.position.set(g,x,w),e.push(a),this.tailMeshGroup.add(a.mesh)}return e}update(e){if(this.isExplode){this.flower.update(e);let t=this.flower.mesh.geometry.attributes.position;for(let n=0,r=this.tails.length;n<r;n++){let s=this.tails[n];s.update(e);let{x:a,y:o,z:l}=Jp(n),c=new K(t.array[a],t.array[o],t.array[l]),u=s.mesh.geometry.attributes.position,f=s.mesh.geometry.attributes.velocity;for(let m=0;m<u.count;m++){let v=Jp(m),y=new K,_=new K(u.array[v.x],u.array[v.y],u.array[v.z]),b=new K(f.array[v.x],f.array[v.y],f.array[v.z]);y.subVectors(c,_);let g=y.sub(b);g.normalize(),g.multiplyScalar(Math.random()*3e-4*this.life),f.array[v.x]+=g.x,f.array[v.y]+=g.y,f.array[v.z]+=g.z}f.needsUpdate=!0}this.life>0&&(this.life-=1.2)}else this.drawTail()}},q4=class{fireworksInstances;scene;sceneOrigin;texture;particleSize;maxFireworks;constructor(e,t,n){this.fireworksInstances=[],this.scene=e,this.sceneOrigin=t,this.texture=xqe(),this.particleSize=n?.defaultParticleSize??jr.defaultParticleSize,this.maxFireworks=n?.maxActiveFireworks??jr.maxActiveFireworks}launchFirework(e){if(this.fireworksInstances.length>=this.maxFireworks)return;let t=e?.particleSize??this.particleSize,n=e?.position,r;e?.forceRich?r=new Z1(this.texture,t,n):e?.forceBasic?r=new Qp(this.texture,t,n):r=Math.random()>.5?new Qp(this.texture,t,n):new Z1(this.texture,t,n),this.fireworksInstances.push(r),n?(this.sceneOrigin.addAndTrack(r.meshGroup),r.meshGroup.position.set(n.x,n.y,n.z)):this.scene.add(r.meshGroup)}repositionAll(){}update(){let e=[];for(let t=this.fireworksInstances.length-1;t>=0;t--){let n=this.fireworksInstances[t];n.update(jr.gravity),n.isExplode&&e.push(t)}for(let t=0,n=e.length;t<n;t++){let r=e[t],s=this.fireworksInstances[r];if(s&&(s.meshGroup.remove(s.seed.mesh),s.seed.disposeAll(),s.life<=0)){if(this.sceneOrigin.removeAndUntrack(s.meshGroup),s instanceof Z1&&s.tailMeshGroup)for(let a of s.tails)a.disposeAll();s.flower?.disposeAll(),this.fireworksInstances.splice(r,1)}}}clear(){for(let e of this.fireworksInstances)if(this.sceneOrigin.removeAndUntrack(e.meshGroup),e.seed.disposeAll(),e.flower&&e.flower.disposeAll(),e instanceof Z1)for(let t of e.tails)t.disposeAll();this.fireworksInstances=[]}dispose(){this.clear(),this.texture.dispose()}};h();p();d();var Ime=Symbol("tracked-proxy"),Sqe=new Set(["add","addScalar","addScaledVector","addVectors","sub","subScalar","subVectors","multiply","multiplyScalar","multiplyVectors","divide","divideScalar","applyEuler","applyAxisAngle","applyMatrix3","applyMatrix4","applyNormalMatrix","applyQuaternion","negate","floor","ceil","round","roundToZero","min","max","clamp","clampLength","clampScalar","project","unproject","reflect","lerp","lerpVectors","cross","crossVectors","setFromMatrixPosition","setFromMatrixColumn","setFromMatrix3Column","setFromEuler","setFromSpherical","setFromSphericalCoords","setFromCylindrical","fromArray","fromBufferAttribute","setComponent","randomDirection","random"]),G4=class{scene;_x=0;_y=0;_z=0;_tracked=new Set;_worldCoords=new WeakMap;_originalPositions=new WeakMap;_trackOptions=new WeakMap;constructor(e){this.scene=e}get x(){return this._x}get y(){return this._y}get z(){return this._z}update(e,t,n){this._x=e,this._y=t,this._z=n;for(let r of this._tracked){let s=this._worldCoords.get(r);this._originalPositions.get(r).set(s.x-e,s.y-t,s.z-n),this._trackOptions.get(r)?.updateMatrix&&r.updateMatrix()}}track(e,t){let n=this._originalPositions.get(e)??e.position,r={x:0,y:0,z:0};this._originalPositions.set(e,n),this._worldCoords.set(e,r),t?this._trackOptions.set(e,t):this._trackOptions.delete(e);let s=this,a=t,o=new Proxy(n,{get(l,c,u){if(c===Ime)return r;if(c==="set")return(m,v,y)=>(r.x=m,r.y=v,r.z=y,l.set(m-s._x,v-s._y,y-s._z),a?.updateMatrix&&e.updateMatrix(),u);if(c==="copy")return m=>{let v=m[Ime],y=v?v.x:m.x,_=v?v.y:m.y,b=v?v.z:m.z;return r.x=y,r.y=_,r.z=b,l.set(y-s._x,_-s._y,b-s._z),a?.updateMatrix&&e.updateMatrix(),u};if(c==="setX")return m=>(r.x=m,l.x=m-s._x,a?.updateMatrix&&e.updateMatrix(),u);if(c==="setY")return m=>(r.y=m,l.y=m-s._y,a?.updateMatrix&&e.updateMatrix(),u);if(c==="setZ")return m=>(r.z=m,l.z=m-s._z,a?.updateMatrix&&e.updateMatrix(),u);if(typeof c=="string"&&Sqe.has(c))return()=>{throw new Error(`Cannot call position.${c}() on a tracked object. Use position.set(x, y, z) instead.`)};let f=l[c];return typeof f=="function"?f.bind(l):f},set(l,c,u){return c==="x"?(r.x=u,l.x=u-s._x,a?.updateMatrix&&e.updateMatrix(),!0):c==="y"?(r.y=u,l.y=u-s._y,a?.updateMatrix&&e.updateMatrix(),!0):c==="z"?(r.z=u,l.z=u-s._z,a?.updateMatrix&&e.updateMatrix(),!0):(l[c]=u,!0)}});Object.defineProperty(e,"position",{value:o,configurable:!0,enumerable:!0}),this._tracked.add(e)}untrack(e){let t=this._originalPositions.get(e);t&&(Object.defineProperty(e,"position",{value:t,configurable:!0,enumerable:!0}),this._tracked.delete(e),this._worldCoords.delete(e),this._originalPositions.delete(e),this._trackOptions.delete(e))}addAndTrack(e,t){this.track(e,t),this.scene.add(e)}removeAndUntrack(e){this.untrack(e),e.removeFromParent()}removeAndUntrackAll(e){e.traverse(t=>{this.untrack(t)}),e.removeFromParent()}getWorldPosition(e){let t=this._worldCoords.get(e);return t?{x:t.x,y:t.y,z:t.z}:void 0}clear(){for(let e of this._tracked)this.untrack(e)}get trackedCount(){return this._tracked.size}toSceneX(e){return e-this._x}toSceneY(e){return e-this._y}toSceneZ(e){return e-this._z}toWorldX(e){return e+this._x}toWorldY(e){return e+this._y}toWorldZ(e){return e+this._z}};gR();h();p();d();var Zme=Jr(pp(),1);bt();var t8=Jr(_i(),1);Q1();vu();mR();h();p();d();bt();vu();Q1();var Lqe=2e6,yR=Nme(),Q4=class{mesh;capacityFaces;w0;w1;w2;w3;sectionSlots=new Map;freeList=[];highWatermark=0;dirtyMin=1/0;dirtyMax=-1;constructor(e,t){this.capacityFaces=Lqe,this.w0=new Uint32Array(this.capacityFaces),this.w1=new Uint32Array(this.capacityFaces),this.w2=new Uint32Array(this.capacityFaces),this.w3=new Uint32Array(this.capacityFaces);let n=new ma,r=new Float32Array(j4*3);n.setAttribute("position",new dt(r,3));let s=a=>{let o=new Ar(a,1);return o.setUsage(Av),o};n.setAttribute("a_w0",s(this.w0)),n.setAttribute("a_w1",s(this.w1)),n.setAttribute("a_w2",s(this.w2)),n.setAttribute("a_w3",s(this.w3)),n.instanceCount=0,this.mesh=new je(n,e),this.mesh.name="globalShaderCubes",this.mesh.frustumCulled=!1,this.mesh.matrixAutoUpdate=!1,this.mesh.matrix.identity(),this.mesh.position.set(0,0,0),t.add(this.mesh)}addSection(e,t,n){if(n<=0){this.removeSection(e);return}this.sectionSlots.has(e)&&this.removeSection(e),n>this.capacityFaces&&this.growCapacity(n);let r=this.takeFreeSlot(n);r||(this.highWatermark+n>this.capacityFaces&&this.growCapacity(this.highWatermark+n),r={start:this.highWatermark,count:n},this.highWatermark+=n);let s=4;for(let a=0;a<n;a++){let o=r.start+a,l=a*s;this.w0[o]=t[l],this.w1[o]=t[l+1],this.w2[o]=t[l+2],this.w3[o]=t[l+3]}this.sectionSlots.set(e,r),this.markDirty(r.start,r.start+n-1),this.mesh.geometry.instanceCount=this.highWatermark}hasSection(e){return this.sectionSlots.has(e)}takeSectionData(e){let t=this.sectionSlots.get(e);if(!t)return;let n=4,r=new Uint32Array(t.count*n);for(let s=0;s<t.count;s++){let a=t.start+s,o=s*n;r[o]=this.w0[a],r[o+1]=this.w1[a],r[o+2]=this.w2[a],r[o+3]=this.w3[a]}return this.removeSection(e),{words:r,count:t.count}}removeSection(e){let t=this.sectionSlots.get(e);if(t){for(let n=t.start;n<t.start+t.count;n++)this.w0[n]=0,this.w1[n]=0,this.w2[n]=yR,this.w3[n]=0;this.markDirty(t.start,t.start+t.count-1),this.sectionSlots.delete(e),this.insertFreeSlot(t),this.shrinkHighWatermark(),this.mesh.geometry.instanceCount=this.highWatermark}}uploadDirtyRange(){if(this.dirtyMin>this.dirtyMax)return;let e=this.dirtyMin,t=this.dirtyMax-this.dirtyMin+1,n=this.mesh.geometry;for(let r of["a_w0","a_w1","a_w2","a_w3"]){let s=n.getAttribute(r);s.updateRange.offset=e,s.updateRange.count=t,s.needsUpdate=!0}this.dirtyMin=1/0,this.dirtyMax=-1}setCameraOrigin(e,t,n){let r=Math.floor(e),s=Math.floor(t),a=Math.floor(n),o=this.mesh.material.uniforms.u_cameraOrigin;o?.value?.set&&o.value.set(r,s,a);let l=this.mesh.material.uniforms.u_cameraOriginFrac;l?.value?.set&&l.value.set(e-r,t-s,n-a)}reset(){this.sectionSlots.clear(),this.freeList.length=0,this.highWatermark=0,this.dirtyMin=1/0,this.dirtyMax=-1,this.w0.fill(0),this.w1.fill(0),this.w2.fill(yR),this.w3.fill(0),this.mesh.geometry.instanceCount=0}dispose(){this.mesh.parent?.remove(this.mesh),this.mesh.geometry.dispose(),this.reset()}markDirty(e,t){e<this.dirtyMin&&(this.dirtyMin=e),t>this.dirtyMax&&(this.dirtyMax=t)}takeFreeSlot(e){for(let t=0;t<this.freeList.length;t++){let n=this.freeList[t];if(n.count>=e){if(this.freeList.splice(t,1),n.count===e)return n;let r={start:n.start,count:e};return this.insertFreeSlot({start:n.start+e,count:n.count-e}),r}}}insertFreeSlot(e){this.freeList.push(e),this.freeList.sort((t,n)=>t.start-n.start),this.mergeFreeList()}mergeFreeList(){if(this.freeList.length<2)return;let e=[],t=this.freeList[0];for(let n=1;n<this.freeList.length;n++){let r=this.freeList[n];t.start+t.count===r.start?t={start:t.start,count:t.count+r.count}:(e.push(t),t=r)}e.push(t),this.freeList=e}shrinkHighWatermark(){for(;this.highWatermark>0;){let e=this.highWatermark-1,t=this.freeList.find(r=>r.start<=e&&r.start+r.count>e);if(!t||t.start+t.count!==this.highWatermark)break;this.highWatermark=t.start;let n=this.freeList.indexOf(t);this.freeList.splice(n,1)}}growCapacity(e){let t=this.capacityFaces;for(;t<e;)t*=2;let n=new Uint32Array(t),r=new Uint32Array(t),s=new Uint32Array(t),a=new Uint32Array(t);n.set(this.w0),r.set(this.w1),s.set(this.w2),a.set(this.w3),s.fill(yR,this.w0.length),this.w0=n,this.w1=r,this.w2=s,this.w3=a,this.capacityFaces=t;let o=this.mesh.geometry,l=(c,u)=>{let f=o.getAttribute(u);f&&(o.deleteAttribute(u),"dispose"in f&&typeof f.dispose=="function"&&f.dispose());let m=new Ar(c,1);m.setUsage(Av),o.setAttribute(u,m)};l(this.w0,"a_w0"),l(this.w1,"a_w1"),l(this.w2,"a_w2"),l(this.w3,"a_w3"),this.dirtyMin=0,this.dirtyMax=this.highWatermark-1}};h();p();d();Q1();vu();function Gme(i,e,t,n,r){if(e<=0)return;let s=t-8,a=n-8,o=r-8,l=J4,c=16,u=16,f=16,m=-1,v=-1,y=-1;for(let A=0;A<e;A++){let P=i[A*l],C=P&(1<<mu.LX_BITS)-1,L=P>>mu.LY_SHIFT&(1<<mu.LY_BITS)-1,M=P>>mu.LZ_SHIFT&(1<<mu.LZ_BITS)-1;C<c&&(c=C),L<u&&(u=L),M<f&&(f=M),C>m&&(m=C),L>v&&(v=L),M>y&&(y=M)}if(m<0)return;let _=s+c,b=a+u,g=o+f,x=s+m+1,w=a+v+1,E=o+y+1;return{minX:_,minY:b,minZ:g,maxX:x,maxY:w,maxZ:E,cx:(_+x)*.5,cy:(b+w)*.5,cz:(g+E)*.5}}function Bqe(i,e,t,n,r,s,a,o,l){return i>=n&&i<=a&&e>=r&&e<=o&&t>=s&&t<=l}function Wme(i,e,t,n,r,s,a,o,l,c,u,f,m){if(Bqe(i,e,t,a,o,l,c,u,f))return;let v=0,y=m;if(Math.abs(n)<1e-8){if(i<a||i>c)return}else{let _=1/n,b=(a-i)*_,g=(c-i)*_;if(b>g){let x=b;b=g,g=x}if(v=Math.max(v,b),y=Math.min(y,g),v>y)return}if(Math.abs(r)<1e-8){if(e<o||e>u)return}else{let _=1/r,b=(o-e)*_,g=(u-e)*_;if(b>g){let x=b;b=g,g=x}if(v=Math.max(v,b),y=Math.min(y,g),v>y)return}if(Math.abs(s)<1e-8){if(t<l||t>f)return}else{let _=1/s,b=(l-t)*_,g=(f-t)*_;if(b>g){let x=b;b=g,g=x}if(v=Math.max(v,b),y=Math.min(y,g),v>y)return}return v<=y&&v>=0?v:void 0}h();p();d();bt();var jme=20,$me=40,Oqe={white_banner:15,orange_banner:14,magenta_banner:13,light_blue_banner:12,yellow_banner:11,lime_banner:10,pink_banner:9,gray_banner:8,light_gray_banner:7,cyan_banner:6,purple_banner:5,blue_banner:4,brown_banner:3,green_banner:2,red_banner:1,black_banner:0},Xme={0:"#1d1d21",1:"#b02e26",2:"#5e7c16",3:"#835432",4:"#3c44aa",5:"#8932b8",6:"#169c9c",7:"#9d9d97",8:"#474f52",9:"#f38baa",10:"#80c71f",11:"#fed83d",12:"#3ab3da",13:"#c74ebd",14:"#f9801d",15:"#f9fffe"};function Nqe(i){let e=i.replace("_wall_banner","_banner");return Oqe[e]??15}var Dqe=(i,e,t,n,r,s,a)=>{switch(i.fillStyle=t,e){case"bs":i.fillRect(n,r,s,a);break;case"ls":i.fillRect(n,r,s/3,a);break;case"rs":i.fillRect(n+s*2/3,r,s/3,a);break;case"ts":i.fillRect(n,r,s,a/3);break;case"ms":i.fillRect(n,r+a/3,s,a/3);break;case"drs":i.fillRect(n,r,s/2,a/2);break;case"dls":i.fillRect(n+s/2,r,s/2,a/2);break;case"ss":for(let o=0;o<s;o+=2)i.fillRect(n+o,r,1,a);break;case"cr":i.fillRect(n,r+a/3,s,a/3),i.fillRect(n+s/3,r,s/3,a);break;case"sc":i.fillRect(n,r+a/2-1,s,2),i.fillRect(n+s/2-1,r,2,a);break;default:i.fillRect(n,r,s,a)}};function Uqe(i,e){if(!e||e.length===0)return`banner_${i}_empty`;let t=e.map(n=>`${n.Pattern??"bs"}_${n.Color??0}`).join(",");return`banner_${i}_${t}`}var Vqe=(i,e,t=(n,r)=>zr(n,r))=>{let r=t(jme*1,$me*1),s=r.getContext("2d");if(!s){console.warn("Failed to get 2d context for banner rendering");return}if(s.imageSmoothingEnabled=!1,e?.Patterns&&e.Patterns.length>0)for(let a of e.Patterns){let o=a.Color??0,l=a.Pattern??"bs",c=Xme[o]||Xme[0];Dqe(s,l,c,0,0,jme*1,$me*1)}return r},e8=new Map;function Yme(i,e,t){let n=Nqe(e),r=Uqe(n,t?.Patterns),s=e8.get(r);if(s)return s.refCount++,s.texture;let a=Vqe(n,t);if(!a)return;let o=new Gt(a);return o.magFilter=Je,o.minFilter=Je,o.needsUpdate=!0,e8.set(r,{texture:o,refCount:1}),o}function Jme(i){for(let[e,t]of e8.entries())if(t.texture===i){t.refCount--,t.refCount<=0&&(t.texture.dispose(),e8.delete(e));return}}function Kme(i,e,t,n){let o,l,c;t?(o=(-14.6+13.4)/2/16-.5,l=1-14.75/16-.5,c=1/2):(o=(1.4+29.4)/2/16,l=1-7.25/16-.5,c=0);let u=new je(new vn(.85,1.75),new st({map:n,transparent:!0}));u.renderOrder=999;let f=.5/16,m=.25/16;t?u.position.set(0,o,l+m+.004):u.position.set(0,o,l+f/2+.004);let v=new ot;return v.rotation.set(0,-yt.degToRad(e*(t?90:45/2)),0),v.add(u),v.bannerTexture=n,v.position.set(i.x+.5,i.y+c,i.z+.5),v}var gu=class gu{constructor(e,t,n,r,s=3){this.worldRenderer=e;this.scene=t;this.material=n;this.worldHeight=r;this.updateViewDistance(s),this.signHeadsRenderer=new bR(e),this.initializePool()}meshPool=[];activeSections=new Map;sectionObjects={};waitingChunksToDisplay={};pendingNearReveal=new Map;nearRevealTimers=new Map;nearRevealGraceTimers=new Map;poolSize;maxPoolSize;minPoolSize;signHeadsRenderer;chunkBoxMaterial=new st({color:0,transparent:!0,opacity:0});cubeShaderMaterial=null;globalBlockBuffer=null;shaderSectionRaycastBoxes=new Map;hits=0;misses=0;bypassPooling=!1;renderTimes=[];maxRenderTimeSamples=30;_performanceOverrideDistance;lastPerformanceCheck=0;performanceCheckInterval=2e3;get performanceOverrideDistance(){return this._performanceOverrideDistance??0}set performanceOverrideDistance(e){this._performanceOverrideDistance=e,this.updateSectionsVisibility()}initializePool(){for(let e=0;e<this.poolSize;e++){let t=new it,n=new je(t,this.material);n.visible=!1,n.matrixAutoUpdate=!1,n.name="pooled-section-mesh";let r={mesh:n,inUse:!1,lastUsedTime:0};this.meshPool.push(r)}}sectionHasRenderableContent(e){return e.positions.length>0?!0:this.isShaderCubesGpuEnabled()?(e.shaderCubes?.count??0)>0:!1}isShaderCubesGpuEnabled(){return this.worldRenderer.shaderCubeBlocksEnabled()}syncCubeShaderUniforms(){if(!this.isShaderCubesGpuEnabled())return;let e=this.cubeShaderMaterial??this.getCubeShaderMaterial();if(!e)return;let t=this.material.map??null;e.uniforms.u_atlas.value=t;let{tintPalette:n}=K4();n.isReady()||n.createTexture(),e.uniforms.u_tintPalette.value=n.getTexture(),e.uniforms.u_debugMode.value=this.worldRenderer.worldRendererConfig.shaderCubeDebugMode??0,e.needsUpdate=!0}getCubeShaderMaterial(){return this.isShaderCubesGpuEnabled()?(this.cubeShaderMaterial||(this.cubeShaderMaterial=W4(),this.syncCubeShaderUniforms()),this.cubeShaderMaterial):null}getGlobalBlockBuffer(){let e=this.getCubeShaderMaterial();return e?(this.globalBlockBuffer||(this.globalBlockBuffer=new Q4(e,this.scene)),this.globalBlockBuffer):null}shouldDeferShaderToPerSection(e){let t=this.worldRenderer.getModule("futuristicReveal");return t?t.isInInitialRevealCampaign?.()?!0:t.shouldUseRevealEffect?.(e)===!0:!1}migrateDeferredShaderToGlobal(e){let t=this.sectionObjects[e];if(!t?.deferredShaderCubes)return;let{words:n,count:r}=t.deferredShaderCubes,s=t.worldX,a=t.worldY,o=t.worldZ;s!==void 0&&a!==void 0&&o!==void 0&&this.registerShaderSectionRaycastBox(e,n,r,s,a,o),this.getGlobalBlockBuffer()?.addSection(e,n,r);let c=t.mesh===t.shaderMesh;t.shaderMesh&&(pR(t.shaderMesh),t.remove(t.shaderMesh),t.shaderMesh=void 0),delete t.deferredShaderCubes,c&&(t.mesh=void 0)}registerShaderSectionRaycastBox(e,t,n,r,s,a){let o=Gme(t,n,r,s,a);o?this.shaderSectionRaycastBoxes.set(e,o):this.shaderSectionRaycastBoxes.delete(e)}unregisterShaderSectionRaycastBox(e){this.shaderSectionRaycastBoxes.delete(e)}raycastShaderSectionAABBs(e,t,n,r=80){let s=e.x,a=e.y,o=e.z,l=t.x,c=t.y,u=t.z,f=r*r,m=n,v=!1;for(let[y,_]of this.shaderSectionRaycastBoxes){let b=this.sectionObjects[y];if(b&&!b.visible)continue;let g=_.cx-s,x=_.cy-a,w=_.cz-o;if(g*g+x*x+w*w>f)continue;let E=Wme(s,a,o,l,c,u,_.minX,_.minY,_.minZ,_.maxX,_.maxY,_.maxZ,m);E!==void 0&&E<m&&(m=E,v=!0)}return v?m:void 0}updateSection(e,t){let n=t.positions.length>0,r=t.shaderCubes,s=this.isShaderCubesGpuEnabled()&&(r?.count??0)>0;if(!n&&!s)return this.releaseSection(e),null;let a=this.sectionObjects[e];a&&this.cleanupSection(e),n||this.releasePooledMesh(e);let o;if(n){let b=this.activeSections.get(e);if(!b){if(b=this.acquireMesh(),!b)return console.warn(`ChunkMeshManager: No available mesh in pool for section ${e}`),null;this.activeSections.set(e,b),b.sectionKey=e}let{mesh:g}=b;this.updateGeometryAttribute(g.geometry,"position",t.positions,3),this.updateGeometryAttribute(g.geometry,"normal",t.normals,3),this.updateGeometryAttribute(g.geometry,"color",t.colors,3),this.updateGeometryAttribute(g.geometry,"uv",t.uvs,2),g.geometry.index=new dt(t.indices,1),g.geometry.boundingBox=new Un(new K(-8,-8,-8),new K(8,8,8)),g.geometry.boundingSphere=new jn(new K(0,0,0),Math.sqrt(3*8**2)),this.worldRenderer.sceneOrigin.track(g,{updateMatrix:!0}),g.position.set(t.sx,t.sy,t.sz),g.updateMatrix(),g.visible=!0,g.name="mesh",b.lastUsedTime=performance.now(),o=g}let l=s?this.getCubeShaderMaterial():null,c,u=s&&this.shouldDeferShaderToPerSection(e);s&&r&&(u&&l?(c=Z4(r,l),c.visible=!0):this.getGlobalBlockBuffer()?.addSection(e,r.words,r.count)),a=new ot,o&&(a.add(o),a.mesh=o),c&&(a.add(c),a.shaderMesh=c,r&&(a.deferredShaderCubes={words:r.words,count:r.count}),a.mesh||(a.mesh=c)),s&&r&&this.registerShaderSectionRaycastBox(e,r.words,r.count,t.sx,t.sy,t.sz);let f=0;n&&(f+=t.positions.length/3/4),s&&r&&(f+=r.count),a.tilesCount=f,a.blocksCount=t.blocksCount,a.worldX=t.sx,a.worldY=t.sy,a.worldZ=t.sz,a.sectionKey=e,a.name="chunk";try{if(Object.keys(t.signs).length>0){let b=new ot;b.name="signs";for(let[g,{isWall:x,isHanging:w,rotation:E}]of Object.entries(t.signs)){let A=this.worldRenderer.blockEntities[g];if(!A)continue;let[P,C,L]=g.split(","),M=this.signHeadsRenderer.renderSign(new ft(+P,+C,+L),E,x,w,t8.simplify(A));M&&b.add(M)}a.add(b),a.signsContainer=b}if(Object.keys(t.heads).length>0){let b=new ot;b.name="heads";for(let[g,{isWall:x,rotation:w}]of Object.entries(t.heads)){let E=this.worldRenderer.blockEntities[g];if(!E)continue;let[A,P,C]=g.split(","),L=this.signHeadsRenderer.renderHead(new ft(+A,+P,+C),w,x,t8.simplify(E));L&&b.add(L)}a.add(b),a.headsContainer=b}if(Object.keys(t.banners).length>0){let b=new ot;b.name="banners",a.bannersContainer=b,a.add(b);for(let[g,{isWall:x,rotation:w,blockName:E}]of Object.entries(t.banners)){let A=this.worldRenderer.blockEntities[g];if(!A)continue;let[P,C,L]=g.split(","),M=Yme(this.worldRenderer,E,t8.simplify(A));if(!M)continue;let T=Kme(new ft(+P,+C,+L),w,x,M),{x:F,y:Z,z:U}=T.position;this.worldRenderer.sceneOrigin.track(T),T.position.set(F,Z,U),b.add(T)}}}catch(b){console.error("ChunkMeshManager: Error adding signs, heads, or banners to section",b)}this.sectionObjects[e]=a,this.scene.add(a),a.matrixAutoUpdate=!1,this.worldRenderer.displayOptions?.inWorldRenderingConfig?.showChunkBorders&&this.updateBoxHelper(e,!0);let m=e.split(","),v=`${m[0]},${m[2]}`,y=!!this.worldRenderer.displayOptions?.inWorldRenderingConfig?._renderByChunks,_=!!this.worldRenderer.worldRendererConfig?.wasmMesher;if((y||_)&&!this.worldRenderer.finishedChunks[v]){a.visible=!1,a._waitingForChunkDisplay=!0;let b=this.waitingChunksToDisplay[v]??(this.waitingChunksToDisplay[v]=[]);b.includes(e)||b.push(e)}return a}finishChunkDisplay(e){if(!this.waitingChunksToDisplay[e]){this.tryRevealPending();return}if(this.isWasmGateActive()&&this.isBlockedByNearer(e,0)){this.pendingNearReveal.set(e,Date.now()),this.armNearRevealTimer(e),this.armExpectedGraceTimer(e);return}this.flushChunkDisplay(e),this.tryRevealPending()}flushChunkDisplay(e){let t=this.waitingChunksToDisplay[e];if(this.pendingNearReveal.delete(e),this.clearNearRevealTimer(e),this.clearExpectedGraceTimer(e),!!t){for(let n of t){let r=this.sectionObjects[n];r&&(r._waitingForChunkDisplay=!1,r.visible=!0)}delete this.waitingChunksToDisplay[e]}}tryRevealPending(){if(this.pendingNearReveal.size===0)return;let e=Date.now();for(let[t,n]of[...this.pendingNearReveal])this.isBlockedByNearer(t,e-n)||this.flushChunkDisplay(t)}onChunkRemovedFromGate(e){this.pendingNearReveal.delete(e),this.clearNearRevealTimer(e),this.clearExpectedGraceTimer(e),delete this.waitingChunksToDisplay[e],this.tryRevealPending()}isWasmGateActive(){return!!this.worldRenderer.worldRendererConfig?.wasmMesher}isBlockedByNearer(e,t){let n=this.worldRenderer.viewerChunkPosition;if(!n)return!1;let r=e.split(",");if(r.length!==2)return!1;let s=Number(r[0]),a=Number(r[1]),o=Math.floor(n.x/16),l=Math.floor(n.z/16),c=(s>>4)-o,u=(a>>4)-l,f=c*c+u*u;if(f===0)return!1;let m=this.worldRenderer.finishedChunks,v=this.worldRenderer.loadedChunks,y=this.worldRenderer.viewDistance;if(t<gu.EXPECTED_NEAR_GRACE_MS&&y>0){let b=y*y,g=Math.min(y,Math.ceil(Math.sqrt(Math.max(0,f-1))));for(let x=-g;x<=g;x++)for(let w=-g;w<=g;w++){let E=x*x+w*w;if(E>=f||E>b)continue;let A=o+x<<4,P=l+w<<4,C=`${A},${P}`;if(C!==e&&!m[C])return!0}return!1}for(let b in v){if(b===e||m[b])continue;let g=b.split(",");if(g.length!==2)continue;let x=(Number(g[0])>>4)-o,w=(Number(g[1])>>4)-l;if(x*x+w*w<f)return!0}return!1}armNearRevealTimer(e){if(this.nearRevealTimers.has(e))return;let t=setTimeout(()=>{this.nearRevealTimers.delete(e),this.pendingNearReveal.has(e)&&(console.warn(`[chunk-reveal] safety timeout for ${e} \u2014 a nearer pending column never finished, force-revealing`),this.flushChunkDisplay(e),this.tryRevealPending())},gu.NEAR_REVEAL_TIMEOUT_MS);this.nearRevealTimers.set(e,t)}clearNearRevealTimer(e){let t=this.nearRevealTimers.get(e);t&&(clearTimeout(t),this.nearRevealTimers.delete(e))}armExpectedGraceTimer(e){if(this.nearRevealGraceTimers.has(e))return;let t=setTimeout(()=>{this.nearRevealGraceTimers.delete(e),this.pendingNearReveal.has(e)&&this.tryRevealPending()},gu.EXPECTED_NEAR_GRACE_MS+50);this.nearRevealGraceTimers.set(e,t)}clearExpectedGraceTimer(e){let t=this.nearRevealGraceTimers.get(e);t&&(clearTimeout(t),this.nearRevealGraceTimers.delete(e))}cleanupSection(e){let t=this.sectionObjects[e];if(t){if(t._waitingForChunkDisplay){let n=e.split(","),r=`${n[0]},${n[2]}`,s=this.waitingChunksToDisplay[r];if(s){let a=s.indexOf(e);a!==-1&&s.splice(a,1),s.length===0&&delete this.waitingChunksToDisplay[r]}}if(t.bannersContainer&&(t.bannersContainer.traverse(n=>{n.bannerTexture&&Jme(n.bannerTexture)}),this.disposeContainer(t.bannersContainer)),this.globalBlockBuffer?.removeSection(e),this.unregisterShaderSectionRaycastBox(e),t.shaderMesh&&(pR(t.shaderMesh),t.shaderMesh=void 0),delete t.deferredShaderCubes,t.signsContainer&&this.disposeContainer(t.signsContainer),t.headsContainer&&this.disposeContainer(t.headsContainer),this.worldRenderer.sceneOrigin.removeAndUntrackAll(t),this.scene.remove(t),t.boxHelper){this.worldRenderer.sceneOrigin.removeAndUntrack(t.boxHelper),this.scene.remove(t.boxHelper),t.boxHelper.geometry.dispose();let n=t.boxHelper.material;if(Array.isArray(n))for(let r of n)r.dispose();else n.dispose();t.boxHelper=void 0}delete this.sectionObjects[e]}}releasePooledMesh(e){let t=this.activeSections.get(e);t&&(t.mesh.visible=!1,t.inUse=!1,t.sectionKey=void 0,t.lastUsedTime=0,this.clearGeometry(t.mesh.geometry),this.activeSections.delete(e),this.cleanupExcessMeshes())}releaseSection(e){this.cleanupSection(e);let t=this.activeSections.get(e);return t?(t.mesh.visible=!1,t.inUse=!1,t.sectionKey=void 0,t.lastUsedTime=0,this.clearGeometry(t.mesh.geometry),this.activeSections.delete(e),this.cleanupExcessMeshes(),!0):!1}getSectionObject(e){return this.sectionObjects[e]}updateBoxHelper(e,t,n=this.chunkBoxMaterial){let r=this.sectionObjects[e];if(r?.mesh)if(t){if(!r.boxHelper){let s=new je(new nn(16,16,16),n),a=new va(s,16776960);a.name="helper";let o=r.worldX??0,l=r.worldY??0,c=r.worldZ??0;this.worldRenderer.sceneOrigin.track(a,{updateMatrix:!0}),a.position.set(o,l,c),a.updateMatrix(),this.scene.add(a),r.boxHelper=a}r.boxHelper.visible=!0}else r.boxHelper&&(r.boxHelper.visible=!1)}updateAllBoxHelpers(e){for(let t of Object.keys(this.sectionObjects))this.updateBoxHelper(t,e)}cleanSignChunkTextures(e,t){this.signHeadsRenderer.cleanChunkTextures(e,t)}getSectionMesh(e){return this.activeSections.get(e)?.mesh}hasSection(e){return this.activeSections.has(e)}updateViewDistance(e){let t=(e*2+1)**2,n=this.worldHeight/16,r=5;if(this.minPoolSize=Math.floor(t*r),this.maxPoolSize=Math.floor(t*n)+1,this.poolSize??=this.minPoolSize,this.minPoolSize>this.poolSize){let s=Math.min(this.minPoolSize,this.maxPoolSize);this.expandPool(s)}console.log(`ChunkMeshManager: Updated view max distance to ${e}, pool: ${this.poolSize}/${this.maxPoolSize}, optimal: ${this.minPoolSize}`)}getStats(){let e=this.meshPool.filter(r=>!r.inUse).length,t=this.hits+this.misses>0?(this.hits/(this.hits+this.misses)*100).toFixed(1):"0",n=this.getEstimatedMemoryUsage();return{poolSize:this.poolSize,activeCount:this.activeSections.size,freeCount:e,hitRate:`${t}%`,hits:this.hits,misses:this.misses,memoryUsage:n}}getTotalTiles(){return Object.values(this.sectionObjects).reduce((e,t)=>e+(t.tilesCount||0),0)}getTotalBlocks(){return Object.values(this.sectionObjects).reduce((e,t)=>e+(t.blocksCount||0),0)}getEstimatedMemoryUsage(){let e=0,t=0,n=0,r=0,s=0,a=0,o=0,l=this.globalBlockBuffer?.mesh.geometry;if(l)for(let u of["a_w0","a_w1","a_w2","a_w3"]){let f=l.getAttribute(u);if(f){let m=f.array.byteLength;o+=m,e+=m}}for(let u of Object.values(this.sectionObjects)){let f=u.shaderMesh?.geometry;if(f)for(let m of["a_w0","a_w1","a_w2","a_w3"]){let v=f.getAttribute(m);if(v){let y=v.array.byteLength;o+=y,e+=y}}}for(let u of this.meshPool)if(u.inUse&&u.mesh.geometry){let{geometry:f}=u.mesh,m=f.getAttribute("position");if(m){let b=m.array.byteLength;t+=b,e+=b}let v=f.getAttribute("normal");if(v){let b=v.array.byteLength;n+=b,e+=b}let y=f.getAttribute("color");if(y){let b=y.array.byteLength;r+=b,e+=b}let _=f.getAttribute("uv");if(_){let b=_.array.byteLength;s+=b,e+=b}if(f.index){let b=f.index.array.byteLength;a+=b,e+=b}}return{total:`${(e/(1024*1024)).toFixed(2)} MB`,breakdown:{position:`${(t/(1024*1024)).toFixed(2)} MB`,normal:`${(n/(1024*1024)).toFixed(2)} MB`,color:`${(r/(1024*1024)).toFixed(2)} MB`,uv:`${(s/(1024*1024)).toFixed(2)} MB`,index:`${(a/(1024*1024)).toFixed(2)} MB`,shaderInstances:`${(o/(1024*1024)).toFixed(2)} MB`}}}dispose(){let e=[...this.activeSections.keys()];for(let t of e)this.releaseSection(t);this.signHeadsRenderer.dispose();for(let t of this.meshPool)t.mesh.geometry.dispose();this.meshPool.length=0,this.activeSections.clear(),this.chunkBoxMaterial.dispose(),this.shaderSectionRaycastBoxes.clear(),this.globalBlockBuffer?.dispose(),this.globalBlockBuffer=null,this.cubeShaderMaterial?.dispose(),this.cubeShaderMaterial=null,this.pendingNearReveal.clear();for(let t of this.nearRevealTimers.values())clearTimeout(t);this.nearRevealTimers.clear();for(let t of this.nearRevealGraceTimers.values())clearTimeout(t);this.nearRevealGraceTimers.clear()}acquireMesh(){if(this.bypassPooling){let t={mesh:new je(new it,this.material),inUse:!0,lastUsedTime:performance.now()};return this.meshPool.push(t),this.poolSize++,t}for(let t of this.meshPool)if(!t.inUse)return t.inUse=!0,t.lastUsedTime=performance.now(),this.hits++,t;this.misses++;let e=Math.min(this.poolSize+16,this.maxPoolSize);e<=this.meshPool.length&&(e=this.meshPool.length+8,this.maxPoolSize=e,console.warn(`ChunkMeshManager: Pool exhausted (${this.poolSize}/${this.maxPoolSize}). Emergency expansion to ${e}`)),this.expandPool(e);for(let t=this.meshPool.length-1;t>=0;t--){let n=this.meshPool[t];if(!n.inUse)return n.inUse=!0,n.lastUsedTime=performance.now(),n}throw new Error("ChunkMeshManager: Failed to acquire mesh after pool expansion")}expandPool(e){let t=this.meshPool.length;this.poolSize=e;for(let n=t;n<e;n++){let r=new it,s=new je(r,this.material);s.visible=!1,s.matrixAutoUpdate=!1,s.name="pooled-section-mesh";let a={mesh:s,inUse:!1,lastUsedTime:0};this.meshPool.push(a)}}updateGeometryAttribute(e,t,n,r){let s=e.getAttribute(t);s&&s.count===n.length/r?(s.array.set(n),s.needsUpdate=!0):e.setAttribute(t,new dt(n,r))}clearGeometry(e){let t=["position","normal","color","uv"];for(let n of t)e.hasAttribute(n)&&e.deleteAttribute(n);e.index&&e.setIndex(null),e.boundingBox=null,e.boundingSphere=null}cleanupExcessMeshes(){if(this.poolSize>this.maxPoolSize){let e=this.meshPool.filter(t=>!t.inUse).length;if(e>0){let t=Math.min(this.poolSize-this.maxPoolSize,e);for(let n=0;n<t;n++){let r=this.meshPool.findIndex(s=>!s.inUse);r!==-1&&(this.meshPool[r].mesh.geometry.dispose(),this.meshPool.splice(r,1),this.poolSize--)}}}}disposeContainer(e){Hn(e,!0)}recordRenderTime(e){this.renderTimes.push(e),this.renderTimes.length>this.maxRenderTimeSamples&&this.renderTimes.shift();let t=performance.now();t-this.lastPerformanceCheck>this.performanceCheckInterval&&(this.checkPerformance(),this.lastPerformanceCheck=t)}getEffectiveRenderDistance(){return this.performanceOverrideDistance||this.worldRenderer.viewDistance}resetPerformanceOverride(){this.performanceOverrideDistance=void 0,this.renderTimes.length=0,console.log("ChunkMeshManager: Performance override reset")}getAverageRenderTime(){return this.renderTimes.length===0?0:this.renderTimes.reduce((e,t)=>e+t,0)/this.renderTimes.length}checkPerformance(){if(this.renderTimes.length<this.maxRenderTimeSamples)return;let e=this.getAverageRenderTime(),t=16.67,n=t*1.5;if(e>n){let r=this.worldRenderer.viewDistance,s=Math.max(1,Math.floor(r*.8));(!this.performanceOverrideDistance||s<this.performanceOverrideDistance)&&(this.performanceOverrideDistance=s,console.warn(`ChunkMeshManager: Performance degraded (${e.toFixed(2)}ms avg). Reducing effective render distance to ${s}`))}else if(this.performanceOverrideDistance&&e<t*1.1){let r=this.worldRenderer.viewDistance,s=Math.min(r,this.performanceOverrideDistance+1);s!==this.performanceOverrideDistance&&(this.performanceOverrideDistance=s>=r?void 0:s,console.log(`ChunkMeshManager: Performance improved. Restoring render distance to ${s}`))}}updateSectionsVisibility(){let e=this.worldRenderer.cameraSectionPos;for(let[t,n]of Object.entries(this.sectionObjects)){if(n._waitingForChunkDisplay){n.visible=!1;continue}if(!this.performanceOverrideDistance){n.visible=!0;continue}let[r,s,a]=t.split(",").map(Number),o={x:r/16,y:s/16,z:a/16},l=o.x-e.x,c=o.z-e.z,u=Math.floor(Math.hypot(l,c));n.visible=u<=this.performanceOverrideDistance}}};Cn(gu,"NEAR_REVEAL_TIMEOUT_MS",5e3),Cn(gu,"EXPECTED_NEAR_GRACE_MS",1500);var em=gu,bR=class{constructor(e){this.worldRendererThree=e}chunkTextures=new Map;dispose(){for(let[,e]of this.chunkTextures)for(let t of Object.keys(e))e[t].dispose();this.chunkTextures.clear()}renderHead(e,t,n,r){let s;if(r.SkullOwner?s=r.SkullOwner.Properties?.textures?.[0]?.Value:s=r.profile?.properties?.find(a=>a.name==="textures")?.value,!!s)try{let o=JSON.parse(Buffer.from(s,"base64").toString()).textures?.SKIN?.url,{skinTexturesProxy:l}=this.worldRendererThree.worldRendererConfig;l&&(o=o?.replace("http://textures.minecraft.net/",l).replace("https://textures.minecraft.net/",l));let c=kl(this.worldRendererThree,o,Cl.head),u=new ot;return n&&c.position.set(0,.3125,.3125),c.position.y-=23/16,u.add(c),this.worldRendererThree.sceneOrigin.track(u),u.position.set(e.x+.5,e.y+.045,e.z+.5),u.rotation.set(0,-yt.degToRad(t*(n?90:45/2)),0),u.scale.set(.8,.8,.8),u}catch(a){console.error("Error decoding player texture:",a)}}renderSign(e,t,n,r,s){let a=this.getSignTexture(e,s,r);if(!a)return;let o=new je(new vn(1,1),new st({map:a,transparent:!0}));o.renderOrder=999;let l=7/16,c=r?1.3:1;o.scale.set(1*c,l*c,1*c);let u=(r?2:1.5)/16,f=.25/16;n&&!r?o.position.set(0,0,-.5+u+f+1e-4):o.position.set(0,0,u/2+1e-4);let m=new ot;m.rotation.set(0,-yt.degToRad(t*(n?90:45/2)),0),m.add(o);let v=(r?10:8)/16,y=(r?0:n?4.333:9.333)/16,_=v/2+y;return this.worldRendererThree.sceneOrigin.track(m),m.position.set(e.x+.5,e.y+_,e.z+.5),m}getSignTexture(e,t,n,r=!1){let s=d1(e),a=this.chunkTextures.get(`${s[0]},${s[1]}`);a||(a={},this.chunkTextures.set(`${s[0]},${s[1]}`,a));let o=`${e.x},${e.y},${e.z}`;if(a[o])return a[o];let l=(0,Zme.default)(this.worldRendererThree.version),c=w7(t,n,l);if(!c)return;let u=new Gt(c);return u.magFilter=Je,u.minFilter=Je,u.needsUpdate=!0,a[o]=u,u}cleanChunkTextures(e,t){let n=`${Math.floor(e/16)},${Math.floor(t/16)}`,r=this.chunkTextures.get(n);if(r)for(let s of Object.keys(r))r[s].dispose(),delete r[s]}};h();p();d();h();p();d();bt();var n8={},Qme=!1;function Fqe(){if(Qme)return;let i=globalThis.loadedData?.tints;if(i){for(let e of Object.keys(i))n8[e]=zqe(i[e]);Qme=!0}}function zqe(i){let e={},t=e3e(i.default??16777215);if(i.data)for(let n of i.data){let r=e3e(n.color);for(let s of n.keys)e[s]=r}return new Proxy(e,{get(n,r){return n[r]??t}})}function e3e(i){return[(i>>16&255)/255,(i>>8&255)/255,(i&255)/255]}function t3e(i,e){return Fqe(),i==="grass_block"?[1,1,1]:i==="redstone_wire"?[1,1,1]:i==="birch_leaves"||i==="spruce_leaves"||i==="lily_pad"?n8.constant?.[i]??[1,1,1]:i.includes("leaves")||i==="vine"?n8.foliage?.[e]??[1,1,1]:["short_grass","tall_grass","fern","large_fern","sugar_cane","grass"].includes(i)?n8.grass?.[e]??[1,1,1]:[1,1,1]}var Hqe=512,_R=1/20,wR=class{constructor(e){this.worldRenderer=e}particles=[];sharedMaterial;enabled=!1;tickAccumulator=0;nextParticleIndex=0;enable(){this.enabled||(this.enabled=!0,this.ensureMaterial())}disable(){this.enabled&&(this.enabled=!1)}dispose(){for(let e of this.particles)e.active&&this.worldRenderer.sceneOrigin.removeAndUntrack(e.mesh),e.mesh.geometry.dispose();this.particles=[],this.sharedMaterial?.dispose(),this.sharedMaterial=void 0,this.nextParticleIndex=0}render=e=>{if(!this.enabled)return;for(this.tickAccumulator+=e;this.tickAccumulator>=_R;)this.tickAccumulator-=_R,this.tickPhysics();let t=this.tickAccumulator/_R;this.updateVisuals(t)};spawnBlockBreakParticles(e,t,n,r,s,a="plains"){if(!this.enabled)return;let o=this.resolveBlockTexture(r);if(!o)return;let l=t3e(r,a);for(let c=0;c<4;c++)for(let u=0;u<4;u++)for(let f=0;f<4;f++){let m=e+(c+.5)/4,v=t+(u+.5)/4,y=n+(f+.5)/4,_=m-e-.5,b=v-t-.5,g=y-n-.5;_+=(Math.random()*2-1)*.4,b+=(Math.random()*2-1)*.4,g+=(Math.random()*2-1)*.4;let x=(Math.random()+Math.random()+1)*.15,w=Math.sqrt(_*_+b*b+g*g),E=_/w*x*.4,A=b/w*x*.4+.1,P=g/w*x*.4,C=Math.floor(4/(Math.random()*.9+.1));this.createParticle(m,v,y,E,A,P,C,o,s,e,n,1,l)}}tickPhysics(){for(let e of this.particles){if(!e.active)continue;if(e.prevX=e.x,e.prevY=e.y,e.prevZ=e.z,e.age++,e.age>=e.maxAge){this.deactivateParticle(e);continue}e.yd-=.04,e.x+=e.xd,e.y+=e.yd,e.z+=e.zd;let t=this.getFloorY(e);e.y<=t?(e.y=t,e.yd=0,e.onGround=!0):e.onGround=!1,e.xd*=.98,e.yd*=.98,e.zd*=.98,e.onGround&&(e.xd*=.7,e.zd*=.7)}}updateVisuals(e){let t=this.worldRenderer.camera.position;for(let n of this.particles){if(!n.active)continue;let r=n.prevX+(n.x-n.prevX)*e,s=n.prevY+(n.y-n.prevY)*e,a=n.prevZ+(n.z-n.prevZ)*e;n.mesh.position.set(r,s,a),n.mesh.lookAt(t.x,t.y,t.z)}}spawnCrackParticle(e,t,n,r,s,a,o="plains"){if(!this.enabled)return;let l=this.resolveBlockTexture(s);if(!l)return;let c=t3e(s,o),u=e+Math.random()*.8+.1,f=t+Math.random()*.8+.1,m=n+Math.random()*.8+.1;switch(r){case 0:f=t-.1;break;case 1:f=t+1+.1;break;case 2:m=n-.1;break;case 3:m=n+1+.1;break;case 4:u=e-.1;break;case 5:u=e+1+.1;break}let v=(Math.random()*2-1)*.4*.2,y=(Math.random()*2-1)*.4*.2+.1*.2,_=(Math.random()*2-1)*.4*.2,b=Math.floor(4/(Math.random()*.9+.1));this.createParticle(u,f,m,v,y,_,b,l,a,e,n,.6,c)}createParticle(e,t,n,r,s,a,o,l,c,u,f,m=1,v=[1,1,1]){this.ensureMaterial();let y=this.findInactiveParticle();y||(this.particles.length<Hqe?y=this.allocateParticle():y=this.recycleOldest());let _=Math.floor(Math.random()*4),b=Math.floor(Math.random()*4),g=l.u+_/4*l.su,x=l.v+b/4*l.sv,w=l.su/4,E=l.sv/4;this.setGeometryUVs(y.mesh.geometry,g,x,w,E),y.active=!0,y.x=e,y.y=t,y.z=n,y.prevX=e,y.prevY=t,y.prevZ=n,y.xd=r,y.yd=s,y.zd=a,y.age=0,y.maxAge=o,y.onGround=!1,y.floorMap=c,y.blockX=Math.floor(u),y.blockZ=Math.floor(f);let A=.1*(.5+Math.random()*.5)*2*m;y.mesh.scale.set(A,A,A),y.mesh.position.set(e,t,n),y.mesh.visible=!0;let P=.6*v[0],C=.6*v[1],L=.6*v[2],M=new Float32Array([P,C,L,P,C,L,P,C,L,P,C,L]),T=y.mesh.geometry.getAttribute("color");T?(T.set(M),T.needsUpdate=!0):y.mesh.geometry.setAttribute("color",new qe(M,3)),this.worldRenderer.sceneOrigin.addAndTrack(y.mesh)}allocateParticle(){let e=new vn(1,1),t=new je(e,this.sharedMaterial);t.visible=!1;let n={mesh:t,active:!1,x:0,y:0,z:0,prevX:0,prevY:0,prevZ:0,xd:0,yd:0,zd:0,age:0,maxAge:0,onGround:!1,floorMap:[],blockX:0,blockZ:0};return this.particles.push(n),n}findInactiveParticle(){for(let e=0;e<this.particles.length;e++){let t=(this.nextParticleIndex+e)%this.particles.length;if(!this.particles[t].active)return this.nextParticleIndex=(t+1)%this.particles.length,this.particles[t]}}recycleOldest(){let e=this.particles[0];for(let t of this.particles)t.age>e.age&&(e=t);return this.deactivateParticle(e),e}deactivateParticle(e){e.active&&(e.active=!1,e.mesh.visible=!1,this.worldRenderer.sceneOrigin.removeAndUntrack(e.mesh))}getFloorY(e){let t=Math.floor(e.x)-e.blockX,n=Math.floor(e.z)-e.blockZ;return t=Math.max(-2,Math.min(2,t)),n=Math.max(-2,Math.min(2,n)),e.floorMap[(n+2)*5+(t+2)]}resolveBlockTexture(e){let t=this.worldRenderer.resourcesManager.currentResources;if(!t)return null;let n=t.blocksAtlasJson,r=n.textures;if(r[e])return this.extractUV(r[e],n);for(let s of["_side","_top","_front","_0",""]){let a=e+s;if(r[a])return this.extractUV(r[a],n)}for(let s of Object.keys(r))if(s.startsWith(e))return this.extractUV(r[s],n);return null}extractUV(e,t){return{u:e.u,v:e.v,su:e.su??t.suSv,sv:e.sv??t.suSv}}setGeometryUVs(e,t,n,r,s){let a=e.getAttribute("uv");a.setXY(0,t,n),a.setXY(1,t+r,n),a.setXY(2,t,n+s),a.setXY(3,t+r,n+s),a.needsUpdate=!0}ensureMaterial(){if(this.sharedMaterial)return;let e=this.worldRenderer.material.map;e&&(this.sharedMaterial=new st({map:e,vertexColors:!0,transparent:!0,alphaTest:.1}))}},n3e={id:"blockBreakParticles",controller:wR,enabledDefault:!0,cannotBeDisabled:!0,requiresHeightmap:!1};h();p();d();var xR=class{constructor(e){this.worldRenderer=e}enabled=!1;lastBobWalkDist=0;lastBobTickTime=0;enable(){this.enabled=!0}disable(){this.enabled=!1,this.worldRenderer.cameraShake.setCameraBobInput(null);let{perspective:e}=this.worldRenderer.playerStateReactive;e==="first_person"&&this.worldRenderer.camera.position.set(0,0,0)}render=()=>{if(!this.enabled)return;let e=this.worldRenderer.displayOptions.inWorldRenderingConfig,{perspective:t}=this.worldRenderer.playerStateReactive;if(e.viewBobbing&&t==="first_person"&&!this.worldRenderer.playerStateUtils.isSpectator()){this.worldRenderer.playerStateReactive.walkDist!==this.lastBobWalkDist&&(this.lastBobTickTime=performance.now(),this.lastBobWalkDist=this.worldRenderer.playerStateReactive.walkDist);let r=Math.min((performance.now()-this.lastBobTickTime)/50,1);this.worldRenderer.cameraShake.setCameraBobInput({walkDist:this.worldRenderer.playerStateReactive.walkDist,prevWalkDist:this.worldRenderer.playerStateReactive.prevWalkDist,bob:this.worldRenderer.playerStateReactive.bob,prevBob:this.worldRenderer.playerStateReactive.prevBob,partialTick:r})}else this.worldRenderer.cameraShake.setCameraBobInput(null)};dispose(){this.disable()}},r3e={id:"cameraBobbing",controller:xR,enabledDefault:!0,cannotBeDisabled:!0};h();p();d();bt();var ER=2e3,i3e=32,s3e=32,r8=12,a3e=24,i8=1.2,qqe=-5;var SR=class{constructor(e){this.worldRenderer=e}instancedMesh;geometry;material;particles=[];enabled=!1;dummy=new ht;tempPosition=new K;tempQuaternion=new Ut;tempScale=new K;enable(){this.enabled||(this.enabled=!0,this.instancedMesh?this.instancedMesh.visible=!0:this.createRain())}disable(){this.enabled&&(this.enabled=!1,this.instancedMesh&&(this.instancedMesh.visible=!1))}autoEnableCheck(){return this.worldRenderer.worldRendererConfig.isRaining===!0}render=e=>{if(!this.enabled||!this.instancedMesh||!this.material)return;this.syncMaterialToSceneFog();let t=this.worldRenderer.getCameraPosition();this.instancedMesh.position.set(0,0,0);let n=this.worldRenderer.reactiveState.world.heightmaps,{dummy:r,tempPosition:s,tempQuaternion:a,tempScale:o}=this,l=NaN,c=NaN,u;for(let f=0;f<ER;f++){let m=this.particles[f];this.instancedMesh.getMatrixAt(f,r),r.decompose(s,a,o),s.addScaledVector(m.velocity,e);let v=s.y,y=Math.sqrt(s.x*s.x+s.z*s.z),_=t.x+s.x,b=t.y+s.y,g=t.z+s.z,x=Math.floor(_/16),w=Math.floor(g/16);(x!==l||w!==c)&&(u=n.get(`${x},${w}`),l=x,c=w);let E=(Math.floor(_)%16+16)%16,A=(Math.floor(g)%16+16)%16,P=u?.[A*16+E];if(y>i3e||P!==void 0&&P!==-32768&&b<=P+1+m.despawnOffset||v<qqe){this.respawnParticle(s);let L=r8+Math.random()*(a3e-r8);m.velocity.set((Math.random()-.5)*i8,-L,(Math.random()-.5)*i8),m.despawnOffset=Math.random()*.5}r.compose(s,a,o),this.instancedMesh.setMatrixAt(f,r)}this.instancedMesh.instanceMatrix.needsUpdate=!0};dispose(){this.instancedMesh&&this.worldRenderer.scene.remove(this.instancedMesh),this.geometry?.dispose(),this.material?.dispose(),this.instancedMesh=void 0,this.geometry=void 0,this.material=void 0,this.particles=[]}syncMaterialToSceneFog(){if(!this.material)return;let e=this.worldRenderer.scene.fog;e instanceof so||e instanceof io?this.material.color.copy(e.color):this.material.color.set(13426158),this.material.fog=!0}createRain(){this.geometry=new nn(.03,.3,.03),this.material=new st({color:13426158,transparent:!0,opacity:.35,depthWrite:!1,fog:!0}),this.instancedMesh=new T0(this.geometry,this.material,ER),this.instancedMesh.name="rain-particles",this.instancedMesh.frustumCulled=!1,this.syncMaterialToSceneFog();let e=new ht,t=new K;for(let n=0;n<ER;n++){this.respawnParticle(t),t.y=Math.random()*s3e,e.setPosition(t),this.instancedMesh.setMatrixAt(n,e);let r=r8+Math.random()*(a3e-r8);this.particles.push({velocity:new K((Math.random()-.5)*i8,-r,(Math.random()-.5)*i8),age:0,despawnOffset:Math.random()*.5})}this.instancedMesh.instanceMatrix.needsUpdate=!0,this.worldRenderer.scene.add(this.instancedMesh)}respawnParticle(e){let t=Math.random()*Math.PI*2,n=Math.random()*i3e;e.set(Math.cos(t)*n,s3e,Math.sin(t)*n)}},o3e={id:"rain",controller:SR,enabledDefault:!1,requiresHeightmap:!0};h();p();d();bt();var l3e=new Fe(13/255,234/255,238/255),Gqe=9;var Wqe=350,jqe=650;var $qe=120,Xqe=280,AR=class{constructor(e){this.worldRenderer=e;this.wireframeMaterial=new fn({color:l3e,transparent:!0,opacity:1,blending:Li,depthWrite:!1}),this.wireframeGlowMaterial=new fn({color:l3e,transparent:!0,opacity:.55,blending:Li,depthWrite:!1})}pendingGeometries=new Map;revealingSections=new Map;finishedChunkCount=0;revealTriggered=!1;revealStartTime=0;enabled=!1;onWorldSwitchedCb=null;patched=!1;initialWaveDone=!1;initialRevealWaveSettled=!1;wireframeMaterial;wireframeGlowMaterial;pulseTime=0;revealedChunks=new Set;originalFinishChunk=null;originalDestroy=null;originalSceneAdd=null;originalHandleWorkerMessage=null;isFuturisticRevealConfigured(){return this.worldRenderer.worldRendererConfig.futuristicReveal===!0}isInInitialRevealCampaign(){return this.enabled&&!this.initialRevealWaveSettled}autoEnableCheck(){return this.isFuturisticRevealConfigured()}enable(){if(this.isFuturisticRevealConfigured()&&!(this.enabled&&this.patched)){if(this.enabled&&!this.patched){this.patchWorldRenderer();return}this.enabled=!0,this.patchWorldRenderer()}}disable(){this.enabled&&(this.enabled=!1,this.unpatchWorldRenderer(),this.reset())}toggle(){return this.enabled?this.disable():this.enable(),this.enabled}render=e=>{this.enabled&&this.update(e*1e3)};dispose(){this.disable(),this.wireframeMaterial.dispose(),this.wireframeGlowMaterial.dispose()}patchWorldRenderer(){if(this.patched)return;this.patched=!0;let e=this.worldRenderer;this.onWorldSwitchedCb=()=>this.reset(),e.onWorldSwitched.push(this.onWorldSwitchedCb),this.originalFinishChunk=e.finishChunk.bind(e),e.finishChunk=t=>{this.originalFinishChunk(t),this.onChunkFinished(t)},this.originalDestroy=e.destroy.bind(e),e.destroy=()=>{this.dispose(),this.originalDestroy()},this.originalHandleWorkerMessage=e.handleWorkerMessage.bind(e),e.handleWorkerMessage=t=>{this.originalHandleWorkerMessage(t),this.enabled&&t?.type==="geometry"&&Promise.resolve().then(()=>{try{this.registerSection(t.key,t.geometry)}catch(n){console.error("[SciFiReveal] registerSection failed",n)}})},this.originalSceneAdd=e.scene.add.bind(e.scene),e.scene.add=(...t)=>{let n=this.originalSceneAdd(...t);for(let r of t)this.checkAndPatchMesh(r);return n}}unpatchWorldRenderer(){let e=this.worldRenderer;if(this.originalFinishChunk&&(e.finishChunk=this.originalFinishChunk,this.originalFinishChunk=null),this.originalDestroy&&(e.destroy=this.originalDestroy,this.originalDestroy=null),this.originalHandleWorkerMessage&&(e.handleWorkerMessage=this.originalHandleWorkerMessage,this.originalHandleWorkerMessage=null),this.originalSceneAdd&&(e.scene.add=this.originalSceneAdd,this.originalSceneAdd=null),this.onWorldSwitchedCb){let t=e.onWorldSwitched.indexOf(this.onWorldSwitchedCb);t!==-1&&e.onWorldSwitched.splice(t,1),this.onWorldSwitchedCb=null}this.patched=!1}checkAndPatchMesh(e){if(e instanceof je&&(e.name==="mesh"||e.name==="shaderMesh")){let t=this.findSectionKeyForMesh(e);t&&this.shouldUseRevealEffect(t)&&(e.visible=!1,e.hiddenByReveal=!0)}for(let t of e.children)this.checkAndPatchMesh(t)}findSectionKeyForMesh(e){let t=e;for(;t;){let{sectionKey:v}=t;if(v&&this.worldRenderer.chunkMeshManager.sectionObjects[v]===t)return v;t=t.parent}let n=this.worldRenderer.sceneOrigin.getWorldPosition(e),r=n?.x??this.worldRenderer.sceneOrigin.toWorldX(e.position.x),s=n?.y??this.worldRenderer.sceneOrigin.toWorldY(e.position.y),a=n?.z??this.worldRenderer.sceneOrigin.toWorldZ(e.position.z),o=16,l=this.worldRenderer.getSectionHeight(),c=Math.floor(r/o)*o,u=Math.floor(s/l)*l,f=Math.floor(a/o)*o,m=`${c},${u},${f}`;return this.worldRenderer.chunkMeshManager.sectionObjects[m]?m:null}get scene(){return this.worldRenderer.realScene}getCameraPosition(){return this.worldRenderer.getCameraPosition()}sectionHasRevealContent(e){return(e.wireframePositions?.length??0)>0||(e.positions?.length??0)>0?!0:(e.shaderCubes?.count??0)>0}getSectionRenderMeshes(e){let t=this.worldRenderer.chunkMeshManager.sectionObjects[e];if(!t)return[];let n=[];for(let r of["mesh","shaderMesh"]){let s=t.children.find(a=>a.name===r);s instanceof je&&n.push(s)}return n}hideSectionRenderMeshes(e){let t=this.getSectionRenderMeshes(e);for(let n of t)n.visible=!1,n.hiddenByReveal=!0;return t}setMeshFadeOpacity(e,t){if(e.name==="shaderMesh"){e.visible=t>.001;return}let n=e.material;if(!Array.isArray(n))if(n.originalMaterial)n.opacity=t,n.transparent=!0,n.needsUpdate=!0;else{n.originalMaterial=n;let r=n.clone();r.transparent=!0,r.opacity=t,r.needsUpdate=!0,e.material=r}}restoreMeshMaterial(e){let t=e.originalMaterial;if(!t)return;let n=e.material;e.material=t,n!==t&&n.dispose(),delete e.originalMaterial}onChunkFinished(e){this.finishedChunkCount++,!this.revealTriggered&&this.finishedChunkCount>=Gqe&&this.triggerReveal()}registerSection(e,t){if(!(this.revealedChunks.has(e)||this.revealingSections.has(e))){if(this.revealTriggered&&this.initialWaveDone){this.revealedChunks.add(e);return}this.revealTriggered?this.startSectionReveal(e,t):this.pendingGeometries.set(e,t)}}shouldUseRevealEffect(e){return!this.enabled||this.revealTriggered&&this.initialWaveDone?!1:!this.revealedChunks.has(e)&&!this.revealingSections.has(e)}triggerReveal(){this.revealTriggered=!0,this.initialWaveDone=!0,this.revealStartTime=performance.now();let e=this.getCameraPosition(),t=[...this.pendingGeometries.entries()];this.pendingGeometries.clear();let n=t.map(([s,a])=>{let o=Math.hypot(a.sx-e.x,a.sy-e.y,a.sz-e.z);return{key:s,geometry:a,distance:o}}).sort((s,a)=>s.distance-a.distance),r=n.at(-1)?.distance||1;for(let{key:s,geometry:a,distance:o}of n){let l=o/r*1500;setTimeout(()=>{!this.revealedChunks.has(s)&&!this.revealingSections.has(s)&&this.startSectionReveal(s,a)},l)}}startSectionReveal(e,t){if(!this.sectionHasRevealContent(t)||this.revealingSections.has(e)||this.revealedChunks.has(e))return;let n=this.createWireframeGeometry(t),r=this.worldRenderer.chunkMeshManager.globalBlockBuffer,s=r?.hasSection(e)?r.takeSectionData(e):void 0,a=this.hideSectionRenderMeshes(e),o=new In(n,this.wireframeMaterial.clone());this.worldRenderer.sceneOrigin.track(o),o.position.set(t.sx,t.sy,t.sz),o.name="scifi-wireframe",o.renderOrder=1e3;let l=new In(n.clone(),this.wireframeGlowMaterial.clone());this.worldRenderer.sceneOrigin.track(l),l.position.set(t.sx,t.sy,t.sz),l.scale.set(1.02,1.02,1.02),l.name="scifi-glow",l.renderOrder=999;let c=new ot;c.add(o),c.add(l),c.name="scifi-reveal-group",c.sectionKey=e,this.scene.add(c);let u=this.initialWaveDone?$qe:Wqe,f=this.initialWaveDone?Xqe:jqe,m={key:e,wireframeGroup:c,revealStartTime:performance.now(),phase:"wireframe",renderMeshRefs:a,globalShaderRestore:s,wireframeMs:u,revealMs:f};setTimeout(()=>{for(let v of this.getSectionRenderMeshes(e))v.hiddenByReveal||this.hideSectionRenderMeshes(e)},0),this.revealingSections.set(e,m)}createSectionBoundsWireframe(){let n=[[-8,-8,-8],[8,-8,-8],[-8,8,-8],[8,8,-8],[-8,-8,8],[8,-8,8],[-8,8,8],[8,8,8]],r=[[0,1],[1,3],[3,2],[2,0],[4,5],[5,7],[7,6],[6,4],[0,4],[1,5],[2,6],[3,7]],s=[];for(let[o,l]of r)s.push(...n[o],...n[l]);let a=new it;return a.setAttribute("position",new qe(s,3)),a}createWireframeGeometry(e){if(e.wireframePositions&&e.wireframePositions.length>0){let o=new it;return o.setAttribute("position",new qe(e.wireframePositions,3)),o}let t=e.positions,n=e.indices;if(!t?.length||!n?.length)return this.createSectionBoundsWireframe();let r=[],s=new Set;for(let o=0;o<n.length;o+=3){let l=n[o],c=n[o+1],u=n[o+2];this.addEdge(t,l,c,r,s),this.addEdge(t,c,u,r,s),this.addEdge(t,u,l,r,s)}let a=new it;return a.setAttribute("position",new qe(r,3)),a}addEdge(e,t,n,r,s){let a=Math.min(t,n),o=Math.max(t,n),l=`${a}-${o}`;s.has(l)||(s.add(l),r.push(e[t*3],e[t*3+1],e[t*3+2],e[n*3],e[n*3+1],e[n*3+2]))}update(e){if(!this.enabled||this.revealingSections.size===0)return;this.pulseTime+=e*.001;let t=performance.now(),n=.6+.4*Math.sin(this.pulseTime*4),r=[];for(let[s,a]of this.revealingSections){let o=t-a.revealStartTime;if(a.phase==="wireframe"){let l=a.wireframeGroup.children[0],c=a.wireframeGroup.children[1];if(l?.material){let u=l.material;u.opacity=n;let f=.85+.15*Math.sin(this.pulseTime*6+o*.002);u.color.setRGB(13/255*f,234/255*f,238/255*f)}if(c?.material){let u=c.material;u.opacity=n*.4}if(o>a.wireframeMs){a.phase="transitioning",a.renderMeshRefs=this.getSectionRenderMeshes(s);for(let u of a.renderMeshRefs)u.visible=!0,this.setMeshFadeOpacity(u,0)}}else if(a.phase==="transitioning"){let l=o-a.wireframeMs,c=Math.min(1,l/a.revealMs),u=1-(1-c)**3,f=a.wireframeGroup.children[0],m=a.wireframeGroup.children[1];if(f?.material){let v=f.material;v.opacity=1-u}if(m?.material){let v=m.material;v.opacity=(1-u)*.55}for(let v of a.renderMeshRefs)this.setMeshFadeOpacity(v,u);c>=1&&(a.phase="complete",r.push(a))}}for(let s of r)this.completeReveal(s)}completeReveal(e){this.revealingSections.delete(e.key),this.revealedChunks.add(e.key),this.revealTriggered&&this.revealingSections.size===0&&(this.initialRevealWaveSettled=!0);for(let t of e.renderMeshRefs)this.restoreMeshMaterial(t),t.visible=!0,delete t.hiddenByReveal;this.worldRenderer.chunkMeshManager.migrateDeferredShaderToGlobal(e.key),e.globalShaderRestore&&this.worldRenderer.chunkMeshManager.globalBlockBuffer?.addSection(e.key,e.globalShaderRestore.words,e.globalShaderRestore.count),this.disposeWireframeGroup(e.wireframeGroup)}disposeWireframeGroup(e){this.worldRenderer.sceneOrigin.removeAndUntrackAll(e);let t=[];e.traverse(n=>{t.push(n)});for(let n of t){let r=n;if(r.geometry&&r.geometry.dispose(),r.material){let s=r.material;if(Array.isArray(s))for(let a of s)a.dispose();else s&&typeof s.dispose=="function"&&s.dispose()}}e.clear()}reset(){for(let e of this.revealingSections.values())this.disposeWireframeGroup(e.wireframeGroup);this.pendingGeometries.clear(),this.revealingSections.clear(),this.revealedChunks.clear(),this.finishedChunkCount=0,this.revealTriggered=!1,this.initialWaveDone=!1,this.initialRevealWaveSettled=!1,this.revealStartTime=0,this.pulseTime=0}forceCompleteAll(){let e=[...this.revealingSections.values()];for(let t of e){t.renderMeshRefs=this.getSectionRenderMeshes(t.key);for(let n of t.renderMeshRefs)this.restoreMeshMaterial(n),n.visible=!0,delete n.hiddenByReveal;this.completeReveal(t)}}debugGetWireframeGroups(){let e=[];return this.scene.traverse(t=>{t.name==="scifi-reveal-group"&&e.push(t)}),e}debugForceCleanup(){let e=this.debugGetWireframeGroups();console.log(`[SciFiReveal] Found ${e.length} wireframe groups in scene`);for(let t of e)console.log("[SciFiReveal] Removing group:",t),this.disposeWireframeGroup(t);for(let t of this.revealingSections.values())this.disposeWireframeGroup(t.wireframeGroup);this.revealingSections.clear(),console.log(`[SciFiReveal] Cleanup complete. Remaining groups: ${this.debugGetWireframeGroups().length}`)}debugStatus(){let e=this.debugGetWireframeGroups(),t=new Set(this.revealingSections.keys()),n=e.filter(r=>!t.has(r.sectionKey));return{revealTriggered:this.revealTriggered,finishedChunkCount:this.finishedChunkCount,pendingGeometries:this.pendingGeometries.size,revealingSections:this.revealingSections.size,revealedChunks:this.revealedChunks.size,wireframeGroupsInScene:e.length,orphanedWireframeGroups:n.length,orphanedKeys:n.map(r=>r.sectionKey),sections:[...this.revealingSections.entries()].map(([r,s])=>({key:r,phase:s.phase,renderMeshCount:s.renderMeshRefs.length,wireframeInScene:s.wireframeGroup.parent!==null}))}}debugLog(){console.log("[SciFiReveal] Status:",this.debugStatus())}},c3e={id:"futuristicReveal",controller:AR,enabledDefault:!0};h();p();d();bt();var Yqe=parseInt(ga.replaceAll(/\D+/g,""),10),MR=class extends gr{constructor(){super({uniforms:{time:{value:0},fade:{value:1}},vertexShader:`
28811
+ `,jr={textureSize:128,gravity:new K(0,-.005,0),friction:.998,defaultParticleSize:300,maxActiveFireworks:5},Jp=i=>{let t=i*3;return{x:t,y:t+1,z:t+2}},Kp=i=>{let t=i*4;return{r:t,g:t+1,b:t+2,a:t+3}},pu=(i=0,e=0)=>Math.floor(Math.random()*(i+1-e))+e,wqe=(i,e,t,n)=>{i.save();let r=i.createRadialGradient(e,e,0,e,e,e);r.addColorStop(0,"rgba(255,255,255,1.0)"),r.addColorStop(.5,"rgba(255,255,255,0.5)"),r.addColorStop(1,"rgba(255,255,255,0)"),i.fillStyle=r,i.fillRect(0,0,t,n),i.restore()},xqe=()=>{let i=jr.textureSize,e=zr(i,i),t=e.getContext("2d"),n=i/2;wqe(t,n,e.width,e.height);let r=new Gt(e);return r.needsUpdate=!0,r},Eqe=(i,e,t,n,r=jr.defaultParticleSize)=>{let s=new it,a=[],o=[],l=[],c=[],u=[],f=Math.random()>.3?"single":"multiple",m=pu(100,20)*.01,v=()=>pu(100,1)*.01,y="red",_=Math.random();_>.66?y="red":_>.33?y="green":y="blue";for(let g=0;g<i;g++){let x=new K(0,0,0);if(a.push(x.x,x.y,x.z),o.push(e[g].x,e[g].y,e[g].z),t==="seed"){let w=e[g].y**2*.04;g===0&&(w*=1.1),c.push(w),u.push(w*.017),l.push(1,1,1,1)}else if(t==="trail"){let w=Math.random()*.1+.1;c.push(w),u.push(w*.017),l.push(1,1,1,1)}else{let w=pu(r,10)*.001;if(c.push(w),u.push(w*.017),f==="multiple")l.push(v(),v(),v(),1);else switch(y){case"red":l.push(m,.1,.1,1);break;case"green":l.push(.1,m,.1,1);break;case"blue":l.push(.1,.1,m,1);break}}}s.setAttribute("position",new qe(a,3)),s.setAttribute("velocity",new qe(o,3)),s.setAttribute("color",new qe(l,4)),s.setAttribute("adjustSize",new qe(c,1)),s.setAttribute("mass",new qe(u,1));let b=new Pf({uniforms:{size:{value:jr.textureSize},texture:{value:n}},transparent:!0,depthWrite:!1,blending:Li,vertexShader:bqe,fragmentShader:_qe});return new tr(s,b)},Zp=class{particleNum;timerStartFading;mesh;constructor(e,t,n,r,s){this.particleNum=e,this.timerStartFading=10,this.mesh=Eqe(e,t,n,r,s)}update(e){this.timerStartFading>0&&(this.timerStartFading-=.3);let t=this.mesh.geometry.attributes.position,n=this.mesh.geometry.attributes.velocity,r=this.mesh.geometry.attributes.color,s=this.mesh.geometry.attributes.mass,a=()=>Math.random()>.5?.98:.96,o=l=>Math.random()>.5?0:(1-l)*.1;for(let l=0;l<this.particleNum;l++){let{x:c,y:u,z:f}=Jp(l);n.array[u]+=e.y-s.array[l],n.array[c]*=jr.friction,n.array[f]*=jr.friction,n.array[u]*=jr.friction,t.array[c]+=n.array[c],t.array[u]+=n.array[u],t.array[f]+=n.array[f];let{a:m}=Kp(l);this.timerStartFading<=0&&(r.array[m]*=a()-o(r.array[m]),r.array[m]<.001&&(r.array[m]=0))}t.needsUpdate=!0,n.needsUpdate=!0,r.needsUpdate=!0}disposeAll(){this.mesh.geometry.dispose(),this.mesh.material.dispose()}},uR=class extends Zp{constructor(e,t,n){super(e,t,"seed",n)}update(e){let t=this.mesh.geometry.attributes.position,n=this.mesh.geometry.attributes.velocity,r=this.mesh.geometry.attributes.color,s=this.mesh.geometry.attributes.mass,a=()=>Math.random()>.3?.99:.96,o=f=>Math.random()>.3?0:(1-f)*.1,l=()=>Math.random()>.5?.05:-.05,c=()=>Math.random()>.1,u=jr.friction*.98;for(let f=0;f<this.particleNum;f++){let{x:m,y:v,z:y}=Jp(f);n.array[v]+=e.y-s.array[f],n.array[m]*=u,n.array[y]*=u,n.array[v]*=u,t.array[m]+=n.array[m],t.array[v]+=n.array[v],t.array[y]+=n.array[y],c()&&(t.array[m]+=l()),c()&&(t.array[y]+=l());let{a:_}=Kp(f);r.array[_]*=a()-o(r.array[_]),r.array[_]<.001&&(r.array[_]=0)}t.needsUpdate=!0,n.needsUpdate=!0,r.needsUpdate=!0}},fR=class extends Zp{constructor(e,t,n){super(e,t,"trail",n)}update(e){let t=this.mesh.geometry.attributes.position,n=this.mesh.geometry.attributes.velocity,r=this.mesh.geometry.attributes.color,s=this.mesh.geometry.attributes.mass,a=()=>Math.random()>.3?.98:.95,o=()=>Math.random()>.5?.05:-.05,l=()=>Math.random()>.2;for(let c=0;c<this.particleNum;c++){let{x:u,y:f,z:m}=Jp(c);n.array[f]+=e.y-s.array[c],n.array[u]*=jr.friction,n.array[m]*=jr.friction,n.array[f]*=jr.friction,t.array[u]+=n.array[u],t.array[f]+=n.array[f],t.array[m]+=n.array[m],l()&&(t.array[u]+=o()),l()&&(t.array[m]+=o());let{a:v}=Kp(c);r.array[v]*=a(),r.array[v]<.001&&(r.array[v]=0)}t.needsUpdate=!0,n.needsUpdate=!0,r.needsUpdate=!0}},Qp=class{meshGroup;isExplode;petalsNum;life;seed;flowerSizeRate;flower;texture;particleSize;constructor(e,t=jr.defaultParticleSize,n){this.meshGroup=new ot,this.isExplode=!1,this.texture=e,this.particleSize=t;let r=400,s=150;this.petalsNum=pu(r,s),this.life=150,this.seed=this.getSeed(n),this.meshGroup.add(this.seed.mesh),this.flowerSizeRate=yt.mapLinear(this.petalsNum,s,r,.4,.7)}getSeed(e){let n=[];for(let s=0;s<40;s++){let o=s===0?Math.random()*2.5+.9:Math.random()*2+.4,l=0;n.push(new K(0,o,l))}let r=new uR(40,n,this.texture);if(e)r.mesh.position.set(0,0,0);else{let s=Math.random()*80-40,a=-50,o=Math.random()*80-40;r.mesh.position.set(s,a,o)}return r}explode(e){this.isExplode=!0,this.flower=this.getFlower(e),this.meshGroup.add(this.flower.mesh),this.meshGroup.remove(this.seed.mesh),this.seed.disposeAll()}getFlower(e){let t=this.petalsNum,n=[],r;if(Math.random()>.5)for(let o=0;o<t;o++){r=pu(120,60)*.01;let l=yt.degToRad(Math.random()*180),c=yt.degToRad(Math.random()*360),u=Math.sin(l)*Math.cos(c)*r,f=Math.sin(l)*Math.sin(c)*r,m=Math.cos(l)*r,v=new K(u,f,m);v.multiplyScalar(this.flowerSizeRate),n.push(v)}else{let o=180/t,l=360*(Math.random()*20+1)/t,c=l,u=l;r=pu(120,60)*.01;for(let f=0;f<t;f++){let m=Math.sin(yt.degToRad(o*f)),v=Math.cos(yt.degToRad(o*f))*r,y=Math.cos(yt.degToRad(c*f))*m*r,_=Math.sin(yt.degToRad(u*f))*m*r,b=new K(y,_,v);b.multiplyScalar(this.flowerSizeRate),n.push(b)}}let a=new Zp(t,n,"default",this.texture,this.particleSize);return a.mesh.position.set(e.x,e.y,e.z),a}update(e){this.isExplode?(this.flower.update(e),this.life>0&&(this.life-=1)):this.drawTail()}drawTail(){this.seed.update(jr.gravity);let e=this.seed.mesh.geometry.attributes.position,t=this.seed.mesh.geometry.attributes.velocity,n=0;for(let f=0,m=t.array.length;f<m;f++){let v=t.array[f];f%3===1&&v>0&&n++}if(!(n===0))return;let{x:s,y:a,z:o}=this.seed.mesh.position,l=new K(s,a,o),c=0,u;for(let f=0,m=e.array.length;f<m;f++){let v=e.array[f];f%3===1&&v>c&&(c=v,u=new K(e.array[f-1],v,e.array[f+2]))}u&&(l.add(u),this.explode(l))}},Z1=class extends Qp{tailMeshGroup;tails;constructor(e,t=jr.defaultParticleSize,n){super(e,t,n);let r=150,s=100;this.petalsNum=pu(r,s),this.flowerSizeRate=yt.mapLinear(this.petalsNum,s,r,.4,.7),this.tailMeshGroup=new ot,this.tails=[]}explode(e){this.isExplode=!0,this.flower=this.getFlower(e),this.tails=this.getTail(),this.meshGroup.add(this.flower.mesh),this.meshGroup.add(this.tailMeshGroup)}getTail(){let e=[],n=this.flower.mesh.geometry.attributes.color;for(let r=0;r<this.petalsNum;r++){let s=[];for(let E=0;E<20;E++)s.push(new K(0,0,0));let a=new fR(20,s,this.texture),{r:o,g:l,b:c,a:u}=Kp(r),f=n.array[o],m=n.array[l],v=n.array[c],y=n.array[u],_=a.mesh.geometry.attributes.position,b=a.mesh.geometry.attributes.color;for(let E=0;E<_.count;E++){let A=Kp(E);b.array[A.r]=f,b.array[A.g]=m,b.array[A.b]=v,b.array[A.a]=y}let{x:g,y:x,z:w}=this.flower.mesh.position;a.mesh.position.set(g,x,w),e.push(a),this.tailMeshGroup.add(a.mesh)}return e}update(e){if(this.isExplode){this.flower.update(e);let t=this.flower.mesh.geometry.attributes.position;for(let n=0,r=this.tails.length;n<r;n++){let s=this.tails[n];s.update(e);let{x:a,y:o,z:l}=Jp(n),c=new K(t.array[a],t.array[o],t.array[l]),u=s.mesh.geometry.attributes.position,f=s.mesh.geometry.attributes.velocity;for(let m=0;m<u.count;m++){let v=Jp(m),y=new K,_=new K(u.array[v.x],u.array[v.y],u.array[v.z]),b=new K(f.array[v.x],f.array[v.y],f.array[v.z]);y.subVectors(c,_);let g=y.sub(b);g.normalize(),g.multiplyScalar(Math.random()*3e-4*this.life),f.array[v.x]+=g.x,f.array[v.y]+=g.y,f.array[v.z]+=g.z}f.needsUpdate=!0}this.life>0&&(this.life-=1.2)}else this.drawTail()}},q4=class{fireworksInstances;scene;sceneOrigin;texture;particleSize;maxFireworks;constructor(e,t,n){this.fireworksInstances=[],this.scene=e,this.sceneOrigin=t,this.texture=xqe(),this.particleSize=n?.defaultParticleSize??jr.defaultParticleSize,this.maxFireworks=n?.maxActiveFireworks??jr.maxActiveFireworks}launchFirework(e){if(this.fireworksInstances.length>=this.maxFireworks)return;let t=e?.particleSize??this.particleSize,n=e?.position,r;e?.forceRich?r=new Z1(this.texture,t,n):e?.forceBasic?r=new Qp(this.texture,t,n):r=Math.random()>.5?new Qp(this.texture,t,n):new Z1(this.texture,t,n),this.fireworksInstances.push(r),n?(this.sceneOrigin.addAndTrack(r.meshGroup),r.meshGroup.position.set(n.x,n.y,n.z)):this.scene.add(r.meshGroup)}repositionAll(){}update(){let e=[];for(let t=this.fireworksInstances.length-1;t>=0;t--){let n=this.fireworksInstances[t];n.update(jr.gravity),n.isExplode&&e.push(t)}for(let t=0,n=e.length;t<n;t++){let r=e[t],s=this.fireworksInstances[r];if(s&&(s.meshGroup.remove(s.seed.mesh),s.seed.disposeAll(),s.life<=0)){if(this.sceneOrigin.removeAndUntrack(s.meshGroup),s instanceof Z1&&s.tailMeshGroup)for(let a of s.tails)a.disposeAll();s.flower?.disposeAll(),this.fireworksInstances.splice(r,1)}}}clear(){for(let e of this.fireworksInstances)if(this.sceneOrigin.removeAndUntrack(e.meshGroup),e.seed.disposeAll(),e.flower&&e.flower.disposeAll(),e instanceof Z1)for(let t of e.tails)t.disposeAll();this.fireworksInstances=[]}dispose(){this.clear(),this.texture.dispose()}};h();p();d();var Ime=Symbol("tracked-proxy"),Sqe=new Set(["add","addScalar","addScaledVector","addVectors","sub","subScalar","subVectors","multiply","multiplyScalar","multiplyVectors","divide","divideScalar","applyEuler","applyAxisAngle","applyMatrix3","applyMatrix4","applyNormalMatrix","applyQuaternion","negate","floor","ceil","round","roundToZero","min","max","clamp","clampLength","clampScalar","project","unproject","reflect","lerp","lerpVectors","cross","crossVectors","setFromMatrixPosition","setFromMatrixColumn","setFromMatrix3Column","setFromEuler","setFromSpherical","setFromSphericalCoords","setFromCylindrical","fromArray","fromBufferAttribute","setComponent","randomDirection","random"]),G4=class{scene;_x=0;_y=0;_z=0;_tracked=new Set;_worldCoords=new WeakMap;_originalPositions=new WeakMap;_trackOptions=new WeakMap;constructor(e){this.scene=e}get x(){return this._x}get y(){return this._y}get z(){return this._z}update(e,t,n){this._x=e,this._y=t,this._z=n;for(let r of this._tracked){let s=this._worldCoords.get(r);this._originalPositions.get(r).set(s.x-e,s.y-t,s.z-n),this._trackOptions.get(r)?.updateMatrix&&r.updateMatrix()}}track(e,t){let n=this._originalPositions.get(e)??e.position,r={x:0,y:0,z:0};this._originalPositions.set(e,n),this._worldCoords.set(e,r),t?this._trackOptions.set(e,t):this._trackOptions.delete(e);let s=this,a=t,o=new Proxy(n,{get(l,c,u){if(c===Ime)return r;if(c==="set")return(m,v,y)=>(r.x=m,r.y=v,r.z=y,l.set(m-s._x,v-s._y,y-s._z),a?.updateMatrix&&e.updateMatrix(),u);if(c==="copy")return m=>{let v=m[Ime],y=v?v.x:m.x,_=v?v.y:m.y,b=v?v.z:m.z;return r.x=y,r.y=_,r.z=b,l.set(y-s._x,_-s._y,b-s._z),a?.updateMatrix&&e.updateMatrix(),u};if(c==="setX")return m=>(r.x=m,l.x=m-s._x,a?.updateMatrix&&e.updateMatrix(),u);if(c==="setY")return m=>(r.y=m,l.y=m-s._y,a?.updateMatrix&&e.updateMatrix(),u);if(c==="setZ")return m=>(r.z=m,l.z=m-s._z,a?.updateMatrix&&e.updateMatrix(),u);if(typeof c=="string"&&Sqe.has(c))return()=>{throw new Error(`Cannot call position.${c}() on a tracked object. Use position.set(x, y, z) instead.`)};let f=l[c];return typeof f=="function"?f.bind(l):f},set(l,c,u){return c==="x"?(r.x=u,l.x=u-s._x,a?.updateMatrix&&e.updateMatrix(),!0):c==="y"?(r.y=u,l.y=u-s._y,a?.updateMatrix&&e.updateMatrix(),!0):c==="z"?(r.z=u,l.z=u-s._z,a?.updateMatrix&&e.updateMatrix(),!0):(l[c]=u,!0)}});Object.defineProperty(e,"position",{value:o,configurable:!0,enumerable:!0}),this._tracked.add(e)}untrack(e){let t=this._originalPositions.get(e);t&&(Object.defineProperty(e,"position",{value:t,configurable:!0,enumerable:!0}),this._tracked.delete(e),this._worldCoords.delete(e),this._originalPositions.delete(e),this._trackOptions.delete(e))}addAndTrack(e,t){this.track(e,t),this.scene.add(e)}removeAndUntrack(e){this.untrack(e),e.removeFromParent()}removeAndUntrackAll(e){e.traverse(t=>{this.untrack(t)}),e.removeFromParent()}getWorldPosition(e){let t=this._worldCoords.get(e);return t?{x:t.x,y:t.y,z:t.z}:void 0}clear(){for(let e of this._tracked)this.untrack(e)}get trackedCount(){return this._tracked.size}toSceneX(e){return e-this._x}toSceneY(e){return e-this._y}toSceneZ(e){return e-this._z}toWorldX(e){return e+this._x}toWorldY(e){return e+this._y}toWorldZ(e){return e+this._z}};gR();h();p();d();var Zme=Jr(pp(),1);bt();var t8=Jr(_i(),1);Q1();vu();mR();h();p();d();bt();vu();Q1();var Lqe=2e6,yR=Nme(),Q4=class{mesh;capacityFaces;w0;w1;w2;w3;sectionSlots=new Map;freeList=[];highWatermark=0;dirtyMin=1/0;dirtyMax=-1;constructor(e,t){this.capacityFaces=Lqe,this.w0=new Uint32Array(this.capacityFaces),this.w1=new Uint32Array(this.capacityFaces),this.w2=new Uint32Array(this.capacityFaces),this.w3=new Uint32Array(this.capacityFaces);let n=new ma,r=new Float32Array(j4*3);n.setAttribute("position",new dt(r,3));let s=a=>{let o=new Ar(a,1);return o.setUsage(Av),o};n.setAttribute("a_w0",s(this.w0)),n.setAttribute("a_w1",s(this.w1)),n.setAttribute("a_w2",s(this.w2)),n.setAttribute("a_w3",s(this.w3)),n.instanceCount=0,this.mesh=new je(n,e),this.mesh.name="globalShaderCubes",this.mesh.frustumCulled=!1,this.mesh.matrixAutoUpdate=!1,this.mesh.matrix.identity(),this.mesh.position.set(0,0,0),t.add(this.mesh)}addSection(e,t,n){if(n<=0){this.removeSection(e);return}this.sectionSlots.has(e)&&this.removeSection(e),n>this.capacityFaces&&this.growCapacity(n);let r=this.takeFreeSlot(n);r||(this.highWatermark+n>this.capacityFaces&&this.growCapacity(this.highWatermark+n),r={start:this.highWatermark,count:n},this.highWatermark+=n);let s=4;for(let a=0;a<n;a++){let o=r.start+a,l=a*s;this.w0[o]=t[l],this.w1[o]=t[l+1],this.w2[o]=t[l+2],this.w3[o]=t[l+3]}this.sectionSlots.set(e,r),this.markDirty(r.start,r.start+n-1),this.mesh.geometry.instanceCount=this.highWatermark}hasSection(e){return this.sectionSlots.has(e)}takeSectionData(e){let t=this.sectionSlots.get(e);if(!t)return;let n=4,r=new Uint32Array(t.count*n);for(let s=0;s<t.count;s++){let a=t.start+s,o=s*n;r[o]=this.w0[a],r[o+1]=this.w1[a],r[o+2]=this.w2[a],r[o+3]=this.w3[a]}return this.removeSection(e),{words:r,count:t.count}}removeSection(e){let t=this.sectionSlots.get(e);if(t){for(let n=t.start;n<t.start+t.count;n++)this.w0[n]=0,this.w1[n]=0,this.w2[n]=yR,this.w3[n]=0;this.markDirty(t.start,t.start+t.count-1),this.sectionSlots.delete(e),this.insertFreeSlot(t),this.shrinkHighWatermark(),this.mesh.geometry.instanceCount=this.highWatermark}}uploadDirtyRange(){if(this.dirtyMin>this.dirtyMax)return;let e=this.dirtyMin,t=this.dirtyMax-this.dirtyMin+1,n=this.mesh.geometry;for(let r of["a_w0","a_w1","a_w2","a_w3"]){let s=n.getAttribute(r);s.updateRange.offset=e,s.updateRange.count=t,s.needsUpdate=!0}this.dirtyMin=1/0,this.dirtyMax=-1}setCameraOrigin(e,t,n){let r=Math.floor(e),s=Math.floor(t),a=Math.floor(n),o=this.mesh.material.uniforms.u_cameraOrigin;o?.value?.set&&o.value.set(r,s,a);let l=this.mesh.material.uniforms.u_cameraOriginFrac;l?.value?.set&&l.value.set(e-r,t-s,n-a)}reset(){this.sectionSlots.clear(),this.freeList.length=0,this.highWatermark=0,this.dirtyMin=1/0,this.dirtyMax=-1,this.w0.fill(0),this.w1.fill(0),this.w2.fill(yR),this.w3.fill(0),this.mesh.geometry.instanceCount=0}dispose(){this.mesh.parent?.remove(this.mesh),this.mesh.geometry.dispose(),this.reset()}markDirty(e,t){e<this.dirtyMin&&(this.dirtyMin=e),t>this.dirtyMax&&(this.dirtyMax=t)}takeFreeSlot(e){for(let t=0;t<this.freeList.length;t++){let n=this.freeList[t];if(n.count>=e){if(this.freeList.splice(t,1),n.count===e)return n;let r={start:n.start,count:e};return this.insertFreeSlot({start:n.start+e,count:n.count-e}),r}}}insertFreeSlot(e){this.freeList.push(e),this.freeList.sort((t,n)=>t.start-n.start),this.mergeFreeList()}mergeFreeList(){if(this.freeList.length<2)return;let e=[],t=this.freeList[0];for(let n=1;n<this.freeList.length;n++){let r=this.freeList[n];t.start+t.count===r.start?t={start:t.start,count:t.count+r.count}:(e.push(t),t=r)}e.push(t),this.freeList=e}shrinkHighWatermark(){for(;this.highWatermark>0;){let e=this.highWatermark-1,t=this.freeList.find(r=>r.start<=e&&r.start+r.count>e);if(!t||t.start+t.count!==this.highWatermark)break;this.highWatermark=t.start;let n=this.freeList.indexOf(t);this.freeList.splice(n,1)}}growCapacity(e){let t=this.capacityFaces;for(;t<e;)t*=2;let n=new Uint32Array(t),r=new Uint32Array(t),s=new Uint32Array(t),a=new Uint32Array(t);n.set(this.w0),r.set(this.w1),s.set(this.w2),a.set(this.w3),s.fill(yR,this.w0.length),this.w0=n,this.w1=r,this.w2=s,this.w3=a,this.capacityFaces=t;let o=this.mesh.geometry,l=(c,u)=>{let f=o.getAttribute(u);f&&(o.deleteAttribute(u),"dispose"in f&&typeof f.dispose=="function"&&f.dispose());let m=new Ar(c,1);m.setUsage(Av),o.setAttribute(u,m)};l(this.w0,"a_w0"),l(this.w1,"a_w1"),l(this.w2,"a_w2"),l(this.w3,"a_w3"),this.dirtyMin=0,this.dirtyMax=this.highWatermark-1}};h();p();d();Q1();vu();function Gme(i,e,t,n,r){if(e<=0)return;let s=t-8,a=n-8,o=r-8,l=J4,c=16,u=16,f=16,m=-1,v=-1,y=-1;for(let A=0;A<e;A++){let P=i[A*l],C=P&(1<<mu.LX_BITS)-1,L=P>>mu.LY_SHIFT&(1<<mu.LY_BITS)-1,M=P>>mu.LZ_SHIFT&(1<<mu.LZ_BITS)-1;C<c&&(c=C),L<u&&(u=L),M<f&&(f=M),C>m&&(m=C),L>v&&(v=L),M>y&&(y=M)}if(m<0)return;let _=s+c,b=a+u,g=o+f,x=s+m+1,w=a+v+1,E=o+y+1;return{minX:_,minY:b,minZ:g,maxX:x,maxY:w,maxZ:E,cx:(_+x)*.5,cy:(b+w)*.5,cz:(g+E)*.5}}function Bqe(i,e,t,n,r,s,a,o,l){return i>=n&&i<=a&&e>=r&&e<=o&&t>=s&&t<=l}function Wme(i,e,t,n,r,s,a,o,l,c,u,f,m){if(Bqe(i,e,t,a,o,l,c,u,f))return;let v=0,y=m;if(Math.abs(n)<1e-8){if(i<a||i>c)return}else{let _=1/n,b=(a-i)*_,g=(c-i)*_;if(b>g){let x=b;b=g,g=x}if(v=Math.max(v,b),y=Math.min(y,g),v>y)return}if(Math.abs(r)<1e-8){if(e<o||e>u)return}else{let _=1/r,b=(o-e)*_,g=(u-e)*_;if(b>g){let x=b;b=g,g=x}if(v=Math.max(v,b),y=Math.min(y,g),v>y)return}if(Math.abs(s)<1e-8){if(t<l||t>f)return}else{let _=1/s,b=(l-t)*_,g=(f-t)*_;if(b>g){let x=b;b=g,g=x}if(v=Math.max(v,b),y=Math.min(y,g),v>y)return}return v<=y&&v>=0?v:void 0}h();p();d();bt();var jme=20,$me=40,Oqe={white_banner:15,orange_banner:14,magenta_banner:13,light_blue_banner:12,yellow_banner:11,lime_banner:10,pink_banner:9,gray_banner:8,light_gray_banner:7,cyan_banner:6,purple_banner:5,blue_banner:4,brown_banner:3,green_banner:2,red_banner:1,black_banner:0},Xme={0:"#1d1d21",1:"#b02e26",2:"#5e7c16",3:"#835432",4:"#3c44aa",5:"#8932b8",6:"#169c9c",7:"#9d9d97",8:"#474f52",9:"#f38baa",10:"#80c71f",11:"#fed83d",12:"#3ab3da",13:"#c74ebd",14:"#f9801d",15:"#f9fffe"};function Nqe(i){let e=i.replace("_wall_banner","_banner");return Oqe[e]??15}var Dqe=(i,e,t,n,r,s,a)=>{switch(i.fillStyle=t,e){case"bs":i.fillRect(n,r,s,a);break;case"ls":i.fillRect(n,r,s/3,a);break;case"rs":i.fillRect(n+s*2/3,r,s/3,a);break;case"ts":i.fillRect(n,r,s,a/3);break;case"ms":i.fillRect(n,r+a/3,s,a/3);break;case"drs":i.fillRect(n,r,s/2,a/2);break;case"dls":i.fillRect(n+s/2,r,s/2,a/2);break;case"ss":for(let o=0;o<s;o+=2)i.fillRect(n+o,r,1,a);break;case"cr":i.fillRect(n,r+a/3,s,a/3),i.fillRect(n+s/3,r,s/3,a);break;case"sc":i.fillRect(n,r+a/2-1,s,2),i.fillRect(n+s/2-1,r,2,a);break;default:i.fillRect(n,r,s,a)}};function Uqe(i,e){if(!e||e.length===0)return`banner_${i}_empty`;let t=e.map(n=>`${n.Pattern??"bs"}_${n.Color??0}`).join(",");return`banner_${i}_${t}`}var Vqe=(i,e,t=(n,r)=>zr(n,r))=>{let r=t(jme*1,$me*1),s=r.getContext("2d");if(!s){console.warn("Failed to get 2d context for banner rendering");return}if(s.imageSmoothingEnabled=!1,e?.Patterns&&e.Patterns.length>0)for(let a of e.Patterns){let o=a.Color??0,l=a.Pattern??"bs",c=Xme[o]||Xme[0];Dqe(s,l,c,0,0,jme*1,$me*1)}return r},e8=new Map;function Yme(i,e,t){let n=Nqe(e),r=Uqe(n,t?.Patterns),s=e8.get(r);if(s)return s.refCount++,s.texture;let a=Vqe(n,t);if(!a)return;let o=new Gt(a);return o.magFilter=Je,o.minFilter=Je,o.needsUpdate=!0,e8.set(r,{texture:o,refCount:1}),o}function Jme(i){for(let[e,t]of e8.entries())if(t.texture===i){t.refCount--,t.refCount<=0&&(t.texture.dispose(),e8.delete(e));return}}function Kme(i,e,t,n){let o,l,c;t?(o=(-14.6+13.4)/2/16-.5,l=1-14.75/16-.5,c=1/2):(o=(1.4+29.4)/2/16,l=1-7.25/16-.5,c=0);let u=new je(new vn(.85,1.75),new st({map:n,transparent:!0}));u.renderOrder=999;let f=.5/16,m=.25/16;t?u.position.set(0,o,l+m+.004):u.position.set(0,o,l+f/2+.004);let v=new ot;return v.rotation.set(0,-yt.degToRad(e*(t?90:45/2)),0),v.add(u),v.bannerTexture=n,v.position.set(i.x+.5,i.y+c,i.z+.5),v}var gu=class gu{constructor(e,t,n,r,s=3){this.worldRenderer=e;this.scene=t;this.material=n;this.worldHeight=r;this.updateViewDistance(s),this.signHeadsRenderer=new bR(e),this.initializePool()}meshPool=[];activeSections=new Map;sectionObjects={};waitingChunksToDisplay={};pendingNearReveal=new Map;nearRevealTimers=new Map;nearRevealGraceTimers=new Map;poolSize;maxPoolSize;minPoolSize;signHeadsRenderer;chunkBoxMaterial=new st({color:0,transparent:!0,opacity:0});cubeShaderMaterial=null;globalBlockBuffer=null;shaderSectionRaycastBoxes=new Map;hits=0;misses=0;bypassPooling=!1;renderTimes=[];maxRenderTimeSamples=30;_performanceOverrideDistance;lastPerformanceCheck=0;performanceCheckInterval=2e3;get performanceOverrideDistance(){return this._performanceOverrideDistance??0}set performanceOverrideDistance(e){this._performanceOverrideDistance=e,this.updateSectionsVisibility()}initializePool(){for(let e=0;e<this.poolSize;e++){let t=new it,n=new je(t,this.material);n.visible=!1,n.matrixAutoUpdate=!1,n.name="pooled-section-mesh";let r={mesh:n,inUse:!1,lastUsedTime:0};this.meshPool.push(r)}}sectionHasRenderableContent(e){return e.positions.length>0?!0:this.isShaderCubesGpuEnabled()?(e.shaderCubes?.count??0)>0:!1}isShaderCubesGpuEnabled(){return this.worldRenderer.shaderCubeBlocksEnabled()}syncCubeShaderUniforms(){if(!this.isShaderCubesGpuEnabled())return;let e=this.cubeShaderMaterial??this.getCubeShaderMaterial();if(!e)return;let t=this.material.map??null;e.uniforms.u_atlas.value=t;let{tintPalette:n}=K4();n.isReady()||n.createTexture(),e.uniforms.u_tintPalette.value=n.getTexture(),e.uniforms.u_debugMode.value=this.worldRenderer.worldRendererConfig.shaderCubeDebugMode??0,e.needsUpdate=!0}getCubeShaderMaterial(){return this.isShaderCubesGpuEnabled()?(this.cubeShaderMaterial||(this.cubeShaderMaterial=W4(),this.syncCubeShaderUniforms()),this.cubeShaderMaterial):null}getGlobalBlockBuffer(){let e=this.getCubeShaderMaterial();return e?(this.globalBlockBuffer||(this.globalBlockBuffer=new Q4(e,this.scene)),this.globalBlockBuffer):null}shouldDeferShaderToPerSection(e){let t=this.worldRenderer.getModule("futuristicReveal");return t?t.isInInitialRevealCampaign?.()?!0:t.shouldUseRevealEffect?.(e)===!0:!1}migrateDeferredShaderToGlobal(e){let t=this.sectionObjects[e];if(!t?.deferredShaderCubes)return;let{words:n,count:r}=t.deferredShaderCubes,s=t.worldX,a=t.worldY,o=t.worldZ;s!==void 0&&a!==void 0&&o!==void 0&&this.registerShaderSectionRaycastBox(e,n,r,s,a,o),this.getGlobalBlockBuffer()?.addSection(e,n,r);let c=t.mesh===t.shaderMesh;t.shaderMesh&&(pR(t.shaderMesh),t.remove(t.shaderMesh),t.shaderMesh=void 0),delete t.deferredShaderCubes,c&&(t.mesh=void 0)}registerShaderSectionRaycastBox(e,t,n,r,s,a){let o=Gme(t,n,r,s,a);o?this.shaderSectionRaycastBoxes.set(e,o):this.shaderSectionRaycastBoxes.delete(e)}unregisterShaderSectionRaycastBox(e){this.shaderSectionRaycastBoxes.delete(e)}raycastShaderSectionAABBs(e,t,n,r=80){let s=e.x,a=e.y,o=e.z,l=t.x,c=t.y,u=t.z,f=r*r,m=n,v=!1;for(let[y,_]of this.shaderSectionRaycastBoxes){let b=this.sectionObjects[y];if(b&&!b.visible)continue;let g=_.cx-s,x=_.cy-a,w=_.cz-o;if(g*g+x*x+w*w>f)continue;let E=Wme(s,a,o,l,c,u,_.minX,_.minY,_.minZ,_.maxX,_.maxY,_.maxZ,m);E!==void 0&&E<m&&(m=E,v=!0)}return v?m:void 0}updateSection(e,t){let n=t.positions.length>0,r=t.shaderCubes,s=this.isShaderCubesGpuEnabled()&&(r?.count??0)>0;if(!n&&!s)return this.releaseSection(e),null;let a=this.sectionObjects[e];a&&this.cleanupSection(e),n||this.releasePooledMesh(e);let o;if(n){let b=this.activeSections.get(e);if(!b){if(b=this.acquireMesh(),!b)return console.warn(`ChunkMeshManager: No available mesh in pool for section ${e}`),null;this.activeSections.set(e,b),b.sectionKey=e}let{mesh:g}=b;this.updateGeometryAttribute(g.geometry,"position",t.positions,3),this.updateGeometryAttribute(g.geometry,"normal",t.normals,3),this.updateGeometryAttribute(g.geometry,"color",t.colors,3),this.updateGeometryAttribute(g.geometry,"uv",t.uvs,2),g.geometry.index=new dt(t.indices,1),g.geometry.boundingBox=new Un(new K(-8,-8,-8),new K(8,8,8)),g.geometry.boundingSphere=new jn(new K(0,0,0),Math.sqrt(3*8**2)),this.worldRenderer.sceneOrigin.track(g,{updateMatrix:!0}),g.position.set(t.sx,t.sy,t.sz),g.updateMatrix(),g.visible=!0,g.name="mesh",b.lastUsedTime=performance.now(),o=g}let l=s?this.getCubeShaderMaterial():null,c,u=s&&this.shouldDeferShaderToPerSection(e);s&&r&&(u&&l?(c=Z4(r,l),c.visible=!0):this.getGlobalBlockBuffer()?.addSection(e,r.words,r.count)),a=new ot,o&&(a.add(o),a.mesh=o),c&&(a.add(c),a.shaderMesh=c,r&&(a.deferredShaderCubes={words:r.words,count:r.count}),a.mesh||(a.mesh=c)),s&&r&&this.registerShaderSectionRaycastBox(e,r.words,r.count,t.sx,t.sy,t.sz);let f=0;n&&(f+=t.positions.length/3/4),s&&r&&(f+=r.count),a.tilesCount=f,a.blocksCount=t.blocksCount,a.worldX=t.sx,a.worldY=t.sy,a.worldZ=t.sz,a.sectionKey=e,a.name="chunk";try{if(Object.keys(t.signs).length>0){let b=new ot;b.name="signs";for(let[g,{isWall:x,isHanging:w,rotation:E}]of Object.entries(t.signs)){let A=this.worldRenderer.blockEntities[g];if(!A)continue;let[P,C,L]=g.split(","),M=this.signHeadsRenderer.renderSign(new ft(+P,+C,+L),E,x,w,t8.simplify(A));M&&b.add(M)}a.add(b),a.signsContainer=b}if(Object.keys(t.heads).length>0){let b=new ot;b.name="heads";for(let[g,{isWall:x,rotation:w}]of Object.entries(t.heads)){let E=this.worldRenderer.blockEntities[g];if(!E)continue;let[A,P,C]=g.split(","),L=this.signHeadsRenderer.renderHead(new ft(+A,+P,+C),w,x,t8.simplify(E));L&&b.add(L)}a.add(b),a.headsContainer=b}if(Object.keys(t.banners).length>0){let b=new ot;b.name="banners",a.bannersContainer=b,a.add(b);for(let[g,{isWall:x,rotation:w,blockName:E}]of Object.entries(t.banners)){let A=this.worldRenderer.blockEntities[g];if(!A)continue;let[P,C,L]=g.split(","),M=Yme(this.worldRenderer,E,t8.simplify(A));if(!M)continue;let T=Kme(new ft(+P,+C,+L),w,x,M),{x:F,y:Z,z:U}=T.position;this.worldRenderer.sceneOrigin.track(T),T.position.set(F,Z,U),b.add(T)}}}catch(b){console.error("ChunkMeshManager: Error adding signs, heads, or banners to section",b)}this.sectionObjects[e]=a,this.scene.add(a),a.matrixAutoUpdate=!1,this.worldRenderer.displayOptions?.inWorldRenderingConfig?.showChunkBorders&&this.updateBoxHelper(e,!0);let m=e.split(","),v=`${m[0]},${m[2]}`,y=!!this.worldRenderer.displayOptions?.inWorldRenderingConfig?._renderByChunks,_=!!this.worldRenderer.worldRendererConfig?.wasmMesher;if((y||_)&&!this.worldRenderer.finishedChunks[v]){a.visible=!1,a._waitingForChunkDisplay=!0;let b=this.waitingChunksToDisplay[v]??(this.waitingChunksToDisplay[v]=[]);b.includes(e)||b.push(e)}return a}finishChunkDisplay(e){if(!this.waitingChunksToDisplay[e]){this.tryRevealPending();return}if(this.isWasmGateActive()&&this.isBlockedByNearer(e,0)){this.pendingNearReveal.set(e,Date.now()),this.armNearRevealTimer(e),this.armExpectedGraceTimer(e);return}this.flushChunkDisplay(e),this.tryRevealPending()}flushChunkDisplay(e){let t=this.waitingChunksToDisplay[e];if(this.pendingNearReveal.delete(e),this.clearNearRevealTimer(e),this.clearExpectedGraceTimer(e),!!t){for(let n of t){let r=this.sectionObjects[n];r&&(r._waitingForChunkDisplay=!1,r.visible=!0)}delete this.waitingChunksToDisplay[e]}}tryRevealPending(){if(this.pendingNearReveal.size===0)return;let e=Date.now();for(let[t,n]of[...this.pendingNearReveal])this.isBlockedByNearer(t,e-n)||this.flushChunkDisplay(t)}onChunkRemovedFromGate(e){this.pendingNearReveal.delete(e),this.clearNearRevealTimer(e),this.clearExpectedGraceTimer(e),delete this.waitingChunksToDisplay[e],this.tryRevealPending()}isWasmGateActive(){return!!this.worldRenderer.worldRendererConfig?.wasmMesher}isBlockedByNearer(e,t){let n=this.worldRenderer.viewerChunkPosition;if(!n)return!1;let r=e.split(",");if(r.length!==2)return!1;let s=Number(r[0]),a=Number(r[1]),o=Math.floor(n.x/16),l=Math.floor(n.z/16),c=(s>>4)-o,u=(a>>4)-l,f=c*c+u*u;if(f===0)return!1;let m=this.worldRenderer.finishedChunks,v=this.worldRenderer.loadedChunks,y=this.worldRenderer.viewDistance;if(t<gu.EXPECTED_NEAR_GRACE_MS&&y>0){let b=y*y,g=Math.min(y,Math.ceil(Math.sqrt(Math.max(0,f-1))));for(let x=-g;x<=g;x++)for(let w=-g;w<=g;w++){let E=x*x+w*w;if(E>=f||E>b)continue;let A=o+x<<4,P=l+w<<4,C=`${A},${P}`;if(C!==e&&!m[C])return!0}return!1}for(let b in v){if(b===e||m[b])continue;let g=b.split(",");if(g.length!==2)continue;let x=(Number(g[0])>>4)-o,w=(Number(g[1])>>4)-l;if(x*x+w*w<f)return!0}return!1}armNearRevealTimer(e){if(this.nearRevealTimers.has(e))return;let t=setTimeout(()=>{this.nearRevealTimers.delete(e),this.pendingNearReveal.has(e)&&(console.warn(`[chunk-reveal] safety timeout for ${e} \u2014 a nearer pending column never finished, force-revealing`),this.flushChunkDisplay(e),this.tryRevealPending())},gu.NEAR_REVEAL_TIMEOUT_MS);this.nearRevealTimers.set(e,t)}clearNearRevealTimer(e){let t=this.nearRevealTimers.get(e);t&&(clearTimeout(t),this.nearRevealTimers.delete(e))}armExpectedGraceTimer(e){if(this.nearRevealGraceTimers.has(e))return;let t=setTimeout(()=>{this.nearRevealGraceTimers.delete(e),this.pendingNearReveal.has(e)&&this.tryRevealPending()},gu.EXPECTED_NEAR_GRACE_MS+50);this.nearRevealGraceTimers.set(e,t)}clearExpectedGraceTimer(e){let t=this.nearRevealGraceTimers.get(e);t&&(clearTimeout(t),this.nearRevealGraceTimers.delete(e))}cleanupSection(e){let t=this.sectionObjects[e];if(t){if(t._waitingForChunkDisplay){let n=e.split(","),r=`${n[0]},${n[2]}`,s=this.waitingChunksToDisplay[r];if(s){let a=s.indexOf(e);a!==-1&&s.splice(a,1),s.length===0&&delete this.waitingChunksToDisplay[r]}}if(t.bannersContainer&&(t.bannersContainer.traverse(n=>{n.bannerTexture&&Jme(n.bannerTexture)}),this.disposeContainer(t.bannersContainer)),this.globalBlockBuffer?.removeSection(e),this.unregisterShaderSectionRaycastBox(e),t.shaderMesh&&(pR(t.shaderMesh),t.shaderMesh=void 0),delete t.deferredShaderCubes,t.signsContainer&&this.disposeContainer(t.signsContainer),t.headsContainer&&this.disposeContainer(t.headsContainer),this.worldRenderer.sceneOrigin.removeAndUntrackAll(t),this.scene.remove(t),t.boxHelper){this.worldRenderer.sceneOrigin.removeAndUntrack(t.boxHelper),this.scene.remove(t.boxHelper),t.boxHelper.geometry.dispose();let n=t.boxHelper.material;if(Array.isArray(n))for(let r of n)r.dispose();else n.dispose();t.boxHelper=void 0}delete this.sectionObjects[e]}}releasePooledMesh(e){let t=this.activeSections.get(e);t&&(t.mesh.visible=!1,t.inUse=!1,t.sectionKey=void 0,t.lastUsedTime=0,this.clearGeometry(t.mesh.geometry),this.activeSections.delete(e),this.cleanupExcessMeshes())}releaseSection(e){this.cleanupSection(e);let t=this.activeSections.get(e);return t?(t.mesh.visible=!1,t.inUse=!1,t.sectionKey=void 0,t.lastUsedTime=0,this.clearGeometry(t.mesh.geometry),this.activeSections.delete(e),this.cleanupExcessMeshes(),!0):!1}getSectionObject(e){return this.sectionObjects[e]}updateBoxHelper(e,t,n=this.chunkBoxMaterial){let r=this.sectionObjects[e];if(r?.mesh)if(t){if(!r.boxHelper){let s=new je(new nn(16,16,16),n),a=new va(s,16776960);a.name="helper";let o=r.worldX??0,l=r.worldY??0,c=r.worldZ??0;this.worldRenderer.sceneOrigin.track(a,{updateMatrix:!0}),a.position.set(o,l,c),a.updateMatrix(),this.scene.add(a),r.boxHelper=a}r.boxHelper.visible=!0}else r.boxHelper&&(r.boxHelper.visible=!1)}updateAllBoxHelpers(e){for(let t of Object.keys(this.sectionObjects))this.updateBoxHelper(t,e)}cleanSignChunkTextures(e,t){this.signHeadsRenderer.cleanChunkTextures(e,t)}getSectionMesh(e){return this.activeSections.get(e)?.mesh}hasSection(e){return this.activeSections.has(e)}updateViewDistance(e){let t=(e*2+1)**2,n=this.worldHeight/16,r=5;if(this.minPoolSize=Math.floor(t*r),this.maxPoolSize=Math.floor(t*n)+1,this.poolSize??=this.minPoolSize,this.minPoolSize>this.poolSize){let s=Math.min(this.minPoolSize,this.maxPoolSize);this.expandPool(s)}console.log(`ChunkMeshManager: Updated view max distance to ${e}, pool: ${this.poolSize}/${this.maxPoolSize}, optimal: ${this.minPoolSize}`)}getStats(){let e=this.meshPool.filter(r=>!r.inUse).length,t=this.hits+this.misses>0?(this.hits/(this.hits+this.misses)*100).toFixed(1):"0",n=this.getEstimatedMemoryUsage();return{poolSize:this.poolSize,activeCount:this.activeSections.size,freeCount:e,hitRate:`${t}%`,hits:this.hits,misses:this.misses,memoryUsage:n}}getTotalTiles(){return Object.values(this.sectionObjects).reduce((e,t)=>e+(t.tilesCount||0),0)}getTotalBlocks(){return Object.values(this.sectionObjects).reduce((e,t)=>e+(t.blocksCount||0),0)}getEstimatedMemoryUsage(){let e=0,t=0,n=0,r=0,s=0,a=0,o=0,l=this.globalBlockBuffer?.mesh.geometry;if(l)for(let u of["a_w0","a_w1","a_w2","a_w3"]){let f=l.getAttribute(u);if(f){let m=f.array.byteLength;o+=m,e+=m}}for(let u of Object.values(this.sectionObjects)){let f=u.shaderMesh?.geometry;if(f)for(let m of["a_w0","a_w1","a_w2","a_w3"]){let v=f.getAttribute(m);if(v){let y=v.array.byteLength;o+=y,e+=y}}}for(let u of this.meshPool)if(u.inUse&&u.mesh.geometry){let{geometry:f}=u.mesh,m=f.getAttribute("position");if(m){let b=m.array.byteLength;t+=b,e+=b}let v=f.getAttribute("normal");if(v){let b=v.array.byteLength;n+=b,e+=b}let y=f.getAttribute("color");if(y){let b=y.array.byteLength;r+=b,e+=b}let _=f.getAttribute("uv");if(_){let b=_.array.byteLength;s+=b,e+=b}if(f.index){let b=f.index.array.byteLength;a+=b,e+=b}}return{total:`${(e/(1024*1024)).toFixed(2)} MB`,breakdown:{position:`${(t/(1024*1024)).toFixed(2)} MB`,normal:`${(n/(1024*1024)).toFixed(2)} MB`,color:`${(r/(1024*1024)).toFixed(2)} MB`,uv:`${(s/(1024*1024)).toFixed(2)} MB`,index:`${(a/(1024*1024)).toFixed(2)} MB`,shaderInstances:`${(o/(1024*1024)).toFixed(2)} MB`}}}dispose(){let e=[...this.activeSections.keys()];for(let t of e)this.releaseSection(t);this.signHeadsRenderer.dispose();for(let t of this.meshPool)t.mesh.geometry.dispose();this.meshPool.length=0,this.activeSections.clear(),this.chunkBoxMaterial.dispose(),this.shaderSectionRaycastBoxes.clear(),this.globalBlockBuffer?.dispose(),this.globalBlockBuffer=null,this.cubeShaderMaterial?.dispose(),this.cubeShaderMaterial=null,this.pendingNearReveal.clear();for(let t of this.nearRevealTimers.values())clearTimeout(t);this.nearRevealTimers.clear();for(let t of this.nearRevealGraceTimers.values())clearTimeout(t);this.nearRevealGraceTimers.clear()}acquireMesh(){if(this.bypassPooling){let t={mesh:new je(new it,this.material),inUse:!0,lastUsedTime:performance.now()};return this.meshPool.push(t),this.poolSize++,t}for(let t of this.meshPool)if(!t.inUse)return t.inUse=!0,t.lastUsedTime=performance.now(),this.hits++,t;this.misses++;let e=Math.min(this.poolSize+16,this.maxPoolSize);e<=this.meshPool.length&&(e=this.meshPool.length+8,this.maxPoolSize=e,console.warn(`ChunkMeshManager: Pool exhausted (${this.poolSize}/${this.maxPoolSize}). Emergency expansion to ${e}`)),this.expandPool(e);for(let t=this.meshPool.length-1;t>=0;t--){let n=this.meshPool[t];if(!n.inUse)return n.inUse=!0,n.lastUsedTime=performance.now(),n}throw new Error("ChunkMeshManager: Failed to acquire mesh after pool expansion")}expandPool(e){let t=this.meshPool.length;this.poolSize=e;for(let n=t;n<e;n++){let r=new it,s=new je(r,this.material);s.visible=!1,s.matrixAutoUpdate=!1,s.name="pooled-section-mesh";let a={mesh:s,inUse:!1,lastUsedTime:0};this.meshPool.push(a)}}updateGeometryAttribute(e,t,n,r){let s=e.getAttribute(t);s&&s.count===n.length/r?(s.array.set(n),s.needsUpdate=!0):e.setAttribute(t,new dt(n,r))}clearGeometry(e){let t=["position","normal","color","uv"];for(let n of t)e.hasAttribute(n)&&e.deleteAttribute(n);e.index&&e.setIndex(null),e.boundingBox=null,e.boundingSphere=null}cleanupExcessMeshes(){if(this.poolSize>this.maxPoolSize){let e=this.meshPool.filter(t=>!t.inUse).length;if(e>0){let t=Math.min(this.poolSize-this.maxPoolSize,e);for(let n=0;n<t;n++){let r=this.meshPool.findIndex(s=>!s.inUse);r!==-1&&(this.meshPool[r].mesh.geometry.dispose(),this.meshPool.splice(r,1),this.poolSize--)}}}}disposeContainer(e){Hn(e,!0)}recordRenderTime(e){this.renderTimes.push(e),this.renderTimes.length>this.maxRenderTimeSamples&&this.renderTimes.shift();let t=performance.now();t-this.lastPerformanceCheck>this.performanceCheckInterval&&(this.checkPerformance(),this.lastPerformanceCheck=t)}getEffectiveRenderDistance(){return this.performanceOverrideDistance||this.worldRenderer.viewDistance}resetPerformanceOverride(){this.performanceOverrideDistance=void 0,this.renderTimes.length=0,console.log("ChunkMeshManager: Performance override reset")}getAverageRenderTime(){return this.renderTimes.length===0?0:this.renderTimes.reduce((e,t)=>e+t,0)/this.renderTimes.length}checkPerformance(){if(this.renderTimes.length<this.maxRenderTimeSamples)return;let e=this.getAverageRenderTime(),t=16.67,n=t*1.5;if(e>n){let r=this.worldRenderer.viewDistance,s=Math.max(1,Math.floor(r*.8));(!this.performanceOverrideDistance||s<this.performanceOverrideDistance)&&(this.performanceOverrideDistance=s,console.warn(`ChunkMeshManager: Performance degraded (${e.toFixed(2)}ms avg). Reducing effective render distance to ${s}`))}else if(this.performanceOverrideDistance&&e<t*1.1){let r=this.worldRenderer.viewDistance,s=Math.min(r,this.performanceOverrideDistance+1);s!==this.performanceOverrideDistance&&(this.performanceOverrideDistance=s>=r?void 0:s,console.log(`ChunkMeshManager: Performance improved. Restoring render distance to ${s}`))}}updateSectionsVisibility(){let e=this.worldRenderer.cameraSectionPos;for(let[t,n]of Object.entries(this.sectionObjects)){if(n._waitingForChunkDisplay){n.visible=!1;continue}if(!this.performanceOverrideDistance){n.visible=!0;continue}let[r,s,a]=t.split(",").map(Number),o={x:r/16,y:s/16,z:a/16},l=o.x-e.x,c=o.z-e.z,u=Math.floor(Math.hypot(l,c));n.visible=u<=this.performanceOverrideDistance}}};Cn(gu,"NEAR_REVEAL_TIMEOUT_MS",5e3),Cn(gu,"EXPECTED_NEAR_GRACE_MS",1500);var em=gu,bR=class{constructor(e){this.worldRendererThree=e}chunkTextures=new Map;dispose(){for(let[,e]of this.chunkTextures)for(let t of Object.keys(e))e[t].dispose();this.chunkTextures.clear()}renderHead(e,t,n,r){let s;if(r.SkullOwner?s=r.SkullOwner.Properties?.textures?.[0]?.Value:s=r.profile?.properties?.find(a=>a.name==="textures")?.value,!!s)try{let o=JSON.parse(Buffer.from(s,"base64").toString()).textures?.SKIN?.url,{skinTexturesProxy:l}=this.worldRendererThree.worldRendererConfig;l&&(o=o?.replace("http://textures.minecraft.net/",l).replace("https://textures.minecraft.net/",l));let c=kl(this.worldRendererThree,o,Cl.head),u=new ot;return n&&c.position.set(0,.3125,.3125),c.position.y-=23/16,u.add(c),this.worldRendererThree.sceneOrigin.track(u),u.position.set(e.x+.5,e.y+.045,e.z+.5),u.rotation.set(0,-yt.degToRad(t*(n?90:45/2)),0),u.scale.set(.8,.8,.8),u}catch(a){console.error("Error decoding player texture:",a)}}renderSign(e,t,n,r,s){let a=this.getSignTexture(e,s,r);if(!a)return;let o=new je(new vn(1,1),new st({map:a,transparent:!0}));o.renderOrder=999;let l=7/16,c=r?1.3:1;o.scale.set(1*c,l*c,1*c);let u=(r?2:1.5)/16,f=.25/16;n&&!r?o.position.set(0,0,-.5+u+f+1e-4):o.position.set(0,0,u/2+1e-4);let m=new ot;m.rotation.set(0,-yt.degToRad(t*(n?90:45/2)),0),m.add(o);let v=(r?10:8)/16,y=(r?0:n?4.333:9.333)/16,_=v/2+y;return this.worldRendererThree.sceneOrigin.track(m),m.position.set(e.x+.5,e.y+_,e.z+.5),m}getSignTexture(e,t,n,r=!1){let s=d1(e),a=this.chunkTextures.get(`${s[0]},${s[1]}`);a||(a={},this.chunkTextures.set(`${s[0]},${s[1]}`,a));let o=`${e.x},${e.y},${e.z}`;if(a[o])return a[o];let l=(0,Zme.default)(this.worldRendererThree.version),c=w7(t,n,l);if(!c)return;let u=new Gt(c);return u.magFilter=Je,u.minFilter=Je,u.needsUpdate=!0,a[o]=u,u}cleanChunkTextures(e,t){let n=`${Math.floor(e/16)},${Math.floor(t/16)}`,r=this.chunkTextures.get(n);if(r)for(let s of Object.keys(r))r[s].dispose(),delete r[s]}};h();p();d();h();p();d();bt();var n8={},Qme=!1;function Fqe(){if(Qme)return;let i=globalThis.loadedData?.tints;if(i){for(let e of Object.keys(i))n8[e]=zqe(i[e]);Qme=!0}}function zqe(i){let e={},t=e3e(i.default??16777215);if(i.data)for(let n of i.data){let r=e3e(n.color);for(let s of n.keys)e[s]=r}return new Proxy(e,{get(n,r){return n[r]??t}})}function e3e(i){return[(i>>16&255)/255,(i>>8&255)/255,(i&255)/255]}function t3e(i,e){return Fqe(),i==="grass_block"?[1,1,1]:i==="redstone_wire"?[1,1,1]:i==="birch_leaves"||i==="spruce_leaves"||i==="lily_pad"?n8.constant?.[i]??[1,1,1]:i.includes("leaves")||i==="vine"?n8.foliage?.[e]??[1,1,1]:["short_grass","tall_grass","fern","large_fern","sugar_cane","grass"].includes(i)?n8.grass?.[e]??[1,1,1]:[1,1,1]}var Hqe=512,_R=1/20,wR=class{constructor(e){this.worldRenderer=e}particles=[];sharedMaterial;enabled=!1;tickAccumulator=0;nextParticleIndex=0;enable(){this.enabled||(this.enabled=!0,this.ensureMaterial())}disable(){this.enabled&&(this.enabled=!1)}dispose(){for(let e of this.particles)e.active&&this.worldRenderer.sceneOrigin.removeAndUntrack(e.mesh),e.mesh.geometry.dispose();this.particles=[],this.sharedMaterial?.dispose(),this.sharedMaterial=void 0,this.nextParticleIndex=0}render=e=>{if(!this.enabled)return;for(this.tickAccumulator+=e;this.tickAccumulator>=_R;)this.tickAccumulator-=_R,this.tickPhysics();let t=this.tickAccumulator/_R;this.updateVisuals(t)};spawnBlockBreakParticles(e,t,n,r,s,a="plains"){if(!this.enabled)return;let o=this.resolveBlockTexture(r);if(!o)return;let l=t3e(r,a);for(let c=0;c<4;c++)for(let u=0;u<4;u++)for(let f=0;f<4;f++){let m=e+(c+.5)/4,v=t+(u+.5)/4,y=n+(f+.5)/4,_=m-e-.5,b=v-t-.5,g=y-n-.5;_+=(Math.random()*2-1)*.4,b+=(Math.random()*2-1)*.4,g+=(Math.random()*2-1)*.4;let x=(Math.random()+Math.random()+1)*.15,w=Math.sqrt(_*_+b*b+g*g),E=_/w*x*.4,A=b/w*x*.4+.1,P=g/w*x*.4,C=Math.floor(4/(Math.random()*.9+.1));this.createParticle(m,v,y,E,A,P,C,o,s,e,n,1,l)}}tickPhysics(){for(let e of this.particles){if(!e.active)continue;if(e.prevX=e.x,e.prevY=e.y,e.prevZ=e.z,e.age++,e.age>=e.maxAge){this.deactivateParticle(e);continue}e.yd-=.04,e.x+=e.xd,e.y+=e.yd,e.z+=e.zd;let t=this.getFloorY(e);e.y<=t?(e.y=t,e.yd=0,e.onGround=!0):e.onGround=!1,e.xd*=.98,e.yd*=.98,e.zd*=.98,e.onGround&&(e.xd*=.7,e.zd*=.7)}}updateVisuals(e){let t=this.worldRenderer.camera.position;for(let n of this.particles){if(!n.active)continue;let r=n.prevX+(n.x-n.prevX)*e,s=n.prevY+(n.y-n.prevY)*e,a=n.prevZ+(n.z-n.prevZ)*e;n.mesh.position.set(r,s,a),n.mesh.lookAt(t.x,t.y,t.z)}}spawnCrackParticle(e,t,n,r,s,a,o="plains"){if(!this.enabled)return;let l=this.resolveBlockTexture(s);if(!l)return;let c=t3e(s,o),u=e+Math.random()*.8+.1,f=t+Math.random()*.8+.1,m=n+Math.random()*.8+.1;switch(r){case 0:f=t-.1;break;case 1:f=t+1+.1;break;case 2:m=n-.1;break;case 3:m=n+1+.1;break;case 4:u=e-.1;break;case 5:u=e+1+.1;break}let v=(Math.random()*2-1)*.4*.2,y=(Math.random()*2-1)*.4*.2+.1*.2,_=(Math.random()*2-1)*.4*.2,b=Math.floor(4/(Math.random()*.9+.1));this.createParticle(u,f,m,v,y,_,b,l,a,e,n,.6,c)}createParticle(e,t,n,r,s,a,o,l,c,u,f,m=1,v=[1,1,1]){this.ensureMaterial();let y=this.findInactiveParticle();y||(this.particles.length<Hqe?y=this.allocateParticle():y=this.recycleOldest());let _=Math.floor(Math.random()*4),b=Math.floor(Math.random()*4),g=l.u+_/4*l.su,x=l.v+b/4*l.sv,w=l.su/4,E=l.sv/4;this.setGeometryUVs(y.mesh.geometry,g,x,w,E),y.active=!0,y.x=e,y.y=t,y.z=n,y.prevX=e,y.prevY=t,y.prevZ=n,y.xd=r,y.yd=s,y.zd=a,y.age=0,y.maxAge=o,y.onGround=!1,y.floorMap=c,y.blockX=Math.floor(u),y.blockZ=Math.floor(f);let A=.1*(.5+Math.random()*.5)*2*m;y.mesh.scale.set(A,A,A),y.mesh.position.set(e,t,n),y.mesh.visible=!0;let P=.6*v[0],C=.6*v[1],L=.6*v[2],M=new Float32Array([P,C,L,P,C,L,P,C,L,P,C,L]),T=y.mesh.geometry.getAttribute("color");T?(T.set(M),T.needsUpdate=!0):y.mesh.geometry.setAttribute("color",new qe(M,3)),this.worldRenderer.sceneOrigin.addAndTrack(y.mesh)}allocateParticle(){let e=new vn(1,1),t=new je(e,this.sharedMaterial);t.visible=!1;let n={mesh:t,active:!1,x:0,y:0,z:0,prevX:0,prevY:0,prevZ:0,xd:0,yd:0,zd:0,age:0,maxAge:0,onGround:!1,floorMap:[],blockX:0,blockZ:0};return this.particles.push(n),n}findInactiveParticle(){for(let e=0;e<this.particles.length;e++){let t=(this.nextParticleIndex+e)%this.particles.length;if(!this.particles[t].active)return this.nextParticleIndex=(t+1)%this.particles.length,this.particles[t]}}recycleOldest(){let e=this.particles[0];for(let t of this.particles)t.age>e.age&&(e=t);return this.deactivateParticle(e),e}deactivateParticle(e){e.active&&(e.active=!1,e.mesh.visible=!1,this.worldRenderer.sceneOrigin.removeAndUntrack(e.mesh))}getFloorY(e){let t=Math.floor(e.x)-e.blockX,n=Math.floor(e.z)-e.blockZ;return t=Math.max(-2,Math.min(2,t)),n=Math.max(-2,Math.min(2,n)),e.floorMap[(n+2)*5+(t+2)]}resolveBlockTexture(e){let t=this.worldRenderer.resourcesManager.currentResources;if(!t)return null;let n=t.blocksAtlasJson,r=n.textures;if(r[e])return this.extractUV(r[e],n);for(let s of["_side","_top","_front","_0",""]){let a=e+s;if(r[a])return this.extractUV(r[a],n)}for(let s of Object.keys(r))if(s.startsWith(e))return this.extractUV(r[s],n);return null}extractUV(e,t){return{u:e.u,v:e.v,su:e.su??t.suSv,sv:e.sv??t.suSv}}setGeometryUVs(e,t,n,r,s){let a=e.getAttribute("uv");a.setXY(0,t,n),a.setXY(1,t+r,n),a.setXY(2,t,n+s),a.setXY(3,t+r,n+s),a.needsUpdate=!0}ensureMaterial(){if(this.sharedMaterial)return;let e=this.worldRenderer.material.map;e&&(this.sharedMaterial=new st({map:e,vertexColors:!0,transparent:!0,alphaTest:.1}))}},n3e={id:"blockBreakParticles",controller:wR,enabledDefault:!0,cannotBeDisabled:!0,requiresHeightmap:!1};h();p();d();var xR=class{constructor(e){this.worldRenderer=e}enabled=!1;lastBobWalkDist=0;lastBobTickTime=0;enable(){this.enabled=!0}disable(){this.enabled=!1,this.worldRenderer.cameraShake.setCameraBobInput(null);let{perspective:e}=this.worldRenderer.playerStateReactive;e==="first_person"&&this.worldRenderer.camera.position.set(0,0,0)}render=()=>{if(!this.enabled)return;let e=this.worldRenderer.displayOptions.inWorldRenderingConfig,{perspective:t}=this.worldRenderer.playerStateReactive;if(e.viewBobbing&&t==="first_person"&&!this.worldRenderer.playerStateUtils.isSpectator()){this.worldRenderer.playerStateReactive.walkDist!==this.lastBobWalkDist&&(this.lastBobTickTime=performance.now(),this.lastBobWalkDist=this.worldRenderer.playerStateReactive.walkDist);let r=Math.min((performance.now()-this.lastBobTickTime)/50,1);this.worldRenderer.cameraShake.setCameraBobInput({walkDist:this.worldRenderer.playerStateReactive.walkDist,prevWalkDist:this.worldRenderer.playerStateReactive.prevWalkDist,bob:this.worldRenderer.playerStateReactive.bob,prevBob:this.worldRenderer.playerStateReactive.prevBob,partialTick:r})}else this.worldRenderer.cameraShake.setCameraBobInput(null)};dispose(){this.disable()}},r3e={id:"cameraBobbing",controller:xR,enabledDefault:!0,cannotBeDisabled:!0};h();p();d();bt();var ER=2e3,i3e=32,s3e=32,r8=12,a3e=24,i8=1.2,qqe=-5;var SR=class{constructor(e){this.worldRenderer=e}instancedMesh;geometry;material;particles=[];enabled=!1;dummy=new ht;tempPosition=new K;tempQuaternion=new Ut;tempScale=new K;enable(){this.enabled||(this.enabled=!0,this.instancedMesh?this.instancedMesh.visible=!0:this.createRain())}disable(){this.enabled&&(this.enabled=!1,this.instancedMesh&&(this.instancedMesh.visible=!1))}autoEnableCheck(){return this.worldRenderer.worldRendererConfig.isRaining===!0}render=e=>{if(!this.enabled||!this.instancedMesh||!this.material)return;this.syncMaterialToSceneFog();let t=this.worldRenderer.getCameraPosition();this.instancedMesh.position.set(0,0,0);let n=this.worldRenderer.reactiveState.world.heightmaps,{dummy:r,tempPosition:s,tempQuaternion:a,tempScale:o}=this,l=NaN,c=NaN,u;for(let f=0;f<ER;f++){let m=this.particles[f];this.instancedMesh.getMatrixAt(f,r),r.decompose(s,a,o),s.addScaledVector(m.velocity,e);let v=s.y,y=Math.sqrt(s.x*s.x+s.z*s.z),_=t.x+s.x,b=t.y+s.y,g=t.z+s.z,x=Math.floor(_/16),w=Math.floor(g/16);(x!==l||w!==c)&&(u=n.get(`${x},${w}`),l=x,c=w);let E=(Math.floor(_)%16+16)%16,A=(Math.floor(g)%16+16)%16,P=u?.[A*16+E];if(y>i3e||P!==void 0&&P!==-32768&&b<=P+1+m.despawnOffset||v<qqe){this.respawnParticle(s);let L=r8+Math.random()*(a3e-r8);m.velocity.set((Math.random()-.5)*i8,-L,(Math.random()-.5)*i8),m.despawnOffset=Math.random()*.5}r.compose(s,a,o),this.instancedMesh.setMatrixAt(f,r)}this.instancedMesh.instanceMatrix.needsUpdate=!0};dispose(){this.instancedMesh&&this.worldRenderer.scene.remove(this.instancedMesh),this.geometry?.dispose(),this.material?.dispose(),this.instancedMesh=void 0,this.geometry=void 0,this.material=void 0,this.particles=[]}syncMaterialToSceneFog(){if(!this.material)return;let e=this.worldRenderer.scene.fog;e instanceof so||e instanceof io?this.material.color.copy(e.color):this.material.color.set(13426158),this.material.fog=!0}createRain(){this.geometry=new nn(.03,.3,.03),this.material=new st({color:13426158,transparent:!0,opacity:.35,depthWrite:!0,fog:!0}),this.instancedMesh=new T0(this.geometry,this.material,ER),this.instancedMesh.name="rain-particles",this.instancedMesh.frustumCulled=!1,this.syncMaterialToSceneFog();let e=new ht,t=new K;for(let n=0;n<ER;n++){this.respawnParticle(t),t.y=Math.random()*s3e,e.setPosition(t),this.instancedMesh.setMatrixAt(n,e);let r=r8+Math.random()*(a3e-r8);this.particles.push({velocity:new K((Math.random()-.5)*i8,-r,(Math.random()-.5)*i8),age:0,despawnOffset:Math.random()*.5})}this.instancedMesh.instanceMatrix.needsUpdate=!0,this.worldRenderer.scene.add(this.instancedMesh)}respawnParticle(e){let t=Math.random()*Math.PI*2,n=Math.random()*i3e;e.set(Math.cos(t)*n,s3e,Math.sin(t)*n)}},o3e={id:"rain",controller:SR,enabledDefault:!1,requiresHeightmap:!0};h();p();d();bt();var l3e=new Fe(13/255,234/255,238/255),Gqe=9;var Wqe=350,jqe=650;var $qe=120,Xqe=280,AR=class{constructor(e){this.worldRenderer=e;this.wireframeMaterial=new fn({color:l3e,transparent:!0,opacity:1,blending:Li,depthWrite:!1}),this.wireframeGlowMaterial=new fn({color:l3e,transparent:!0,opacity:.55,blending:Li,depthWrite:!1})}pendingGeometries=new Map;revealingSections=new Map;finishedChunkCount=0;revealTriggered=!1;revealStartTime=0;enabled=!1;onWorldSwitchedCb=null;patched=!1;initialWaveDone=!1;initialRevealWaveSettled=!1;wireframeMaterial;wireframeGlowMaterial;pulseTime=0;revealedChunks=new Set;originalFinishChunk=null;originalDestroy=null;originalSceneAdd=null;originalHandleWorkerMessage=null;isFuturisticRevealConfigured(){return this.worldRenderer.worldRendererConfig.futuristicReveal===!0}isInInitialRevealCampaign(){return this.enabled&&!this.initialRevealWaveSettled}autoEnableCheck(){return this.isFuturisticRevealConfigured()}enable(){if(this.isFuturisticRevealConfigured()&&!(this.enabled&&this.patched)){if(this.enabled&&!this.patched){this.patchWorldRenderer();return}this.enabled=!0,this.patchWorldRenderer()}}disable(){this.enabled&&(this.enabled=!1,this.unpatchWorldRenderer(),this.reset())}toggle(){return this.enabled?this.disable():this.enable(),this.enabled}render=e=>{this.enabled&&this.update(e*1e3)};dispose(){this.disable(),this.wireframeMaterial.dispose(),this.wireframeGlowMaterial.dispose()}patchWorldRenderer(){if(this.patched)return;this.patched=!0;let e=this.worldRenderer;this.onWorldSwitchedCb=()=>this.reset(),e.onWorldSwitched.push(this.onWorldSwitchedCb),this.originalFinishChunk=e.finishChunk.bind(e),e.finishChunk=t=>{this.originalFinishChunk(t),this.onChunkFinished(t)},this.originalDestroy=e.destroy.bind(e),e.destroy=()=>{this.dispose(),this.originalDestroy()},this.originalHandleWorkerMessage=e.handleWorkerMessage.bind(e),e.handleWorkerMessage=t=>{this.originalHandleWorkerMessage(t),this.enabled&&t?.type==="geometry"&&Promise.resolve().then(()=>{try{this.registerSection(t.key,t.geometry)}catch(n){console.error("[SciFiReveal] registerSection failed",n)}})},this.originalSceneAdd=e.scene.add.bind(e.scene),e.scene.add=(...t)=>{let n=this.originalSceneAdd(...t);for(let r of t)this.checkAndPatchMesh(r);return n}}unpatchWorldRenderer(){let e=this.worldRenderer;if(this.originalFinishChunk&&(e.finishChunk=this.originalFinishChunk,this.originalFinishChunk=null),this.originalDestroy&&(e.destroy=this.originalDestroy,this.originalDestroy=null),this.originalHandleWorkerMessage&&(e.handleWorkerMessage=this.originalHandleWorkerMessage,this.originalHandleWorkerMessage=null),this.originalSceneAdd&&(e.scene.add=this.originalSceneAdd,this.originalSceneAdd=null),this.onWorldSwitchedCb){let t=e.onWorldSwitched.indexOf(this.onWorldSwitchedCb);t!==-1&&e.onWorldSwitched.splice(t,1),this.onWorldSwitchedCb=null}this.patched=!1}checkAndPatchMesh(e){if(e instanceof je&&(e.name==="mesh"||e.name==="shaderMesh")){let t=this.findSectionKeyForMesh(e);t&&this.shouldUseRevealEffect(t)&&(e.visible=!1,e.hiddenByReveal=!0)}for(let t of e.children)this.checkAndPatchMesh(t)}findSectionKeyForMesh(e){let t=e;for(;t;){let{sectionKey:v}=t;if(v&&this.worldRenderer.chunkMeshManager.sectionObjects[v]===t)return v;t=t.parent}let n=this.worldRenderer.sceneOrigin.getWorldPosition(e),r=n?.x??this.worldRenderer.sceneOrigin.toWorldX(e.position.x),s=n?.y??this.worldRenderer.sceneOrigin.toWorldY(e.position.y),a=n?.z??this.worldRenderer.sceneOrigin.toWorldZ(e.position.z),o=16,l=this.worldRenderer.getSectionHeight(),c=Math.floor(r/o)*o,u=Math.floor(s/l)*l,f=Math.floor(a/o)*o,m=`${c},${u},${f}`;return this.worldRenderer.chunkMeshManager.sectionObjects[m]?m:null}get scene(){return this.worldRenderer.realScene}getCameraPosition(){return this.worldRenderer.getCameraPosition()}sectionHasRevealContent(e){return(e.wireframePositions?.length??0)>0||(e.positions?.length??0)>0?!0:(e.shaderCubes?.count??0)>0}getSectionRenderMeshes(e){let t=this.worldRenderer.chunkMeshManager.sectionObjects[e];if(!t)return[];let n=[];for(let r of["mesh","shaderMesh"]){let s=t.children.find(a=>a.name===r);s instanceof je&&n.push(s)}return n}hideSectionRenderMeshes(e){let t=this.getSectionRenderMeshes(e);for(let n of t)n.visible=!1,n.hiddenByReveal=!0;return t}setMeshFadeOpacity(e,t){if(e.name==="shaderMesh"){e.visible=t>.001;return}let n=e.material;if(!Array.isArray(n))if(n.originalMaterial)n.opacity=t,n.transparent=!0,n.needsUpdate=!0;else{n.originalMaterial=n;let r=n.clone();r.transparent=!0,r.opacity=t,r.needsUpdate=!0,e.material=r}}restoreMeshMaterial(e){let t=e.originalMaterial;if(!t)return;let n=e.material;e.material=t,n!==t&&n.dispose(),delete e.originalMaterial}onChunkFinished(e){this.finishedChunkCount++,!this.revealTriggered&&this.finishedChunkCount>=Gqe&&this.triggerReveal()}registerSection(e,t){if(!(this.revealedChunks.has(e)||this.revealingSections.has(e))){if(this.revealTriggered&&this.initialWaveDone){this.revealedChunks.add(e);return}this.revealTriggered?this.startSectionReveal(e,t):this.pendingGeometries.set(e,t)}}shouldUseRevealEffect(e){return!this.enabled||this.revealTriggered&&this.initialWaveDone?!1:!this.revealedChunks.has(e)&&!this.revealingSections.has(e)}triggerReveal(){this.revealTriggered=!0,this.initialWaveDone=!0,this.revealStartTime=performance.now();let e=this.getCameraPosition(),t=[...this.pendingGeometries.entries()];this.pendingGeometries.clear();let n=t.map(([s,a])=>{let o=Math.hypot(a.sx-e.x,a.sy-e.y,a.sz-e.z);return{key:s,geometry:a,distance:o}}).sort((s,a)=>s.distance-a.distance),r=n.at(-1)?.distance||1;for(let{key:s,geometry:a,distance:o}of n){let l=o/r*1500;setTimeout(()=>{!this.revealedChunks.has(s)&&!this.revealingSections.has(s)&&this.startSectionReveal(s,a)},l)}}startSectionReveal(e,t){if(!this.sectionHasRevealContent(t)||this.revealingSections.has(e)||this.revealedChunks.has(e))return;let n=this.createWireframeGeometry(t),r=this.worldRenderer.chunkMeshManager.globalBlockBuffer,s=r?.hasSection(e)?r.takeSectionData(e):void 0,a=this.hideSectionRenderMeshes(e),o=new In(n,this.wireframeMaterial.clone());this.worldRenderer.sceneOrigin.track(o),o.position.set(t.sx,t.sy,t.sz),o.name="scifi-wireframe",o.renderOrder=1e3;let l=new In(n.clone(),this.wireframeGlowMaterial.clone());this.worldRenderer.sceneOrigin.track(l),l.position.set(t.sx,t.sy,t.sz),l.scale.set(1.02,1.02,1.02),l.name="scifi-glow",l.renderOrder=999;let c=new ot;c.add(o),c.add(l),c.name="scifi-reveal-group",c.sectionKey=e,this.scene.add(c);let u=this.initialWaveDone?$qe:Wqe,f=this.initialWaveDone?Xqe:jqe,m={key:e,wireframeGroup:c,revealStartTime:performance.now(),phase:"wireframe",renderMeshRefs:a,globalShaderRestore:s,wireframeMs:u,revealMs:f};setTimeout(()=>{for(let v of this.getSectionRenderMeshes(e))v.hiddenByReveal||this.hideSectionRenderMeshes(e)},0),this.revealingSections.set(e,m)}createSectionBoundsWireframe(){let n=[[-8,-8,-8],[8,-8,-8],[-8,8,-8],[8,8,-8],[-8,-8,8],[8,-8,8],[-8,8,8],[8,8,8]],r=[[0,1],[1,3],[3,2],[2,0],[4,5],[5,7],[7,6],[6,4],[0,4],[1,5],[2,6],[3,7]],s=[];for(let[o,l]of r)s.push(...n[o],...n[l]);let a=new it;return a.setAttribute("position",new qe(s,3)),a}createWireframeGeometry(e){if(e.wireframePositions&&e.wireframePositions.length>0){let o=new it;return o.setAttribute("position",new qe(e.wireframePositions,3)),o}let t=e.positions,n=e.indices;if(!t?.length||!n?.length)return this.createSectionBoundsWireframe();let r=[],s=new Set;for(let o=0;o<n.length;o+=3){let l=n[o],c=n[o+1],u=n[o+2];this.addEdge(t,l,c,r,s),this.addEdge(t,c,u,r,s),this.addEdge(t,u,l,r,s)}let a=new it;return a.setAttribute("position",new qe(r,3)),a}addEdge(e,t,n,r,s){let a=Math.min(t,n),o=Math.max(t,n),l=`${a}-${o}`;s.has(l)||(s.add(l),r.push(e[t*3],e[t*3+1],e[t*3+2],e[n*3],e[n*3+1],e[n*3+2]))}update(e){if(!this.enabled||this.revealingSections.size===0)return;this.pulseTime+=e*.001;let t=performance.now(),n=.6+.4*Math.sin(this.pulseTime*4),r=[];for(let[s,a]of this.revealingSections){let o=t-a.revealStartTime;if(a.phase==="wireframe"){let l=a.wireframeGroup.children[0],c=a.wireframeGroup.children[1];if(l?.material){let u=l.material;u.opacity=n;let f=.85+.15*Math.sin(this.pulseTime*6+o*.002);u.color.setRGB(13/255*f,234/255*f,238/255*f)}if(c?.material){let u=c.material;u.opacity=n*.4}if(o>a.wireframeMs){a.phase="transitioning",a.renderMeshRefs=this.getSectionRenderMeshes(s);for(let u of a.renderMeshRefs)u.visible=!0,this.setMeshFadeOpacity(u,0)}}else if(a.phase==="transitioning"){let l=o-a.wireframeMs,c=Math.min(1,l/a.revealMs),u=1-(1-c)**3,f=a.wireframeGroup.children[0],m=a.wireframeGroup.children[1];if(f?.material){let v=f.material;v.opacity=1-u}if(m?.material){let v=m.material;v.opacity=(1-u)*.55}for(let v of a.renderMeshRefs)this.setMeshFadeOpacity(v,u);c>=1&&(a.phase="complete",r.push(a))}}for(let s of r)this.completeReveal(s)}completeReveal(e){this.revealingSections.delete(e.key),this.revealedChunks.add(e.key),this.revealTriggered&&this.revealingSections.size===0&&(this.initialRevealWaveSettled=!0);for(let t of e.renderMeshRefs)this.restoreMeshMaterial(t),t.visible=!0,delete t.hiddenByReveal;this.worldRenderer.chunkMeshManager.migrateDeferredShaderToGlobal(e.key),e.globalShaderRestore&&this.worldRenderer.chunkMeshManager.globalBlockBuffer?.addSection(e.key,e.globalShaderRestore.words,e.globalShaderRestore.count),this.disposeWireframeGroup(e.wireframeGroup)}disposeWireframeGroup(e){this.worldRenderer.sceneOrigin.removeAndUntrackAll(e);let t=[];e.traverse(n=>{t.push(n)});for(let n of t){let r=n;if(r.geometry&&r.geometry.dispose(),r.material){let s=r.material;if(Array.isArray(s))for(let a of s)a.dispose();else s&&typeof s.dispose=="function"&&s.dispose()}}e.clear()}reset(){for(let e of this.revealingSections.values())this.disposeWireframeGroup(e.wireframeGroup);this.pendingGeometries.clear(),this.revealingSections.clear(),this.revealedChunks.clear(),this.finishedChunkCount=0,this.revealTriggered=!1,this.initialWaveDone=!1,this.initialRevealWaveSettled=!1,this.revealStartTime=0,this.pulseTime=0}forceCompleteAll(){let e=[...this.revealingSections.values()];for(let t of e){t.renderMeshRefs=this.getSectionRenderMeshes(t.key);for(let n of t.renderMeshRefs)this.restoreMeshMaterial(n),n.visible=!0,delete n.hiddenByReveal;this.completeReveal(t)}}debugGetWireframeGroups(){let e=[];return this.scene.traverse(t=>{t.name==="scifi-reveal-group"&&e.push(t)}),e}debugForceCleanup(){let e=this.debugGetWireframeGroups();console.log(`[SciFiReveal] Found ${e.length} wireframe groups in scene`);for(let t of e)console.log("[SciFiReveal] Removing group:",t),this.disposeWireframeGroup(t);for(let t of this.revealingSections.values())this.disposeWireframeGroup(t.wireframeGroup);this.revealingSections.clear(),console.log(`[SciFiReveal] Cleanup complete. Remaining groups: ${this.debugGetWireframeGroups().length}`)}debugStatus(){let e=this.debugGetWireframeGroups(),t=new Set(this.revealingSections.keys()),n=e.filter(r=>!t.has(r.sectionKey));return{revealTriggered:this.revealTriggered,finishedChunkCount:this.finishedChunkCount,pendingGeometries:this.pendingGeometries.size,revealingSections:this.revealingSections.size,revealedChunks:this.revealedChunks.size,wireframeGroupsInScene:e.length,orphanedWireframeGroups:n.length,orphanedKeys:n.map(r=>r.sectionKey),sections:[...this.revealingSections.entries()].map(([r,s])=>({key:r,phase:s.phase,renderMeshCount:s.renderMeshRefs.length,wireframeInScene:s.wireframeGroup.parent!==null}))}}debugLog(){console.log("[SciFiReveal] Status:",this.debugStatus())}},c3e={id:"futuristicReveal",controller:AR,enabledDefault:!0};h();p();d();bt();var Yqe=parseInt(ga.replaceAll(/\D+/g,""),10),MR=class extends gr{constructor(){super({uniforms:{time:{value:0},fade:{value:1}},vertexShader:`
28812
28812
  uniform float time;
28813
28813
  attribute float size;
28814
28814
  varying vec3 vColor;
@@ -28828,7 +28828,7 @@ void main() {
28828
28828
 
28829
28829
  #include <tonemapping_fragment>
28830
28830
  #include <${Yqe>=154?"colorspace_fragment":"encodings_fragment"}>
28831
- }`})}},TR=class{constructor(e){this.worldRenderer=e}points;clock=new ks;enabled=!1;currentTime;enable(){this.enabled||(this.enabled=!0,this.updateVisibility())}disable(){this.enabled&&(this.enabled=!1,this.removeStars())}toggle(){return this.enabled?this.disable():this.enable(),this.enabled}enablementCheck=()=>this.currentTime?this.currentTime>13500&&this.currentTime<23e3:!1;render=e=>{this.points&&(this.points.position.set(0,0,0),this.points.material.uniforms.time.value=this.clock.getElapsedTime()*.2)};updateTimeOfDay(e){this.currentTime=e,this.enabled&&this.updateVisibility()}updateVisibility(){if(!this.enabled)return;let e=this.enablementCheck?.()??!1;e&&!this.points?this.createStars():!e&&this.points&&this.removeStars()}createStars(){if(this.points)return;let e=80,t=50,n=7e3,r=7,s=10,a=new it,o=_=>new K().setFromSpherical(new y5(_,Math.acos(1-Math.random()*2),Math.random()*2*Math.PI)),l=[],c=[],u=Array.from({length:n},()=>(.5+.5*Math.random())*r),f=new Fe,m=e+t,v=t/n;for(let _=0;_<n;_++)m-=v*Math.random(),l.push(...o(m).toArray()),f.setHSL(_/n,s,.9),c.push(f.r,f.g,f.b);a.setAttribute("position",new qe(l,3)),a.setAttribute("color",new qe(c,3)),a.setAttribute("size",new qe(u,1));let y=new MR;y.blending=Li,y.depthTest=!0,y.depthWrite=!1,y.transparent=!0,this.points=new tr(a,y),this.points.renderOrder=-1,this.worldRenderer.scene.add(this.points)}dispose(){this.removeStars()}removeStars(){this.points&&(this.points.geometry.dispose(),this.points.material.dispose(),this.worldRenderer.scene.remove(this.points),this.points=void 0)}},u3e={id:"starfield",controller:TR,enabledDefault:!0,cannotBeDisabled:!0};var f3e={starfield:u3e,futuristicReveal:c3e,rain:o3e,cameraBobbing:r3e,blockBreakParticles:n3e};h();p();d();h();p();d();var RR=()=>({longRenderTime:!1,constantLongRenderTime:!1,tooManyEntities:!1,tooManyTextures:!1,unknownReason:!1});h();p();d();h();p();d();var tm=class{constructor(e){this.factors=e}renderTimeHistory=[];onFrame(e){this.pushRenderTime(e.totalMs),this.recompute(e)}pushRenderTime(e){this.renderTimeHistory.push(e),this.renderTimeHistory.length>24&&this.renderTimeHistory.shift()}recompute(e){let t=e.fps>0&&e.fps<=45,n=Math.max(0,e.totalMs-e.entitiesMs),r=e.totalMs>=30,s=this.renderTimeHistory.length,a=this.renderTimeHistory.filter(m=>m>=30).length,o=s>=8&&a/s>=.65,l=e.loadedTextureCount>=100,c=t&&e.entitiesMs>=8&&n<=20,f=t&&!(r||o||c||l);this.factors.longRenderTime=r,this.factors.constantLongRenderTime=o,this.factors.tooManyEntities=c,this.factors.tooManyTextures=l,this.factors.unknownReason=f}reset(){this.renderTimeHistory.length=0,this.factors.longRenderTime=!1,this.factors.constantLongRenderTime=!1,this.factors.tooManyEntities=!1,this.factors.tooManyTextures=!1,this.factors.unknownReason=!1}};h();p();d();var tGe=[{key:"longRenderTime",code:"LR"},{key:"constantLongRenderTime",code:"CLR"},{key:"tooManyEntities",code:"ENT"},{key:"tooManyTextures",code:"TEX"},{key:"unknownReason",code:"UNK"}];function CR(i){let e=tGe.filter(({key:t})=>i[t]).map(({code:t})=>t);return e.length>0?e.join("+"):""}var yu=class yu extends C7{constructor(t,n,r){if(!r.resourcesManager)throw new Error("resourcesManager is required in displayOptions");super(r.resourcesManager,r,n);this.renderer=t;this.initOptions=n;this.displayOptions=r;this.performanceMonitor=new tm(this.reactiveState.world.instabilityFactors),this.renderer=t,r.rendererState.renderer=yu.getRendererInfo(t)??"...",this.chunkMeshManager=new em(this,this.scene,this.material,this.worldSizeParams.worldHeight,this.viewDistance),this.onRenderDistanceChanged=s=>{this.chunkMeshManager.updateViewDistance(s)},this.cursorBlock=new L4(this),this.holdingBlock=Yp(this),this.holdingBlockLeft=Yp(this,!0);for(let s of Object.values(f3e))this.registerModule(s);this.skyboxRenderer=new H4(this.realScene,!1,null),this.skyboxRenderer.init(),this.addDebugOverlay(),this.resetScene(),this.init(),this.soundSystem=new O4(this),this.cameraShake=new N4(this,this.onRender),this.media=new D4(this),this.fireworksLegacy=new F4(this),this.waypoints=new V4(this),this.cinimaticScript=new z4(this,(s,a,o)=>this.setCinimaticCamera(s,a,o),s=>this.setCinimaticFov(s),()=>({position:new ft(this.cameraWorldPos.x,this.cameraWorldPos.y,this.cameraWorldPos.z),yaw:this.cameraShake.getBaseRotation().yaw,pitch:this.cameraShake.getBaseRotation().pitch,fov:this.camera.fov})),this.fireworks=new q4(this.realScene,this.sceneOrigin),this.renderUpdateEmitter.on("chunkFinished",s=>{this.finishChunk(s)}),this.worldSwitchActions(),this.initializeModules()}outputFormat="threeJs";isShaderCubeBlocksEnabled(){return this.worldRendererConfig.shaderCubeBlocks===!0&&!!this.renderer?.capabilities?.isWebGL2}chunkMeshManager;get sectionObjects(){return this.chunkMeshManager.sectionObjects}chunkTextures=new Map;signsCache=new Map;cameraSectionPos=new ft(0,0,0);holdingBlock;holdingBlockLeft;scene=new yr;get realScene(){return this.scene}ambientLight=new pa(13421772);directionalLight=new as(16777215,.5);entities=new I4(this,globalThis.mcData);performanceMonitor;cameraGroupVr;material=new st({vertexColors:!0,transparent:!0,alphaTest:.1});itemsTexture;cursorBlock;onRender=[];lastRenderTime=0;animatedFov=0;lastFovAnimTime=0;cameraShake;cameraContainer;media;get waitingChunksToDisplay(){return this.chunkMeshManager.waitingChunksToDisplay}waypoints;cinimaticScript;camera;renderTimeAvg=0;pendingSectionUpdates=new Map;pendingSectionBufferStartTimes=new Map;get estimatedMemoryUsage(){return this.chunkMeshManager.getEstimatedMemoryUsage().total}modules={};sectionsOffsetsAnimations={};fountains=[];fireworksLegacy;DEBUG_RAYCAST=!1;skyboxRenderer;fireworks;sceneOrigin=new G4(this.scene);cameraWorldPos={x:0,y:0,z:0};_cameraPositionAccessWarned=!1;_tmpCameraPos=new K;currentPosTween;currentRotTween;_tpDirection=new K;_tpPitchQuat=new Ut;_tpYawQuat=new Ut;_tpFinalQuat=new Ut;_tpScenePos=new K;_tpAxisX=new K(1,0,0);_tpAxisY=new K(0,1,0);_tpRaycaster=new vo;_tpChunkWorldPos=new K;get tilesRendered(){return this.chunkMeshManager.getTotalTiles()}get blocksRendered(){return this.chunkMeshManager.getTotalBlocks()}registerModule(t){if(t.id in this.modules){console.warn(`Module ${t.id} is already registered`);return}let n=new t.controller(this),r={manifest:t,controller:n,enabled:!1,toggle:()=>this.toggleModule(t.id)};this.modules[t.id]=r,t.enabledDefault&&this.toggleModule(t.id,!0)}enableModule(t){let n=this.modules[t];if(!n){console.warn(`Module ${t} not found`);return}n.enabled||(n.enabled=!0,n.controller.enable(),n.controller.render&&this.onRender.push(n.controller.render))}disableModule(t){let n=this.modules[t];if(!n){console.warn(`Module ${t} not found`);return}if(n.manifest.cannotBeDisabled){console.warn(`Module ${t} cannot be disabled`);return}if(n.enabled&&(n.enabled=!1,n.controller.disable(),n.controller.render)){let r=this.onRender.indexOf(n.controller.render);r>-1&&this.onRender.splice(r,1)}}toggleModule(t,n){let r=this.modules[t];if(!r)return console.warn(`Module ${t} not found`),!1;let s=n!==void 0?n:!r.enabled;if(s===r.enabled)return r.enabled;if(!s&&r.manifest.cannotBeDisabled)return console.warn(`Module ${t} cannot be disabled`),!0;if(r.enabled=s,s)r.controller.enable(),r.controller.render&&!this.onRender.includes(r.controller.render)&&this.onRender.push(r.controller.render);else if(r.controller.disable(),r.controller.render){let a=this.onRender.indexOf(r.controller.render);a>-1&&this.onRender.splice(a,1)}return s}disposeModules(){for(let t of Object.values(this.modules))t.controller.dispose();this.modules={}}initializeModules(){this.updateModulesFromConfig()}getModule(t){return this.modules[t]?.controller}anyModuleRequiresHeightmap(){return Object.values(this.modules).some(t=>t.enabled&&t.manifest.requiresHeightmap)}get cameraObject(){return this.cameraGroupVr??this.cameraContainer}_wrapCameraPositionWithWarning(){let t=this.camera.position,n=this,r=20,s=(l,c,u)=>Math.abs(l)>r||Math.abs(c)>r||Math.abs(u)>r,a=()=>{!n._cameraPositionAccessWarned&&typeof process<"u"},o=new Proxy(t,{set(l,c,u){return(c==="x"||c==="y"||c==="z")&&typeof u=="number"&&Math.abs(u)>r&&a(),l[c]=u,!0},get(l,c,u){let f=l[c];return c==="set"?function(m,v,y){return s(m,v,y)&&a(),l.set(m,v,y)}:c==="setX"||c==="setY"||c==="setZ"?function(m){return Math.abs(m)>r&&a(),l[c](m)}:c==="copy"?function(m){return s(m.x,m.y,m.z)&&a(),l.copy(m)}:typeof f=="function"?f.bind(l):f}});Object.defineProperty(this.camera,"position",{value:o,configurable:!0,enumerable:!0})}worldSwitchActions(){this.onWorldSwitched.push(()=>{this.protocolCustomBlocks.clear(),this.sectionsOffsetsAnimations={},this.waypoints.clear(),this.cinimaticScript.stopScript(),this.fireworks.clear()})}downloadWorldGeometry(){vR(this,new K(this.cameraWorldPos.x,this.cameraWorldPos.y,this.cameraWorldPos.z),this.cameraShake.getBaseRotation(),"world-geometry.json")}updateEntity(t,n=!1){let r={rotation:{head:{x:t.headPitch??t.pitch,y:t.headYaw,z:0}}};n?this.entities.updateEntityPosition(t,!1,r):this.entities.update(t,r)}updatePlayerEntity(t){this.entities.handlePlayerEntity(t)}resetScene(){this.sceneOrigin.update(0,0,0),this.cameraWorldPos.x=0,this.cameraWorldPos.y=0,this.cameraWorldPos.z=0,this.scene.matrixAutoUpdate=!1,this.scene.background=new Fe(this.initOptions.config.sceneBackground),this.scene.add(this.ambientLight),this.directionalLight.position.set(1,1,.5).normalize(),this.directionalLight.castShadow=!0,this.scene.add(this.directionalLight);let t=this.renderer.getSize(new Ue);this.camera=new Yt(75,t.x/t.y,.1,1e3),this._wrapCameraPositionWithWarning(),this.cameraContainer=new At,this.cameraContainer.add(this.camera),this.scene.add(this.cameraContainer)}watchReactivePlayerState(){super.watchReactivePlayerState(),this.onReactivePlayerStateUpdated("inWater",t=>{this.skyboxRenderer.updateWaterState(t,this.playerStateReactive.waterBreathing)}),this.onReactivePlayerStateUpdated("waterBreathing",t=>{this.skyboxRenderer.updateWaterState(this.playerStateReactive.inWater,t)}),this.onReactivePlayerStateUpdated("ambientLight",t=>{t&&(this.ambientLight.intensity=t)}),this.onReactivePlayerStateUpdated("directionalLight",t=>{t&&(this.directionalLight.intensity=t)}),this.onReactivePlayerStateUpdated("lookingAtBlock",t=>{this.cursorBlock.setHighlightCursorBlock(t?new ft(t.x,t.y,t.z):null,t?.shapes)}),this.onReactivePlayerStateUpdated("diggingBlock",t=>{this.cursorBlock.updateBreakAnimation(t?{x:t.x,y:t.y,z:t.z}:void 0,t?.stage??null,t?.mergedShape)}),this.onReactivePlayerStateUpdated("perspective",t=>{let n=new ft(this.cameraWorldPos.x,this.cameraWorldPos.y,this.cameraWorldPos.z);this.updateCamera(n,this.cameraShake.getBaseRotation().yaw,this.cameraShake.getBaseRotation().pitch)})}watchReactiveConfig(){super.watchReactiveConfig(),this.onReactiveConfigUpdated("showChunkBorders",n=>{this.updateShowChunksBorder(n)}),this.onReactiveConfigUpdated("defaultSkybox",n=>{this.skyboxRenderer.updateDefaultSkybox(n)}),this.onReactiveConfigUpdated("shaderCubeDebugMode",()=>{this.chunkMeshManager.syncCubeShaderUniforms()}),this.onReactiveConfigUpdated("futuristicReveal",()=>{this.updateModulesFromConfig()});let t=this.displayOptions.inWorldRenderingConfig.handRenderer;this.onReactiveConfigUpdated("handRenderer",n=>{if(n===t)return;t=n;let r=this.holdingBlock.ready,s=this.holdingBlockLeft.ready;this.holdingBlock.dispose(),this.holdingBlockLeft.dispose(),this.holdingBlock=Yp(this),this.holdingBlockLeft=Yp(this,!0),r&&(this.holdingBlock.ready=!0,this.holdingBlock.updateItem()),s&&(this.holdingBlockLeft.ready=!0,this.holdingBlockLeft.updateItem())}),this.onReactiveConfigUpdated("*",()=>{this.updateModulesFromConfig()}),this.updateModulesFromConfig()}updateModulesFromConfig(){let{moduleStates:t}=this.worldRendererConfig;for(let[n,r]of Object.entries(this.modules)){let s=t[n];if(s==="enabled"){r.enabled||this.toggleModule(n,!0);continue}if(s==="disabled"){r.enabled&&!r.manifest.cannotBeDisabled&&this.toggleModule(n,!1);continue}if(s==="auto"||s===void 0)if(r.controller.autoEnableCheck){let a=r.controller.autoEnableCheck();a&&!r.enabled?this.toggleModule(n,!0):!a&&r.enabled&&!r.manifest.cannotBeDisabled&&this.toggleModule(n,!1)}else{let a=r.manifest.enabledDefault??!1;a&&!r.enabled?this.toggleModule(n,!0):!a&&r.enabled&&!r.manifest.cannotBeDisabled&&this.toggleModule(n,!1)}}}changeHandSwingingState(t,n=!1){let r=n?this.holdingBlockLeft:this.holdingBlock;t?r.startSwing():r.stopSwing()}async updateAssetsData(){let t=this.resourcesManager.currentResources,n=this.material.map,r=this.itemsTexture,s=yp(t.blocksAtlasImage);s.needsUpdate=!0,s.flipY=!1,this.material.map=s,this.chunkMeshManager.syncCubeShaderUniforms();let a=yp(t.itemsAtlasImage);a.needsUpdate=!0,a.flipY=!1,this.itemsTexture=a,n&&n.dispose(),r&&r.dispose(),await super.updateAssetsData(),this.onAllTexturesLoaded(),Object.keys(this.loadedChunks).length>0&&(console.log("rerendering chunks because of texture update"),this.rerenderAllChunks())}onAllTexturesLoaded(){this.holdingBlock.ready=!0,this.holdingBlock.updateItem(),this.holdingBlockLeft.ready=!0,this.holdingBlockLeft.updateItem()}changeBackgroundColor(t){this.realScene.background=new Fe(t[0],t[1],t[2])}changeCardinalLight(t){this.worldRendererConfig.cardinalLight=t}timeUpdated(t){let n=this.getModule("starfield");n?.updateTimeOfDay&&n.updateTimeOfDay(t),this.skyboxRenderer.updateTime(t)}biomeUpdated(t){t?.temperature!==void 0&&this.skyboxRenderer.updateTemperature(t.temperature)}biomeReset(){this.skyboxRenderer.updateTemperature(cR)}getItemRenderData(t,n){return Tme(t,n,this.resourcesManager,this.playerStateReactive)}async demoModel(){let t=cursorBlockRel(0,1,0).position,n=await Hp();Tde(n,t);let r=new va(n,16776960);n.add(r),this.realScene.add(n)}demoItem(){let t=cursorBlockRel(0,1,0).position,{mesh:n}=this.entities.getItemMesh({itemId:541},{});n.position.set(t.x+.5,t.y+.5,t.z+.5);let r=new va(n,16776960);n.add(r),this.realScene.add(n)}debugOverlayAdded=!1;addDebugOverlay(){if(this.debugOverlayAdded)return;this.debugOverlayAdded=!0;let t=M7("debug-overlay",80,0,void 0,{className:A7});setInterval(()=>{if(t.setVisibility(this.displayAdvancedStats),this.displayAdvancedStats){let n=l=>new Intl.NumberFormat("en-US",{}).format(l),r=l=>new Intl.NumberFormat("en-US",{notation:"compact",maximumFractionDigits:1}).format(l),s="";s+=`TE: ${n(this.renderer.info.memory.textures)} `,s+=`F: ${r(this.tilesRendered)} `,s+=`B: ${r(this.blocksRendered)} `,s+=`MEM: ${this.chunkMeshManager.getEstimatedMemoryUsage().total} `;let a=this.chunkMeshManager.getStats();s+=`POOL: ${a.activeCount}/${a.poolSize} `;let o=CR(this.reactiveState.world.instabilityFactors);o&&(s+=`PF: ${o} `),t.updateText(s),this.backendInfoReport=s}},200)}updatePosDataChunk(t){let n=this.sectionObjects[t];if(!n)return;let[r,s,a]=t.split(",").map(u=>Math.floor(+u/16)),l=500-(Math.abs(r-this.cameraSectionPos.x)+Math.abs(s-this.cameraSectionPos.y)+Math.abs(a-this.cameraSectionPos.z)),c=n.mesh??n.shaderMesh??n.children.find(u=>u.name==="mesh"||u.name==="shaderMesh");c&&(c.renderOrder=l)}updateViewerPosition(t){this.viewerChunkPosition=t}cameraSectionPositionUpdate(){for(let t in this.sectionObjects)this.sectionObjects[t]&&this.updatePosDataChunk(t)}getDir(t,n){return t===n?0:t<n?1:-1}finishChunk(t){this.chunkMeshManager.finishChunkDisplay(t)}applyPendingSectionUpdates(){if(this.pendingSectionUpdates.size===0)return;let t=performance.now(),n=this.getSectionHeight(),r=[];for(let s of this.pendingSectionUpdates.keys()){let a=this.pendingSectionBufferStartTimes.get(s)??t;if(t-a<yu.MAX_SECTION_UPDATE_BUFFER_MS){let[l,c,u]=s.split(",").map(Number),f=[`${l-16},${c},${u}`,`${l+16},${c},${u}`,`${l},${c-n},${u}`,`${l},${c+n},${u}`,`${l},${c},${u-16}`,`${l},${c},${u+16}`],m=!1;for(let v of f)if(this.sectionsWaiting.has(v)&&!this.pendingSectionUpdates.has(v)&&this.sectionObjects[v]){m=!0;break}if(m)continue}r.push(s)}if(r.length!==0)for(let s of r){let a=this.pendingSectionUpdates.get(s);this.pendingSectionUpdates.delete(s),this.pendingSectionBufferStartTimes.delete(s);let o=a.key.split(","),l=`${o[0]},${o[2]}`;if(!this.loadedChunks[l]||!this.active){this.chunkMeshManager.releaseSection(a.key);continue}if(!this.chunkMeshManager.sectionHasRenderableContent(a.geometry)){this.chunkMeshManager.releaseSection(a.key);continue}this.chunkMeshManager.updateSection(a.key,a.geometry),this.updatePosDataChunk(a.key)}}clearPendingSectionUpdatesForChunk(t,n){for(let r of[...this.pendingSectionUpdates.keys()])r.startsWith(`${t},`)&&r.endsWith(`,${n}`)&&(this.pendingSectionUpdates.delete(r),this.pendingSectionBufferStartTimes.delete(r))}handleWorkerMessage(t){if(t.type==="geometry"){let n=t.key.split(","),r=`${n[0]},${n[2]}`;if(!this.loadedChunks[r]||!this.active){this.pendingSectionUpdates.delete(t.key),this.pendingSectionBufferStartTimes.delete(t.key);return}if(this.sectionObjects[t.key]){this.pendingSectionUpdates.set(t.key,t),this.pendingSectionBufferStartTimes.has(t.key)||this.pendingSectionBufferStartTimes.set(t.key,performance.now());return}if(!this.chunkMeshManager.sectionHasRenderableContent(t.geometry)){this.chunkMeshManager.releaseSection(t.key);return}this.chunkMeshManager.updateSection(t.key,t.geometry),this.updatePosDataChunk(t.key)}}getSignTexture(t,n,r,s=!1){let a=d1(t),o=this.chunkTextures.get(`${a[0]},${a[1]}`);o||(o={},this.chunkTextures.set(`${a[0]},${a[1]}`,o));let l=`${t.x},${t.y},${t.z}`;if(o[l])return o[l];let c=(0,p3e.default)(this.version),u=w7(n,r,c);if(!u)return;let f=new Gt(u);return f.magFilter=Je,f.minFilter=Je,f.needsUpdate=!0,o[l]=f,f}getCameraPosition(t){return(t??this._tmpCameraPos).set(this.cameraWorldPos.x,this.cameraWorldPos.y,this.cameraWorldPos.z)}getSectionCameraPosition(){let t=this.getCameraPosition();return new ft(Math.floor(t.x/16),Math.floor(t.y/16),Math.floor(t.z/16))}updateCameraSectionPos(){let t=this.getSectionCameraPosition();this.cameraSectionPos.equals(t)||(this.cameraSectionPos=t,this.cameraSectionPositionUpdate())}setFirstPersonCamera(t,n,r){let s=this.playerStateReactive.eyeHeight;this.updateCamera(t?.offset(0,s,0)??null,n,r),this.updateCameraSectionPos()}getThirdPersonCamera(t,n,r){t??=new K(this.cameraWorldPos.x,this.cameraWorldPos.y,this.cameraWorldPos.z);let s=this.playerStateReactive.perspective==="third_person_back",a=4,o=this._tpDirection.set(0,0,-1),l=this._tpPitchQuat.setFromAxisAngle(this._tpAxisX,r),c=this._tpYawQuat.setFromAxisAngle(this._tpAxisY,n),u=this._tpFinalQuat.multiplyQuaternions(c,l);o.applyQuaternion(u),s&&o.multiplyScalar(-1),this.DEBUG_RAYCAST&&this.debugRaycast(t,o,a);let f=this._tpScenePos.set(this.sceneOrigin.toSceneX(t.x),this.sceneOrigin.toSceneY(t.y),this.sceneOrigin.toSceneZ(t.z)),m=this._tpRaycaster;m.set(f,o),m.far=a;let v=80,y=v*v,_=t.x,b=t.y,g=t.z,x=[];for(let C of Object.values(this.sectionObjects)){if(C.name!=="chunk"||!C.visible||C.worldX===void 0)continue;let L=C.worldX-_,M=C.worldY-b,T=C.worldZ-g;if(L*L+M*M+T*T>y)continue;let F=C.children.find(Z=>Z.name==="mesh"||Z.name==="shaderMesh");F&&x.push(F)}let w=m.intersectObjects(x,!1),E=a;w.length>0&&(E=Math.max(.5,w[0].distance-.2));let A=this.chunkMeshManager.raycastShaderSectionAABBs(t,o,E,v);return A!==void 0&&(E=Math.max(.5,A-.2)),new ft(t.x+o.x*E,t.y+o.y*E,t.z+o.z*E)}debugRaycastHelper;debugHitPoint;debugRaycast(t,n,r){this.debugRaycastHelper&&(this.realScene.remove(this.debugRaycastHelper),this.debugRaycastHelper=void 0),this.debugHitPoint&&(this.realScene.remove(this.debugHitPoint),this.debugHitPoint=void 0);let s=new K(this.sceneOrigin.toSceneX(t.x),this.sceneOrigin.toSceneY(t.y),this.sceneOrigin.toSceneZ(t.z));this.debugRaycastHelper=new bc(n.clone().normalize(),s,r,16711680,r*.1,r*.05),this.realScene.add(this.debugRaycastHelper);let a=new is(.2,8,8),o=new st({color:65280});this.debugHitPoint=new je(a,o),this.debugHitPoint.position.copy(s).add(n.clone().multiplyScalar(r)),this.realScene.add(this.debugHitPoint)}prevFramePerspective=null;setCinimaticCamera(t,n,r){this.cameraWorldPos.x=t.x,this.cameraWorldPos.y=t.y,this.cameraWorldPos.z=t.z,this.sceneOrigin.update(t.x,t.y,t.z),this.cameraObject.position.set(0,0,0),this.cameraShake.setBaseRotation(r,n),this.updateCameraSectionPos()}setCinimaticFov(t){this.animatedFov=t,this.camera.fov=t,this.camera.updateProjectionMatrix()}updateSmoothFov(){if(this.cinimaticScript.running)return;let t=this.displayOptions.inWorldRenderingConfig.fov,n=this.playerStateReactive.fovMultiplier,r=t*(Number.isFinite(n)?n:1),s=performance.now();if(this.animatedFov===0&&(this.animatedFov=r),Math.abs(this.animatedFov-r)>=.01){let a=s-this.lastFovAnimTime,o=Math.min(a/yu.FOV_TRANSITION_MS,1),l=c=>1-(1-c)**3;this.animatedFov+=(r-this.animatedFov)*l(o),Math.abs(this.animatedFov-r)<.01&&(this.animatedFov=r)}else this.animatedFov=r;this.lastFovAnimTime=s,this.camera.fov!==this.animatedFov&&(this.camera.fov=this.animatedFov,this.camera.updateProjectionMatrix())}updateCamera(t,n,r){if(!this.cinimaticScript.running){if(t){this.renderer.xr.isPresenting&&(t.y-=this.camera.position.y),this.currentPosTween?.stop();let s=this.displayOptions.inWorldRenderingConfig.instantCameraUpdate?0:this.playerStateUtils.isSpectatingEntity()?150:50;this.currentPosTween=new xr(this.cameraWorldPos).to({x:t.x,y:t.y,z:t.z},s).onUpdate(()=>{this.sceneOrigin.update(this.cameraWorldPos.x,this.cameraWorldPos.y,this.cameraWorldPos.z),this.cameraObject.position.set(0,0,0)}).start()}if(this.playerStateUtils.isSpectatingEntity()){let s=this.cameraShake.getBaseRotation(),a=0,o=Math.PI/2;s.yaw<o&&n>Math.PI+o?a=-Math.PI*2:n<o&&s.yaw>Math.PI+o&&(a=Math.PI*2),this.currentRotTween?.stop(),this.currentRotTween=new xr(s).to({pitch:r,yaw:n+a},100).onUpdate(l=>this.cameraShake.setBaseRotation(l.pitch,l.yaw-a)).start()}else{this.currentRotTween?.stop(),this.cameraShake.setBaseRotation(r,n);let{perspective:s}=this.playerStateReactive;if(s==="third_person_back"||s==="third_person_front"){let a=new K(this.cameraWorldPos.x,this.cameraWorldPos.y,this.cameraWorldPos.z),o=this.getThirdPersonCamera(a,n,r),l=a.distanceTo(new K(o.x,o.y,o.z)),c=s==="third_person_back"?l:-l;this.camera.position.set(0,0,c),s==="third_person_front"?this.camera.rotation.set(0,Math.PI,0):this.camera.rotation.set(0,0,0)}else this.camera.position.z=0,this.camera.rotation.set(0,0,0),this.debugRaycastHelper&&(this.realScene.remove(this.debugRaycastHelper),this.debugRaycastHelper=void 0),this.debugHitPoint&&(this.realScene.remove(this.debugHitPoint),this.debugHitPoint=void 0)}this.updateCameraSectionPos()}}debugChunksVisibilityOverride(){let{chunksRenderAboveOverride:t,chunksRenderBelowOverride:n,chunksRenderDistanceOverride:r,chunksRenderAboveEnabled:s,chunksRenderBelowEnabled:a,chunksRenderDistanceEnabled:o}=this.reactiveDebugParams,l=this.getSectionHeight(),c=this.cameraSectionPos.y*l;if(this.displayOptions.inWorldRenderingConfig.enableDebugOverlay&&t!==void 0||n!==void 0||r!==void 0)for(let[u,f]of Object.entries(this.sectionObjects)){if(f._waitingForChunkDisplay)continue;let[m,v,y]=u.split(",").map(Number),_=s&&t!==void 0?v<=c+t:a&&n!==void 0?v>=c-n:o&&r!==void 0?Math.abs(v-c)<=r:!0;f.visible=_}else this.chunkMeshManager.updateSectionsVisibility()}render(t=!1){if(this.currentRenderedFrames++,this.reactiveDebugParams.stopRendering)return;this.debugChunksVisibilityOverride();let n=performance.now();this.lastRendered=performance.now();let r=this.lastRenderTime>0?Math.min(Math.max((n-this.lastRenderTime)/1e3,0),.1):1/60;this.lastRenderTime=n,this.cursorBlock.render(),this.updateSectionOffsets();let s=this.getCameraPosition();if(this.skyboxRenderer.update(s,this.viewDistance),this.updateSmoothFov(),t){let f=this.renderer.getSize(new Ue);this.camera.aspect=f.width/f.height,this.camera.updateProjectionMatrix()}let a=0;if(!this.reactiveDebugParams.disableEntities){let f=performance.now();this.entities.render(),a=performance.now()-f}let o=this.cameraGroupVr instanceof ot?this.cameraGroupVr.children.find(f=>f instanceof Yt):this.camera;this.applyPendingSectionUpdates();let l=this.chunkMeshManager.globalBlockBuffer;l&&(l.setCameraOrigin(this.cameraWorldPos.x,this.cameraWorldPos.y,this.cameraWorldPos.z),l.uploadDirtyRange()),this.renderer.render(this.scene,o),this.displayOptions.inWorldRenderingConfig.showHand&&this.playerStateReactive.gameMode!=="spectator"&&this.playerStateReactive.perspective==="first_person"&&!this.renderer.xr.isPresenting&&(this.holdingBlock.render(this.camera,this.renderer,this.ambientLight,this.directionalLight),this.holdingBlockLeft.render(this.camera,this.renderer,this.ambientLight,this.directionalLight));for(let f of this.fountains)this.sectionObjects[f.sectionId]&&!this.sectionObjects[f.sectionId].foutain&&(f.createParticles(this.sectionObjects[f.sectionId]),this.sectionObjects[f.sectionId].foutain=!0),f.render();this.waypoints.render(),this.fireworks.update();for(let f of this.onRender)f(r);let u=performance.now()-n;this.worldRendererConfig.autoLowerRenderDistance&&this.chunkMeshManager.recordRenderTime(u),this.renderTimeAvgCount++,this.renderTimeAvg=(this.renderTimeAvg*(this.renderTimeAvgCount-1)+u)/this.renderTimeAvgCount,this.renderTimeMax=Math.max(this.renderTimeMax,u),this.performanceMonitor.onFrame({totalMs:u,entitiesMs:a,loadedTextureCount:this.renderer.info.memory.textures,fps:this.lastFps})}renderHead(t,n,r,s){let a;if(s.SkullOwner?a=s.SkullOwner.Properties?.textures?.[0]?.Value:a=s.profile?.properties?.find(o=>o.name==="textures")?.value,!!a)try{let l=JSON.parse(Buffer.from(a,"base64").toString()).textures?.SKIN?.url,{skinTexturesProxy:c}=this.worldRendererConfig;c&&(l=l?.replace("http://textures.minecraft.net/",c).replace("https://textures.minecraft.net/",c));let u=kl(this,l,Cl.head),f=new ot;return r&&u.position.set(0,.3125,.3125),u.position.y-=23/16,f.add(u),this.sceneOrigin.track(f),f.position.set(t.x+.5,t.y+.045,t.z+.5),f.rotation.set(0,-yt.degToRad(n*(r?90:45/2)),0),f.scale.set(.8,.8,.8),f}catch(o){console.error("Error decoding player texture:",o)}}renderSign(t,n,r,s,a){let o=this.getSignTexture(t,a,s);if(!o)return;let l=new je(new vn(1,1),new st({map:o,transparent:!0}));l.renderOrder=999;let c=7/16,u=s?1.3:1;l.scale.set(1*u,c*u,1*u);let f=(s?2:1.5)/16,m=.25/16;r&&!s?l.position.set(0,0,-.5+f+m+1e-4):l.position.set(0,0,f/2+1e-4);let v=new ot;v.rotation.set(0,-yt.degToRad(n*(r?90:45/2)),0),v.add(l);let y=(s?10:8)/16,_=(s?0:r?4.333:9.333)/16,b=y/2+_;return this.sceneOrigin.track(v),v.position.set(t.x+.5,t.y+b,t.z+.5),v}lightUpdate(t,n){for(let r=this.worldSizeParams.minY;r<this.worldSizeParams.worldHeight;r+=16)this.setSectionDirty(new ft(t,r,n))}rerenderAllChunks(){for(let t of Object.keys(this.sectionObjects)){let[n,r,s]=t.split(",").map(Number);this.setSectionDirty(new ft(n,r,s))}}updateShowChunksBorder(t){this.chunkMeshManager.updateAllBoxHelpers(t)}resetWorld(){super.resetWorld(),this.pendingSectionUpdates.clear(),this.pendingSectionBufferStartTimes.clear(),this.chunkMeshManager.dispose(),this.chunkMeshManager=new em(this,this.scene,this.material,this.worldSizeParams.worldHeight,this.viewDistance),this.debugRaycastHelper&&(this.realScene.remove(this.debugRaycastHelper),this.debugRaycastHelper=void 0),this.debugHitPoint&&(this.realScene.remove(this.debugHitPoint),this.debugHitPoint=void 0)}getLoadedChunksRelative(t,n=!1){let[r,s,a]=vA(t);return Object.fromEntries(Object.entries(this.sectionObjects).map(([o,l])=>{let[c,u,f]=o.split(",").map(Number),[m,v,y]=vA({x:c,y:u,z:f});return[n?`${m-r},${v-s},${y-a}`:`${m-r},${y-a}`,l]}))}cleanChunkTextures(t,n){let r=this.chunkTextures.get(`${Math.floor(t/16)},${Math.floor(n/16)}`)??{};for(let s of Object.keys(r))r[s].dispose(),delete r[s];this.chunkMeshManager.cleanSignChunkTextures(t,n)}readdChunks(){for(let t of Object.keys(this.sectionObjects))this.scene.remove(this.sectionObjects[t]);setTimeout(()=>{for(let t of Object.keys(this.sectionObjects))this.scene.add(this.sectionObjects[t])},500)}disableUpdates(t=this.scene.children){for(let n of t)n.matrixWorldNeedsUpdate=!1,this.disableUpdates(n.children??[])}removeColumn(t,n){super.removeColumn(t,n),this.cleanChunkTextures(t,n),this.clearPendingSectionUpdatesForChunk(t,n);let r=this.getSectionHeight(),s=this.worldMinYRender;for(let a=s;a<this.worldSizeParams.worldHeight;a+=r){let o=`${t},${a},${n}`;this.chunkMeshManager.sectionObjects[o]&&this.chunkMeshManager.releaseSection(o)}this.chunkMeshManager.onChunkRemovedFromGate(`${t},${n}`)}onViewerChunkPositionChanged(){this.chunkMeshManager.tryRevealPending()}setSectionDirty(...t){let[n]=t;this.cleanChunkTextures(n.x,n.z),super.setSectionDirty(...t)}static getRendererInfo(t){try{let n=t.getContext();return`${n.getParameter(n.getExtension("WEBGL_debug_renderer_info").UNMASKED_RENDERER_WEBGL)}`}catch(n){console.warn("Failed to get renderer info",n)}}worldStop(){this.media.onWorldStop()}destroy(){this.performanceMonitor?.reset(),this.pendingSectionUpdates.clear(),this.pendingSectionBufferStartTimes.clear(),this.chunkMeshManager.dispose(),this.disposeModules(),this.fireworksLegacy.destroy(),super.destroy(),this.skyboxRenderer.dispose(),this.fireworks.dispose()}shouldObjectVisible(t){let r=this.getSectionHeight(),s,a,o,l=this.sceneOrigin.getWorldPosition(t);l?(s=l.x,a=l.y,o=l.z):(s=this.sceneOrigin.toWorldX(t.position.x),a=this.sceneOrigin.toWorldY(t.position.y),o=this.sceneOrigin.toWorldZ(t.position.z));let c=Math.floor(s/16)*16,u=Math.floor(o/16)*16,f=Math.floor(a/r)*r,m=`${c},${u}`,v=`${c},${f},${u}`;return!!this.finishedChunks[m]||!!this.sectionObjects[v]}handleUserClick(t){this.media.handleUserClick(t)}updateSectionOffsets(){let t=performance.now();for(let[n,r]of Object.entries(this.sectionsOffsetsAnimations)){let s=(t-r.time)/1e3;r.time=t,r.currentOffsetX+=r.speedX*s,r.currentOffsetY+=r.speedY*s,r.currentOffsetZ+=r.speedZ*s,r.limitX!==void 0&&(r.speedX>0?r.currentOffsetX=Math.min(r.currentOffsetX,r.limitX):r.currentOffsetX=Math.max(r.currentOffsetX,r.limitX)),r.limitY!==void 0&&(r.speedY>0?r.currentOffsetY=Math.min(r.currentOffsetY,r.limitY):r.currentOffsetY=Math.max(r.currentOffsetY,r.limitY)),r.limitZ!==void 0&&(r.speedZ>0?r.currentOffsetZ=Math.min(r.currentOffsetZ,r.limitZ):r.currentOffsetZ=Math.max(r.currentOffsetZ,r.limitZ));let a=this.sectionObjects[n];a&&(a.position.set(r.currentOffsetX,r.currentOffsetY,r.currentOffsetZ),a.updateMatrix())}}reloadWorld(){this.entities.reloadEntities()}};Cn(yu,"FOV_TRANSITION_MS",200),Cn(yu,"MAX_SECTION_UPDATE_BUFFER_MS",500);var bu=yu;h();p();d();h();p();d();var nm="1.21.4";h();p();d();function _u(i,e){i.aspect=e.width/e.height,i.updateProjectionMatrix()}h();p();d();h();p();d();var t0={mode:"futuristic",minecraftTextures:!0,futuristicScene:"light",futuristicCamera:"dive",futuristicBlockGroup:"stainedGlass",futuristicCameraSpeedPercent:80,futuristicBlockSpeedPercent:40},PR=i=>i/100,s8={camera:PR(t0.futuristicCameraSpeedPercent),block:PR(t0.futuristicBlockSpeedPercent)};function IR(i,e=!1){return i?.mode?i.mode:e?"worldBlocks":t0.mode}h();p();d();h();p();d();h();p();d();X2();var LR={},m3e=!1;function nGe(){if(m3e)return LR;m3e=!0;var i=sl;function e(s){if(typeof s!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(s))}function t(s,a){for(var o="",l=0,c=-1,u=0,f,m=0;m<=s.length;++m){if(m<s.length)f=s.charCodeAt(m);else{if(f===47)break;f=47}if(f===47){if(!(c===m-1||u===1))if(c!==m-1&&u===2){if(o.length<2||l!==2||o.charCodeAt(o.length-1)!==46||o.charCodeAt(o.length-2)!==46){if(o.length>2){var v=o.lastIndexOf("/");if(v!==o.length-1){v===-1?(o="",l=0):(o=o.slice(0,v),l=o.length-1-o.lastIndexOf("/")),c=m,u=0;continue}}else if(o.length===2||o.length===1){o="",l=0,c=m,u=0;continue}}a&&(o.length>0?o+="/..":o="..",l=2)}else o.length>0?o+="/"+s.slice(c+1,m):o=s.slice(c+1,m),l=m-c-1;c=m,u=0}else f===46&&u!==-1?++u:u=-1}return o}function n(s,a){var o=a.dir||a.root,l=a.base||(a.name||"")+(a.ext||"");return o?o===a.root?o+l:o+s+l:l}var r={resolve:function(){for(var a="",o=!1,l,c=arguments.length-1;c>=-1&&!o;c--){var u;c>=0?u=arguments[c]:(l===void 0&&(l=i.cwd()),u=l),e(u),u.length!==0&&(a=u+"/"+a,o=u.charCodeAt(0)===47)}return a=t(a,!o),o?a.length>0?"/"+a:"/":a.length>0?a:"."},normalize:function(a){if(e(a),a.length===0)return".";var o=a.charCodeAt(0)===47,l=a.charCodeAt(a.length-1)===47;return a=t(a,!o),a.length===0&&!o&&(a="."),a.length>0&&l&&(a+="/"),o?"/"+a:a},isAbsolute:function(a){return e(a),a.length>0&&a.charCodeAt(0)===47},join:function(){if(arguments.length===0)return".";for(var a,o=0;o<arguments.length;++o){var l=arguments[o];e(l),l.length>0&&(a===void 0?a=l:a+="/"+l)}return a===void 0?".":r.normalize(a)},relative:function(a,o){if(e(a),e(o),a===o||(a=r.resolve(a),o=r.resolve(o),a===o))return"";for(var l=1;l<a.length&&a.charCodeAt(l)===47;++l);for(var c=a.length,u=c-l,f=1;f<o.length&&o.charCodeAt(f)===47;++f);for(var m=o.length,v=m-f,y=u<v?u:v,_=-1,b=0;b<=y;++b){if(b===y){if(v>y){if(o.charCodeAt(f+b)===47)return o.slice(f+b+1);if(b===0)return o.slice(f+b)}else u>y&&(a.charCodeAt(l+b)===47?_=b:b===0&&(_=0));break}var g=a.charCodeAt(l+b),x=o.charCodeAt(f+b);if(g!==x)break;g===47&&(_=b)}var w="";for(b=l+_+1;b<=c;++b)(b===c||a.charCodeAt(b)===47)&&(w.length===0?w+="..":w+="/..");return w.length>0?w+o.slice(f+_):(f+=_,o.charCodeAt(f)===47&&++f,o.slice(f))},_makeLong:function(a){return a},dirname:function(a){if(e(a),a.length===0)return".";for(var o=a.charCodeAt(0),l=o===47,c=-1,u=!0,f=a.length-1;f>=1;--f)if(o=a.charCodeAt(f),o===47){if(!u){c=f;break}}else u=!1;return c===-1?l?"/":".":l&&c===1?"//":a.slice(0,c)},basename:function(a,o){if(o!==void 0&&typeof o!="string")throw new TypeError('"ext" argument must be a string');e(a);var l=0,c=-1,u=!0,f;if(o!==void 0&&o.length>0&&o.length<=a.length){if(o.length===a.length&&o===a)return"";var m=o.length-1,v=-1;for(f=a.length-1;f>=0;--f){var y=a.charCodeAt(f);if(y===47){if(!u){l=f+1;break}}else v===-1&&(u=!1,v=f+1),m>=0&&(y===o.charCodeAt(m)?--m===-1&&(c=f):(m=-1,c=v))}return l===c?c=v:c===-1&&(c=a.length),a.slice(l,c)}else{for(f=a.length-1;f>=0;--f)if(a.charCodeAt(f)===47){if(!u){l=f+1;break}}else c===-1&&(u=!1,c=f+1);return c===-1?"":a.slice(l,c)}},extname:function(a){e(a);for(var o=-1,l=0,c=-1,u=!0,f=0,m=a.length-1;m>=0;--m){var v=a.charCodeAt(m);if(v===47){if(!u){l=m+1;break}continue}c===-1&&(u=!1,c=m+1),v===46?o===-1?o=m:f!==1&&(f=1):o!==-1&&(f=-1)}return o===-1||c===-1||f===0||f===1&&o===c-1&&o===l+1?"":a.slice(o,c)},format:function(a){if(a===null||typeof a!="object")throw new TypeError('The "pathObject" argument must be of type Object. Received type '+typeof a);return n("/",a)},parse:function(a){e(a);var o={root:"",dir:"",base:"",ext:"",name:""};if(a.length===0)return o;var l=a.charCodeAt(0),c=l===47,u;c?(o.root="/",u=1):u=0;for(var f=-1,m=0,v=-1,y=!0,_=a.length-1,b=0;_>=u;--_){if(l=a.charCodeAt(_),l===47){if(!y){m=_+1;break}continue}v===-1&&(y=!1,v=_+1),l===46?f===-1?f=_:b!==1&&(b=1):f!==-1&&(b=-1)}return f===-1||v===-1||b===0||b===1&&f===v-1&&f===m+1?v!==-1&&(m===0&&c?o.base=o.name=a.slice(1,v):o.base=o.name=a.slice(m,v)):(m===0&&c?(o.name=a.slice(1,f),o.base=a.slice(1,v)):(o.name=a.slice(m,f),o.base=a.slice(m,v)),o.ext=a.slice(f,v)),m>0?o.dir=a.slice(0,m-1):c&&(o.dir="/"),o},sep:"/",delimiter:":",win32:null,posix:null};return r.posix=r,LR=r,LR}var $r=nGe();X2();var _mn=$r._makeLong,wmn=$r.basename,xmn=$r.delimiter,Emn=$r.dirname,Smn=$r.extname,Amn=$r.format,Mmn=$r.isAbsolute,BR=$r.join,Tmn=$r.normalize,Rmn=$r.parse,kmn=$r.posix,Cmn=$r.relative,Pmn=$r.resolve,Imn=$r.sep,Lmn=$r.win32;bt();var OR=new Date,v3e=OR.getMonth()===11&&OR.getDate()>=24&&OR.getDate()<=26,rGe=["panorama_3.webp","panorama_1.webp","panorama_4.webp","panorama_5.webp","panorama_0.webp","panorama_2.webp"],iGe=200,rm=class{constructor(e){this.documentRenderer=e;this.scene=new yr,this.scene.background=new Fe(3294568);let t=new pa(13421772);this.scene.add(t);let n=new as(16777215,.5);n.position.set(1,1,.5).normalize(),n.castShadow=!0,this.scene.add(n),this.camera=new Yt(85,e.canvas.width/e.canvas.height,.05,1e3),this.camera.position.set(0,0,0),this.camera.rotation.set(0,0,0)}scene;camera;startTimes=new Map;time=0;panoramaGroup=null;async init(){this.buildCubemap()}update(e,t){t&&_u(this.camera,this.documentRenderer.canvas)}dispose(){this.scene.clear(),this.panoramaGroup=null,this.startTimes.clear()}buildCubemap(){let e=new nn(1e3,1e3,1e3),t=[];for(let s of rGe)(async()=>{let{texture:o}=R7(BR("background",v3e?"christmas":"",s));o.matrixAutoUpdate=!1,o.matrix.set(-1,0,1,0,1,0,0,0,1),o.wrapS=mn,o.wrapT=mn,o.minFilter=jt,o.magFilter=jt;let l=new st({map:o,transparent:!0,side:cn,depthWrite:!1,opacity:0});this.startTimes.set(l,Date.now()),t.push(l)})();let n=new je(e,t);n.onBeforeRender=()=>{this.time+=.01,n.rotation.y=Math.PI+this.time*.01,n.rotation.z=Math.sin(-this.time*.001)*.001;for(let s of t){let a=this.startTimes.get(s);if(a){let o=Date.now()-a;s.opacity=Math.min(1,o/iGe)}}};let r=new At;if(r.add(n),!v3e)for(let s=0;s<20;s++){let a=new e0("1.16.4","squid").mesh;a.position.set(Math.random()*30-15,Math.random()*20-10,Math.random()*10-17),a.rotation.set(0,Math.PI+Math.random(),-Math.PI/4,"ZYX");let o=Math.random()*.01;a.children[0].onBeforeRender=()=>{a.rotation.y+=o,a.rotation.z=Math.cos(n.rotation.y*3)*Math.PI/4-Math.PI/2},r.add(a)}this.scene.add(r),this.panoramaGroup=r}async debugImageInFrontOfCamera(){let e=await fl(BR("background","panorama_0.webp")),t=new je(new vn(1e3,1e3),new st({map:e}));t.position.set(0,0,-500),this.scene.add(t)}};h();p();d();bt();h();p();d();var ed=["galaxy","nether","end","cyber","light"],td=["cruise","barrel","dive","orbit","snake"],a8={galaxy:"Galaxy",nether:"Nether",end:"The End",cyber:"Cyber",light:"Light Space"},o8={cruise:"Cruise",barrel:"Barrel",dive:"Dive",orbit:"Orbit",snake:"Snake"},nd=["mixed","stainedGlass","wool","construction","glow","world"],l8={mixed:"Mixed",stainedGlass:"Stained glass",wool:"Wool",construction:"Construction",glow:"Glow",world:"World (grass & ores)"};var g3e=.1,_3e={mixed:["white_wool","cyan_wool","blue_wool","purple_wool","white_stained_glass","cyan_stained_glass","blue_stained_glass","purple_stained_glass","glowstone","sea_lantern","amethyst_block","copper_block","gold_block","diamond_block"],stainedGlass:["white_stained_glass","orange_stained_glass","magenta_stained_glass","light_blue_stained_glass","yellow_stained_glass","lime_stained_glass","pink_stained_glass","gray_stained_glass","light_gray_stained_glass","cyan_stained_glass","purple_stained_glass","blue_stained_glass","brown_stained_glass","green_stained_glass","red_stained_glass","black_stained_glass"],wool:["white_wool","orange_wool","magenta_wool","light_blue_wool","yellow_wool","lime_wool","pink_wool","gray_wool","light_gray_wool","cyan_wool","purple_wool","blue_wool","brown_wool","green_wool","red_wool","black_wool"],construction:["copper_block","exposed_copper","weathered_copper","oxidized_copper","cut_copper","exposed_cut_copper","weathered_cut_copper","oxidized_cut_copper","iron_block","gold_block","diamond_block","emerald_block","netherite_block","lapis_block","redstone_block","coal_block","quartz_block","amethyst_block","bricks","stone_bricks","deepslate_bricks","polished_blackstone"],glow:["glowstone","sea_lantern","shroomlight","ochre_froglight","verdant_froglight","pearlescent_froglight","redstone_lamp","beacon"],world:["grass_block","podzol","mycelium","dirt","coarse_dirt","rooted_dirt","mud","clay","stone","cobblestone","mossy_cobblestone","deepslate","cobbled_deepslate","tuff","calcite","sand","red_sand","gravel","snow_block","coal_ore","deepslate_coal_ore","iron_ore","deepslate_iron_ore","copper_ore","deepslate_copper_ore","gold_ore","deepslate_gold_ore","diamond_ore","deepslate_diamond_ore","emerald_ore","deepslate_emerald_ore","lapis_ore","deepslate_lapis_ore","redstone_ore","deepslate_redstone_ore","nether_gold_ore","ancient_debris","oak_log","birch_log","spruce_log","jungle_log","acacia_log","dark_oak_log","mangrove_log","cherry_log","netherrack","soul_sand","basalt","end_stone"]},y3e={galaxy:{bg:132114,fog:132114,fogD:.011,blocks:[61695,54527,47359,59647,2280703,43263],emit:[13158,8789,6724],nebula:[4403,1114146,4386],galFn:i=>new Fe(i*.05,i*.2,i),ambient:264216,dir:3368703,pt1:43775,pt2:16729343,name:"GALAXY"},nether:{bg:917760,fog:917760,fogD:.016,blocks:[16720384,16737792,16750848,13373696,16729122,16755200],emit:[2230272,1114112,3346688],nebula:[1704960,851968,1705984],galFn:i=>new Fe(i,i*.15,0),ambient:1573376,dir:16724736,pt1:16729088,pt2:16755200,name:"NETHER"},end:{bg:0,fog:0,fogD:.009,blocks:[7807658,11158732,5570679,14527231,3342421,12299007],emit:[655381,1572901,327696],nebula:[524312,851989,262158],galFn:i=>new Fe(i*.4,0,i),ambient:393232,dir:10040319,pt1:11158783,pt2:4456618,name:"THE END"},cyber:{bg:2566,fog:2566,fogD:.01,blocks:[65535,65416,11206400,52479,6749952,65518],emit:[8721,6656,6690],nebula:[6674,5120,4634],galFn:i=>new Fe(0,i,i*.6),ambient:6669,dir:65450,pt1:65484,pt2:4521728,name:"CYBER"},light:{bg:8951984,fog:7899296,fogD:.006,gradientBg:{top:14214392,mid:10531016,bottom:6846608,radial:!0},blocks:[15266559,13691135,12114175,10537208,8960240,7383272,10012927,12640511,15792383,7909608,14216447,14739711],emit:[6854864,8958176,11061488,12638456],nebula:[9480392,11059424,12637420,14215416,7901360],galFn:i=>{let e=new Fe;return i<.4?e.lerpColors(new Fe(16054527),new Fe(14215423),i/.4):i<.75?e.lerpColors(new Fe(14215423),new Fe(11061488),(i-.4)/.35):e.lerpColors(new Fe(11061488),new Fe(9482464),(i-.75)/.25),e},ambient:7899296,dir:13688040,pt1:11061503,pt2:13162751,name:"LIGHT",starColor:15266047,starOpacity:.5,galaxyOpacity:.7,nebulaOpacity:.32,edgeLineColor:10010856,blockOpacity:[.42,.56]}},sGe={cruise:{pos:(i,e,t)=>({x:Math.sin(i*.28)*18+Math.cos(i*.11)*7+e*10,y:Math.sin(i*.19)*6+Math.cos(i*.31)*3+t*6,z:0}),look:(i,e,t)=>({x:Math.sin((i+.18)*.28)*18+e*8,y:Math.sin((i+.18)*.19)*6+t*4,z:-25}),roll:(i,e=0)=>e*.05+Math.sin(i*.22)*.015,spd:.18},barrel:{pos:(i,e,t)=>{let r=i*2.4;return{x:Math.cos(r)*10+e*4,y:Math.sin(r)*10+t*4,z:Math.sin(i*.4)*8}},look:i=>({x:Math.sin(i*.5)*5,y:Math.cos(i*.5)*5,z:-30}),roll:i=>i*2.4+Math.PI*.5,spd:.24},dive:{pos:(i,e,t)=>({x:Math.sin(i*.6)*30+e*8,y:Math.cos(i*.4)*18+t*6,z:Math.sin(i*.3)*12}),look:(i,e,t)=>({x:Math.sin(i*.6+.2)*30+e*6,y:Math.cos(i*.4+.2)*18-8+t*4,z:-35}),roll:(i,e=0)=>e*.08+Math.sin(i*.6)*.12,spd:.3},orbit:{pos:(i,e,t)=>({x:Math.cos(i*.5)*20+e*5,y:Math.sin(i*.25)*10+t*5,z:Math.sin(i*.5)*20}),look:()=>({x:0,y:0,z:-60}),roll:i=>Math.sin(i*.5)*.08,spd:.15},snake:{pos:(i,e,t)=>({x:Math.sin(i*1.1)*22+Math.sin(i*.37)*8+e*10,y:Math.sin(i*.7)*10+e*4+t*8,z:0}),look:(i,e,t)=>{let n=i+.12;return{x:Math.sin(n*1.1)*22+Math.sin(n*.37)*8+e*8,y:Math.sin(n*.7)*10+t*6,z:-22}},roll:(i,e=0)=>e*.1+Math.sin(i*1.1)*.06,spd:.22}},aGe={cruise:1,barrel:1.6,dive:2.2,orbit:.7,snake:1.4},oGe=250,c8=1e4,u8=3e3,rd=i=>i[Math.floor(Math.random()*i.length)],NR=i=>"#"+i.toString(16).padStart(6,"0"),b3e=i=>{if(typeof document>"u")return null;let e=document.createElement("canvas");e.width=4,e.height=512;let t=e.getContext("2d");if(!t)return null;let n=e.width,r=e.height,s=i.radial?t.createRadialGradient(n/2,r*.32,0,n/2,r*.32,r*.85):t.createLinearGradient(0,0,0,r);s.addColorStop(0,NR(i.top)),i.mid!=null&&s.addColorStop(.45,NR(i.mid)),s.addColorStop(1,NR(i.bottom)),t.fillStyle=s,t.fillRect(0,0,n,r);let a=new yn(e);return a.needsUpdate=!0,a},id=class{constructor(e,t={},n){this.documentRenderer=e;this.abortSignal=n;let r=t0;this.curScene=t.initialScene??r.futuristicScene,this.curCam=t.initialCamera??r.futuristicCamera,this.blockGroup=t.initialBlockGroup??r.futuristicBlockGroup,this.cameraSpeed=t.initialCameraSpeed??s8.camera,this.blockSpeed=t.initialBlockSpeed??s8.block,this.useMinecraftTextures=t.useMinecraftTextures??r.minecraftTextures,this.resourcesManager=t.resourcesManager;let s=y3e[this.curScene];this.scene=new yr,this.scene.fog=new io(s.fog,s.fogD),this.applyScenePalette(s),this.camera=new Yt(80,this.documentRenderer.canvas.width/this.documentRenderer.canvas.height,.1,700),this.ambient=new pa(s.ambient,2.5),this.scene.add(this.ambient),this.dir=new as(s.dir,4),this.dir.position.set(1,1,0),this.scene.add(this.dir),this.pt1=new po(s.pt1,5,100),this.scene.add(this.pt1),this.pt2=new po(s.pt2,4,80),this.pt2.position.set(30,20,-30),this.scene.add(this.pt2);for(let m=0;m<oGe;m++)this.spawnBlock(s,!0);if(!this.useMinecraftTextures){let m=s.edgeLineColor??62975;for(let v=0;v<40;v++){let y=new fn({color:m,transparent:!0,opacity:.25});rd(this.blocks).mesh.add(new In(this.eGeo,y))}}this.scene.add(this.bGroup);let a=new it,o=new Float32Array(5e3*3);for(let m=0;m<5e3*3;m++)o[m]=(Math.random()-.5)*500;a.setAttribute("position",new dt(o,3)),this.stars=new tr(a,new Lr({color:s.starColor??16777215,size:.3,transparent:!0,opacity:s.starOpacity??.7,sizeAttenuation:!0})),this.scene.add(this.stars),this.galGeo=new it;let l=new Float32Array(c8*3),c=new Float32Array(c8*3);for(let m=0;m<c8;m++){let v=m%3,y=Math.random(),_=v/3*Math.PI*2+y*Math.PI*5,b=y*90+Math.random()*10,g=(1-y)*18;l[m*3]=Math.cos(_)*b+(Math.random()-.5)*g,l[m*3+1]=(Math.random()-.5)*7,l[m*3+2]=Math.sin(_)*b+(Math.random()-.5)*g-180;let x=.2+y*.8,w=s.galFn(x);c[m*3]=w.r,c[m*3+1]=w.g,c[m*3+2]=w.b}this.galGeo.setAttribute("position",new dt(l,3)),this.galGeo.setAttribute("color",new dt(c,3)),this.galaxy=new tr(this.galGeo,new Lr({size:.9,vertexColors:!0,transparent:!0,opacity:s.galaxyOpacity??.55,sizeAttenuation:!0})),this.scene.add(this.galaxy),this.nebGeo=new it;let u=new Float32Array(u8*3),f=new Float32Array(u8*3);for(let m=0;m<u8;m++){let v=25+Math.random()*110,y=Math.random()*Math.PI*2,_=(Math.random()-.5)*Math.PI*.5;u[m*3]=v*Math.cos(y)*Math.cos(_),u[m*3+1]=v*Math.sin(_)*.6,u[m*3+2]=v*Math.sin(y)*Math.cos(_)-80;let b=new Fe(rd(s.nebula));f[m*3]=b.r,f[m*3+1]=b.g,f[m*3+2]=b.b}this.nebGeo.setAttribute("position",new dt(u,3)),this.nebGeo.setAttribute("color",new dt(f,3)),this.nebula=new tr(this.nebGeo,new Lr({size:3,vertexColors:!0,transparent:!0,opacity:s.nebulaOpacity??.3,sizeAttenuation:!0})),this.scene.add(this.nebula),this.addBackgroundTextPlane(),this.setupMouseTracking()}scene;camera;ambient;dir;pt1;pt2;blocks=[];bGroup=new ot;galaxy;nebula;stars;galGeo;nebGeo;bGeo=new nn(1,1,1);eGeo=new k0(this.bGeo);curScene;curCam;blockGroup;cameraSpeed;blockSpeed;camT=0;mx=0;my=0;tmx=0;tmy=0;transitioning=!1;useMinecraftTextures=!1;resourcesManager;atlasTexture=null;blockMaterialPool=new Map;gradientSky=null;gradientSkyTexture=null;disposed=!1;animTime=0;async init(){if(this.useMinecraftTextures)try{await this.loadMinecraftTextures()}catch(e){console.warn("[FuturisticMenuBackground] Failed to load Minecraft textures, using solid colors:",e),this.useMinecraftTextures=!1}}applyScenePalette(e){if(this.documentRenderer.renderer.setClearColor(e.bg),e.gradientBg)if(this.scene.background=null,this.gradientSky){if(this.gradientSky.visible=!0,this.gradientSkyTexture&&e.gradientBg){let s=b3e(e.gradientBg);s&&(this.gradientSkyTexture.dispose(),this.gradientSkyTexture=s,this.gradientSky.material.map=s,this.gradientSky.material.needsUpdate=!0)}}else{let s=b3e(e.gradientBg);s?(this.gradientSkyTexture=s,this.gradientSky=new je(new vn(900,700),new st({map:s,depthWrite:!1,side:cn})),this.gradientSky.position.set(0,0,-280),this.gradientSky.renderOrder=-1e3,this.scene.add(this.gradientSky)):this.scene.background=new Fe(e.bg)}else this.scene.background=new Fe(e.bg),this.gradientSky&&(this.gradientSky.visible=!1);this.scene.fog instanceof io&&(this.scene.fog.color.set(e.fog),this.scene.fog.density=e.fogD);let t=this.stars?.material;t&&(t.color.set(e.starColor??16777215),t.opacity=e.starOpacity??.7);let n=this.galaxy?.material;n&&(n.opacity=e.galaxyOpacity??.55);let r=this.nebula?.material;r&&(r.opacity=e.nebulaOpacity??.3)}setupMouseTracking(){let e=n=>{let r=typeof window<"u"?window.innerWidth:this.documentRenderer.canvas.width,s=typeof window<"u"?window.innerHeight:this.documentRenderer.canvas.height;this.tmx=(n.clientX/r-.5)*2,this.tmy=-(n.clientY/s-.5)*2};(typeof document<"u"?document:void 0)?.addEventListener("mousemove",e,{signal:this.abortSignal})}addBackgroundTextPlane(){let n=typeof document<"u"?document.createElement("canvas"):null;if(!n)return;n.width=2048,n.height=768;let r=n.getContext("2d");if(!r)return;r.clearRect(0,0,2048,768),r.save(),r.font="bold 560px Orbitron, sans-serif",r.textAlign="center",r.textBaseline="middle",r.shadowColor="rgba(0,200,255,0.35)",r.shadowBlur=80,r.fillStyle="rgba(255,255,255,0.055)",r.fillText("V2",2048*.28,768*.5),r.restore(),r.save(),r.font="bold 148px Orbitron, sans-serif",r.textAlign="center",r.textBaseline="middle",r.shadowColor="rgba(0,200,255,0.2)",r.shadowBlur=40,r.fillStyle="rgba(255,255,255,0.038)",r.fillText("by ZARDOY",2048*.72,768*.52),r.restore();let s=new yn(n),a=new je(new vn(280,105),new st({map:s,transparent:!0,opacity:1,depthWrite:!1,side:cn,blending:Li}));a.position.set(8,4,-320),this.scene.add(a)}spawnBlock(e,t,n){let r=this.createBlockMaterial(e,n),s=new je(this.bGeo,r),a=.3+Math.random()*3;s.scale.setScalar(a),s.position.set((Math.random()-.5)*140,(Math.random()-.5)*70,t?-(Math.random()*140):-155-Math.random()*30),s.rotation.set(Math.random()*Math.PI*2,Math.random()*Math.PI*2,Math.random()*Math.PI*2);let o={mesh:s,spd:.04+Math.random()*.12,dx:(Math.random()-.5)*.012,dy:(Math.random()-.5)*.008,rx:(Math.random()-.5)*.012,ry:(Math.random()-.5)*.012,rz:(Math.random()-.5)*.01,minecraftBlockName:n};this.blocks.push(o),this.bGroup.add(s)}createBlockMaterial(e,t){if(this.useMinecraftTextures&&t){let s=this.blockMaterialPool.get(t);if(s)return s.clone()}let[n,r]=e.blockOpacity??[.32,.46];return new st({color:rd(e.blocks),transparent:!0,opacity:n+Math.random()*(r-n),depthWrite:!1,blending:Li})}removeBlockEdgeLines(){for(let e of this.blocks){let t=e.mesh.children.filter(n=>n instanceof In);for(let n of t){e.mesh.remove(n),n.geometry?.dispose();let r=n.material;Array.isArray(r)?r.forEach(s=>s.dispose()):r.dispose()}}}async ensureMcDataLoaded(){let e=globalThis._LOAD_MC_DATA;e&&await e()}resolveBlockAtlasUv(e,t,n){let r=s=>{let a=t[s];return a?{u:a.u,v:a.v,su:a.su??n.suSv,sv:a.sv??n.suSv}:null};if(t[e])return r(e);for(let s of["_top","_side","_front","_0"]){let a=r(`${e}${s}`);if(a)return a}for(let s of Object.keys(t))if(s.startsWith(e))return r(s);return null}async loadMinecraftTextures(){await this.ensureMcDataLoaded();let e=this.resourcesManager??new J0;!e.currentResources?.blocksAtlasImage&&(e.currentConfig={...e.currentConfig,version:nm,noInventoryGui:!0},await e.updateAssetsData?.({}));let n=e.currentResources;if(!n?.blocksAtlasImage||!n.blocksAtlasJson)throw new Error("Block atlas not available");let r=n.blocksAtlasJson,s=r.textures;this.atlasTexture=yp(n.blocksAtlasImage),this.atlasTexture.flipY=!1,this.atlasTexture.needsUpdate=!0;for(let a of _3e[this.blockGroup]){let o=this.resolveBlockAtlasUv(a,s,r);if(!o)continue;let l=this.atlasTexture.clone();l.flipY=!1,l.offset.set(o.u,o.v),l.repeat.set(o.su,o.sv),l.needsUpdate=!0;let c=a.includes("glass"),u=new st({map:l,side:cn,transparent:c,opacity:c?.85:1,alphaTest:c?.08:0,depthWrite:!0,toneMapped:!1});this.blockMaterialPool.set(a,u)}if(this.blockMaterialPool.size===0)throw new Error("No block textures resolved from atlas (check block names vs atlas keys)");this.removeBlockEdgeLines();for(let a of this.blocks){let o=rd([...this.blockMaterialPool.keys()]);a.minecraftBlockName=o,a.mesh.material=this.blockMaterialPool.get(o).clone()}}setScene(e){if(!ed.includes(e)||e===this.curScene||this.transitioning)return;this.transitioning=!0,this.curScene=e;let t=y3e[e];setTimeout(()=>{if(this.disposed)return;this.applyScenePalette(t),this.ambient.color.set(t.ambient),this.dir.color.set(t.dir),this.pt1.color.set(t.pt1),this.pt2.color.set(t.pt2);for(let s of this.blocks)this.useMinecraftTextures&&s.minecraftBlockName||s.mesh.material instanceof st&&s.mesh.material.color.set(rd(t.blocks));let n=this.nebGeo.attributes.color;for(let s=0;s<u8;s++){let a=new Fe(rd(t.nebula));n.setXYZ(s,a.r,a.g,a.b)}n.needsUpdate=!0;let r=this.galGeo.attributes.color;for(let s=0;s<c8;s++){let a=.2+Math.random()*.8,o=t.galFn(a);r.setXYZ(s,o.r,o.g,o.b)}r.needsUpdate=!0,this.transitioning=!1},150)}setCamera(e){td.includes(e)&&(this.curCam=e)}setCameraSpeed(e){this.cameraSpeed=Math.max(0,e)}setBlockSpeed(e){this.blockSpeed=Math.max(0,e)}async setBlockGroup(e){if(nd.includes(e)&&e!==this.blockGroup&&(this.blockGroup=e,!(!this.useMinecraftTextures||this.disposed))){for(let t of this.blockMaterialPool.values())t.map?.dispose(),t.dispose();this.blockMaterialPool.clear();try{await this.loadMinecraftTextures()}catch(t){console.warn("[FuturisticMenuBackground] Failed to reload block group textures:",t)}}}getSceneId(){return this.curScene}getCameraId(){return this.curCam}getBlockGroupId(){return this.blockGroup}update(e,t){t&&_u(this.camera,this.documentRenderer.canvas);let n=sGe[this.curCam],r=this.cameraSpeed,s=this.blockSpeed;this.camT+=e*n.spd*r,this.mx+=(this.tmx-this.mx)*.05,this.my+=(this.tmy-this.my)*.05;let a=this.mx*g3e,o=this.my*g3e,l=n.pos(this.camT,a,o),c=n.look(this.camT,a,o);this.camera.position.set(l.x,l.y,l.z),this.camera.lookAt(c.x,c.y,c.z),this.camera.rotation.z=n.roll(this.camT,a);let u=aGe[this.curCam]*s;this.animTime+=e*1e3*s;for(let f of this.blocks){if(f.mesh.position.z+=f.spd*u*60*e,f.mesh.position.x+=f.dx*60*e*s,f.mesh.position.y+=f.dy*60*e*s,f.mesh.rotation.x+=f.rx*u,f.mesh.rotation.y+=f.ry*u,f.mesh.rotation.z+=f.rz,!this.useMinecraftTextures&&f.mesh.material instanceof st){let m=f.mesh.userData.baseOpacity??.38;f.mesh.userData.baseOpacity==null&&(f.mesh.userData.baseOpacity=m);let v=.88+Math.abs(Math.sin(this.animTime*8e-4+f.mesh.position.x*.3))*.12;f.mesh.material.opacity=m*v}f.mesh.position.z>this.camera.position.z+15&&f.mesh.position.set((Math.random()-.5)*140,(Math.random()-.5)*70,this.camera.position.z-155-Math.random()*30)}this.pt1.position.set(Math.sin(this.camT*.8)*25+this.camera.position.x,Math.cos(this.camT*.6)*12+this.camera.position.y,this.camera.position.z-18),this.pt2.position.set(Math.cos(this.camT*.5)*20+this.camera.position.x,Math.sin(this.camT*.9)*15+this.camera.position.y,this.camera.position.z-30),this.galaxy.rotation.y+=e*.006*s,this.nebula.rotation.y-=e*.003*s,this.stars.rotation.y+=e*4e-4*s}dispose(){this.disposed=!0,this.scene.clear(),this.bGeo.dispose(),this.eGeo.dispose(),this.galGeo.dispose(),this.nebGeo.dispose(),this.gradientSkyTexture?.dispose(),this.atlasTexture?.dispose();for(let e of this.blockMaterialPool.values())e.map?.dispose(),e.dispose();this.blockMaterialPool.clear()}};h();p();d();bt();h();p();d();var ege=Jr(T3e(),1),tge=Jr(Q6e(),1);var nge=i=>{let e=(0,ege.default)(i),t=(0,tge.default)(i),n=new e(i).sync,r=OWe(n);for(let s of r)if(s.startsWith("set")&&s!=="setColumn"){let a=n[s].bind(n);n[s]=(...o)=>{let l=o[0];l.x!==void 0&&!n.getColumnAt(l)&&n.setColumn(Math.floor(l.x/16),Math.floor(l.z/16),new t(void 0)),a(...o)}}return n};function OWe(i){let e=new Set,t=i;do for(let n of Object.getOwnPropertyNames(t))typeof i[n]=="function"&&n!=="constructor"&&e.add(n);while(t=Object.getPrototypeOf(t));return[...e]}h();p();d();var rge={paused:!1,showChunkBorders:!1,enableDebugOverlay:!1,debugWasmPerf:!1,debugModelVariant:void 0,futuristicReveal:!1,wasmMesher:!0,shaderCubeBlocks:!1,shaderCubeDebugMode:0,mesherWorkers:1,addChunksBatchWaitTime:200,_experimentalSmoothChunkLoading:!0,_renderByChunks:!1,autoLowerRenderDistance:!1,disableMesherConversionCache:!1,dedicatedChangeWorker:!1,shadingTheme:"high-contrast",cardinalLight:"default",dayCycle:!0,smoothLighting:!0,enableLighting:!0,starfield:!0,defaultSkybox:!0,renderEntities:!0,extraBlockRenderers:!0,foreground:!0,fov:75,volume:1,showHand:!1,viewBobbing:!1,handRenderer:"vanilla",renderEars:!0,highlightBlockColor:"blue",fetchPlayerSkins:!0,skinTexturesProxy:void 0,vrSupport:!0,vrPageGameRendering:!0,clipWorldBelowY:void 0,isPlayground:!1,instantCameraUpdate:!1,isRaining:!1,moduleStates:{}};var Fk=()=>({reactive:yo({world:{chunksLoaded:new Set,heightmaps:new Map,allChunksLoaded:!1,mesherWork:!1,instabilityFactors:RR(),intersectMedia:null},renderer:"...",preventEscapeMenu:!1}),nonReactive:{fps:0,worstRenderTime:0,avgRenderTime:0,world:{chunksLoaded:new Set,chunksTotalNumber:0},renderer:{timeline:{live:[],frozen:[],lastSecond:[]}}}});h();p();d();h();p();d();h();p();d();Cs();var Pm=i=>[Math.floor(i.x/16),Math.floor(i.z/16)];var NWe=async(i,e,t,n=1)=>{for(let r=0;r<i.length;r+=n)e&&await new Promise(s=>setTimeout(s,e)),await t(i[r],r)},Im=class Im extends B0{static restoreTransferred(e,t){let n=new Im;return t&&t.addEventListener("message",({data:r})=>{r.class===Im.restorerName&&r.type==="event"&&n.emit(r.eventName,...r.args)}),n}};Cn(Im,"restorerName","WorldViewWorker");var vd=Im,K8=class extends B0{constructor(t,n,r=new ft(0,0,0)){super();this.world=t;this.viewDistance=n;this.lastPos=new ft(0,0,0).update(r)}spiralNumber=0;gotPanicLastTime=!1;panicChunksReload=()=>{};loadedChunks={};inLoading=!1;chunkReceiveTimes=[];lastChunkReceiveTime=0;lastChunkReceiveTimeAvg=0;panicTimeout;lastPos;eventListeners={};debugChunksInfo={};waitingSpiralChunksLoad={};addWaitTime=1;keepChunksDistance=0;isPlayground=!1;allowPositionUpdate=!0;prepareForTransfer(t){if(t){let n=this.emit.bind(this);this.emit=(r,...s)=>{n(r,...s),t.postMessage({class:vd.restorerName,type:"event",eventName:r,args:s})}}return{__restorer:vd.restorerName}}setBlockStateId(t,n){let r=this.world.setBlockStateId(t,n);if(r&&typeof r.then=="function")throw new Error("setBlockStateId returned promise (not supported)");this.emit("blockUpdate",{pos:t,stateId:n})}updateViewDistance(t){this.viewDistance=t,this.emit("renderDistance",t)}async init(t,n){console.log("WorldView init"),this.updateViewDistance(this.viewDistance),this.emit("chunkPosUpdate",{pos:t}),n?.time?.timeOfDay!==void 0&&this.emit("time",n.time.timeOfDay),n?.entity&&this.emit("playerEntity",n.entity),this.emitterGotConnected(n);let[r,s]=Pm(t),a=bp(this.viewDistance).map(([o,l])=>new ft((r+o)*16,0,(s+l)*16));this.lastPos.update(t),await this._loadChunks(a,t)}chunkProgress(){if(this.panicTimeout&&clearTimeout(this.panicTimeout),this.chunkReceiveTimes.length>=5){let t=this.chunkReceiveTimes.reduce((r,s)=>r+s,0)/this.chunkReceiveTimes.length;this.lastChunkReceiveTimeAvg=t;let n=t*2+1e3;this.panicTimeout&&clearTimeout(this.panicTimeout),this.panicTimeout=setTimeout(()=>{!this.gotPanicLastTime&&this.inLoading&&(console.warn("Chunk loading seems stuck, triggering panic reload"),this.gotPanicLastTime=!0,this.panicChunksReload())},n)}}async _loadChunks(t,n){this.spiralNumber++;let{spiralNumber:r}=this;for(let a of Object.keys(this.waitingSpiralChunksLoad))this.waitingSpiralChunksLoad[a](!1),delete this.waitingSpiralChunksLoad[a];let s=!0;this.inLoading=!0,await NWe(t,this.addWaitTime,async a=>{!s||this.loadedChunks[`${a.x},${a.z}`]||(this.world.getColumnAt(a)||(s=await new Promise(o=>{this.waitingSpiralChunksLoad[`${a.x},${a.z}`]=o})),s&&(await this.loadChunk(a,void 0,`spiral ${r} from ${n.x},${n.z}`),this.chunkProgress()))}),this.panicTimeout&&clearTimeout(this.panicTimeout),this.inLoading=!1,this.gotPanicLastTime=!1,this.chunkReceiveTimes=[],this.lastChunkReceiveTime=0}async loadChunk(t,n=!1,r="spiral"){let[s,a]=Pm(this.lastPos),o=Math.abs(s-Math.floor(t.x/16)),l=Math.abs(a-Math.floor(t.z/16));if(o<=this.viewDistance&&l<=this.viewDistance){let c=await this.world.getColumnAt(t.y!==void 0?t:new ft(t.x,0,t.z));if(c){let u=c.toJson(),f={minY:c.minY??0,worldHeight:c.worldHeight??256};this.emit("loadChunk",{x:t.x,z:t.z,chunk:u,blockEntities:c.blockEntities,worldConfig:f,isLightUpdate:n}),this.loadedChunks[`${t.x},${t.z}`]=!0,this.debugChunksInfo[`${t.x},${t.z}`]??={loads:[]},this.debugChunksInfo[`${t.x},${t.z}`].loads.push({dataLength:u.length,reason:r,time:Date.now()})}else this.isPlayground&&this.emit("markAsLoaded",{x:t.x,z:t.z})}}unloadAllChunks(){for(let t of Object.keys(this.loadedChunks)){let[n,r]=t.split(",").map(Number);this.unloadChunk({x:n,z:r})}}unloadChunk(t){this.emit("unloadChunk",{x:t.x,z:t.z}),delete this.loadedChunks[`${t.x},${t.z}`],delete this.debugChunksInfo[`${t.x},${t.z}`]}emitterGotConnected(t){typeof globalThis.WorkerGlobalScope<"u"&&globalThis instanceof globalThis.WorkerGlobalScope||!t||this.emit("blockEntities",new Proxy({},{get(r,s,a){if(typeof s!="string")return;let[o,l,c]=s.split(",").map(Number);return t.world.getBlock(new ft(o,l,c))?.entity}}))}lastBiomeId=null;updateBiome(t){try{if(!this.world.getBiome)return;let n=this.world.getBiome(t);n!==this.lastBiomeId&&(this.lastBiomeId=n,this.emit("biomeReset"))}catch(n){console.error("error updating biome",n)}}lastPosCheck=null;async updatePosition(t,n=!1){if(!this.allowPositionUpdate)return;let r=t.floored();if(!n&&this.lastPosCheck&&this.lastPosCheck.equals(r))return;this.lastPosCheck=r,this.updateBiome(t);let[s,a]=Pm(this.lastPos),[o,l]=Pm(t);if(s!==o||a!==l||n){this.emit("chunkPosUpdate",{pos:t});let c=[],u=n?this.viewDistance:this.viewDistance+this.keepChunksDistance;for(let m of Object.keys(this.loadedChunks)){let[v,y]=m.split(",").map(Number),_=new ft(v,0,y),[b,g]=Pm(_),x=Math.abs(o-b),w=Math.abs(l-g);(x>u||w>u)&&c.push(_)}for(let m of c)this.unloadChunk(m);let f=bp(this.viewDistance).map(([m,v])=>{let y=new ft((o+m)*16,0,(l+v)*16);if(!this.loadedChunks[`${y.x},${y.z}`])return y}).filter(m=>!!m);this.lastPos.update(t),this._loadChunks(f,t)}else this.emit("chunkPosUpdate",{pos:t}),this.lastPos.update(t)}};var Lm=class{constructor(e,t,n){this.documentRenderer=e;this.options=t;this.abortSignal=n;this._scene=new yr,this._scene.background=new Fe(3294568),this._camera=new Yt(85,e.canvas.width/e.canvas.height,.05,1e3),this.camera.position.set(0,0,0),this.camera.rotation.set(0,0,0)}_scene;_camera;get scene(){return this._scene}get camera(){return this._camera}worldRenderer;WorldRendererClass=bu;async init(){let e=nm,t=new J0;if(t.currentConfig={version:e,noInventoryGui:!0},await t.updateAssetsData?.({}),this.abortSignal.aborted)return;console.time("load menu background scene");let n=nge(e),s=oi()(e),o=globalThis.mcData.blocksArray.filter(v=>{if(!v.name.includes("stained_glass"))return!1;let y=s.fromStateId(v.defaultState,0);if(y.shapes?.length!==1)return!1;let _=y.shapes[0];return _[0]===0&&_[1]===0&&_[2]===0&&_[3]===1&&_[4]===1&&_[5]===1}),l=-15,c=100,u=100;for(let v=-c;v<c;v++)for(let y=-u;y<u;y++){let _=o[Math.floor(Math.random()*o.length)];n.setBlockStateId(new ft(v,y,l),_.defaultState)}this._camera.updateProjectionMatrix(),this._camera.position.set(.5,u/2+.5,.5),this._camera.rotation.set(0,0,0);let f=new ft(...this._camera.position.toArray()),m=new K8(n,2,f);this.abortSignal.aborted||(this.worldRenderer=new this.WorldRendererClass(this.documentRenderer.renderer,this.options,{version:e,worldView:m,inWorldRenderingConfig:rge,playerStateReactive:_de().reactive,rendererState:Fk().reactive,nonReactiveState:Fk().nonReactive,resourcesManager:t}),this.worldRenderer instanceof bu&&(this._scene=this.worldRenderer.realScene,this._camera=this.worldRenderer.camera),m.init(f),await this.worldRenderer.waitForChunksToRender(),!this.abortSignal.aborted&&(this.setupMouseParallax(),console.timeEnd("load menu background scene")))}update(e,t){t&&_u(this.camera,this.documentRenderer.canvas)}dispose(){this.worldRenderer?.destroy(),this.worldRenderer=void 0,this._scene.clear()}setupMouseParallax(){let e=this._camera,t=e.position.x,n=e.position.y,r;document.body.addEventListener("pointermove",s=>{if(s.pointerType!=="mouse")return;let a=.2,o=s.clientX/window.innerWidth-.5,l=-(s.clientY/window.innerHeight-.5);r?.stop(),r=new xr(e.position).to({x:t+o*a,y:n+l*a},0),r.start(),e.updateProjectionMatrix()},{signal:this.abortSignal})}};h();p();d();bt();var Bm=class{constructor(e,t,n={},r=!1){this.documentRenderer=e;this.options=t;this.mode=IR(n,r)}active;abortController=new AbortController;mode;lastFrameTime=0;get futuristic(){return this.active instanceof id?this.active:void 0}get scene(){return this.active?.scene}get camera(){return this.active?.camera}async start(e={}){this.active=this.createImplementation(e),await this.active.init(),this.active.scene.background instanceof Fe&&this.documentRenderer.renderer.setClearColor(this.active.scene.background),this.lastFrameTime=performance.now(),this.documentRenderer.render=(t=!1)=>{let n=performance.now(),r=Math.min((n-this.lastFrameTime)/1e3,.05);this.lastFrameTime=n;let s=this.active;s&&(s.update(r,t),this.documentRenderer.renderer.render(s.scene,s.camera))}}createImplementation(e){switch(this.mode){case"futuristic":return new id(this.documentRenderer,{useMinecraftTextures:e.useMinecraftTextures,initialScene:e.futuristicScene,initialCamera:e.futuristicCamera,initialBlockGroup:e.futuristicBlockGroup,initialCameraSpeed:e.futuristicCameraSpeed,initialBlockSpeed:e.futuristicBlockSpeed,resourcesManager:e.resourcesManager},this.abortController.signal);case"worldBlocks":return new Lm(this.documentRenderer,this.options,this.abortController.signal);default:return new rm(this.documentRenderer)}}dispose(){this.active?.dispose(),this.active=void 0,this.abortController.abort()}};h();p();d();var Du=t0,DWe={rendererWorldPerformance:"normal",rendererMeshersCountOverride:null,starfieldRendering:!0,defaultSkybox:!0,menuBackgroundMode:Du.mode,menuBackgroundMinecraftTextures:Du.minecraftTextures,menuBackgroundFuturisticScene:Du.futuristicScene,menuBackgroundFuturisticCamera:Du.futuristicCamera,menuBackgroundFuturisticBlockGroup:Du.futuristicBlockGroup,menuBackgroundFuturisticCameraSpeed:Du.futuristicCameraSpeedPercent,menuBackgroundFuturisticBlockSpeed:Du.futuristicBlockSpeedPercent,rendererFuturisticReveal:!1,rendererPerfDebugOverlay:!1,disableBlockEntityTextures:!1,rendererMesher:"wasm",rendererShaderCubeDebugMode:"off",showChunkBorders:!1,renderEntities:!0,renderDebug:"basic",frameLimit:!1,backgroundRendering:"20fps",vanillaLook:!1,smoothLighting:!0,newVersionsLighting:!1,vrSupport:!0,vrPageGameRendering:!1,clipWorldBelowY:void 0,highlightBlockColor:"auto",loadPlayerSkins:!0,renderEars:!0,showHand:!0,viewBobbing:!0,dayCycleAndLighting:!0,keepChunksDistance:1,gpuPreference:"default",fov:75};var UWe={menuBackgroundMode:{possibleValues:[["classic","Classic"],["futuristic","Futuristic"]],requiresRestart:!0},menuBackgroundMinecraftTextures:{text:"Minecraft block textures",tooltip:"Use block atlas on futuristic menu cubes (loads assets on menu)"},menuBackgroundFuturisticScene:{possibleValues:ed.map(i=>[i,a8[i]])},menuBackgroundFuturisticCamera:{possibleValues:td.map(i=>[i,o8[i]])},menuBackgroundFuturisticBlockGroup:{possibleValues:nd.map(i=>[i,l8[i]]),text:"Block pool",tooltip:"Block set for textured menu cubes (requires Minecraft textures)"},menuBackgroundFuturisticCameraSpeed:{text:"Camera speed",tooltip:"Orbit / fly-through camera path speed. 0 freezes the path; mouse parallax still works.",min:0,max:200,unit:"%"},menuBackgroundFuturisticBlockSpeed:{text:"Block speed",tooltip:"Floating blocks and sky rotation. Independent of camera path speed.",min:0,max:200,unit:"%"},rendererWorldPerformance:{text:"World performance",tooltip:"Background workers for chunk geometry. Reload to apply.",requiresRestart:!0,possibleValues:[["low-energy","Low Energy"],["normal","Normal"],["maximum","Maximum"]]},starfieldRendering:{text:"Starfield"},defaultSkybox:{text:"Default skybox"},rendererFuturisticReveal:{text:"Futuristic world reveal"},rendererPerfDebugOverlay:{text:"Performance debug overlay"},disableBlockEntityTextures:{text:"Disable block entity textures",tooltip:"Skips signs, banners, heads, maps, etc."},rendererMesher:{possibleValues:[["wasm","WASM"],["legacy-js","Legacy JS"]],text:"Mesher pipeline",tooltip:"WASM is faster. Use JS if WASM is not working. Requires reload.",requiresRestart:!0},rendererShaderCubeDebugMode:{text:"Shader cube debug",tooltip:"Instanced cube path visualization (requires shader cubes enabled).",possibleValues:[["off","Off"],["holes","Hole test (red)"],["texIndex","Tile index colors"],["faces","Face id colors"],["atlasAlpha","Atlas alpha"]]},showChunkBorders:{text:"Chunk borders"},renderEntities:{text:"Render entities"},renderDebug:{possibleValues:["advanced","basic","none"]},frameLimit:{text:"Frame limit",tooltip:"false = VSync / unlimited when focused"},backgroundRendering:{text:"Background FPS limit",possibleValues:[["full","NO"],["5fps","5 FPS"],["20fps","20 FPS"]]},vanillaLook:{text:"Vanilla shading",tooltip:"On: Minecraft-style face shading. Off: higher-contrast client shading."},smoothLighting:{},newVersionsLighting:{text:"Lighting in newer versions"},vrSupport:{text:"VR support",tooltip:"Shows VR entry; does not force VR on."},vrPageGameRendering:{text:"VR page game rendering"},clipWorldBelowY:{text:"Clip world below Y"},highlightBlockColor:{possibleValues:[["auto","Auto"],["blue","Blue"],["classic","Classic"]]},loadPlayerSkins:{},renderEars:{tooltip:"Deadmau5 ears when the skin texture includes them"},showHand:{},viewBobbing:{},dayCycleAndLighting:{text:"Day cycle"},keepChunksDistance:{text:"Keep chunks distance",tooltip:"Extra distance before unloading chunks",max:5,unit:""},fov:{min:30,max:110,unit:"\xB0",text:"Field of view"},gpuPreference:{text:"GPU preference",tooltip:"WebGL power preference. Requires reload / backend restart to apply.",requiresRestart:!0,possibleValues:[["default","Auto"],["high-performance","Dedicated"],["low-power","Low power"]]}};pi.enabled=!1;globalThis.THREE=Lt;var ige=i=>({updateMap:i.entities.updateMap.bind(i.entities),updateCustomBlock:i.updateCustomBlock.bind(i),getBlockInfo:i.getBlockInfo.bind(i),playEntityAnimation:i.entities.playAnimation.bind(i.entities),damageEntity:i.entities.handleDamageEvent.bind(i.entities),updatePlayerSkin:i.entities.updatePlayerSkin.bind(i.entities),changeHandSwingingState:i.changeHandSwingingState.bind(i),getHighestBlocks:i.getHighestBlocks.bind(i),reloadWorld:i.reloadWorld.bind(i),updateEntityModel:i.entities.updateEntityModel.bind(i.entities),playEntityModelAnimation:i.entities.playEntityModelAnimation.bind(i.entities),addMedia:i.media.addMedia.bind(i.media),destroyMedia:i.media.destroyMedia.bind(i.media),setControlMode:i.media.setControlMode.bind(i.media),setVideoPlaying:i.media.setVideoPlaying.bind(i.media),setVideoSeeking:i.media.setVideoSeeking.bind(i.media),setVideoVolume:i.media.setVideoVolume.bind(i.media),setVideoSpeed:i.media.setVideoSpeed.bind(i.media),handleUserClick:i.media.handleUserClick.bind(i.media),addSectionAnimation(e,t){i.sectionsOffsetsAnimations[e]=t},removeSectionAnimation(e){delete i.sectionsOffsetsAnimations[e]},shakeFromDamage:i.cameraShake.shakeFromDamage.bind(i.cameraShake),onPageInteraction:i.media.onPageInteraction.bind(i.media),downloadMesherLog:i.downloadMesherLog.bind(i),explodeFirework:i.fireworksLegacy.explode.bind(i.fireworksLegacy),explodeFireworkFacingCamera:i.fireworksLegacy.explodeFacingCamera.bind(i.fireworksLegacy),addWaypoint:i.waypoints.addWaypoint.bind(i.waypoints),removeWaypoint:i.waypoints.removeWaypoint.bind(i.waypoints),startCinimaticScript:i.cinimaticScript.startScript.bind(i.cinimaticScript),stopCinimaticScript:i.cinimaticScript.stopScript.bind(i.cinimaticScript),launchFirework:i.fireworks.launchFirework.bind(i.fireworks),setSkyboxImage:i.skyboxRenderer.setSkyboxImage.bind(i.skyboxRenderer),setRain:e=>i.toggleModule("rain",e),spawnBlockBreakParticles(e,t,n,r,s,a){i.getModule("blockBreakParticles")?.spawnBlockBreakParticles(e,t,n,r,s,a)},spawnBlockCrackParticle(e,t,n,r,s,a,o){i.getModule("blockBreakParticles")?.spawnCrackParticle(e,t,n,r,s,a,o)},async loadGeometryExport(e){let{applyWorldGeometryExport:t}=await Promise.resolve().then(()=>(gR(),qme));return t(i,e)},feedChunkPacket(e){let{kind:t,...n}=e,r={type:t,...n};for(let s of i.workers)s.postMessage(r)}}),VWe=[],Z8=(i,...e)=>{for(let t of Object.values(globalThis.loadedMods??{}))try{t.threeJsBackendModule?.[i]?.(...e)}catch(n){let r=`[mod three.js] Error calling ${i} on ${t.name}: ${n}`;throw new Error(r)}},sge=()=>{let i,e=null,t=null,n=null,r=null,s=(u,f)=>{Jn?i=Cv(u,VWe,globalThis):i=u,e=new S7(i,f?.canvas),globalThis.renderer=e.renderer,globalThis.documentRenderer=e,globalThis.threeJsBackend=c,Z8("default",c)},a=async u=>{if(!e)throw new Error("Document renderer not initialized");if(!n&&!t){let f={...i.config.menuBackground,...u};t=new Bm(e,{...i},f,!!process.env.SINGLE_FILE_BUILD_MODE),Z8("menuBackgroundCreated",t),await t.start(f),Z8("menuBackgroundReady",t)}},o=async u=>{let m=Jn?Cv(u,[J0,vd],globalThis):u;if(!e)throw new Error("Document renderer not initialized");e.nonReactiveState=m.nonReactiveState,globalThis.resourcesManager=m.resourcesManager,t&&(t.dispose(),t=null),n=new bu(e.renderer,i,m),await n.worldReadyPromise,r=new F6(m.nonReactiveState),globalThis.frameTimingCollector=r;let v=e.render;e.render=function(y){v.call(this,y),r?.markFrameStart(),m.inWorldRenderingConfig.paused||n?.render(y),r?.markFrameEnd(),r?.markFrameDisplay()},e.inWorldRenderingConfig=m.inWorldRenderingConfig,globalThis.world=n,Z8("worldReady",n)},l=()=>{t&&(t.dispose(),t=null),e&&e.dispose(),n&&(n.destroy(),n=null)},c={id:"threejs",displayName:`three.js ${ga}`,startMenuBackground:a,startWorld:o,disconnect:l,setRendering(u){e.setPaused(!u),n&&(n.renderingActive=u)},getMenuBackground:()=>t??void 0,getDebugOverlay:()=>({get entitiesString(){return n?.entities.getDebugString()},get left(){return{"Geo Memory":n?.chunkMeshManager.getEstimatedMemoryUsage().total??"-"}}}),updateCamera(u,f,m){r?.markCameraUpdate(!u),n?.setFirstPersonCamera(u,f,m)},get soundSystem(){return n?.soundSystem},get backendMethods(){if(n)return ige(n)}};return{main:{init:s,backend:c},workerProxy(){return sB({init(u,f){s(u,{canvas:f})},updateSizeExternal(u,f,m){e?.updateSizeExternal(u,f,m)},startMenuBackground:a,startWorld:o,disconnect:l,setRendering:c.setRendering,updateCamera(u,f,m){let v=u?new ft(u.x,u.y,u.z):null;r?.markCameraUpdate(!v),c.updateCamera(v,f,m)},async callBackendMethod(u,...f){if(!n)throw new Error("World renderer not initialized");let v=ige(n)[u];if(!v)throw new Error(`Backend method ${String(u)} is unavailable`);return v(...f)}})}}};globalThis.structuredClone??=i=>JSON.parse(JSON.stringify(i));self.addEventListener("message",i=>{let e=i.data,t=globalThis;if(e.type==="mcData"){t.mcData=e.mcData,t.loadedData=e.mcData,console.log("data loaded");return}Array.isArray(e)&&e.forEach(n=>{n.type==="mcData"&&(t.mcData=n.mcData,t.loadedData=n.mcData)})});var FWe=sge();FWe.workerProxy();})();
28831
+ }`})}},TR=class{constructor(e){this.worldRenderer=e}points;clock=new ks;enabled=!1;currentTime;enable(){this.enabled||(this.enabled=!0,this.updateVisibility())}disable(){this.enabled&&(this.enabled=!1,this.removeStars())}toggle(){return this.enabled?this.disable():this.enable(),this.enabled}enablementCheck=()=>this.currentTime?this.currentTime>13500&&this.currentTime<23e3:!1;render=e=>{this.points&&(this.points.position.set(0,0,0),this.points.material.uniforms.time.value=this.clock.getElapsedTime()*.2)};updateTimeOfDay(e){this.currentTime=e,this.enabled&&this.updateVisibility()}updateVisibility(){if(!this.enabled)return;let e=this.enablementCheck?.()??!1;e&&!this.points?this.createStars():!e&&this.points&&this.removeStars()}createStars(){if(this.points)return;let e=80,t=50,n=7e3,r=7,s=10,a=new it,o=_=>new K().setFromSpherical(new y5(_,Math.acos(1-Math.random()*2),Math.random()*2*Math.PI)),l=[],c=[],u=Array.from({length:n},()=>(.5+.5*Math.random())*r),f=new Fe,m=e+t,v=t/n;for(let _=0;_<n;_++)m-=v*Math.random(),l.push(...o(m).toArray()),f.setHSL(_/n,s,.9),c.push(f.r,f.g,f.b);a.setAttribute("position",new qe(l,3)),a.setAttribute("color",new qe(c,3)),a.setAttribute("size",new qe(u,1));let y=new MR;y.blending=Li,y.depthTest=!0,y.depthWrite=!1,y.transparent=!0,this.points=new tr(a,y),this.points.renderOrder=-1,this.worldRenderer.scene.add(this.points)}dispose(){this.removeStars()}removeStars(){this.points&&(this.points.geometry.dispose(),this.points.material.dispose(),this.worldRenderer.scene.remove(this.points),this.points=void 0)}},u3e={id:"starfield",controller:TR,enabledDefault:!0,cannotBeDisabled:!0};var f3e={starfield:u3e,futuristicReveal:c3e,rain:o3e,cameraBobbing:r3e,blockBreakParticles:n3e};h();p();d();h();p();d();var RR=()=>({longRenderTime:!1,constantLongRenderTime:!1,tooManyEntities:!1,tooManyTextures:!1,unknownReason:!1});h();p();d();h();p();d();var tm=class{constructor(e){this.factors=e}renderTimeHistory=[];onFrame(e){this.pushRenderTime(e.totalMs),this.recompute(e)}pushRenderTime(e){this.renderTimeHistory.push(e),this.renderTimeHistory.length>24&&this.renderTimeHistory.shift()}recompute(e){let t=e.fps>0&&e.fps<=45,n=Math.max(0,e.totalMs-e.entitiesMs),r=e.totalMs>=30,s=this.renderTimeHistory.length,a=this.renderTimeHistory.filter(m=>m>=30).length,o=s>=8&&a/s>=.65,l=e.loadedTextureCount>=100,c=t&&e.entitiesMs>=8&&n<=20,f=t&&!(r||o||c||l);this.factors.longRenderTime=r,this.factors.constantLongRenderTime=o,this.factors.tooManyEntities=c,this.factors.tooManyTextures=l,this.factors.unknownReason=f}reset(){this.renderTimeHistory.length=0,this.factors.longRenderTime=!1,this.factors.constantLongRenderTime=!1,this.factors.tooManyEntities=!1,this.factors.tooManyTextures=!1,this.factors.unknownReason=!1}};h();p();d();var tGe=[{key:"longRenderTime",code:"LR"},{key:"constantLongRenderTime",code:"CLR"},{key:"tooManyEntities",code:"ENT"},{key:"tooManyTextures",code:"TEX"},{key:"unknownReason",code:"UNK"}];function CR(i){let e=tGe.filter(({key:t})=>i[t]).map(({code:t})=>t);return e.length>0?e.join("+"):""}var yu=class yu extends C7{constructor(t,n,r){if(!r.resourcesManager)throw new Error("resourcesManager is required in displayOptions");super(r.resourcesManager,r,n);this.renderer=t;this.initOptions=n;this.displayOptions=r;this.performanceMonitor=new tm(this.reactiveState.world.instabilityFactors),this.renderer=t,r.rendererState.renderer=yu.getRendererInfo(t)??"...",this.chunkMeshManager=new em(this,this.scene,this.material,this.worldSizeParams.worldHeight,this.viewDistance),this.onRenderDistanceChanged=s=>{this.chunkMeshManager.updateViewDistance(s)},this.cursorBlock=new L4(this),this.holdingBlock=Yp(this),this.holdingBlockLeft=Yp(this,!0);for(let s of Object.values(f3e))this.registerModule(s);this.skyboxRenderer=new H4(this.realScene,!1,null),this.skyboxRenderer.init(),this.addDebugOverlay(),this.resetScene(),this.init(),this.soundSystem=new O4(this),this.cameraShake=new N4(this,this.onRender),this.media=new D4(this),this.fireworksLegacy=new F4(this),this.waypoints=new V4(this),this.cinimaticScript=new z4(this,(s,a,o)=>this.setCinimaticCamera(s,a,o),s=>this.setCinimaticFov(s),()=>({position:new ft(this.cameraWorldPos.x,this.cameraWorldPos.y,this.cameraWorldPos.z),yaw:this.cameraShake.getBaseRotation().yaw,pitch:this.cameraShake.getBaseRotation().pitch,fov:this.camera.fov})),this.fireworks=new q4(this.realScene,this.sceneOrigin),this.renderUpdateEmitter.on("chunkFinished",s=>{this.finishChunk(s)}),this.worldSwitchActions(),this.initializeModules()}outputFormat="threeJs";isShaderCubeBlocksEnabled(){return this.worldRendererConfig.shaderCubeBlocks===!0&&!!this.renderer?.capabilities?.isWebGL2}chunkMeshManager;get sectionObjects(){return this.chunkMeshManager.sectionObjects}chunkTextures=new Map;signsCache=new Map;cameraSectionPos=new ft(0,0,0);holdingBlock;holdingBlockLeft;scene=new yr;get realScene(){return this.scene}ambientLight=new pa(13421772);directionalLight=new as(16777215,.5);entities=new I4(this,globalThis.mcData);performanceMonitor;cameraGroupVr;material=new st({vertexColors:!0,transparent:!0,alphaTest:.1});itemsTexture;cursorBlock;onRender=[];lastRenderTime=0;animatedFov=0;lastFovAnimTime=0;cameraShake;cameraContainer;media;get waitingChunksToDisplay(){return this.chunkMeshManager.waitingChunksToDisplay}waypoints;cinimaticScript;camera;renderTimeAvg=0;pendingSectionUpdates=new Map;pendingSectionBufferStartTimes=new Map;get estimatedMemoryUsage(){return this.chunkMeshManager.getEstimatedMemoryUsage().total}modules={};sectionsOffsetsAnimations={};fountains=[];fireworksLegacy;DEBUG_RAYCAST=!1;skyboxRenderer;fireworks;sceneOrigin=new G4(this.scene);cameraWorldPos={x:0,y:0,z:0};_cameraPositionAccessWarned=!1;_tmpCameraPos=new K;currentPosTween;currentRotTween;_tpDirection=new K;_tpPitchQuat=new Ut;_tpYawQuat=new Ut;_tpFinalQuat=new Ut;_tpScenePos=new K;_tpAxisX=new K(1,0,0);_tpAxisY=new K(0,1,0);_tpRaycaster=new vo;_tpChunkWorldPos=new K;get tilesRendered(){return this.chunkMeshManager.getTotalTiles()}get blocksRendered(){return this.chunkMeshManager.getTotalBlocks()}registerModule(t){if(t.id in this.modules){console.warn(`Module ${t.id} is already registered`);return}let n=new t.controller(this),r={manifest:t,controller:n,enabled:!1,toggle:()=>this.toggleModule(t.id)};this.modules[t.id]=r,t.enabledDefault&&this.toggleModule(t.id,!0)}enableModule(t){let n=this.modules[t];if(!n){console.warn(`Module ${t} not found`);return}n.enabled||(n.enabled=!0,n.controller.enable(),n.controller.render&&this.onRender.push(n.controller.render))}disableModule(t){let n=this.modules[t];if(!n){console.warn(`Module ${t} not found`);return}if(n.manifest.cannotBeDisabled){console.warn(`Module ${t} cannot be disabled`);return}if(n.enabled&&(n.enabled=!1,n.controller.disable(),n.controller.render)){let r=this.onRender.indexOf(n.controller.render);r>-1&&this.onRender.splice(r,1)}}toggleModule(t,n){let r=this.modules[t];if(!r)return console.warn(`Module ${t} not found`),!1;let s=n!==void 0?n:!r.enabled;if(s===r.enabled)return r.enabled;if(!s&&r.manifest.cannotBeDisabled)return console.warn(`Module ${t} cannot be disabled`),!0;if(r.enabled=s,s)r.controller.enable(),r.controller.render&&!this.onRender.includes(r.controller.render)&&this.onRender.push(r.controller.render);else if(r.controller.disable(),r.controller.render){let a=this.onRender.indexOf(r.controller.render);a>-1&&this.onRender.splice(a,1)}return s}disposeModules(){for(let t of Object.values(this.modules))t.controller.dispose();this.modules={}}initializeModules(){this.updateModulesFromConfig()}getModule(t){return this.modules[t]?.controller}anyModuleRequiresHeightmap(){return Object.values(this.modules).some(t=>t.enabled&&t.manifest.requiresHeightmap)}get cameraObject(){return this.cameraGroupVr??this.cameraContainer}_wrapCameraPositionWithWarning(){let t=this.camera.position,n=this,r=20,s=(l,c,u)=>Math.abs(l)>r||Math.abs(c)>r||Math.abs(u)>r,a=()=>{!n._cameraPositionAccessWarned&&typeof process<"u"},o=new Proxy(t,{set(l,c,u){return(c==="x"||c==="y"||c==="z")&&typeof u=="number"&&Math.abs(u)>r&&a(),l[c]=u,!0},get(l,c,u){let f=l[c];return c==="set"?function(m,v,y){return s(m,v,y)&&a(),l.set(m,v,y)}:c==="setX"||c==="setY"||c==="setZ"?function(m){return Math.abs(m)>r&&a(),l[c](m)}:c==="copy"?function(m){return s(m.x,m.y,m.z)&&a(),l.copy(m)}:typeof f=="function"?f.bind(l):f}});Object.defineProperty(this.camera,"position",{value:o,configurable:!0,enumerable:!0})}worldSwitchActions(){this.onWorldSwitched.push(()=>{this.protocolCustomBlocks.clear(),this.sectionsOffsetsAnimations={},this.waypoints.clear(),this.cinimaticScript.stopScript(),this.fireworks.clear()})}downloadWorldGeometry(){vR(this,new K(this.cameraWorldPos.x,this.cameraWorldPos.y,this.cameraWorldPos.z),this.cameraShake.getBaseRotation(),"world-geometry.json")}updateEntity(t,n=!1){let r={rotation:{head:{x:t.headPitch??t.pitch,y:t.headYaw,z:0}}};n?this.entities.updateEntityPosition(t,!1,r):this.entities.update(t,r)}updatePlayerEntity(t){this.entities.handlePlayerEntity(t)}resetScene(){this.sceneOrigin.update(0,0,0),this.cameraWorldPos.x=0,this.cameraWorldPos.y=0,this.cameraWorldPos.z=0,this.scene.matrixAutoUpdate=!1,this.scene.background=new Fe(this.initOptions.config.sceneBackground),this.scene.add(this.ambientLight),this.directionalLight.position.set(1,1,.5).normalize(),this.directionalLight.castShadow=!0,this.scene.add(this.directionalLight);let t=this.renderer.getSize(new Ue);this.camera=new Yt(75,t.x/t.y,.1,1e3),this._wrapCameraPositionWithWarning(),this.cameraContainer=new At,this.cameraContainer.add(this.camera),this.scene.add(this.cameraContainer)}watchReactivePlayerState(){super.watchReactivePlayerState(),this.onReactivePlayerStateUpdated("inWater",t=>{this.skyboxRenderer.updateWaterState(t,this.playerStateReactive.waterBreathing)}),this.onReactivePlayerStateUpdated("waterBreathing",t=>{this.skyboxRenderer.updateWaterState(this.playerStateReactive.inWater,t)}),this.onReactivePlayerStateUpdated("ambientLight",t=>{t&&(this.ambientLight.intensity=t)}),this.onReactivePlayerStateUpdated("directionalLight",t=>{t&&(this.directionalLight.intensity=t)}),this.onReactivePlayerStateUpdated("lookingAtBlock",t=>{this.cursorBlock.setHighlightCursorBlock(t?new ft(t.x,t.y,t.z):null,t?.shapes)}),this.onReactivePlayerStateUpdated("diggingBlock",t=>{this.cursorBlock.updateBreakAnimation(t?{x:t.x,y:t.y,z:t.z}:void 0,t?.stage??null,t?.mergedShape)}),this.onReactivePlayerStateUpdated("perspective",t=>{let n=new ft(this.cameraWorldPos.x,this.cameraWorldPos.y,this.cameraWorldPos.z);this.updateCamera(n,this.cameraShake.getBaseRotation().yaw,this.cameraShake.getBaseRotation().pitch)})}watchReactiveConfig(){super.watchReactiveConfig(),this.onReactiveConfigUpdated("showChunkBorders",n=>{this.updateShowChunksBorder(n)}),this.onReactiveConfigUpdated("defaultSkybox",n=>{this.skyboxRenderer.updateDefaultSkybox(n)}),this.onReactiveConfigUpdated("shaderCubeDebugMode",()=>{this.chunkMeshManager.syncCubeShaderUniforms()}),this.onReactiveConfigUpdated("futuristicReveal",()=>{this.updateModulesFromConfig()});let t=this.displayOptions.inWorldRenderingConfig.handRenderer;this.onReactiveConfigUpdated("handRenderer",n=>{if(n===t)return;t=n;let r=this.holdingBlock.ready,s=this.holdingBlockLeft.ready;this.holdingBlock.dispose(),this.holdingBlockLeft.dispose(),this.holdingBlock=Yp(this),this.holdingBlockLeft=Yp(this,!0),r&&(this.holdingBlock.ready=!0,this.holdingBlock.updateItem()),s&&(this.holdingBlockLeft.ready=!0,this.holdingBlockLeft.updateItem())}),this.onReactiveConfigUpdated("*",()=>{this.updateModulesFromConfig()}),this.updateModulesFromConfig()}updateModulesFromConfig(){let{moduleStates:t}=this.worldRendererConfig;for(let[n,r]of Object.entries(this.modules)){let s=t[n];if(s==="enabled"){r.enabled||this.toggleModule(n,!0);continue}if(s==="disabled"){r.enabled&&!r.manifest.cannotBeDisabled&&this.toggleModule(n,!1);continue}if(s==="auto"||s===void 0)if(r.controller.autoEnableCheck){let a=r.controller.autoEnableCheck();a&&!r.enabled?this.toggleModule(n,!0):!a&&r.enabled&&!r.manifest.cannotBeDisabled&&this.toggleModule(n,!1)}else{let a=r.manifest.enabledDefault??!1;a&&!r.enabled?this.toggleModule(n,!0):!a&&r.enabled&&!r.manifest.cannotBeDisabled&&this.toggleModule(n,!1)}}}changeHandSwingingState(t,n=!1){let r=n?this.holdingBlockLeft:this.holdingBlock;t?r.startSwing():r.stopSwing()}async updateAssetsData(){let t=this.resourcesManager.currentResources,n=this.material.map,r=this.itemsTexture,s=yp(t.blocksAtlasImage);s.needsUpdate=!0,s.flipY=!1,this.material.map=s,this.chunkMeshManager.syncCubeShaderUniforms();let a=yp(t.itemsAtlasImage);a.needsUpdate=!0,a.flipY=!1,this.itemsTexture=a,n&&n.dispose(),r&&r.dispose(),await super.updateAssetsData(),this.onAllTexturesLoaded(),Object.keys(this.loadedChunks).length>0&&(console.log("rerendering chunks because of texture update"),this.rerenderAllChunks())}onAllTexturesLoaded(){this.holdingBlock.ready=!0,this.holdingBlock.updateItem(),this.holdingBlockLeft.ready=!0,this.holdingBlockLeft.updateItem()}changeBackgroundColor(t){this.realScene.background=new Fe(t[0],t[1],t[2])}changeCardinalLight(t){this.worldRendererConfig.cardinalLight=t}timeUpdated(t){let n=this.getModule("starfield");n?.updateTimeOfDay&&n.updateTimeOfDay(t),this.skyboxRenderer.updateTime(t)}biomeUpdated(t){t?.temperature!==void 0&&this.skyboxRenderer.updateTemperature(t.temperature)}biomeReset(){this.skyboxRenderer.updateTemperature(cR)}getItemRenderData(t,n){return Tme(t,n,this.resourcesManager,this.playerStateReactive)}async demoModel(){let t=cursorBlockRel(0,1,0).position,n=await Hp();Tde(n,t);let r=new va(n,16776960);n.add(r),this.realScene.add(n)}demoItem(){let t=cursorBlockRel(0,1,0).position,{mesh:n}=this.entities.getItemMesh({itemId:541},{});n.position.set(t.x+.5,t.y+.5,t.z+.5);let r=new va(n,16776960);n.add(r),this.realScene.add(n)}debugOverlayAdded=!1;addDebugOverlay(){if(this.debugOverlayAdded)return;this.debugOverlayAdded=!0;let t=M7("debug-overlay",80,0,void 0,{className:A7});setInterval(()=>{if(t.setVisibility(this.displayAdvancedStats),this.displayAdvancedStats){let n=l=>new Intl.NumberFormat("en-US",{}).format(l),r=l=>new Intl.NumberFormat("en-US",{notation:"compact",maximumFractionDigits:1}).format(l),s="";s+=`TE: ${n(this.renderer.info.memory.textures)} `,s+=`F: ${r(this.tilesRendered)} `,s+=`B: ${r(this.blocksRendered)} `,s+=`MEM: ${this.chunkMeshManager.getEstimatedMemoryUsage().total} `;let a=this.chunkMeshManager.getStats();s+=`POOL: ${a.activeCount}/${a.poolSize} `;let o=CR(this.reactiveState.world.instabilityFactors);o&&(s+=`PF: ${o} `),t.updateText(s),this.backendInfoReport=s}},200)}updatePosDataChunk(t){let n=this.sectionObjects[t];if(!n)return;let[r,s,a]=t.split(",").map(u=>Math.floor(+u/16)),l=500-(Math.abs(r-this.cameraSectionPos.x)+Math.abs(s-this.cameraSectionPos.y)+Math.abs(a-this.cameraSectionPos.z)),c=n.mesh??n.shaderMesh??n.children.find(u=>u.name==="mesh"||u.name==="shaderMesh");c&&(c.renderOrder=l)}updateViewerPosition(t){this.viewerChunkPosition=t}cameraSectionPositionUpdate(){for(let t in this.sectionObjects)this.sectionObjects[t]&&this.updatePosDataChunk(t)}getDir(t,n){return t===n?0:t<n?1:-1}finishChunk(t){this.chunkMeshManager.finishChunkDisplay(t)}applyPendingSectionUpdates(){if(this.pendingSectionUpdates.size===0)return;let t=performance.now(),n=this.getSectionHeight(),r=[];for(let s of this.pendingSectionUpdates.keys()){let a=this.pendingSectionBufferStartTimes.get(s)??t;if(t-a<yu.MAX_SECTION_UPDATE_BUFFER_MS){let[l,c,u]=s.split(",").map(Number),f=[`${l-16},${c},${u}`,`${l+16},${c},${u}`,`${l},${c-n},${u}`,`${l},${c+n},${u}`,`${l},${c},${u-16}`,`${l},${c},${u+16}`],m=!1;for(let v of f)if(this.sectionsWaiting.has(v)&&!this.pendingSectionUpdates.has(v)&&this.sectionObjects[v]){m=!0;break}if(m)continue}r.push(s)}if(r.length!==0)for(let s of r){let a=this.pendingSectionUpdates.get(s);this.pendingSectionUpdates.delete(s),this.pendingSectionBufferStartTimes.delete(s);let o=a.key.split(","),l=`${o[0]},${o[2]}`;if(!this.loadedChunks[l]||!this.active){this.chunkMeshManager.releaseSection(a.key);continue}if(!this.chunkMeshManager.sectionHasRenderableContent(a.geometry)){this.chunkMeshManager.releaseSection(a.key);continue}this.chunkMeshManager.updateSection(a.key,a.geometry),this.updatePosDataChunk(a.key)}}clearPendingSectionUpdatesForChunk(t,n){for(let r of[...this.pendingSectionUpdates.keys()])r.startsWith(`${t},`)&&r.endsWith(`,${n}`)&&(this.pendingSectionUpdates.delete(r),this.pendingSectionBufferStartTimes.delete(r))}handleWorkerMessage(t){if(t.type==="geometry"){let n=t.key.split(","),r=`${n[0]},${n[2]}`;if(!this.loadedChunks[r]||!this.active){this.pendingSectionUpdates.delete(t.key),this.pendingSectionBufferStartTimes.delete(t.key);return}if(this.sectionObjects[t.key]){this.pendingSectionUpdates.set(t.key,t),this.pendingSectionBufferStartTimes.has(t.key)||this.pendingSectionBufferStartTimes.set(t.key,performance.now());return}if(!this.chunkMeshManager.sectionHasRenderableContent(t.geometry)){this.chunkMeshManager.releaseSection(t.key);return}this.chunkMeshManager.updateSection(t.key,t.geometry),this.updatePosDataChunk(t.key)}}getSignTexture(t,n,r,s=!1){let a=d1(t),o=this.chunkTextures.get(`${a[0]},${a[1]}`);o||(o={},this.chunkTextures.set(`${a[0]},${a[1]}`,o));let l=`${t.x},${t.y},${t.z}`;if(o[l])return o[l];let c=(0,p3e.default)(this.version),u=w7(n,r,c);if(!u)return;let f=new Gt(u);return f.magFilter=Je,f.minFilter=Je,f.needsUpdate=!0,o[l]=f,f}getCameraPosition(t){return(t??this._tmpCameraPos).set(this.cameraWorldPos.x,this.cameraWorldPos.y,this.cameraWorldPos.z)}getSectionCameraPosition(){let t=this.getCameraPosition();return new ft(Math.floor(t.x/16),Math.floor(t.y/16),Math.floor(t.z/16))}updateCameraSectionPos(){let t=this.getSectionCameraPosition();this.cameraSectionPos.equals(t)||(this.cameraSectionPos=t,this.cameraSectionPositionUpdate())}setFirstPersonCamera(t,n,r){let s=this.playerStateReactive.eyeHeight;this.updateCamera(t?.offset(0,s,0)??null,n,r),this.updateCameraSectionPos()}getThirdPersonCamera(t,n,r){t??=new K(this.cameraWorldPos.x,this.cameraWorldPos.y,this.cameraWorldPos.z);let s=this.playerStateReactive.perspective==="third_person_back",a=4,o=this._tpDirection.set(0,0,-1),l=this._tpPitchQuat.setFromAxisAngle(this._tpAxisX,r),c=this._tpYawQuat.setFromAxisAngle(this._tpAxisY,n),u=this._tpFinalQuat.multiplyQuaternions(c,l);o.applyQuaternion(u),s&&o.multiplyScalar(-1),this.DEBUG_RAYCAST&&this.debugRaycast(t,o,a);let f=this._tpScenePos.set(this.sceneOrigin.toSceneX(t.x),this.sceneOrigin.toSceneY(t.y),this.sceneOrigin.toSceneZ(t.z)),m=this._tpRaycaster;m.set(f,o),m.far=a;let v=80,y=v*v,_=t.x,b=t.y,g=t.z,x=[];for(let C of Object.values(this.sectionObjects)){if(C.name!=="chunk"||!C.visible||C.worldX===void 0)continue;let L=C.worldX-_,M=C.worldY-b,T=C.worldZ-g;if(L*L+M*M+T*T>y)continue;let F=C.children.find(Z=>Z.name==="mesh"||Z.name==="shaderMesh");F&&x.push(F)}let w=m.intersectObjects(x,!1),E=a;w.length>0&&(E=Math.max(.5,w[0].distance-.2));let A=this.chunkMeshManager.raycastShaderSectionAABBs(t,o,E,v);return A!==void 0&&(E=Math.max(.5,A-.2)),new ft(t.x+o.x*E,t.y+o.y*E,t.z+o.z*E)}debugRaycastHelper;debugHitPoint;debugRaycast(t,n,r){this.debugRaycastHelper&&(this.realScene.remove(this.debugRaycastHelper),this.debugRaycastHelper=void 0),this.debugHitPoint&&(this.realScene.remove(this.debugHitPoint),this.debugHitPoint=void 0);let s=new K(this.sceneOrigin.toSceneX(t.x),this.sceneOrigin.toSceneY(t.y),this.sceneOrigin.toSceneZ(t.z));this.debugRaycastHelper=new bc(n.clone().normalize(),s,r,16711680,r*.1,r*.05),this.realScene.add(this.debugRaycastHelper);let a=new is(.2,8,8),o=new st({color:65280});this.debugHitPoint=new je(a,o),this.debugHitPoint.position.copy(s).add(n.clone().multiplyScalar(r)),this.realScene.add(this.debugHitPoint)}prevFramePerspective=null;setCinimaticCamera(t,n,r){this.cameraWorldPos.x=t.x,this.cameraWorldPos.y=t.y,this.cameraWorldPos.z=t.z,this.sceneOrigin.update(t.x,t.y,t.z),this.cameraObject.position.set(0,0,0),this.cameraShake.setBaseRotation(r,n),this.updateCameraSectionPos()}setCinimaticFov(t){this.animatedFov=t,this.camera.fov=t,this.camera.updateProjectionMatrix()}updateSmoothFov(){if(this.cinimaticScript.running)return;let t=this.displayOptions.inWorldRenderingConfig.fov,n=this.playerStateReactive.fovMultiplier,r=t*(Number.isFinite(n)?n:1),s=performance.now();if(this.animatedFov===0&&(this.animatedFov=r),Math.abs(this.animatedFov-r)>=.01){let a=s-this.lastFovAnimTime,o=Math.min(a/yu.FOV_TRANSITION_MS,1),l=c=>1-(1-c)**3;this.animatedFov+=(r-this.animatedFov)*l(o),Math.abs(this.animatedFov-r)<.01&&(this.animatedFov=r)}else this.animatedFov=r;this.lastFovAnimTime=s,this.camera.fov!==this.animatedFov&&(this.camera.fov=this.animatedFov,this.camera.updateProjectionMatrix())}updateCamera(t,n,r){if(!this.cinimaticScript.running){if(t){this.renderer.xr.isPresenting&&(t.y-=this.camera.position.y),this.currentPosTween?.stop();let s=this.displayOptions.inWorldRenderingConfig.instantCameraUpdate?0:this.playerStateUtils.isSpectatingEntity()?150:50;this.currentPosTween=new xr(this.cameraWorldPos).to({x:t.x,y:t.y,z:t.z},s).onUpdate(()=>{this.sceneOrigin.update(this.cameraWorldPos.x,this.cameraWorldPos.y,this.cameraWorldPos.z),this.cameraObject.position.set(0,0,0)}).start()}if(this.playerStateUtils.isSpectatingEntity()){let s=this.cameraShake.getBaseRotation(),a=0,o=Math.PI/2;s.yaw<o&&n>Math.PI+o?a=-Math.PI*2:n<o&&s.yaw>Math.PI+o&&(a=Math.PI*2),this.currentRotTween?.stop(),this.currentRotTween=new xr(s).to({pitch:r,yaw:n+a},100).onUpdate(l=>this.cameraShake.setBaseRotation(l.pitch,l.yaw-a)).start()}else{this.currentRotTween?.stop(),this.cameraShake.setBaseRotation(r,n);let{perspective:s}=this.playerStateReactive;if(s==="third_person_back"||s==="third_person_front"){let a=new K(this.cameraWorldPos.x,this.cameraWorldPos.y,this.cameraWorldPos.z),o=this.getThirdPersonCamera(a,n,r),l=a.distanceTo(new K(o.x,o.y,o.z)),c=s==="third_person_back"?l:-l;this.camera.position.set(0,0,c),s==="third_person_front"?this.camera.rotation.set(0,Math.PI,0):this.camera.rotation.set(0,0,0)}else this.camera.position.z=0,this.camera.rotation.set(0,0,0),this.debugRaycastHelper&&(this.realScene.remove(this.debugRaycastHelper),this.debugRaycastHelper=void 0),this.debugHitPoint&&(this.realScene.remove(this.debugHitPoint),this.debugHitPoint=void 0)}this.updateCameraSectionPos()}}debugChunksVisibilityOverride(){let{chunksRenderAboveOverride:t,chunksRenderBelowOverride:n,chunksRenderDistanceOverride:r,chunksRenderAboveEnabled:s,chunksRenderBelowEnabled:a,chunksRenderDistanceEnabled:o}=this.reactiveDebugParams,l=this.getSectionHeight(),c=this.cameraSectionPos.y*l;if(this.displayOptions.inWorldRenderingConfig.enableDebugOverlay&&t!==void 0||n!==void 0||r!==void 0)for(let[u,f]of Object.entries(this.sectionObjects)){if(f._waitingForChunkDisplay)continue;let[m,v,y]=u.split(",").map(Number),_=s&&t!==void 0?v<=c+t:a&&n!==void 0?v>=c-n:o&&r!==void 0?Math.abs(v-c)<=r:!0;f.visible=_}else this.chunkMeshManager.updateSectionsVisibility()}render(t=!1){if(this.currentRenderedFrames++,this.reactiveDebugParams.stopRendering)return;this.debugChunksVisibilityOverride();let n=performance.now();this.lastRendered=performance.now();let r=this.lastRenderTime>0?Math.min(Math.max((n-this.lastRenderTime)/1e3,0),.1):1/60;this.lastRenderTime=n,this.cursorBlock.render(),this.updateSectionOffsets();let s=this.getCameraPosition();if(this.skyboxRenderer.update(s,this.viewDistance),this.updateSmoothFov(),t){let f=this.renderer.getSize(new Ue);this.camera.aspect=f.width/f.height,this.camera.updateProjectionMatrix()}let a=0;if(!this.reactiveDebugParams.disableEntities){let f=performance.now();this.entities.render(),a=performance.now()-f}let o=this.cameraGroupVr instanceof ot?this.cameraGroupVr.children.find(f=>f instanceof Yt):this.camera;this.applyPendingSectionUpdates();let l=this.chunkMeshManager.globalBlockBuffer;l&&(l.setCameraOrigin(this.cameraWorldPos.x,this.cameraWorldPos.y,this.cameraWorldPos.z),l.uploadDirtyRange()),this.renderer.render(this.scene,o),this.displayOptions.inWorldRenderingConfig.showHand&&this.playerStateReactive.gameMode!=="spectator"&&this.playerStateReactive.perspective==="first_person"&&!this.renderer.xr.isPresenting&&(this.holdingBlock.render(this.camera,this.renderer,this.ambientLight,this.directionalLight),this.holdingBlockLeft.render(this.camera,this.renderer,this.ambientLight,this.directionalLight));for(let f of this.fountains)this.sectionObjects[f.sectionId]&&!this.sectionObjects[f.sectionId].foutain&&(f.createParticles(this.sectionObjects[f.sectionId]),this.sectionObjects[f.sectionId].foutain=!0),f.render();this.waypoints.render(),this.fireworks.update();for(let f of this.onRender)f(r);let u=performance.now()-n;this.worldRendererConfig.autoLowerRenderDistance&&this.chunkMeshManager.recordRenderTime(u),this.renderTimeAvgCount++,this.renderTimeAvg=(this.renderTimeAvg*(this.renderTimeAvgCount-1)+u)/this.renderTimeAvgCount,this.renderTimeMax=Math.max(this.renderTimeMax,u),this.performanceMonitor.onFrame({totalMs:u,entitiesMs:a,loadedTextureCount:this.renderer.info.memory.textures,fps:this.lastFps})}renderHead(t,n,r,s){let a;if(s.SkullOwner?a=s.SkullOwner.Properties?.textures?.[0]?.Value:a=s.profile?.properties?.find(o=>o.name==="textures")?.value,!!a)try{let l=JSON.parse(Buffer.from(a,"base64").toString()).textures?.SKIN?.url,{skinTexturesProxy:c}=this.worldRendererConfig;c&&(l=l?.replace("http://textures.minecraft.net/",c).replace("https://textures.minecraft.net/",c));let u=kl(this,l,Cl.head),f=new ot;return r&&u.position.set(0,.3125,.3125),u.position.y-=23/16,f.add(u),this.sceneOrigin.track(f),f.position.set(t.x+.5,t.y+.045,t.z+.5),f.rotation.set(0,-yt.degToRad(n*(r?90:45/2)),0),f.scale.set(.8,.8,.8),f}catch(o){console.error("Error decoding player texture:",o)}}renderSign(t,n,r,s,a){let o=this.getSignTexture(t,a,s);if(!o)return;let l=new je(new vn(1,1),new st({map:o,transparent:!0}));l.renderOrder=999;let c=7/16,u=s?1.3:1;l.scale.set(1*u,c*u,1*u);let f=(s?2:1.5)/16,m=.25/16;r&&!s?l.position.set(0,0,-.5+f+m+1e-4):l.position.set(0,0,f/2+1e-4);let v=new ot;v.rotation.set(0,-yt.degToRad(n*(r?90:45/2)),0),v.add(l);let y=(s?10:8)/16,_=(s?0:r?4.333:9.333)/16,b=y/2+_;return this.sceneOrigin.track(v),v.position.set(t.x+.5,t.y+b,t.z+.5),v}lightUpdate(t,n){for(let r=this.worldSizeParams.minY;r<this.worldSizeParams.worldHeight;r+=16)this.setSectionDirty(new ft(t,r,n))}rerenderAllChunks(){for(let t of Object.keys(this.sectionObjects)){let[n,r,s]=t.split(",").map(Number);this.setSectionDirty(new ft(n,r,s))}}updateShowChunksBorder(t){this.chunkMeshManager.updateAllBoxHelpers(t)}resetWorld(){super.resetWorld(),this.pendingSectionUpdates.clear(),this.pendingSectionBufferStartTimes.clear(),this.chunkMeshManager.dispose(),this.chunkMeshManager=new em(this,this.scene,this.material,this.worldSizeParams.worldHeight,this.viewDistance),this.debugRaycastHelper&&(this.realScene.remove(this.debugRaycastHelper),this.debugRaycastHelper=void 0),this.debugHitPoint&&(this.realScene.remove(this.debugHitPoint),this.debugHitPoint=void 0)}getLoadedChunksRelative(t,n=!1){let[r,s,a]=vA(t);return Object.fromEntries(Object.entries(this.sectionObjects).map(([o,l])=>{let[c,u,f]=o.split(",").map(Number),[m,v,y]=vA({x:c,y:u,z:f});return[n?`${m-r},${v-s},${y-a}`:`${m-r},${y-a}`,l]}))}cleanChunkTextures(t,n){let r=this.chunkTextures.get(`${Math.floor(t/16)},${Math.floor(n/16)}`)??{};for(let s of Object.keys(r))r[s].dispose(),delete r[s];this.chunkMeshManager.cleanSignChunkTextures(t,n)}readdChunks(){for(let t of Object.keys(this.sectionObjects))this.scene.remove(this.sectionObjects[t]);setTimeout(()=>{for(let t of Object.keys(this.sectionObjects))this.scene.add(this.sectionObjects[t])},500)}disableUpdates(t=this.scene.children){for(let n of t)n.matrixWorldNeedsUpdate=!1,this.disableUpdates(n.children??[])}removeColumn(t,n){super.removeColumn(t,n),this.cleanChunkTextures(t,n),this.clearPendingSectionUpdatesForChunk(t,n);let r=this.getSectionHeight(),s=this.worldMinYRender;for(let a=s;a<this.worldSizeParams.worldHeight;a+=r){let o=`${t},${a},${n}`;this.chunkMeshManager.sectionObjects[o]&&this.chunkMeshManager.releaseSection(o)}this.chunkMeshManager.onChunkRemovedFromGate(`${t},${n}`)}onViewerChunkPositionChanged(){this.chunkMeshManager.tryRevealPending()}setSectionDirty(...t){let[n]=t;this.cleanChunkTextures(n.x,n.z),super.setSectionDirty(...t)}static getRendererInfo(t){try{let n=t.getContext();return`${n.getParameter(n.getExtension("WEBGL_debug_renderer_info").UNMASKED_RENDERER_WEBGL)}`}catch(n){console.warn("Failed to get renderer info",n)}}worldStop(){this.media.onWorldStop()}destroy(){this.performanceMonitor?.reset(),this.pendingSectionUpdates.clear(),this.pendingSectionBufferStartTimes.clear(),this.chunkMeshManager.dispose(),this.disposeModules(),this.fireworksLegacy.destroy(),super.destroy(),this.skyboxRenderer.dispose(),this.fireworks.dispose()}shouldObjectVisible(t){let r=this.getSectionHeight(),s,a,o,l=this.sceneOrigin.getWorldPosition(t);l?(s=l.x,a=l.y,o=l.z):(s=this.sceneOrigin.toWorldX(t.position.x),a=this.sceneOrigin.toWorldY(t.position.y),o=this.sceneOrigin.toWorldZ(t.position.z));let c=Math.floor(s/16)*16,u=Math.floor(o/16)*16,f=Math.floor(a/r)*r,m=`${c},${u}`,v=`${c},${f},${u}`;return!!this.finishedChunks[m]||!!this.sectionObjects[v]}handleUserClick(t){this.media.handleUserClick(t)}updateSectionOffsets(){let t=performance.now();for(let[n,r]of Object.entries(this.sectionsOffsetsAnimations)){let s=(t-r.time)/1e3;r.time=t,r.currentOffsetX+=r.speedX*s,r.currentOffsetY+=r.speedY*s,r.currentOffsetZ+=r.speedZ*s,r.limitX!==void 0&&(r.speedX>0?r.currentOffsetX=Math.min(r.currentOffsetX,r.limitX):r.currentOffsetX=Math.max(r.currentOffsetX,r.limitX)),r.limitY!==void 0&&(r.speedY>0?r.currentOffsetY=Math.min(r.currentOffsetY,r.limitY):r.currentOffsetY=Math.max(r.currentOffsetY,r.limitY)),r.limitZ!==void 0&&(r.speedZ>0?r.currentOffsetZ=Math.min(r.currentOffsetZ,r.limitZ):r.currentOffsetZ=Math.max(r.currentOffsetZ,r.limitZ));let a=this.sectionObjects[n];a&&(a.position.set(r.currentOffsetX,r.currentOffsetY,r.currentOffsetZ),a.updateMatrix())}}reloadWorld(){this.entities.reloadEntities()}};Cn(yu,"FOV_TRANSITION_MS",200),Cn(yu,"MAX_SECTION_UPDATE_BUFFER_MS",500);var bu=yu;h();p();d();h();p();d();var nm="1.21.4";h();p();d();function _u(i,e){i.aspect=e.width/e.height,i.updateProjectionMatrix()}h();p();d();h();p();d();var t0={mode:"futuristic",minecraftTextures:!0,futuristicScene:"light",futuristicCamera:"dive",futuristicBlockGroup:"stainedGlass",futuristicCameraSpeedPercent:80,futuristicBlockSpeedPercent:40},PR=i=>i/100,s8={camera:PR(t0.futuristicCameraSpeedPercent),block:PR(t0.futuristicBlockSpeedPercent)};function IR(i,e=!1){return i?.mode?i.mode:e?"worldBlocks":t0.mode}h();p();d();h();p();d();h();p();d();X2();var LR={},m3e=!1;function nGe(){if(m3e)return LR;m3e=!0;var i=sl;function e(s){if(typeof s!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(s))}function t(s,a){for(var o="",l=0,c=-1,u=0,f,m=0;m<=s.length;++m){if(m<s.length)f=s.charCodeAt(m);else{if(f===47)break;f=47}if(f===47){if(!(c===m-1||u===1))if(c!==m-1&&u===2){if(o.length<2||l!==2||o.charCodeAt(o.length-1)!==46||o.charCodeAt(o.length-2)!==46){if(o.length>2){var v=o.lastIndexOf("/");if(v!==o.length-1){v===-1?(o="",l=0):(o=o.slice(0,v),l=o.length-1-o.lastIndexOf("/")),c=m,u=0;continue}}else if(o.length===2||o.length===1){o="",l=0,c=m,u=0;continue}}a&&(o.length>0?o+="/..":o="..",l=2)}else o.length>0?o+="/"+s.slice(c+1,m):o=s.slice(c+1,m),l=m-c-1;c=m,u=0}else f===46&&u!==-1?++u:u=-1}return o}function n(s,a){var o=a.dir||a.root,l=a.base||(a.name||"")+(a.ext||"");return o?o===a.root?o+l:o+s+l:l}var r={resolve:function(){for(var a="",o=!1,l,c=arguments.length-1;c>=-1&&!o;c--){var u;c>=0?u=arguments[c]:(l===void 0&&(l=i.cwd()),u=l),e(u),u.length!==0&&(a=u+"/"+a,o=u.charCodeAt(0)===47)}return a=t(a,!o),o?a.length>0?"/"+a:"/":a.length>0?a:"."},normalize:function(a){if(e(a),a.length===0)return".";var o=a.charCodeAt(0)===47,l=a.charCodeAt(a.length-1)===47;return a=t(a,!o),a.length===0&&!o&&(a="."),a.length>0&&l&&(a+="/"),o?"/"+a:a},isAbsolute:function(a){return e(a),a.length>0&&a.charCodeAt(0)===47},join:function(){if(arguments.length===0)return".";for(var a,o=0;o<arguments.length;++o){var l=arguments[o];e(l),l.length>0&&(a===void 0?a=l:a+="/"+l)}return a===void 0?".":r.normalize(a)},relative:function(a,o){if(e(a),e(o),a===o||(a=r.resolve(a),o=r.resolve(o),a===o))return"";for(var l=1;l<a.length&&a.charCodeAt(l)===47;++l);for(var c=a.length,u=c-l,f=1;f<o.length&&o.charCodeAt(f)===47;++f);for(var m=o.length,v=m-f,y=u<v?u:v,_=-1,b=0;b<=y;++b){if(b===y){if(v>y){if(o.charCodeAt(f+b)===47)return o.slice(f+b+1);if(b===0)return o.slice(f+b)}else u>y&&(a.charCodeAt(l+b)===47?_=b:b===0&&(_=0));break}var g=a.charCodeAt(l+b),x=o.charCodeAt(f+b);if(g!==x)break;g===47&&(_=b)}var w="";for(b=l+_+1;b<=c;++b)(b===c||a.charCodeAt(b)===47)&&(w.length===0?w+="..":w+="/..");return w.length>0?w+o.slice(f+_):(f+=_,o.charCodeAt(f)===47&&++f,o.slice(f))},_makeLong:function(a){return a},dirname:function(a){if(e(a),a.length===0)return".";for(var o=a.charCodeAt(0),l=o===47,c=-1,u=!0,f=a.length-1;f>=1;--f)if(o=a.charCodeAt(f),o===47){if(!u){c=f;break}}else u=!1;return c===-1?l?"/":".":l&&c===1?"//":a.slice(0,c)},basename:function(a,o){if(o!==void 0&&typeof o!="string")throw new TypeError('"ext" argument must be a string');e(a);var l=0,c=-1,u=!0,f;if(o!==void 0&&o.length>0&&o.length<=a.length){if(o.length===a.length&&o===a)return"";var m=o.length-1,v=-1;for(f=a.length-1;f>=0;--f){var y=a.charCodeAt(f);if(y===47){if(!u){l=f+1;break}}else v===-1&&(u=!1,v=f+1),m>=0&&(y===o.charCodeAt(m)?--m===-1&&(c=f):(m=-1,c=v))}return l===c?c=v:c===-1&&(c=a.length),a.slice(l,c)}else{for(f=a.length-1;f>=0;--f)if(a.charCodeAt(f)===47){if(!u){l=f+1;break}}else c===-1&&(u=!1,c=f+1);return c===-1?"":a.slice(l,c)}},extname:function(a){e(a);for(var o=-1,l=0,c=-1,u=!0,f=0,m=a.length-1;m>=0;--m){var v=a.charCodeAt(m);if(v===47){if(!u){l=m+1;break}continue}c===-1&&(u=!1,c=m+1),v===46?o===-1?o=m:f!==1&&(f=1):o!==-1&&(f=-1)}return o===-1||c===-1||f===0||f===1&&o===c-1&&o===l+1?"":a.slice(o,c)},format:function(a){if(a===null||typeof a!="object")throw new TypeError('The "pathObject" argument must be of type Object. Received type '+typeof a);return n("/",a)},parse:function(a){e(a);var o={root:"",dir:"",base:"",ext:"",name:""};if(a.length===0)return o;var l=a.charCodeAt(0),c=l===47,u;c?(o.root="/",u=1):u=0;for(var f=-1,m=0,v=-1,y=!0,_=a.length-1,b=0;_>=u;--_){if(l=a.charCodeAt(_),l===47){if(!y){m=_+1;break}continue}v===-1&&(y=!1,v=_+1),l===46?f===-1?f=_:b!==1&&(b=1):f!==-1&&(b=-1)}return f===-1||v===-1||b===0||b===1&&f===v-1&&f===m+1?v!==-1&&(m===0&&c?o.base=o.name=a.slice(1,v):o.base=o.name=a.slice(m,v)):(m===0&&c?(o.name=a.slice(1,f),o.base=a.slice(1,v)):(o.name=a.slice(m,f),o.base=a.slice(m,v)),o.ext=a.slice(f,v)),m>0?o.dir=a.slice(0,m-1):c&&(o.dir="/"),o},sep:"/",delimiter:":",win32:null,posix:null};return r.posix=r,LR=r,LR}var $r=nGe();X2();var _mn=$r._makeLong,wmn=$r.basename,xmn=$r.delimiter,Emn=$r.dirname,Smn=$r.extname,Amn=$r.format,Mmn=$r.isAbsolute,BR=$r.join,Tmn=$r.normalize,Rmn=$r.parse,kmn=$r.posix,Cmn=$r.relative,Pmn=$r.resolve,Imn=$r.sep,Lmn=$r.win32;bt();var OR=new Date,v3e=OR.getMonth()===11&&OR.getDate()>=24&&OR.getDate()<=26,rGe=["panorama_3.webp","panorama_1.webp","panorama_4.webp","panorama_5.webp","panorama_0.webp","panorama_2.webp"],iGe=200,rm=class{constructor(e){this.documentRenderer=e;this.scene=new yr,this.scene.background=new Fe(3294568);let t=new pa(13421772);this.scene.add(t);let n=new as(16777215,.5);n.position.set(1,1,.5).normalize(),n.castShadow=!0,this.scene.add(n),this.camera=new Yt(85,e.canvas.width/e.canvas.height,.05,1e3),this.camera.position.set(0,0,0),this.camera.rotation.set(0,0,0)}scene;camera;startTimes=new Map;time=0;panoramaGroup=null;async init(){this.buildCubemap()}update(e,t){t&&_u(this.camera,this.documentRenderer.canvas)}dispose(){this.scene.clear(),this.panoramaGroup=null,this.startTimes.clear()}buildCubemap(){let e=new nn(1e3,1e3,1e3),t=[];for(let s of rGe)(async()=>{let{texture:o}=R7(BR("background",v3e?"christmas":"",s));o.matrixAutoUpdate=!1,o.matrix.set(-1,0,1,0,1,0,0,0,1),o.wrapS=mn,o.wrapT=mn,o.minFilter=jt,o.magFilter=jt;let l=new st({map:o,transparent:!0,side:cn,depthWrite:!1,opacity:0});this.startTimes.set(l,Date.now()),t.push(l)})();let n=new je(e,t);n.onBeforeRender=()=>{this.time+=.01,n.rotation.y=Math.PI+this.time*.01,n.rotation.z=Math.sin(-this.time*.001)*.001;for(let s of t){let a=this.startTimes.get(s);if(a){let o=Date.now()-a;s.opacity=Math.min(1,o/iGe)}}};let r=new At;if(r.add(n),!v3e)for(let s=0;s<20;s++){let a=new e0("1.16.4","squid").mesh;a.position.set(Math.random()*30-15,Math.random()*20-10,Math.random()*10-17),a.rotation.set(0,Math.PI+Math.random(),-Math.PI/4,"ZYX");let o=Math.random()*.01;a.children[0].onBeforeRender=()=>{a.rotation.y+=o,a.rotation.z=Math.cos(n.rotation.y*3)*Math.PI/4-Math.PI/2},r.add(a)}this.scene.add(r),this.panoramaGroup=r}async debugImageInFrontOfCamera(){let e=await fl(BR("background","panorama_0.webp")),t=new je(new vn(1e3,1e3),new st({map:e}));t.position.set(0,0,-500),this.scene.add(t)}};h();p();d();bt();h();p();d();var ed=["galaxy","nether","end","cyber","light"],td=["cruise","barrel","dive","orbit","snake"],a8={galaxy:"Galaxy",nether:"Nether",end:"The End",cyber:"Cyber",light:"Light Space"},o8={cruise:"Cruise",barrel:"Barrel",dive:"Dive",orbit:"Orbit",snake:"Snake"},nd=["mixed","stainedGlass","wool","construction","glow","world"],l8={mixed:"Mixed",stainedGlass:"Stained glass",wool:"Wool",construction:"Construction",glow:"Glow",world:"World (grass & ores)"};var g3e=.1,_3e={mixed:["white_wool","cyan_wool","blue_wool","purple_wool","white_stained_glass","cyan_stained_glass","blue_stained_glass","purple_stained_glass","glowstone","sea_lantern","amethyst_block","copper_block","gold_block","diamond_block"],stainedGlass:["white_stained_glass","orange_stained_glass","magenta_stained_glass","light_blue_stained_glass","yellow_stained_glass","lime_stained_glass","pink_stained_glass","gray_stained_glass","light_gray_stained_glass","cyan_stained_glass","purple_stained_glass","blue_stained_glass","brown_stained_glass","green_stained_glass","red_stained_glass","black_stained_glass"],wool:["white_wool","orange_wool","magenta_wool","light_blue_wool","yellow_wool","lime_wool","pink_wool","gray_wool","light_gray_wool","cyan_wool","purple_wool","blue_wool","brown_wool","green_wool","red_wool","black_wool"],construction:["copper_block","exposed_copper","weathered_copper","oxidized_copper","cut_copper","exposed_cut_copper","weathered_cut_copper","oxidized_cut_copper","iron_block","gold_block","diamond_block","emerald_block","netherite_block","lapis_block","redstone_block","coal_block","quartz_block","amethyst_block","bricks","stone_bricks","deepslate_bricks","polished_blackstone"],glow:["glowstone","sea_lantern","shroomlight","ochre_froglight","verdant_froglight","pearlescent_froglight","redstone_lamp","beacon"],world:["grass_block","podzol","mycelium","dirt","coarse_dirt","rooted_dirt","mud","clay","stone","cobblestone","mossy_cobblestone","deepslate","cobbled_deepslate","tuff","calcite","sand","red_sand","gravel","snow_block","coal_ore","deepslate_coal_ore","iron_ore","deepslate_iron_ore","copper_ore","deepslate_copper_ore","gold_ore","deepslate_gold_ore","diamond_ore","deepslate_diamond_ore","emerald_ore","deepslate_emerald_ore","lapis_ore","deepslate_lapis_ore","redstone_ore","deepslate_redstone_ore","nether_gold_ore","ancient_debris","oak_log","birch_log","spruce_log","jungle_log","acacia_log","dark_oak_log","mangrove_log","cherry_log","netherrack","soul_sand","basalt","end_stone"]},y3e={galaxy:{bg:132114,fog:132114,fogD:.011,blocks:[61695,54527,47359,59647,2280703,43263],emit:[13158,8789,6724],nebula:[4403,1114146,4386],galFn:i=>new Fe(i*.05,i*.2,i),ambient:264216,dir:3368703,pt1:43775,pt2:16729343,name:"GALAXY"},nether:{bg:917760,fog:917760,fogD:.016,blocks:[16720384,16737792,16750848,13373696,16729122,16755200],emit:[2230272,1114112,3346688],nebula:[1704960,851968,1705984],galFn:i=>new Fe(i,i*.15,0),ambient:1573376,dir:16724736,pt1:16729088,pt2:16755200,name:"NETHER"},end:{bg:0,fog:0,fogD:.009,blocks:[7807658,11158732,5570679,14527231,3342421,12299007],emit:[655381,1572901,327696],nebula:[524312,851989,262158],galFn:i=>new Fe(i*.4,0,i),ambient:393232,dir:10040319,pt1:11158783,pt2:4456618,name:"THE END"},cyber:{bg:2566,fog:2566,fogD:.01,blocks:[65535,65416,11206400,52479,6749952,65518],emit:[8721,6656,6690],nebula:[6674,5120,4634],galFn:i=>new Fe(0,i,i*.6),ambient:6669,dir:65450,pt1:65484,pt2:4521728,name:"CYBER"},light:{bg:8951984,fog:7899296,fogD:.006,gradientBg:{top:14214392,mid:10531016,bottom:6846608,radial:!0},blocks:[15266559,13691135,12114175,10537208,8960240,7383272,10012927,12640511,15792383,7909608,14216447,14739711],emit:[6854864,8958176,11061488,12638456],nebula:[9480392,11059424,12637420,14215416,7901360],galFn:i=>{let e=new Fe;return i<.4?e.lerpColors(new Fe(16054527),new Fe(14215423),i/.4):i<.75?e.lerpColors(new Fe(14215423),new Fe(11061488),(i-.4)/.35):e.lerpColors(new Fe(11061488),new Fe(9482464),(i-.75)/.25),e},ambient:7899296,dir:13688040,pt1:11061503,pt2:13162751,name:"LIGHT",starColor:15266047,starOpacity:.5,galaxyOpacity:.7,nebulaOpacity:.32,edgeLineColor:10010856,blockOpacity:[.42,.56]}},sGe={cruise:{pos:(i,e,t)=>({x:Math.sin(i*.28)*18+Math.cos(i*.11)*7+e*10,y:Math.sin(i*.19)*6+Math.cos(i*.31)*3+t*6,z:0}),look:(i,e,t)=>({x:Math.sin((i+.18)*.28)*18+e*8,y:Math.sin((i+.18)*.19)*6+t*4,z:-25}),roll:(i,e=0)=>e*.05+Math.sin(i*.22)*.015,spd:.18},barrel:{pos:(i,e,t)=>{let r=i*2.4;return{x:Math.cos(r)*10+e*4,y:Math.sin(r)*10+t*4,z:Math.sin(i*.4)*8}},look:i=>({x:Math.sin(i*.5)*5,y:Math.cos(i*.5)*5,z:-30}),roll:i=>i*2.4+Math.PI*.5,spd:.24},dive:{pos:(i,e,t)=>({x:Math.sin(i*.6)*30+e*8,y:Math.cos(i*.4)*18+t*6,z:Math.sin(i*.3)*12}),look:(i,e,t)=>({x:Math.sin(i*.6+.2)*30+e*6,y:Math.cos(i*.4+.2)*18-8+t*4,z:-35}),roll:(i,e=0)=>e*.08+Math.sin(i*.6)*.12,spd:.3},orbit:{pos:(i,e,t)=>({x:Math.cos(i*.5)*20+e*5,y:Math.sin(i*.25)*10+t*5,z:Math.sin(i*.5)*20}),look:()=>({x:0,y:0,z:-60}),roll:i=>Math.sin(i*.5)*.08,spd:.15},snake:{pos:(i,e,t)=>({x:Math.sin(i*1.1)*22+Math.sin(i*.37)*8+e*10,y:Math.sin(i*.7)*10+e*4+t*8,z:0}),look:(i,e,t)=>{let n=i+.12;return{x:Math.sin(n*1.1)*22+Math.sin(n*.37)*8+e*8,y:Math.sin(n*.7)*10+t*6,z:-22}},roll:(i,e=0)=>e*.1+Math.sin(i*1.1)*.06,spd:.22}},aGe={cruise:1,barrel:1.6,dive:2.2,orbit:.7,snake:1.4},oGe=250,c8=1e4,u8=3e3,rd=i=>i[Math.floor(Math.random()*i.length)],NR=i=>"#"+i.toString(16).padStart(6,"0"),b3e=i=>{if(typeof document>"u")return null;let e=document.createElement("canvas");e.width=4,e.height=512;let t=e.getContext("2d");if(!t)return null;let n=e.width,r=e.height,s=i.radial?t.createRadialGradient(n/2,r*.32,0,n/2,r*.32,r*.85):t.createLinearGradient(0,0,0,r);s.addColorStop(0,NR(i.top)),i.mid!=null&&s.addColorStop(.45,NR(i.mid)),s.addColorStop(1,NR(i.bottom)),t.fillStyle=s,t.fillRect(0,0,n,r);let a=new yn(e);return a.needsUpdate=!0,a},id=class{constructor(e,t={},n){this.documentRenderer=e;this.abortSignal=n;let r=t0;this.curScene=t.initialScene??r.futuristicScene,this.curCam=t.initialCamera??r.futuristicCamera,this.blockGroup=t.initialBlockGroup??r.futuristicBlockGroup,this.cameraSpeed=t.initialCameraSpeed??s8.camera,this.blockSpeed=t.initialBlockSpeed??s8.block,this.useMinecraftTextures=t.useMinecraftTextures??r.minecraftTextures,this.resourcesManager=t.resourcesManager;let s=y3e[this.curScene];this.scene=new yr,this.scene.fog=new io(s.fog,s.fogD),this.applyScenePalette(s),this.camera=new Yt(80,this.documentRenderer.canvas.width/this.documentRenderer.canvas.height,.1,700),this.ambient=new pa(s.ambient,2.5),this.scene.add(this.ambient),this.dir=new as(s.dir,4),this.dir.position.set(1,1,0),this.scene.add(this.dir),this.pt1=new po(s.pt1,5,100),this.scene.add(this.pt1),this.pt2=new po(s.pt2,4,80),this.pt2.position.set(30,20,-30),this.scene.add(this.pt2);for(let m=0;m<oGe;m++)this.spawnBlock(s,!0);if(!this.useMinecraftTextures){let m=s.edgeLineColor??62975;for(let v=0;v<40;v++){let y=new fn({color:m,transparent:!0,opacity:.25});rd(this.blocks).mesh.add(new In(this.eGeo,y))}}this.scene.add(this.bGroup);let a=new it,o=new Float32Array(5e3*3);for(let m=0;m<5e3*3;m++)o[m]=(Math.random()-.5)*500;a.setAttribute("position",new dt(o,3)),this.stars=new tr(a,new Lr({color:s.starColor??16777215,size:.3,transparent:!0,opacity:s.starOpacity??.7,sizeAttenuation:!0})),this.scene.add(this.stars),this.galGeo=new it;let l=new Float32Array(c8*3),c=new Float32Array(c8*3);for(let m=0;m<c8;m++){let v=m%3,y=Math.random(),_=v/3*Math.PI*2+y*Math.PI*5,b=y*90+Math.random()*10,g=(1-y)*18;l[m*3]=Math.cos(_)*b+(Math.random()-.5)*g,l[m*3+1]=(Math.random()-.5)*7,l[m*3+2]=Math.sin(_)*b+(Math.random()-.5)*g-180;let x=.2+y*.8,w=s.galFn(x);c[m*3]=w.r,c[m*3+1]=w.g,c[m*3+2]=w.b}this.galGeo.setAttribute("position",new dt(l,3)),this.galGeo.setAttribute("color",new dt(c,3)),this.galaxy=new tr(this.galGeo,new Lr({size:.9,vertexColors:!0,transparent:!0,opacity:s.galaxyOpacity??.55,sizeAttenuation:!0})),this.scene.add(this.galaxy),this.nebGeo=new it;let u=new Float32Array(u8*3),f=new Float32Array(u8*3);for(let m=0;m<u8;m++){let v=25+Math.random()*110,y=Math.random()*Math.PI*2,_=(Math.random()-.5)*Math.PI*.5;u[m*3]=v*Math.cos(y)*Math.cos(_),u[m*3+1]=v*Math.sin(_)*.6,u[m*3+2]=v*Math.sin(y)*Math.cos(_)-80;let b=new Fe(rd(s.nebula));f[m*3]=b.r,f[m*3+1]=b.g,f[m*3+2]=b.b}this.nebGeo.setAttribute("position",new dt(u,3)),this.nebGeo.setAttribute("color",new dt(f,3)),this.nebula=new tr(this.nebGeo,new Lr({size:3,vertexColors:!0,transparent:!0,opacity:s.nebulaOpacity??.3,sizeAttenuation:!0})),this.scene.add(this.nebula),this.addBackgroundTextPlane(),this.setupMouseTracking()}scene;camera;ambient;dir;pt1;pt2;blocks=[];bGroup=new ot;galaxy;nebula;stars;galGeo;nebGeo;bGeo=new nn(1,1,1);eGeo=new k0(this.bGeo);curScene;curCam;blockGroup;cameraSpeed;blockSpeed;camT=0;mx=0;my=0;tmx=0;tmy=0;transitioning=!1;useMinecraftTextures=!1;resourcesManager;atlasTexture=null;blockMaterialPool=new Map;gradientSky=null;gradientSkyTexture=null;disposed=!1;animTime=0;async init(){if(this.useMinecraftTextures)try{await this.loadMinecraftTextures()}catch(e){console.warn("[FuturisticMenuBackground] Failed to load Minecraft textures, using solid colors:",e),this.useMinecraftTextures=!1}}applyScenePalette(e){if(this.documentRenderer.renderer.setClearColor(e.bg),e.gradientBg)if(this.scene.background=null,this.gradientSky){if(this.gradientSky.visible=!0,this.gradientSkyTexture&&e.gradientBg){let s=b3e(e.gradientBg);s&&(this.gradientSkyTexture.dispose(),this.gradientSkyTexture=s,this.gradientSky.material.map=s,this.gradientSky.material.needsUpdate=!0)}}else{let s=b3e(e.gradientBg);s?(this.gradientSkyTexture=s,this.gradientSky=new je(new vn(900,700),new st({map:s,depthWrite:!1,side:cn})),this.gradientSky.position.set(0,0,-280),this.gradientSky.renderOrder=-1e3,this.scene.add(this.gradientSky)):this.scene.background=new Fe(e.bg)}else this.scene.background=new Fe(e.bg),this.gradientSky&&(this.gradientSky.visible=!1);this.scene.fog instanceof io&&(this.scene.fog.color.set(e.fog),this.scene.fog.density=e.fogD);let t=this.stars?.material;t&&(t.color.set(e.starColor??16777215),t.opacity=e.starOpacity??.7);let n=this.galaxy?.material;n&&(n.opacity=e.galaxyOpacity??.55);let r=this.nebula?.material;r&&(r.opacity=e.nebulaOpacity??.3)}setupMouseTracking(){let e=n=>{let r=typeof window<"u"?window.innerWidth:this.documentRenderer.canvas.width,s=typeof window<"u"?window.innerHeight:this.documentRenderer.canvas.height;this.tmx=(n.clientX/r-.5)*2,this.tmy=-(n.clientY/s-.5)*2};(typeof document<"u"?document:void 0)?.addEventListener("mousemove",e,{signal:this.abortSignal})}addBackgroundTextPlane(){let n=typeof document<"u"?document.createElement("canvas"):null;if(!n)return;n.width=2048,n.height=768;let r=n.getContext("2d");if(!r)return;r.clearRect(0,0,2048,768),r.save(),r.font="bold 560px Orbitron, sans-serif",r.textAlign="center",r.textBaseline="middle",r.shadowColor="rgba(0,200,255,0.35)",r.shadowBlur=80,r.fillStyle="rgba(255,255,255,0.055)",r.fillText("V2",2048*.28,768*.5),r.restore(),r.save(),r.font="bold 148px Orbitron, sans-serif",r.textAlign="center",r.textBaseline="middle",r.shadowColor="rgba(0,200,255,0.2)",r.shadowBlur=40,r.fillStyle="rgba(255,255,255,0.038)",r.fillText("by ZARDOY",2048*.72,768*.52),r.restore();let s=new yn(n),a=new je(new vn(280,105),new st({map:s,transparent:!0,opacity:1,depthWrite:!1,side:cn,blending:Li}));a.position.set(8,4,-320),this.scene.add(a)}spawnBlock(e,t,n){let r=this.createBlockMaterial(e,n),s=new je(this.bGeo,r),a=.3+Math.random()*3;s.scale.setScalar(a),s.position.set((Math.random()-.5)*140,(Math.random()-.5)*70,t?-(Math.random()*140):-155-Math.random()*30),s.rotation.set(Math.random()*Math.PI*2,Math.random()*Math.PI*2,Math.random()*Math.PI*2);let o={mesh:s,spd:.04+Math.random()*.12,dx:(Math.random()-.5)*.012,dy:(Math.random()-.5)*.008,rx:(Math.random()-.5)*.012,ry:(Math.random()-.5)*.012,rz:(Math.random()-.5)*.01,minecraftBlockName:n};this.blocks.push(o),this.bGroup.add(s)}createBlockMaterial(e,t){if(this.useMinecraftTextures&&t){let s=this.blockMaterialPool.get(t);if(s)return s.clone()}let[n,r]=e.blockOpacity??[.32,.46];return new st({color:rd(e.blocks),transparent:!0,opacity:n+Math.random()*(r-n),depthWrite:!1,blending:Li})}removeBlockEdgeLines(){for(let e of this.blocks){let t=e.mesh.children.filter(n=>n instanceof In);for(let n of t){e.mesh.remove(n),n.geometry?.dispose();let r=n.material;Array.isArray(r)?r.forEach(s=>s.dispose()):r.dispose()}}}async ensureMcDataLoaded(){let e=globalThis._LOAD_MC_DATA;e&&await e()}resolveBlockAtlasUv(e,t,n){let r=s=>{let a=t[s];return a?{u:a.u,v:a.v,su:a.su??n.suSv,sv:a.sv??n.suSv}:null};if(t[e])return r(e);for(let s of["_top","_side","_front","_0"]){let a=r(`${e}${s}`);if(a)return a}for(let s of Object.keys(t))if(s.startsWith(e))return r(s);return null}async loadMinecraftTextures(){await this.ensureMcDataLoaded();let e=this.resourcesManager??new J0;!e.currentResources?.blocksAtlasImage&&(e.currentConfig={...e.currentConfig,version:nm,noInventoryGui:!0},await e.updateAssetsData?.({}));let n=e.currentResources;if(!n?.blocksAtlasImage||!n.blocksAtlasJson)throw new Error("Block atlas not available");let r=n.blocksAtlasJson,s=r.textures;this.atlasTexture=yp(n.blocksAtlasImage),this.atlasTexture.flipY=!1,this.atlasTexture.needsUpdate=!0;for(let a of _3e[this.blockGroup]){let o=this.resolveBlockAtlasUv(a,s,r);if(!o)continue;let l=this.atlasTexture.clone();l.flipY=!1,l.offset.set(o.u,o.v),l.repeat.set(o.su,o.sv),l.needsUpdate=!0;let c=a.includes("glass"),u=new st({map:l,side:cn,transparent:c,opacity:c?.85:1,alphaTest:c?.08:0,depthWrite:!0,toneMapped:!1});this.blockMaterialPool.set(a,u)}if(this.blockMaterialPool.size===0)throw new Error("No block textures resolved from atlas (check block names vs atlas keys)");this.removeBlockEdgeLines();for(let a of this.blocks){let o=rd([...this.blockMaterialPool.keys()]);a.minecraftBlockName=o,a.mesh.material=this.blockMaterialPool.get(o).clone()}}setScene(e){if(!ed.includes(e)||e===this.curScene||this.transitioning)return;this.transitioning=!0,this.curScene=e;let t=y3e[e];setTimeout(()=>{if(this.disposed)return;this.applyScenePalette(t),this.ambient.color.set(t.ambient),this.dir.color.set(t.dir),this.pt1.color.set(t.pt1),this.pt2.color.set(t.pt2);for(let s of this.blocks)this.useMinecraftTextures&&s.minecraftBlockName||s.mesh.material instanceof st&&s.mesh.material.color.set(rd(t.blocks));let n=this.nebGeo.attributes.color;for(let s=0;s<u8;s++){let a=new Fe(rd(t.nebula));n.setXYZ(s,a.r,a.g,a.b)}n.needsUpdate=!0;let r=this.galGeo.attributes.color;for(let s=0;s<c8;s++){let a=.2+Math.random()*.8,o=t.galFn(a);r.setXYZ(s,o.r,o.g,o.b)}r.needsUpdate=!0,this.transitioning=!1},150)}setCamera(e){td.includes(e)&&(this.curCam=e)}setCameraSpeed(e){this.cameraSpeed=Math.max(0,e)}setBlockSpeed(e){this.blockSpeed=Math.max(0,e)}async setBlockGroup(e){if(nd.includes(e)&&e!==this.blockGroup&&(this.blockGroup=e,!(!this.useMinecraftTextures||this.disposed))){for(let t of this.blockMaterialPool.values())t.map?.dispose(),t.dispose();this.blockMaterialPool.clear();try{await this.loadMinecraftTextures()}catch(t){console.warn("[FuturisticMenuBackground] Failed to reload block group textures:",t)}}}getSceneId(){return this.curScene}getCameraId(){return this.curCam}getBlockGroupId(){return this.blockGroup}update(e,t){t&&_u(this.camera,this.documentRenderer.canvas);let n=sGe[this.curCam],r=this.cameraSpeed,s=this.blockSpeed;this.camT+=e*n.spd*r,this.mx+=(this.tmx-this.mx)*.05,this.my+=(this.tmy-this.my)*.05;let a=this.mx*g3e,o=this.my*g3e,l=n.pos(this.camT,a,o),c=n.look(this.camT,a,o);this.camera.position.set(l.x,l.y,l.z),this.camera.lookAt(c.x,c.y,c.z),this.camera.rotation.z=n.roll(this.camT,a);let u=aGe[this.curCam]*s;this.animTime+=e*1e3*s;for(let f of this.blocks){if(f.mesh.position.z+=f.spd*u*60*e,f.mesh.position.x+=f.dx*60*e*s,f.mesh.position.y+=f.dy*60*e*s,f.mesh.rotation.x+=f.rx*u,f.mesh.rotation.y+=f.ry*u,f.mesh.rotation.z+=f.rz,!this.useMinecraftTextures&&f.mesh.material instanceof st){let m=f.mesh.userData.baseOpacity??.38;f.mesh.userData.baseOpacity==null&&(f.mesh.userData.baseOpacity=m);let v=.88+Math.abs(Math.sin(this.animTime*8e-4+f.mesh.position.x*.3))*.12;f.mesh.material.opacity=m*v}f.mesh.position.z>this.camera.position.z+15&&f.mesh.position.set((Math.random()-.5)*140,(Math.random()-.5)*70,this.camera.position.z-155-Math.random()*30)}this.pt1.position.set(Math.sin(this.camT*.8)*25+this.camera.position.x,Math.cos(this.camT*.6)*12+this.camera.position.y,this.camera.position.z-18),this.pt2.position.set(Math.cos(this.camT*.5)*20+this.camera.position.x,Math.sin(this.camT*.9)*15+this.camera.position.y,this.camera.position.z-30),this.galaxy.rotation.y+=e*.006*s,this.nebula.rotation.y-=e*.003*s,this.stars.rotation.y+=e*4e-4*s}dispose(){this.disposed=!0,this.scene.clear(),this.bGeo.dispose(),this.eGeo.dispose(),this.galGeo.dispose(),this.nebGeo.dispose(),this.gradientSkyTexture?.dispose(),this.atlasTexture?.dispose();for(let e of this.blockMaterialPool.values())e.map?.dispose(),e.dispose();this.blockMaterialPool.clear()}};h();p();d();bt();h();p();d();var ege=Jr(T3e(),1),tge=Jr(Q6e(),1);var nge=i=>{let e=(0,ege.default)(i),t=(0,tge.default)(i),n=new e(i).sync,r=OWe(n);for(let s of r)if(s.startsWith("set")&&s!=="setColumn"){let a=n[s].bind(n);n[s]=(...o)=>{let l=o[0];l.x!==void 0&&!n.getColumnAt(l)&&n.setColumn(Math.floor(l.x/16),Math.floor(l.z/16),new t(void 0)),a(...o)}}return n};function OWe(i){let e=new Set,t=i;do for(let n of Object.getOwnPropertyNames(t))typeof i[n]=="function"&&n!=="constructor"&&e.add(n);while(t=Object.getPrototypeOf(t));return[...e]}h();p();d();var rge={paused:!1,showChunkBorders:!1,enableDebugOverlay:!1,debugWasmPerf:!1,debugModelVariant:void 0,futuristicReveal:!1,wasmMesher:!0,shaderCubeBlocks:!1,shaderCubeDebugMode:0,mesherWorkers:1,addChunksBatchWaitTime:200,_experimentalSmoothChunkLoading:!0,_renderByChunks:!1,autoLowerRenderDistance:!1,disableMesherConversionCache:!1,dedicatedChangeWorker:!1,shadingTheme:"high-contrast",cardinalLight:"default",dayCycle:!0,smoothLighting:!0,enableLighting:!0,starfield:!0,defaultSkybox:!0,renderEntities:!0,extraBlockRenderers:!0,foreground:!0,fov:75,volume:1,showHand:!1,viewBobbing:!1,handRenderer:"vanilla",renderEars:!0,highlightBlockColor:"blue",fetchPlayerSkins:!0,skinTexturesProxy:void 0,vrSupport:!0,vrPageGameRendering:!0,clipWorldBelowY:void 0,isPlayground:!1,instantCameraUpdate:!1,isRaining:!1,moduleStates:{}};var Fk=()=>({reactive:yo({world:{chunksLoaded:new Set,heightmaps:new Map,allChunksLoaded:!1,mesherWork:!1,instabilityFactors:RR(),intersectMedia:null},renderer:"...",preventEscapeMenu:!1}),nonReactive:{fps:0,worstRenderTime:0,avgRenderTime:0,world:{chunksLoaded:new Set,chunksTotalNumber:0},renderer:{timeline:{live:[],frozen:[],lastSecond:[]}}}});h();p();d();h();p();d();h();p();d();Cs();var Pm=i=>[Math.floor(i.x/16),Math.floor(i.z/16)];var NWe=async(i,e,t,n=1)=>{for(let r=0;r<i.length;r+=n)e&&await new Promise(s=>setTimeout(s,e)),await t(i[r],r)},Im=class Im extends B0{static restoreTransferred(e,t){let n=new Im;return t&&t.addEventListener("message",({data:r})=>{r.class===Im.restorerName&&r.type==="event"&&n.emit(r.eventName,...r.args)}),n}};Cn(Im,"restorerName","WorldViewWorker");var vd=Im,K8=class extends B0{constructor(t,n,r=new ft(0,0,0)){super();this.world=t;this.viewDistance=n;this.lastPos=new ft(0,0,0).update(r)}spiralNumber=0;gotPanicLastTime=!1;panicChunksReload=()=>{};loadedChunks={};inLoading=!1;chunkReceiveTimes=[];lastChunkReceiveTime=0;lastChunkReceiveTimeAvg=0;panicTimeout;lastPos;eventListeners={};debugChunksInfo={};waitingSpiralChunksLoad={};addWaitTime=1;keepChunksDistance=0;isPlayground=!1;allowPositionUpdate=!0;prepareForTransfer(t){if(t){let n=this.emit.bind(this);this.emit=(r,...s)=>{n(r,...s),t.postMessage({class:vd.restorerName,type:"event",eventName:r,args:s})}}return{__restorer:vd.restorerName}}setBlockStateId(t,n){let r=this.world.setBlockStateId(t,n);if(r&&typeof r.then=="function")throw new Error("setBlockStateId returned promise (not supported)");this.emit("blockUpdate",{pos:t,stateId:n})}updateViewDistance(t){this.viewDistance=t,this.emit("renderDistance",t)}async init(t,n){console.log("WorldView init"),this.updateViewDistance(this.viewDistance),this.emit("chunkPosUpdate",{pos:t}),n?.time?.timeOfDay!==void 0&&this.emit("time",n.time.timeOfDay),n?.entity&&this.emit("playerEntity",n.entity),this.emitterGotConnected(n);let[r,s]=Pm(t),a=bp(this.viewDistance).map(([o,l])=>new ft((r+o)*16,0,(s+l)*16));this.lastPos.update(t),await this._loadChunks(a,t)}chunkProgress(){if(this.panicTimeout&&clearTimeout(this.panicTimeout),this.chunkReceiveTimes.length>=5){let t=this.chunkReceiveTimes.reduce((r,s)=>r+s,0)/this.chunkReceiveTimes.length;this.lastChunkReceiveTimeAvg=t;let n=t*2+1e3;this.panicTimeout&&clearTimeout(this.panicTimeout),this.panicTimeout=setTimeout(()=>{!this.gotPanicLastTime&&this.inLoading&&(console.warn("Chunk loading seems stuck, triggering panic reload"),this.gotPanicLastTime=!0,this.panicChunksReload())},n)}}async _loadChunks(t,n){this.spiralNumber++;let{spiralNumber:r}=this;for(let a of Object.keys(this.waitingSpiralChunksLoad))this.waitingSpiralChunksLoad[a](!1),delete this.waitingSpiralChunksLoad[a];let s=!0;this.inLoading=!0,await NWe(t,this.addWaitTime,async a=>{!s||this.loadedChunks[`${a.x},${a.z}`]||(this.world.getColumnAt(a)||(s=await new Promise(o=>{this.waitingSpiralChunksLoad[`${a.x},${a.z}`]=o})),s&&(await this.loadChunk(a,void 0,`spiral ${r} from ${n.x},${n.z}`),this.chunkProgress()))}),this.panicTimeout&&clearTimeout(this.panicTimeout),this.inLoading=!1,this.gotPanicLastTime=!1,this.chunkReceiveTimes=[],this.lastChunkReceiveTime=0}async loadChunk(t,n=!1,r="spiral"){let[s,a]=Pm(this.lastPos),o=Math.abs(s-Math.floor(t.x/16)),l=Math.abs(a-Math.floor(t.z/16));if(o<=this.viewDistance&&l<=this.viewDistance){let c=await this.world.getColumnAt(t.y!==void 0?t:new ft(t.x,0,t.z));if(c){let u=c.toJson(),f={minY:c.minY??0,worldHeight:c.worldHeight??256};this.emit("loadChunk",{x:t.x,z:t.z,chunk:u,blockEntities:c.blockEntities,worldConfig:f,isLightUpdate:n}),this.loadedChunks[`${t.x},${t.z}`]=!0,this.debugChunksInfo[`${t.x},${t.z}`]??={loads:[]},this.debugChunksInfo[`${t.x},${t.z}`].loads.push({dataLength:u.length,reason:r,time:Date.now()})}else this.isPlayground&&this.emit("markAsLoaded",{x:t.x,z:t.z})}}unloadAllChunks(){for(let t of Object.keys(this.loadedChunks)){let[n,r]=t.split(",").map(Number);this.unloadChunk({x:n,z:r})}}unloadChunk(t){this.emit("unloadChunk",{x:t.x,z:t.z}),delete this.loadedChunks[`${t.x},${t.z}`],delete this.debugChunksInfo[`${t.x},${t.z}`]}emitterGotConnected(t){typeof globalThis.WorkerGlobalScope<"u"&&globalThis instanceof globalThis.WorkerGlobalScope||!t||this.emit("blockEntities",new Proxy({},{get(r,s,a){if(typeof s!="string")return;let[o,l,c]=s.split(",").map(Number);return t.world.getBlock(new ft(o,l,c))?.entity}}))}lastBiomeId=null;updateBiome(t){try{if(!this.world.getBiome)return;let n=this.world.getBiome(t);n!==this.lastBiomeId&&(this.lastBiomeId=n,this.emit("biomeReset"))}catch(n){console.error("error updating biome",n)}}lastPosCheck=null;async updatePosition(t,n=!1){if(!this.allowPositionUpdate)return;let r=t.floored();if(!n&&this.lastPosCheck&&this.lastPosCheck.equals(r))return;this.lastPosCheck=r,this.updateBiome(t);let[s,a]=Pm(this.lastPos),[o,l]=Pm(t);if(s!==o||a!==l||n){this.emit("chunkPosUpdate",{pos:t});let c=[],u=n?this.viewDistance:this.viewDistance+this.keepChunksDistance;for(let m of Object.keys(this.loadedChunks)){let[v,y]=m.split(",").map(Number),_=new ft(v,0,y),[b,g]=Pm(_),x=Math.abs(o-b),w=Math.abs(l-g);(x>u||w>u)&&c.push(_)}for(let m of c)this.unloadChunk(m);let f=bp(this.viewDistance).map(([m,v])=>{let y=new ft((o+m)*16,0,(l+v)*16);if(!this.loadedChunks[`${y.x},${y.z}`])return y}).filter(m=>!!m);this.lastPos.update(t),this._loadChunks(f,t)}else this.emit("chunkPosUpdate",{pos:t}),this.lastPos.update(t)}};var Lm=class{constructor(e,t,n){this.documentRenderer=e;this.options=t;this.abortSignal=n;this._scene=new yr,this._scene.background=new Fe(3294568),this._camera=new Yt(85,e.canvas.width/e.canvas.height,.05,1e3),this.camera.position.set(0,0,0),this.camera.rotation.set(0,0,0)}_scene;_camera;get scene(){return this._scene}get camera(){return this._camera}worldRenderer;WorldRendererClass=bu;async init(){let e=nm,t=new J0;if(t.currentConfig={version:e,noInventoryGui:!0},await t.updateAssetsData?.({}),this.abortSignal.aborted)return;console.time("load menu background scene");let n=nge(e),s=oi()(e),o=globalThis.mcData.blocksArray.filter(v=>{if(!v.name.includes("stained_glass"))return!1;let y=s.fromStateId(v.defaultState,0);if(y.shapes?.length!==1)return!1;let _=y.shapes[0];return _[0]===0&&_[1]===0&&_[2]===0&&_[3]===1&&_[4]===1&&_[5]===1}),l=-15,c=100,u=100;for(let v=-c;v<c;v++)for(let y=-u;y<u;y++){let _=o[Math.floor(Math.random()*o.length)];n.setBlockStateId(new ft(v,y,l),_.defaultState)}this._camera.updateProjectionMatrix(),this._camera.position.set(.5,u/2+.5,.5),this._camera.rotation.set(0,0,0);let f=new ft(...this._camera.position.toArray()),m=new K8(n,2,f);this.abortSignal.aborted||(this.worldRenderer=new this.WorldRendererClass(this.documentRenderer.renderer,this.options,{version:e,worldView:m,inWorldRenderingConfig:rge,playerStateReactive:_de().reactive,rendererState:Fk().reactive,nonReactiveState:Fk().nonReactive,resourcesManager:t}),this.worldRenderer instanceof bu&&(this._scene=this.worldRenderer.realScene,this._camera=this.worldRenderer.camera),m.init(f),await this.worldRenderer.waitForChunksToRender(),!this.abortSignal.aborted&&(this.setupMouseParallax(),console.timeEnd("load menu background scene")))}update(e,t){t&&_u(this.camera,this.documentRenderer.canvas)}dispose(){this.worldRenderer?.destroy(),this.worldRenderer=void 0,this._scene.clear()}setupMouseParallax(){let e=this._camera,t=e.position.x,n=e.position.y,r;document.body.addEventListener("pointermove",s=>{if(s.pointerType!=="mouse")return;let a=.2,o=s.clientX/window.innerWidth-.5,l=-(s.clientY/window.innerHeight-.5);r?.stop(),r=new xr(e.position).to({x:t+o*a,y:n+l*a},0),r.start(),e.updateProjectionMatrix()},{signal:this.abortSignal})}};h();p();d();bt();var Bm=class{constructor(e,t,n={},r=!1){this.documentRenderer=e;this.options=t;this.mode=IR(n,r)}active;abortController=new AbortController;mode;lastFrameTime=0;get futuristic(){return this.active instanceof id?this.active:void 0}get scene(){return this.active?.scene}get camera(){return this.active?.camera}async start(e={}){this.active=this.createImplementation(e),await this.active.init(),this.active.scene.background instanceof Fe&&this.documentRenderer.renderer.setClearColor(this.active.scene.background),this.lastFrameTime=performance.now(),this.documentRenderer.render=(t=!1)=>{let n=performance.now(),r=Math.min((n-this.lastFrameTime)/1e3,.05);this.lastFrameTime=n;let s=this.active;s&&(s.update(r,t),this.documentRenderer.renderer.render(s.scene,s.camera))}}createImplementation(e){switch(this.mode){case"futuristic":return new id(this.documentRenderer,{useMinecraftTextures:e.useMinecraftTextures,initialScene:e.futuristicScene,initialCamera:e.futuristicCamera,initialBlockGroup:e.futuristicBlockGroup,initialCameraSpeed:e.futuristicCameraSpeed,initialBlockSpeed:e.futuristicBlockSpeed,resourcesManager:e.resourcesManager},this.abortController.signal);case"worldBlocks":return new Lm(this.documentRenderer,this.options,this.abortController.signal);default:return new rm(this.documentRenderer)}}dispose(){this.active?.dispose(),this.active=void 0,this.abortController.abort()}};h();p();d();var Du=t0,DWe={rendererWorldPerformance:"normal",rendererMeshersCountOverride:null,starfieldRendering:!0,defaultSkybox:!0,menuBackgroundMode:Du.mode,menuBackgroundMinecraftTextures:Du.minecraftTextures,menuBackgroundFuturisticScene:Du.futuristicScene,menuBackgroundFuturisticCamera:Du.futuristicCamera,menuBackgroundFuturisticBlockGroup:Du.futuristicBlockGroup,menuBackgroundFuturisticCameraSpeed:Du.futuristicCameraSpeedPercent,menuBackgroundFuturisticBlockSpeed:Du.futuristicBlockSpeedPercent,rendererFuturisticReveal:!1,rendererPerfDebugOverlay:!1,disableBlockEntityTextures:!1,rendererMesher:"wasm",rendererShaderCubeBlocks:!1,rendererShaderCubeDebugMode:"off",showChunkBorders:!1,renderEntities:!0,renderDebug:"basic",frameLimit:!1,backgroundRendering:"20fps",vanillaLook:!1,smoothLighting:!0,newVersionsLighting:!1,vrSupport:!0,vrPageGameRendering:!1,clipWorldBelowY:void 0,highlightBlockColor:"auto",loadPlayerSkins:!0,renderEars:!0,showHand:!0,viewBobbing:!0,dayCycleAndLighting:!0,keepChunksDistance:1,gpuPreference:"default",fov:75};var UWe={menuBackgroundMode:{possibleValues:[["classic","Classic"],["futuristic","Futuristic"]],requiresRestart:!0},menuBackgroundMinecraftTextures:{text:"Minecraft block textures",tooltip:"Use block atlas on futuristic menu cubes (loads assets on menu)"},menuBackgroundFuturisticScene:{possibleValues:ed.map(i=>[i,a8[i]])},menuBackgroundFuturisticCamera:{possibleValues:td.map(i=>[i,o8[i]])},menuBackgroundFuturisticBlockGroup:{possibleValues:nd.map(i=>[i,l8[i]]),text:"Block pool",tooltip:"Block set for textured menu cubes (requires Minecraft textures)"},menuBackgroundFuturisticCameraSpeed:{text:"Camera speed",tooltip:"Orbit / fly-through camera path speed. 0 freezes the path; mouse parallax still works.",min:0,max:200,unit:"%"},menuBackgroundFuturisticBlockSpeed:{text:"Block speed",tooltip:"Floating blocks and sky rotation. Independent of camera path speed.",min:0,max:200,unit:"%"},rendererWorldPerformance:{text:"World performance",tooltip:"Background workers for chunk geometry. Reload to apply.",requiresRestart:!0,possibleValues:[["low-energy","Low Energy"],["normal","Normal"],["maximum","Maximum"]]},starfieldRendering:{text:"Starfield"},defaultSkybox:{text:"Default skybox"},rendererFuturisticReveal:{text:"Futuristic world reveal"},rendererPerfDebugOverlay:{text:"Performance debug overlay"},disableBlockEntityTextures:{text:"Disable block entity textures",tooltip:"Skips signs, banners, heads, maps, etc."},rendererMesher:{possibleValues:[["wasm","WASM"],["legacy-js","Legacy JS"]],text:"Mesher pipeline",tooltip:"WASM is faster. Use JS if WASM is not working. Requires reload.",requiresRestart:!0},rendererShaderCubeBlocks:{text:"Instanced shader cubes",tooltip:"Render full blocks through the global GPU instanced path. Requires WASM mesher and WebGL2.",requiresChunksReload:!0},rendererShaderCubeDebugMode:{text:"Shader cube debug",tooltip:"Instanced cube path visualization (requires shader cubes enabled).",possibleValues:[["off","Off"],["holes","Hole test (red)"],["texIndex","Tile index colors"],["faces","Face id colors"],["atlasAlpha","Atlas alpha"]]},showChunkBorders:{text:"Chunk borders"},renderEntities:{text:"Render entities"},renderDebug:{possibleValues:["advanced","basic","none"]},frameLimit:{text:"Frame limit",tooltip:"false = VSync / unlimited when focused"},backgroundRendering:{text:"Background FPS limit",possibleValues:[["full","NO"],["5fps","5 FPS"],["20fps","20 FPS"]]},vanillaLook:{text:"Vanilla shading",tooltip:"On: Minecraft-style face shading. Off: higher-contrast client shading."},smoothLighting:{},newVersionsLighting:{text:"Lighting in newer versions"},vrSupport:{text:"VR support",tooltip:"Shows VR entry; does not force VR on."},vrPageGameRendering:{text:"VR page game rendering"},clipWorldBelowY:{text:"Clip world below Y"},highlightBlockColor:{possibleValues:[["auto","Auto"],["blue","Blue"],["classic","Classic"]]},loadPlayerSkins:{},renderEars:{tooltip:"Deadmau5 ears when the skin texture includes them"},showHand:{},viewBobbing:{},dayCycleAndLighting:{text:"Day cycle"},keepChunksDistance:{text:"Keep chunks distance",tooltip:"Extra distance before unloading chunks",max:5,unit:""},fov:{min:30,max:110,unit:"\xB0",text:"FOV (Field of View)"},gpuPreference:{text:"GPU preference",tooltip:"WebGL power preference. Requires reload / backend restart to apply.",requiresRestart:!0,possibleValues:[["default","Auto"],["high-performance","Dedicated"],["low-power","Low power"]]}};pi.enabled=!1;globalThis.THREE=Lt;var ige=i=>({updateMap:i.entities.updateMap.bind(i.entities),updateCustomBlock:i.updateCustomBlock.bind(i),getBlockInfo:i.getBlockInfo.bind(i),playEntityAnimation:i.entities.playAnimation.bind(i.entities),damageEntity:i.entities.handleDamageEvent.bind(i.entities),updatePlayerSkin:i.entities.updatePlayerSkin.bind(i.entities),changeHandSwingingState:i.changeHandSwingingState.bind(i),getHighestBlocks:i.getHighestBlocks.bind(i),reloadWorld:i.reloadWorld.bind(i),updateEntityModel:i.entities.updateEntityModel.bind(i.entities),playEntityModelAnimation:i.entities.playEntityModelAnimation.bind(i.entities),addMedia:i.media.addMedia.bind(i.media),destroyMedia:i.media.destroyMedia.bind(i.media),setControlMode:i.media.setControlMode.bind(i.media),setVideoPlaying:i.media.setVideoPlaying.bind(i.media),setVideoSeeking:i.media.setVideoSeeking.bind(i.media),setVideoVolume:i.media.setVideoVolume.bind(i.media),setVideoSpeed:i.media.setVideoSpeed.bind(i.media),handleUserClick:i.media.handleUserClick.bind(i.media),addSectionAnimation(e,t){i.sectionsOffsetsAnimations[e]=t},removeSectionAnimation(e){delete i.sectionsOffsetsAnimations[e]},shakeFromDamage:i.cameraShake.shakeFromDamage.bind(i.cameraShake),onPageInteraction:i.media.onPageInteraction.bind(i.media),downloadMesherLog:i.downloadMesherLog.bind(i),explodeFirework:i.fireworksLegacy.explode.bind(i.fireworksLegacy),explodeFireworkFacingCamera:i.fireworksLegacy.explodeFacingCamera.bind(i.fireworksLegacy),addWaypoint:i.waypoints.addWaypoint.bind(i.waypoints),removeWaypoint:i.waypoints.removeWaypoint.bind(i.waypoints),startCinimaticScript:i.cinimaticScript.startScript.bind(i.cinimaticScript),stopCinimaticScript:i.cinimaticScript.stopScript.bind(i.cinimaticScript),launchFirework:i.fireworks.launchFirework.bind(i.fireworks),setSkyboxImage:i.skyboxRenderer.setSkyboxImage.bind(i.skyboxRenderer),setRain:e=>i.toggleModule("rain",e),spawnBlockBreakParticles(e,t,n,r,s,a){i.getModule("blockBreakParticles")?.spawnBlockBreakParticles(e,t,n,r,s,a)},spawnBlockCrackParticle(e,t,n,r,s,a,o){i.getModule("blockBreakParticles")?.spawnCrackParticle(e,t,n,r,s,a,o)},async loadGeometryExport(e){let{applyWorldGeometryExport:t}=await Promise.resolve().then(()=>(gR(),qme));return t(i,e)},feedChunkPacket(e){let{kind:t,...n}=e,r={type:t,...n};for(let s of i.workers)s.postMessage(r)}}),VWe=[],Z8=(i,...e)=>{for(let t of Object.values(globalThis.loadedMods??{}))try{t.threeJsBackendModule?.[i]?.(...e)}catch(n){let r=`[mod three.js] Error calling ${i} on ${t.name}: ${n}`;throw new Error(r)}},sge=()=>{let i,e=null,t=null,n=null,r=null,s=(u,f)=>{Jn?i=Cv(u,VWe,globalThis):i=u,e=new S7(i,f?.canvas),globalThis.renderer=e.renderer,globalThis.documentRenderer=e,globalThis.threeJsBackend=c,Z8("default",c)},a=async u=>{if(!e)throw new Error("Document renderer not initialized");if(!n&&!t){let f={...i.config.menuBackground,...u};t=new Bm(e,{...i},f,!!process.env.SINGLE_FILE_BUILD_MODE),Z8("menuBackgroundCreated",t),await t.start(f),Z8("menuBackgroundReady",t)}},o=async u=>{let m=Jn?Cv(u,[J0,vd],globalThis):u;if(!e)throw new Error("Document renderer not initialized");e.nonReactiveState=m.nonReactiveState,globalThis.resourcesManager=m.resourcesManager,t&&(t.dispose(),t=null),n=new bu(e.renderer,i,m),await n.worldReadyPromise,r=new F6(m.nonReactiveState),globalThis.frameTimingCollector=r;let v=e.render;e.render=function(y){v.call(this,y),r?.markFrameStart(),m.inWorldRenderingConfig.paused||n?.render(y),r?.markFrameEnd(),r?.markFrameDisplay()},e.inWorldRenderingConfig=m.inWorldRenderingConfig,globalThis.world=n,Z8("worldReady",n)},l=()=>{t&&(t.dispose(),t=null),e&&e.dispose(),n&&(n.destroy(),n=null)},c={id:"threejs",displayName:`three.js ${ga}`,startMenuBackground:a,startWorld:o,disconnect:l,setRendering(u){e.setPaused(!u),n&&(n.renderingActive=u)},getMenuBackground:()=>t??void 0,getDebugOverlay:()=>({get entitiesString(){return n?.entities.getDebugString()},get left(){return{"Geo Memory":n?.chunkMeshManager.getEstimatedMemoryUsage().total??"-"}}}),updateCamera(u,f,m){r?.markCameraUpdate(!u),n?.setFirstPersonCamera(u,f,m)},get soundSystem(){return n?.soundSystem},get backendMethods(){if(n)return ige(n)}};return{main:{init:s,backend:c},workerProxy(){return sB({init(u,f){s(u,{canvas:f})},updateSizeExternal(u,f,m){e?.updateSizeExternal(u,f,m)},startMenuBackground:a,startWorld:o,disconnect:l,setRendering:c.setRendering,updateCamera(u,f,m){let v=u?new ft(u.x,u.y,u.z):null;r?.markCameraUpdate(!v),c.updateCamera(v,f,m)},async callBackendMethod(u,...f){if(!n)throw new Error("World renderer not initialized");let v=ige(n)[u];if(!v)throw new Error(`Backend method ${String(u)} is unavailable`);return v(...f)}})}}};globalThis.structuredClone??=i=>JSON.parse(JSON.stringify(i));self.addEventListener("message",i=>{let e=i.data,t=globalThis;if(e.type==="mcData"){t.mcData=e.mcData,t.loadedData=e.mcData,console.log("data loaded");return}Array.isArray(e)&&e.forEach(n=>{n.type==="mcData"&&(t.mcData=n.mcData,t.loadedData=n.mcData)})});var FWe=sge();FWe.workerProxy();})();
28832
28832
  /*! Bundled license information:
28833
28833
 
28834
28834
  @jspm/core/nodelibs/browser/chunk-DtuTasat.js: