var vt=Object.defineProperty;var kt=(a,t,s)=>t in a?vt(a,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):a[t]=s;var i=(a,t,s)=>(kt(a,typeof t!="symbol"?t+"":t,s),s);import{P as wt,W as bt,S as J,F as st,C as ot,a as Z,A as Mt,T as xt,N as v,M as m,R as I,B as L,b as _,I as S,c as at,d as F,e as P,V as y,f as Ct,g as K,h as It,E as Pt,i as zt,j as Lt,k as V}from"./vendor.b16e062d.js";const St=function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const o of document.querySelectorAll('link[rel="modulepreload"]'))e(o);new MutationObserver(o=>{for(const n of o)if(n.type==="childList")for(const d of n.addedNodes)d.tagName==="LINK"&&d.rel==="modulepreload"&&e(d)}).observe(document,{childList:!0,subtree:!0});function s(o){const n={};return o.integrity&&(n.integrity=o.integrity),o.referrerpolicy&&(n.referrerPolicy=o.referrerpolicy),o.crossorigin==="use-credentials"?n.credentials="include":o.crossorigin==="anonymous"?n.credentials="omit":n.credentials="same-origin",n}function e(o){if(o.ep)return;o.ep=!0;const n=s(o);fetch(o.href,n)}};St();class Et{constructor(){i(this,"camera");i(this,"scene");i(this,"renderer");i(this,"initCamera",()=>{this.camera.fov=50,this.camera.aspect=window.innerWidth/window.innerHeight,this.camera.near=.01,this.camera.far=500,this.camera.updateProjectionMatrix(),this.camera.position.set(8,50,8),this.camera.lookAt(100,30,100),window.addEventListener("resize",()=>{this.camera.aspect=window.innerWidth/window.innerHeight,this.camera.updateProjectionMatrix()})});i(this,"initScene",()=>{this.scene=new J;const t=8900331;this.scene.fog=new st(t,1,96),this.scene.background=new ot(t);const s=new Z(16777215,.5);s.position.set(500,500,500),this.scene.add(s);const e=new Z(16777215,.2);e.position.set(-500,500,-500),this.scene.add(e);const o=new Mt(4210752);this.scene.add(o)});i(this,"initRenderer",()=>{this.renderer.setSize(window.innerWidth,window.innerHeight),document.body.appendChild(this.renderer.domElement),window.addEventListener("resize",()=>{this.renderer.setSize(window.innerWidth,window.innerHeight)})});this.camera=new wt,this.renderer=new bt,this.scene=new J,this.initScene(),this.initRenderer(),this.initCamera()}}var b=(a=>(a.walking="walking",a.sprinting="sprinting",a.flying="flying",a.sprintFlying="sprintFlying",a.sneaking="sneaking",a))(b||{}),G=(a=>(a[a.walking=5.612]="walking",a[a.sprinting=5.612]="sprinting",a[a.flying=21.78]="flying",a[a.sprintFlying=21.78]="sprintFlying",a[a.sneaking=1.95]="sneaking",a))(G||{});class Ft{constructor(){i(this,"mode","walking");i(this,"speed",G[this.mode]);i(this,"falling",38.4);i(this,"jump",1.2522);i(this,"body",{height:1.8,width:.5})}setMode(t){this.mode=t,this.speed=G[this.mode]}}var Ht="/dist/assets/stone.fa5e82cb.png",At="/dist/assets/coal_ore.29c9a29e.png",jt="/dist/assets/iron_ore.78230e9e.png",Bt="/dist/assets/grass_block_side.1f5d4845.png",qt="/dist/assets/grass_top_green.be9cf310.png",Rt="/dist/assets/dirt.fb045025.png",Ot="/dist/assets/oak_log.fc1a2462.png",_t="/dist/assets/oak_log_top.6a68c340.png",Gt="/dist/assets/oak_leaves.776aee85.png",Xt="/dist/assets/sand.f4bf1751.png",$t="/dist/assets/oak_planks.be4a7f91.png",Nt="/dist/assets/diamond_block.fb45cc99.png",Tt="/dist/assets/quartz_block_side.0e4d401c.png",Yt="/dist/assets/glass.17e849a2.png",Dt="/dist/assets/bedrock.3e3a8330.png",w=(a=>(a.grass="grass",a.dirt="dirt",a.tree="tree",a.leaf="leaf",a.sand="sand",a.stone="stone",a.coal="coal",a.wood="wood",a.diamond="diamond",a.quartz="quartz",a.glass="glass",a.bedrock="bedrock",a))(w||{});let k=new xt;const nt=k.load(qt),q=k.load(Bt),R=k.load(Ot),X=k.load(_t),$=k.load(Rt),rt=k.load(Ht),lt=k.load(At),Ut=k.load(jt),ht=k.load(Gt),ct=k.load(Xt),dt=k.load($t),ut=k.load(Nt),mt=k.load(Tt),gt=k.load(Yt),ft=k.load(Dt);nt.magFilter=v;q.magFilter=v;R.magFilter=v;X.magFilter=v;$.magFilter=v;rt.magFilter=v;lt.magFilter=v;Ut.magFilter=v;ht.magFilter=v;ct.magFilter=v;dt.magFilter=v;ut.magFilter=v;mt.magFilter=v;gt.magFilter=v;ft.magFilter=v;class Wt{constructor(){i(this,"materials",{grass:[new m({map:q}),new m({map:q}),new m({map:nt}),new m({map:$}),new m({map:q}),new m({map:q})],dirt:new m({map:$}),sand:new m({map:ct}),tree:[new m({map:R}),new m({map:R}),new m({map:X}),new m({map:X}),new m({map:R}),new m({map:R})],leaf:new m({map:ht,color:new ot(0,1,0),transparent:!0}),stone:new m({map:rt}),coal:new m({map:lt}),wood:new m({map:dt}),diamond:new m({map:ut}),quartz:new m({map:mt}),glass:new m({map:gt,transparent:!0}),bedrock:new m({map:ft})});i(this,"get",t=>this.materials[t])}}class N{constructor(t,s,e,o,n){i(this,"object");i(this,"x");i(this,"y");i(this,"z");i(this,"type");i(this,"placed");this.x=t,this.y=s,this.z=e,this.type=o,this.placed=n}}class Jt{constructor(t,s,e){i(this,"scene");i(this,"camera");i(this,"terrain");i(this,"raycaster");i(this,"block",null);i(this,"geometry",new L(1.01,1.01,1.01));i(this,"material",new m({transparent:!0,opacity:.25}));i(this,"mesh",new _(new L,this.material));i(this,"index",0);i(this,"instanceMesh",new S(new L,new at,1e3));this.camera=s,this.scene=t,this.terrain=e,this.raycaster=new I,this.raycaster.far=8}update(){this.scene.remove(this.mesh),this.index=0,this.instanceMesh.instanceMatrix=new F(new Float32Array(1e3*16),16);const t=this.camera.position,s=new P,e=new Map,o=this.terrain.noise;let n=Math.round(t.x),d=Math.round(t.z);for(let l=-8;l<8;l++)for(let h=-8;h<8;h++){let g=n+l,u=d+h,p=Math.floor(o.get(g/o.gap,u/o.gap,o.seed)*o.amp)+30;e.set(`${g}_${p}_${u}`,this.index),s.setPosition(g,p,u),this.instanceMesh.setMatrixAt(this.index++,s);let M=o.get(g/o.stoneGap,u/o.stoneGap,o.stoneSeed)*o.stoneAmp;if(o.get(g/o.treeGap,u/o.treeGap,o.treeSeed)*o.treeAmp>o.treeThreshold&&p-30>=-3&&Mthis.noise.noise(t,s,e))}}function Kt(){return new Worker("/dist/assets/generate.707bb76c.js",{type:"module"})}var f=(a=>(a[a.grass=0]="grass",a[a.sand=1]="sand",a[a.tree=2]="tree",a[a.leaf=3]="leaf",a[a.dirt=4]="dirt",a[a.stone=5]="stone",a[a.coal=6]="coal",a[a.wood=7]="wood",a[a.diamond=8]="diamond",a[a.quartz=9]="quartz",a[a.glass=10]="glass",a[a.bedrock=11]="bedrock",a))(f||{});class Vt{constructor(t,s){i(this,"scene");i(this,"camera");i(this,"distance",3);i(this,"chunkSize",24);i(this,"maxCount");i(this,"chunk",new K(0,0));i(this,"previousChunk",new K(0,0));i(this,"noise",new Zt);i(this,"materials",new Wt);i(this,"materialType",[w.grass,w.sand,w.tree,w.leaf,w.dirt,w.stone,w.coal,w.wood,w.diamond,w.quartz,w.glass,w.bedrock]);i(this,"blocks",[]);i(this,"blocksCount",[]);i(this,"blocksFactor",[1,.2,.1,.7,.1,.2,.1,.1,.1,.1,.1,.1]);i(this,"customBlocks",[]);i(this,"highlight");i(this,"idMap",new Map);i(this,"generateWorker",new Kt);i(this,"cloud",new S(new L(20,5,14),new m({transparent:!0,color:16777215,opacity:.4}),1e3));i(this,"cloudCount",0);i(this,"cloudGap",5);i(this,"getCount",t=>this.blocksCount[t]);i(this,"setCount",t=>{this.blocksCount[t]=this.blocksCount[t]+1});i(this,"initBlocks",()=>{for(const s of this.blocks)this.scene.remove(s);this.blocks=[];const t=new L;for(let s=0;s{for(let t=0;t{if(this.blocksCount=new Array(this.blocks.length).fill(0),this.generateWorker.postMessage({distance:this.distance,chunk:this.chunk,noiseSeed:this.noise.seed,treeSeed:this.noise.treeSeed,stoneSeed:this.noise.stoneSeed,coalSeed:this.noise.coalSeed,idMap:new Map,blocksFactor:this.blocksFactor,blocksCount:this.blocksCount,customBlocks:this.customBlocks,chunkSize:this.chunkSize}),this.cloudGap++>5){this.cloudGap=0,this.cloud.instanceMatrix=new F(new Float32Array(1e3*16),16),this.cloudCount=0;for(let t=-this.chunkSize*this.distance*3+this.chunkSize*this.chunk.x;t.8&&this.cloud.setMatrixAt(this.cloudCount++,e)}this.cloud.instanceMatrix.needsUpdate=!0}});i(this,"generateAdjacentBlocks",t=>{const{x:s,y:e,z:o}=t,n=this.noise,d=Math.floor(n.get(s/n.gap,o/n.gap,n.seed)*n.amp);if(e>30+d)return;const l=n.get(s/n.stoneGap,o/n.stoneGap,n.stoneSeed)*n.stoneAmp;let h;l>n.stoneThreshold||e<23?h=5:d<-3?h=1:h=4,this.buildBlock(new y(s,e-1,o),h),this.buildBlock(new y(s,e+1,o),h),this.buildBlock(new y(s-1,e,o),h),this.buildBlock(new y(s+1,e,o),h),this.buildBlock(new y(s,e,o-1),h),this.buildBlock(new y(s,e,o+1),h),this.blocks[h].instanceMatrix.needsUpdate=!0});i(this,"buildBlock",(t,s)=>{const e=this.noise,o=Math.floor(e.get(t.x/e.gap,t.z/e.gap,e.seed)*e.amp);if(t.y>=30+o||t.y<0)return;t.y===0&&(s=11);for(const d of this.customBlocks)if(d.x===t.x&&d.y===t.y&&d.z===t.z)return;this.customBlocks.push(new N(t.x,t.y,t.z,s,!0));const n=new P;n.setPosition(t),this.blocks[s].setMatrixAt(this.getCount(s),n),this.blocks[s].instanceMatrix.needsUpdate=!0,this.setCount(s)});i(this,"update",()=>{this.chunk.set(Math.floor(this.camera.position.x/this.chunkSize),Math.floor(this.camera.position.z/this.chunkSize)),(this.chunk.x!==this.previousChunk.x||this.chunk.y!==this.previousChunk.y)&&this.generate(),this.previousChunk.copy(this.chunk),this.highlight.update()});this.scene=t,this.camera=s,this.maxCount=(this.distance*this.chunkSize*2+this.chunkSize)**2+500,this.highlight=new Jt(t,s,this),this.scene.add(this.cloud),this.generateWorker.onmessage=e=>{this.resetBlocks(),this.idMap=e.data.idMap,this.blocksCount=e.data.blocksCount;for(let o=0;o{const t=document.createElement("template");t.innerHTML=a,window.document.body.appendChild(t.content)},x=/Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent);class te{constructor(t,s,e,o,n){i(this,"scene");i(this,"camera");i(this,"player");i(this,"terrain");i(this,"control");i(this,"audio");i(this,"velocity",new y(0,0,0));i(this,"frontCollide",!1);i(this,"backCollide",!1);i(this,"leftCollide",!1);i(this,"rightCollide",!1);i(this,"downCollide",!0);i(this,"upCollide",!1);i(this,"isJumping",!1);i(this,"raycasterDown",new I);i(this,"raycasterUp",new I);i(this,"raycasterFront",new I);i(this,"raycasterBack",new I);i(this,"raycasterRight",new I);i(this,"raycasterLeft",new I);i(this,"tempMesh",new S(new L(1,1,1),new at,100));i(this,"tempMeshMatrix",new F(new Float32Array(100*16),16));i(this,"p1",performance.now());i(this,"p2",performance.now());i(this,"raycaster");i(this,"far");i(this,"holdingBlock",f.grass);i(this,"holdingBlocks",[f.grass,f.stone,f.tree,f.wood,f.diamond,f.quartz,f.glass,f.grass,f.grass,f.grass]);i(this,"holdingIndex",0);i(this,"wheelGap",!1);i(this,"clickInterval");i(this,"jumpInterval");i(this,"mouseHolding",!1);i(this,"spaceHolding",!1);i(this,"initRayCaster",()=>{this.raycasterUp.ray.direction=new y(0,1,0),this.raycasterDown.ray.direction=new y(0,-1,0),this.raycasterFront.ray.direction=new y(1,0,0),this.raycasterBack.ray.direction=new y(-1,0,0),this.raycasterLeft.ray.direction=new y(0,0,-1),this.raycasterRight.ray.direction=new y(0,0,1),this.raycasterUp.far=1.2,this.raycasterDown.far=this.player.body.height,this.raycasterFront.far=this.player.body.width,this.raycasterBack.far=this.player.body.width,this.raycasterLeft.far=this.player.body.width,this.raycasterRight.far=this.player.body.width});i(this,"setMovementHandler",t=>{if(!t.repeat)switch(t.key){case"q":this.player.mode===b.walking?this.player.setMode(b.flying):this.player.setMode(b.walking),this.velocity.y=0,this.velocity.x=0,this.velocity.z=0;break;case"w":case"W":this.velocity.x+=this.player.speed;break;case"s":case"S":this.velocity.x-=this.player.speed;break;case"a":case"A":this.velocity.z-=this.player.speed;break;case"d":case"D":this.velocity.z+=this.player.speed;break;case" ":this.player.mode===b.walking?this.isJumping||(this.velocity.y=8,this.isJumping=!0,this.downCollide=!1,this.far=0,setTimeout(()=>{this.far=this.player.body.height},300)):this.velocity.y+=this.player.speed,this.player.mode===b.walking&&!this.spaceHolding&&(this.spaceHolding=!0,this.jumpInterval=setInterval(()=>{this.setMovementHandler(t)},10));break;case"Shift":this.player.mode===b.walking||(this.velocity.y-=this.player.speed);break}});i(this,"resetMovementHandler",t=>{if(!t.repeat)switch(t.key){case"w":case"W":this.velocity.x=0;break;case"s":case"S":this.velocity.x=0;break;case"a":case"A":this.velocity.z=0;break;case"d":case"D":this.velocity.z=0;break;case" ":if(this.jumpInterval&&clearInterval(this.jumpInterval),this.spaceHolding=!1,this.player.mode===b.walking)return;this.velocity.y=0;break;case"Shift":if(this.player.mode===b.walking)return;this.velocity.y=0;break}});i(this,"mousedownHandler",t=>{t.preventDefault(),this.raycaster.setFromCamera({x:0,y:0},this.camera);const s=this.raycaster.intersectObjects(this.terrain.blocks)[0],e=new P;switch(t.button){case 0:if(s&&s.object instanceof S){s.object.getMatrixAt(s.instanceId,e);const o=new y().setFromMatrixPosition(e);if(f[s.object.name]===f.bedrock){this.terrain.generateAdjacentBlocks(o);return}s.object.setMatrixAt(s.instanceId,new P().set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)),this.audio.playSound(f[s.object.name]);const n=new _(new L(1,1,1),this.terrain.materials.get(this.terrain.materialType[parseInt(f[s.object.name])]));n.position.set(o.x,o.y,o.z),this.scene.add(n);const d=performance.now();let l=0;const h=()=>{if(performance.now()-d>250){this.scene.remove(n),cancelAnimationFrame(l);return}l=requestAnimationFrame(h),n.geometry.scale(.85,.85,.85)};h(),s.object.instanceMatrix.needsUpdate=!0;let g=!1;for(const u of this.terrain.customBlocks)u.x===o.x&&u.y===o.y&&u.z===o.z&&(g=!0,u.placed=!1);g||this.terrain.customBlocks.push(new N(o.x,o.y,o.z,f[s.object.name],!1)),this.terrain.generateAdjacentBlocks(o)}break;case 2:if(s&&s.object instanceof S){const o=s.face.normal;s.object.getMatrixAt(s.instanceId,e);const n=new y().setFromMatrixPosition(e);if(n.x+o.x===Math.round(this.camera.position.x)&&n.z+o.z===Math.round(this.camera.position.z)&&(n.y+o.y===Math.round(this.camera.position.y)||n.y+o.y===Math.round(this.camera.position.y-1)))return;e.setPosition(o.x+n.x,o.y+n.y,o.z+n.z),this.terrain.blocks[this.holdingBlock].setMatrixAt(this.terrain.getCount(this.holdingBlock),e),this.terrain.setCount(this.holdingBlock),this.audio.playSound(this.holdingBlock),this.terrain.blocks[this.holdingBlock].instanceMatrix.needsUpdate=!0,this.terrain.customBlocks.push(new N(o.x+n.x,o.y+n.y,o.z+n.z,this.holdingBlock,!0))}break}!x&&!this.mouseHolding&&(this.mouseHolding=!0,this.clickInterval=setInterval(()=>{this.mousedownHandler(t)},333))});i(this,"mouseupHandler",()=>{this.clickInterval&&clearInterval(this.clickInterval),this.mouseHolding=!1});i(this,"changeHoldingBlockHandler",t=>{var s;isNaN(parseInt(t.key))||t.key==="0"||(this.holdingIndex=parseInt(t.key)-1,this.holdingBlock=(s=this.holdingBlocks[this.holdingIndex])!=null?s:f.grass)});i(this,"wheelHandler",t=>{var s;this.wheelGap||(this.wheelGap=!0,setTimeout(()=>{this.wheelGap=!1},100),t.deltaY>0?(this.holdingIndex++,this.holdingIndex>9&&(this.holdingIndex=0)):t.deltaY<0&&(this.holdingIndex--,this.holdingIndex<0&&(this.holdingIndex=9)),this.holdingBlock=(s=this.holdingBlocks[this.holdingIndex])!=null?s:f.grass)});i(this,"initEventListeners",()=>{document.addEventListener("pointerlockchange",()=>{document.pointerLockElement?(document.body.addEventListener("keydown",this.changeHoldingBlockHandler),document.body.addEventListener("wheel",this.wheelHandler),document.body.addEventListener("keydown",this.setMovementHandler),document.body.addEventListener("keyup",this.resetMovementHandler),document.body.addEventListener("mousedown",this.mousedownHandler),document.body.addEventListener("mouseup",this.mouseupHandler)):(document.body.removeEventListener("keydown",this.changeHoldingBlockHandler),document.body.removeEventListener("wheel",this.wheelHandler),document.body.removeEventListener("keydown",this.setMovementHandler),document.body.removeEventListener("keyup",this.resetMovementHandler),document.body.removeEventListener("mousedown",this.mousedownHandler),document.body.removeEventListener("mouseup",this.mouseupHandler),this.velocity=new y(0,0,0))})});i(this,"moveZ",(t,s)=>{this.camera.position.z+=t*(this.player.speed/Math.PI)*2*s});i(this,"collideCheckAll",(t,s,e,o)=>{this.collideCheck(4,t,s,e,o),this.collideCheck(0,t,s,e),this.collideCheck(1,t,s,e),this.collideCheck(2,t,s,e),this.collideCheck(3,t,s,e),this.collideCheck(5,t,s,e)});i(this,"collideCheck",(t,s,e,o,n=this.player.body.width)=>{const d=new P;let l=0;this.tempMesh.instanceMatrix=new F(new Float32Array(100*16),16);let h=!1,g=new Array(this.terrain.noise.treeHeight+1).fill(!1),u=Math.round(s.x),p=Math.round(s.z);switch(t){case 0:u++,this.raycasterFront.ray.origin=s;break;case 1:u--,this.raycasterBack.ray.origin=s;break;case 2:p--,this.raycasterLeft.ray.origin=s;break;case 3:p++,this.raycasterRight.ray.origin=s;break;case 4:this.raycasterDown.ray.origin=s,this.raycasterDown.far=n;break;case 5:this.raycasterUp.ray.origin=new y().copy(s),this.raycasterUp.ray.origin.y--;break}let M=Math.floor(e.get(u/e.gap,p/e.gap,e.seed)*e.amp)+30;for(const c of o)if(c.x===u&&c.z===p)if(c.placed)d.setPosition(c.x,c.y,c.z),this.tempMesh.setMatrixAt(l++,d);else if(c.y===M)h=!0;else for(let r=1;r<=this.terrain.noise.treeHeight;r++)c.y===M+r&&(g[r]=!0);h||(d.setPosition(u,M,p),this.tempMesh.setMatrixAt(l++,d));for(let c=1;c<=this.terrain.noise.treeHeight;c++)if(!g[c]){let r=e.get(u/e.treeGap,p/e.treeGap,e.treeSeed)*e.treeAmp,z=e.get(u/e.stoneGap,p/e.stoneGap,e.stoneSeed)*e.stoneAmp;r>e.treeThreshold&&M>=27&&z{this.p1=performance.now();const t=(this.p1-this.p2)/1e3;if(this.player.mode===b.flying)this.control.moveForward(this.velocity.x*t),this.control.moveRight(this.velocity.z*t),this.camera.position.y+=this.velocity.y*t;else{this.collideCheckAll(this.camera.position,this.terrain.noise,this.terrain.customBlocks,this.far-this.velocity.y*t),Math.abs(this.velocity.y)0&&this.velocity.x>0?(!this.leftCollide&&e>Math.PI/2||!this.rightCollide&&e0&&this.control.moveForward(this.velocity.x*t),e<0&&e>-Math.PI&&this.velocity.x<0?(!this.leftCollide&&e>-Math.PI/2||!this.rightCollide&&e<-Math.PI/2)&&this.moveZ(-Math.PI/2-e,t):!this.leftCollide&&!this.rightCollide&&this.velocity.x<0&&this.control.moveForward(this.velocity.x*t),e-Math.PI/2&&this.velocity.z<0?(!this.rightCollide&&e<0||!this.leftCollide&&e>0)&&this.moveZ(-e,t):!this.leftCollide&&!this.rightCollide&&this.velocity.z<0&&this.control.moveRight(this.velocity.z*t),(e<-Math.PI/2||e>Math.PI/2)&&this.velocity.z>0?(!this.rightCollide&&e>0&&this.moveZ(Math.PI-e,t),!this.leftCollide&&e<0&&this.moveZ(-Math.PI-e,t)):!this.leftCollide&&!this.rightCollide&&this.velocity.z>0&&this.control.moveRight(this.velocity.z*t)),this.backCollide&&(e<0&&e>-Math.PI&&this.velocity.x>0?(!this.leftCollide&&e<-Math.PI/2||!this.rightCollide&&e>-Math.PI/2)&&this.moveZ(Math.PI/2+e,t):!this.leftCollide&&!this.rightCollide&&this.velocity.x>0&&this.control.moveForward(this.velocity.x*t),e0&&this.velocity.x<0?(!this.leftCollide&&eMath.PI/2)&&this.moveZ(e-Math.PI/2,t):!this.leftCollide&&!this.rightCollide&&this.velocity.x<0&&this.control.moveForward(this.velocity.x*t),(e<-Math.PI/2||e>Math.PI/2)&&this.velocity.z<0?(!this.leftCollide&&e>0&&this.moveZ(-Math.PI+e,t),!this.rightCollide&&e<0&&this.moveZ(Math.PI+e,t)):!this.leftCollide&&!this.rightCollide&&this.velocity.z<0&&this.control.moveRight(this.velocity.z*t),e-Math.PI/2&&this.velocity.z>0?(!this.leftCollide&&e<0||!this.rightCollide&&e>0)&&this.moveZ(e,t):!this.leftCollide&&!this.rightCollide&&this.velocity.z>0&&this.control.moveRight(this.velocity.z*t)),this.leftCollide&&((e<-Math.PI/2||e>Math.PI/2)&&this.velocity.x>0?(!this.frontCollide&&e>0&&this.moveX(Math.PI-e,t),!this.backCollide&&e<0&&this.moveX(-Math.PI-e,t)):!this.frontCollide&&!this.backCollide&&this.velocity.x>0?this.control.moveForward(this.velocity.x*t):this.frontCollide&&e<0&&e>-Math.PI/2&&this.velocity.x>0?this.control.moveForward(this.velocity.x*t):this.backCollide&&e0&&this.velocity.x>0&&this.control.moveForward(this.velocity.x*t),e-Math.PI/2&&this.velocity.x<0?(!this.frontCollide&&e<0||!this.backCollide&&e>0)&&this.moveX(-e,t):!this.frontCollide&&!this.backCollide&&this.velocity.x<0?this.control.moveForward(this.velocity.x*t):this.frontCollide&&eMath.PI/2&&this.velocity.x<0?this.control.moveForward(this.velocity.x*t):this.backCollide&&e>-Math.PI&&e<-Math.PI/2&&this.velocity.x<0&&this.control.moveForward(this.velocity.x*t),e>0&&eMath.PI/2||!this.frontCollide&&e-Math.PI&&e<-Math.PI/2&&this.velocity.z<0?this.control.moveRight(this.velocity.z*t):this.backCollide&&e>-Math.PI/2&&e<0&&this.velocity.z<0&&this.control.moveRight(this.velocity.z*t),e<0&&e>-Math.PI&&this.velocity.z>0?(!this.backCollide&&e>-Math.PI/2||!this.frontCollide&&e<-Math.PI/2)&&this.moveX(-Math.PI/2-e,t):!this.frontCollide&&!this.backCollide&&this.velocity.z>0?this.control.moveRight(this.velocity.z*t):this.frontCollide&&e0&&this.velocity.z>0?this.control.moveRight(this.velocity.z*t):this.backCollide&&eMath.PI/2&&this.velocity.z>0&&this.control.moveRight(this.velocity.z*t)),this.rightCollide&&(e-Math.PI/2&&this.velocity.x>0?(!this.backCollide&&e<0||!this.frontCollide&&e>0)&&this.moveX(e,t):!this.frontCollide&&!this.backCollide&&this.velocity.x>0?this.control.moveForward(this.velocity.x*t):this.frontCollide&&e<-Math.PI/2&&e>-Math.PI&&this.velocity.x>0?this.control.moveForward(this.velocity.x*t):this.backCollide&&eMath.PI/2&&this.velocity.x>0&&this.control.moveForward(this.velocity.x*t),(e<-Math.PI/2||e>Math.PI/2)&&this.velocity.x<0?(!this.backCollide&&e>0&&this.moveX(-Math.PI+e,t),!this.frontCollide&&e<0&&this.moveX(Math.PI+e,t)):!this.frontCollide&&!this.backCollide&&this.velocity.x<0?this.control.moveForward(this.velocity.x*t):this.frontCollide&&e0&&this.velocity.x<0?this.control.moveForward(this.velocity.x*t):this.backCollide&&e<0&&e>-Math.PI/2&&this.velocity.x<0&&this.control.moveForward(this.velocity.x*t),e<0&&e>-Math.PI&&this.velocity.z<0?(!this.frontCollide&&e>-Math.PI/2||!this.backCollide&&e<-Math.PI/2)&&this.moveX(Math.PI/2+e,t):!this.frontCollide&&!this.backCollide&&this.velocity.z<0?this.control.moveRight(this.velocity.z*t):this.frontCollide&&e>Math.PI/2&&e0&&e0&&e0?(!this.frontCollide&&e>Math.PI/2||!this.backCollide&&e0?this.control.moveRight(this.velocity.z*t):this.frontCollide&&e>-Math.PI/2&&e<0&&this.velocity.z>0?this.control.moveRight(this.velocity.z*t):this.backCollide&&e>-Math.PI&&e<-Math.PI/2&&this.velocity.z>0&&this.control.moveRight(this.velocity.z*t))):(this.control.moveForward(this.velocity.x*t),this.control.moveRight(this.velocity.z*t)),this.camera.position.y+=this.velocity.y*t,this.camera.position.y<-100&&(this.camera.position.y=60)}this.p2=this.p1});this.scene=t,this.camera=s,this.player=e,this.terrain=o,this.control=new It(s,document.body),this.audio=n,this.raycaster=new I,this.raycaster.far=8,this.far=this.player.body.height,this.initRayCaster(),this.initEventListeners()}moveX(t,s){this.camera.position.x+=t*(this.player.speed/Math.PI)*2*s}}class ee{constructor(){i(this,"p1",performance.now());i(this,"p2",performance.now());i(this,"gap",performance.now());i(this,"fps",document.createElement("div"));i(this,"count",0);i(this,"update",()=>{this.p1=performance.now(),this.count++,performance.now()-this.gap>1e3&&(this.fps.innerHTML=`FPS: ${this.count}`,this.gap=performance.now(),this.count=0),this.p2=this.p1});this.fps.className="fps",this.fps.innerHTML="FPS: 60",document.body.appendChild(this.fps)}}var ie="/dist/assets/grass.020eb145.png",se="/dist/assets/stone.53e38748.png",oe="/dist/assets/tree.98a9b0d4.png",ae="/dist/assets/wood.9768871f.png",ne="/dist/assets/diamond.b6171099.png",re="/dist/assets/quartz.9ffd1d51.png",le="/dist/assets/glass.3e48b289.png";class he{constructor(){i(this,"wheelGap",!1);i(this,"current",0);i(this,"icon",[ie,se,oe,ae,ne,re,le]);i(this,"iconIndex",0);i(this,"y",0);i(this,"bag",document.createElement("div"));i(this,"items",new Array(10).fill(null).map(()=>{let t=document.createElement("div");t.className="item";let s=document.createElement("img");return this.icon[this.iconIndex]&&(s.className="icon",s.alt="block",s.src=this.icon[this.iconIndex++],t.appendChild(s)),t}));if(!x){this.bag.className="bag",this.items[0].classList.add("selected");for(let t=0;t{if(!(isNaN(parseInt(t.key))||t.key==="0")){for(let s=0;s{if(!this.wheelGap){this.wheelGap=!0,setTimeout(()=>{this.wheelGap=!1},100),t.deltaY>0?(this.current++,this.current>9&&(this.current=0)):t.deltaY<0&&(this.current--,this.current<0&&(this.current=9));for(let s=0;s `;class de{constructor(t){i(this,"control");i(this,"pageX",0);i(this,"pageY",0);i(this,"clickX",0);i(this,"clickY",0);i(this,"euler");i(this,"clickTimeout");i(this,"clickInterval");i(this,"hold",!1);i(this,"emitKeyboardEvent",t=>({key:t}));i(this,"emitClickEvent",t=>({button:t,preventDefault:()=>{}}));i(this,"initButton",({actionKey:t,key:s})=>{const e=document.querySelector(`#action-${t}`);e.addEventListener("pointermove",o=>{o.stopPropagation()}),e.addEventListener("pointerdown",o=>{this.control.setMovementHandler(this.emitKeyboardEvent(s)),o.stopPropagation()}),e.addEventListener("pointerup",o=>{this.control.resetMovementHandler(this.emitKeyboardEvent(s)),o.stopPropagation()}),t==="mode"&&s==="q"&&(this.initButton({actionKey:"mode",key:" "}),e.addEventListener("pointerdown",()=>{var o,n;this.control.player.mode===b.flying?(o=document.querySelector("#action-down"))==null||o.classList.remove("hidden"):(n=document.querySelector("#action-down"))==null||n.classList.add("hidden")}))});i(this,"init",()=>{Qt(ce),this.initButton({actionKey:"front",key:"w"}),this.initButton({actionKey:"left",key:"a"}),this.initButton({actionKey:"right",key:"d"}),this.initButton({actionKey:"back",key:"s"}),this.initButton({actionKey:"mode",key:"q"}),this.initButton({actionKey:"up",key:" "}),this.initButton({actionKey:"down",key:"Shift"}),document.addEventListener("pointermove",t=>{(this.pageX!==0||this.pageY!==0)&&(this.euler.setFromQuaternion(this.control.camera.quaternion),this.euler.y-=.01*(t.pageX-this.pageX),this.euler.x-=.01*(t.pageY-this.pageY),this.euler.x=Math.max(-Math.PI/2,Math.min(Math.PI/2,this.euler.x)),this.control.camera.quaternion.setFromEuler(this.euler)),this.pageX=t.pageX,this.pageY=t.pageY,this.clickTimeout&&clearTimeout(this.clickTimeout)}),document.addEventListener("pointerdown",t=>{this.clickX=t.pageX,this.clickY=t.pageY,this.clickTimeout=setTimeout(()=>{t.pageX===this.clickX&&t.pageY===this.clickY&&(this.control.mousedownHandler(this.emitClickEvent(0)),this.clickInterval=setInterval(()=>{this.control.mousedownHandler(this.emitClickEvent(0))},333),this.hold=!0)},500)}),document.addEventListener("pointerup",t=>{this.clickTimeout&&clearTimeout(this.clickTimeout),this.clickInterval&&clearInterval(this.clickInterval),!this.hold&&t.pageX===this.clickX&&t.pageY===this.clickY&&this.control.mousedownHandler(this.emitClickEvent(2)),this.hold=!1,this.pageX=0,this.pageY=0})});this.control=t,this.euler=new Pt(0,0,0,"YXZ")}}class ue{constructor(t,s){i(this,"fps");i(this,"bag");i(this,"joystick");i(this,"menu",document.querySelector(".menu"));i(this,"crossHair",document.createElement("div"));i(this,"play",document.querySelector("#play"));i(this,"control",document.querySelector("#control"));i(this,"setting",document.querySelector("#setting"));i(this,"feature",document.querySelector("#feature"));i(this,"back",document.querySelector("#back"));i(this,"exit",document.querySelector("#exit"));i(this,"save",document.querySelector("#save"));i(this,"saveModal",document.querySelector(".save-modal"));i(this,"loadModal",document.querySelector(".load-modal"));i(this,"settings",document.querySelector(".settings"));i(this,"features",document.querySelector(".features"));i(this,"github",document.querySelector(".github"));i(this,"distance",document.querySelector("#distance"));i(this,"distanceInput",document.querySelector("#distance-input"));i(this,"fov",document.querySelector("#fov"));i(this,"fovInput",document.querySelector("#fov-input"));i(this,"music",document.querySelector("#music"));i(this,"musicInput",document.querySelector("#music-input"));i(this,"settingBack",document.querySelector("#setting-back"));i(this,"onPlay",()=>{var t,s,e;x&&this.joystick.init(),(t=this.menu)==null||t.classList.add("hidden"),(s=this.menu)==null||s.classList.remove("start"),this.play&&(this.play.innerHTML="Resume"),this.crossHair.classList.remove("hidden"),this.github&&this.github.classList.add("hidden"),(e=this.feature)==null||e.classList.add("hidden")});i(this,"onPause",()=>{var t;(t=this.menu)==null||t.classList.remove("hidden"),this.crossHair.classList.add("hidden"),this.save&&(this.save.innerHTML="Save and Exit"),this.github&&this.github.classList.remove("hidden")});i(this,"onExit",()=>{var t,s;(t=this.menu)==null||t.classList.add("start"),this.play&&(this.play.innerHTML="Play"),this.save&&(this.save.innerHTML="Load Game"),(s=this.feature)==null||s.classList.remove("hidden")});i(this,"onSave",()=>{var t;(t=this.saveModal)==null||t.classList.remove("hidden"),setTimeout(()=>{var s;(s=this.saveModal)==null||s.classList.add("show")}),setTimeout(()=>{var s;(s=this.saveModal)==null||s.classList.remove("show")},1e3),setTimeout(()=>{var s;(s=this.saveModal)==null||s.classList.add("hidden")},1350)});i(this,"onLoad",()=>{var t;(t=this.loadModal)==null||t.classList.remove("hidden"),setTimeout(()=>{var s;(s=this.loadModal)==null||s.classList.add("show")}),setTimeout(()=>{var s;(s=this.loadModal)==null||s.classList.remove("show")},1e3),setTimeout(()=>{var s;(s=this.loadModal)==null||s.classList.add("hidden")},1350)});i(this,"update",()=>{this.fps.update()});var e,o,n,d,l,h,g,u,p,M,C,c;this.fps=new ee,this.bag=new he,this.joystick=new de(s),this.crossHair.className="cross-hair",this.crossHair.innerHTML="+",document.body.appendChild(this.crossHair),(e=this.play)==null||e.addEventListener("click",()=>{var r;((r=this.play)==null?void 0:r.innerHTML)==="Play"&&(this.onPlay(),t.noise.seed=Math.random(),t.noise.stoneSeed=Math.random(),t.noise.treeSeed=Math.random(),t.noise.coalSeed=Math.random(),t.noise.leafSeed=Math.random(),t.customBlocks=[],t.initBlocks(),t.generate(),t.camera.position.y=40,s.player.setMode(b.walking)),!x&&s.control.lock()}),(o=this.save)==null||o.addEventListener("click",()=>{var r,z,U,W;if(((r=this.save)==null?void 0:r.innerHTML)==="Save and Exit")window.localStorage.setItem("block",JSON.stringify(t.customBlocks)),window.localStorage.setItem("seed",JSON.stringify(t.noise.seed)),window.localStorage.setItem("position",JSON.stringify({x:t.camera.position.x,y:t.camera.position.y,z:t.camera.position.z})),this.onExit(),this.onSave();else{t.noise.seed=(z=Number(window.localStorage.getItem("seed")))!=null?z:Math.random();const pt=(U=JSON.parse(window.localStorage.getItem("block")||"null"))!=null?U:[];t.customBlocks=pt,t.initBlocks(),t.generate();const E=(W=JSON.parse(window.localStorage.getItem("position")||"null"))!=null?W:null;E&&(t.camera.position.x=E.x),E&&(t.camera.position.y=E.y),E&&(t.camera.position.z=E.z),this.onPlay(),this.onLoad(),!x&&s.control.lock()}}),(n=this.feature)==null||n.addEventListener("click",()=>{var r;(r=this.features)==null||r.classList.remove("hidden")}),(d=this.back)==null||d.addEventListener("click",()=>{var r;(r=this.features)==null||r.classList.add("hidden")}),(l=this.setting)==null||l.addEventListener("click",()=>{var r;(r=this.settings)==null||r.classList.remove("hidden")}),(h=this.settingBack)==null||h.addEventListener("click",()=>{var r;(r=this.settings)==null||r.classList.add("hidden")}),(g=this.distanceInput)==null||g.addEventListener("input",r=>{this.distance&&r.target instanceof HTMLInputElement&&(this.distance.innerHTML=`Render Distance: ${r.target.value}`)}),(u=this.fovInput)==null||u.addEventListener("input",r=>{this.fov&&r.target instanceof HTMLInputElement&&(this.fov.innerHTML=`Field of View: ${r.target.value}`,s.camera.fov=parseInt(r.target.value),s.camera.updateProjectionMatrix())}),(p=this.musicInput)==null||p.addEventListener("input",r=>{if(this.fov&&r.target instanceof HTMLInputElement){const z=r.target.value==="0";s.audio.disabled=z,this.music.innerHTML=`Music: ${z?"Off":"On"}`}}),(M=this.settingBack)==null||M.addEventListener("click",()=>{this.distanceInput instanceof HTMLInputElement&&(t.distance=parseInt(this.distanceInput.value),t.maxCount=(t.distance*t.chunkSize*2+t.chunkSize)**2+500,t.initBlocks(),t.generate(),t.scene.fog=new st(8900331,1,t.distance*24+24))}),document.body.addEventListener("keydown",r=>{r.key==="e"&&document.pointerLockElement&&!x&&s.control.unlock(),r.key==="f"&&(document.fullscreenElement?document.exitFullscreen():document.body.requestFullscreen())}),(C=this.exit)==null||C.addEventListener("click",()=>{this.onExit()}),document.addEventListener("pointerlockchange",()=>{document.pointerLockElement?this.onPlay():this.onPause()}),document.addEventListener("contextmenu",r=>{r.preventDefault()}),(c=document.querySelector("canvas"))==null||c.addEventListener("click",r=>{r.preventDefault(),!x&&s.control.lock()})}}var me="/dist/assets/hal3.2642662e.ogg",ge="/dist/assets/grass1.3619fdb8.ogg",fe="/dist/assets/grass2.b0763cf2.ogg",ye="/dist/assets/grass3.9ac02803.ogg",pe="/dist/assets/grass4.dd733357.ogg",ve="/dist/assets/sand1.1260ef32.ogg",ke="/dist/assets/sand2.74ef2fa1.ogg",we="/dist/assets/sand3.0441e996.ogg",be="/dist/assets/sand4.42ac9116.ogg",H="/dist/assets/stone1.97f2a8a7.ogg",A="/dist/assets/stone2.98a5c319.ogg",j="/dist/assets/stone3.19273f0e.ogg",B="/dist/assets/stone4.b164e732.ogg",Me="/dist/assets/dirt1.55a610c8.ogg",xe="/dist/assets/dirt2.60ebf0ed.ogg",Ce="/dist/assets/dirt3.ab5e4b40.ogg",Ie="/dist/assets/dirt4.fd4aa755.ogg",Q="/dist/assets/tree1.cb6071c8.ogg",tt="/dist/assets/tree2.59edca84.ogg",et="/dist/assets/tree3.cf6be231.ogg",it="/dist/assets/tree4.de868b31.ogg",Pe="/dist/assets/leaf1.74400cfe.ogg",ze="/dist/assets/leaf2.b7636085.ogg",Le="/dist/assets/leaf3.6228533c.ogg",Se="/dist/assets/leaf4.72db3634.ogg";class Ee{constructor(t){i(this,"disabled",!1);i(this,"sourceSet",[[ge,fe,ye,pe],[ve,ke,we,be],[Q,tt,et,it],[Pe,ze,Le,Se],[Me,xe,Ce,Ie],[H,A,j,B],[H,A,j,B],[Q,tt,et,it],[H,A,j,B],[H,A,j,B],[H,A,j,B]]);i(this,"soundSet",[]);i(this,"index",0);if(x)return;const s=new zt,e=new Lt;t.add(s);const o=new V(s);o.autoplay=!1,e.load(me,n=>{o.setBuffer(n),o.setVolume(.1),o.setLoop(!0),o.isPlaying&&(o.pause(),o.play())}),document.addEventListener("pointerlockchange",()=>{document.pointerLockElement&&!o.isPlaying&&!this.disabled?o.play():o.pause()});for(const n of this.sourceSet){const d=[];for(const l of n)e.load(l,h=>{const g=new V(s);g.setBuffer(h),g.setVolume(.15),d.push(g)});this.soundSet.push(d)}}playSound(t){var s,e;!this.disabled&&!x&&(this.index++===3&&(this.index=0),(e=(s=this.soundSet[t])==null?void 0:s[this.index])==null||e.play())}}const T=new Et,O=T.camera,Y=T.scene,Fe=T.renderer,He=new Ft,Ae=new Ee(O),D=new Vt(Y,O),yt=new te(Y,O,He,D,Ae),je=new ue(D,yt);(function a(){requestAnimationFrame(a),yt.update(),D.update(),je.update(),Fe.render(Y,O)})(); //# sourceMappingURL=index.3d64fa62.js.map