Files
misode.github.io/assets/deepslate.esm.c77f95a7.js
2022-10-26 00:01:47 +00:00

88 lines
79 KiB
JavaScript

import{p as Se,e as Ee,c as et,i as zt,t as nt,r as De,a as jt,b as Me,s as Ie,f as bt,d as Oe,n as Le,g as Ue,h as Ge,j as Ye,k as He,l as Ve,m as he,o as ze,q as je}from"./index.8b902684.js";var F;(function(a){a.UP="up",a.DOWN="down",a.NORTH="north",a.EAST="east",a.SOUTH="south",a.WEST="west"})(F||(F={}));const Je={[F.UP]:[0,1,0],[F.DOWN]:[0,-1,0],[F.NORTH]:[0,0,-1],[F.EAST]:[1,0,0],[F.SOUTH]:[0,0,1],[F.WEST]:[-1,0,0]};var rt;(function(a){a.ALL=[a.UP,a.DOWN,a.NORTH,a.EAST,a.SOUTH,a.WEST],a.normal=function(t){return Je[t]}})(F||(F={})),function(a){a.create=function(t,e,s){return[t,e,s]},a.offset=function(t,e,s,i){return[t[0]+e,t[1]+s,t[2]+i]},a.towards=function(t,e){return a.offset(t,...F.normal(e))}}(rt||(rt={}));const ut={end:0,byte:1,short:2,int:3,long:4,float:5,double:6,byteArray:7,string:8,list:9,compound:10,intArray:11,longArray:12},ue=["end","byte","short","int","long","float","double","byteArray","string","list","compound","intArray","longArray"];class Xe{constructor(t,e=!1){this.byte=this.readNum.bind(this,"getInt8",1),this.short=this.readNum.bind(this,"getInt16",2),this.int=this.readNum.bind(this,"getInt32",4),this.float=this.readNum.bind(this,"getFloat32",4),this.double=this.readNum.bind(this,"getFloat64",8),this.offset=0,this.littleEndian=e,this.arrayView=t,this.dataView=new DataView(t.buffer,t.byteOffset)}end(){return null}readNum(t,e){const s=this.dataView[t](this.offset,this.littleEndian);return this.offset+=e,s}long(){return[this.int(),this.int()]}byteArray(){const t=this.int(),e=[];for(let s=0;s<t;s++)e.push(this.byte());return e}intArray(){const t=this.int(),e=[];for(let s=0;s<t;s++)e.push(this.int());return e}longArray(){const t=this.int(),e=[];for(let s=0;s<t;s++)e.push(this.long());return e}string(){const t=this.short(),e=this.arrayView.slice(this.offset,this.offset+t);return this.offset+=t,function(s){var i,n=[];for(i=0;i<s.length;i++)(128&s[i])==0?n.push(127&s[i]):i+1<s.length&&(224&s[i])==192&&(192&s[i+1])==128?n.push((31&s[i])<<6|63&s[i+1]):i+2<s.length&&(240&s[i])==224&&(192&s[i+1])==128&&(192&s[i+2])==128?n.push((15&s[i])<<12|(63&s[i+1])<<6|63&s[i+2]):i+3<s.length&&(248&s[i])==240&&(192&s[i+1])==128&&(192&s[i+2])==128&&(192&s[i+3])==128&&n.push((7&s[i])<<18|(63&s[i+1])<<12|(63&s[i+2])<<6|63&s[i+3]);return String.fromCharCode.apply(null,n)}(e)}list(){const t=ue[this.byte()],e=this.int(),s=[];for(let i=0;i<e;i++)s.push(this[t]());return{type:t,value:s}}compound(){const t={};for(;;){const e=ue[this.byte()];if(e==="end")break;const s=this.string(),i=this[e]();t[s]={type:e,value:i}}return t}}class Ze{constructor(t=!1){this.byte=this.writeNum.bind(this,"setInt8",1),this.short=this.writeNum.bind(this,"setInt16",2),this.int=this.writeNum.bind(this,"setInt32",4),this.float=this.writeNum.bind(this,"setFloat32",4),this.double=this.writeNum.bind(this,"setFloat64",8),this.offset=0,this.littleEndian=t,this.buffer=new ArrayBuffer(1024),this.arrayView=new Uint8Array(this.buffer),this.dataView=new DataView(this.buffer)}accommodate(t){const e=this.offset+t;if(this.buffer.byteLength>=e)return;let s=this.buffer.byteLength;for(;s<e;)s*=2;const i=new ArrayBuffer(s),n=new Uint8Array(i);n.set(this.arrayView),this.offset>this.buffer.byteLength&&n.fill(0,this.buffer.byteLength,this.offset),this.buffer=i,this.dataView=new DataView(i),this.arrayView=n}getData(){return this.accommodate(0),this.arrayView.slice(0,this.offset)}end(t){}writeNum(t,e,s){this.accommodate(e),this.dataView[t](this.offset,s,this.littleEndian),this.offset+=e}long(t){this.int(t[0]),this.int(t[1])}byteArray(t){this.int(t.length),this.accommodate(t.length),this.arrayView.set(t,this.offset),this.offset+=t.length}intArray(t){this.int(t.length);for(let e=0;e<t.length;e++)this.int(t[e])}longArray(t){this.int(t.length);for(let e=0;e<t.length;e++)this.long(t[e])}string(t){const e=function(s){var i,n,r=[];for(i=0;i<s.length;i++)(n=s.charCodeAt(i))<128?r.push(n):n<2048?(r.push(192|n>>6),r.push(128|63&n)):n<65536?(r.push(224|n>>12),r.push(128|n>>6&63),r.push(128|63&n)):(r.push(240|n>>18&7),r.push(128|n>>12&63),r.push(128|n>>6&63),r.push(128|63&n));return r}(t);this.short(e.length),this.accommodate(e.length),this.arrayView.set(e,this.offset),this.offset+=e.length}list(t){this.byte(ut[t.type]),this.int(t.value.length),t.value;for(let e=0;e<t.value.length;e++)this[t.type](t.value[e])}compound(t){for(const e in t)this.byte(ut[t[e].type]),this.string(e),this[t[e].type](t[e].value);this.byte(ut.end)}}function ie(a,t){const e=new Xe(a,t);if(e.byte()!==ut.compound)throw new Error("Top tag should be a compound");return{name:e.string(),value:e.compound()}}function we(a,t){return ie(Se.inflate(a),t)}function ds(a,t){return(e=new Uint8Array(a.slice(0,2))).length===2&&e[0]===31&&e[1]===139?{compressed:!0,result:we(a,t)}:{compressed:!1,result:ie(a,t)};var e}function fs(a){const t=[];for(let e=0;e<32;e+=1)for(let s=0;s<32;s+=1){const i=4*((31&e)+32*(31&s));if(a[i+3]===0)continue;const n=(a[i]<<16)+(a[i+1]<<8)+a[i+2],r=(a[i+4096]<<24)+(a[i+4097]<<16)+(a[i+4098]<<8)+a[i+4099],o=4096*n,h=(a[o]<<24)+(a[o+1]<<16)+(a[o+2]<<8)+a[o+3],c=a[o+4],l=a.slice(o+5,o+4+h);t.push({x:e,z:s,timestamp:r,compression:c,data:l})}return t}function gs(a,t,e){const s=Ne(a,t,e);switch(s.compression){case 1:case 2:s.nbt=we(s.data);break;case 3:s.nbt=ie(s.data);break;default:throw new Error(`Invalid compression mode ${s.compression}`)}return s}function ne(a,t){const e=new Ze(t);return e.byte(ut.compound),e.string(a.name),e.compound(a.value),e.getData()}function Jt(a,t,e){const s=ne(a,t);return Se[e?"deflate":"gzip"](s)}function ps(a,t,e){return t?Jt(a,e):ne(a,e)}function ms(a){let t=0;for(const n of a)t+=Math.ceil(n.data.length/4096);const e=new Uint8Array(8192+4096*t),s=new DataView(e.buffer);let i=2;for(const n of a){const r=4*((31&n.x)+32*(31&n.z)),o=Math.ceil(n.data.length/4096);s.setInt8(r,i>>16),s.setInt16(r+1,65535&i),s.setInt8(r+3,o),s.setInt32(r+4096,n.timestamp);const h=4096*i;s.setInt32(h,n.data.length+1),s.setInt8(h+4,n.compression),e.set(n.data,h+5),i+=o}return e}function vs(a,t,e,s){const i=Ne(a,t,e);switch(i.compression){case 1:i.data=Jt(s);break;case 2:i.data=Jt(s,!1,!0);break;case 3:i.data=ne(s);break;default:throw new Error(`Invalid compression mode ${i.compression}`)}return i}function Ne(a,t,e){const s=a.find(i=>i.x===t&&i.z===e);if(s===void 0)throw new Error(`Cannot find chunk [${t}, ${e}]`);return s}function st(a,t,e){if(!a[t])throw new Error(`Missing ${t} tag`);if(a[t].type!==e)throw new Error(`Expected ${t} to be of type ${e}, but found ${a[t].type}`);return a[t].value}function vt(a,t,e,s){const i=st(a,t,"list");if(i.type!==e)throw new Error(`Expected ${t} to be a list of ${e}s, but found ${i.type}s`);if(s&&i.value.length!==s)throw new Error(`Expected ${t} to be a list of length ${s}, but found length ${i.value.length}`);return i.value}function Ae(a,t){try{return a()}catch{return t}}var p,H,Xt,it,ct;(function(a){function t(e){return typeof e=="object"&&e!==null?e:void 0}a.readNumber=function(e){return typeof e=="number"?e:void 0},a.readInt=function(e){return typeof e=="number"?Math.floor(e):void 0},a.readString=function(e){return typeof e=="string"?e:void 0},a.readBoolean=function(e){return typeof e=="boolean"?e:void 0},a.readObject=t,a.readArray=function(e,s){if(Array.isArray(e))return e.map(i=>s(i))},a.readMap=function(e,s){var i;const n=(i=t(e))!==null&&i!==void 0?i:{};return Object.fromEntries(Object.entries(n).map(([r,o])=>[r,s(o)]))},a.compose=function(e,s,i){const n=s(e);return n?i(n):void 0}})(p||(p={}));class M{constructor(t,e={}){this.name=t,this.properties=e}getName(){return this.name}getProperties(){return this.properties}getProperty(t){return this.properties[t]}isFluid(){return this.name==="minecraft:water"||this.name==="minecraft:lava"}equals(t){return this.name===t.name&&Object.keys(this.properties).every(e=>t.properties[e]===this.properties[e])}toString(){return Object.keys(this.properties).length===0?this.name:`${this.name}[${Object.entries(this.properties).map(([t,e])=>t+"="+e).join(",")}]`}static fromNbt(t){const e=st(t.value,"Name","string"),s=Ae(()=>st(t.value,"Properties","compound"),{}),i=Object.keys(s).reduce((n,r)=>Object.assign(Object.assign({},n),{[r]:st(s,r,"string")}),{});return new M(e,i)}static fromJson(t){var e,s;const i=(e=p.readObject(t))!==null&&e!==void 0?e:{},n=(s=p.readString(i.Name))!==null&&s!==void 0?s:"minecraft:stone",r=p.readMap(i.Properties,o=>{var h;return(h=p.readString(o))!==null&&h!==void 0?h:""});return new M(n,r)}}M.AIR=new M("minecraft:air");class ${constructor(t){this.minY=t,this.storage=Array($.SIZE),this.palette=[M.AIR]}get minBlockY(){return this.minY<<4}index(t,e,s){return(t<<8)+(e<<4)+s}getBlockState(t,e,s){var i;const n=this.storage[this.index(t,e,s)];return(i=this.palette[n])!==null&&i!==void 0?i:M.AIR}setBlockState(t,e,s,i){let n=this.palette.findIndex(r=>r.equals(i));n===-1&&(n=this.palette.length,this.palette.push(i)),this.storage[this.index(t,e,s)]=n}}$.WIDTH=16,$.SIZE=$.WIDTH*$.WIDTH*$.WIDTH;class bs{constructor(t,e,s){this.minY=t,this.height=e,this.pos=s,this.sections=Array(this.sectionsCount).fill(null)}get maxY(){return this.minY+this.height}get minSection(){return this.minY>>4}get maxSection(){return 1+(this.maxY-1>>4)}get sectionsCount(){return this.maxSection-this.minSection}getSectionIndex(t){return(t>>4)-this.minSection}getBlockState(t){var e;const[s,i,n]=t,r=this.sections[this.getSectionIndex(i)];return(e=r==null?void 0:r.getBlockState(15&s,15&i,15&n))!==null&&e!==void 0?e:M.AIR}setBlockState(t,e){const[s,i,n]=t,r=this.getSectionIndex(i);let o=this.sections[r];if(o===null){if(e.equals(M.AIR))return;o=this.getOrCreateSection(r)}o.setBlockState(15&s,15&i,15&n,e)}getOrCreateSection(t){return this.sections[t]==null&&(this.sections[t]=new $(this.minSection+t)),this.sections[t]}}(function(a){function t(e,s){return BigInt(4294967295&e)|BigInt(4294967295&s)<<BigInt(32)}a.create=function(e,s){return[e,s]},a.fromBlockPos=function(e){return[e[0]>>4,e[2]>>4]},a.fromLong=function(e){return[4294967295&Number(e),Number(e>>BigInt(32))]},a.toLong=function(e){return t(e[0],e[1])},a.asLong=t,a.minBlockX=function(e){return e[0]<<4},a.minBlockZ=function(e){return e[1]<<4},a.maxBlockX=function(e){return 15+(e[0]<<4)},a.maxBlockZ=function(e){return 15+(e[1]<<4)}})(H||(H={}));class ye{constructor(t,e=[],s=[]){this.size=t,this.palette=e,this.blocks=s,this.blocksMap=[],s.forEach(i=>{if(!this.isInside(i.pos))throw new Error(`Found block at ${i.pos} which is outside the structure bounds ${this.size}`);this.blocksMap[i.pos[0]*t[1]*t[2]+i.pos[1]*t[2]+i.pos[2]]=i})}getSize(){return this.size}addBlock(t,e,s,i){if(!this.isInside(t))throw new Error(`Cannot add block at ${t} outside the structure bounds ${this.size}`);const n=new M(e,s);let r=this.palette.findIndex(o=>o.equals(n));return r===-1&&(r=this.palette.length,this.palette.push(n)),this.blocks.push({pos:t,state:r,nbt:i}),this.blocksMap[t[0]*this.size[1]*this.size[2]+t[1]*this.size[2]+t[2]]={pos:t,state:r,nbt:i},this}getBlocks(){return this.blocks.map(t=>({pos:t.pos,state:this.palette[t.state],nbt:t.nbt}))}getBlock(t){if(!this.isInside(t))return null;const e=this.blocksMap[t[0]*this.size[1]*this.size[2]+t[1]*this.size[2]+t[2]];return e?{pos:e.pos,state:this.palette[e.state],nbt:e.nbt}:null}isInside(t){return t[0]>=0&&t[0]<this.size[0]&&t[1]>=0&&t[1]<this.size[1]&&t[2]>=0&&t[2]<this.size[2]}static fromNbt(t){const e=vt(t.value,"size","int",3),s=vt(t.value,"palette","compound").map(n=>M.fromNbt({name:"",value:n})),i=vt(t.value,"blocks","compound").map(n=>({pos:vt(n,"pos","int",3),state:st(n,"state","int"),nbt:Ae(()=>st(n,"nbt","compound"),void 0)}));return new ye(e,s,i)}}function Lt(a){let t=null;return()=>(t==null&&(t=a()),t)}function re(a,t,e){const s=a.get(t);if(s)return s;const i=e(t);return a.set(t,i),i}function j(a){return a*a}function Z(a,t,e){return Math.max(t,Math.min(e,a))}function k(a,t,e){return t+a*(e-t)}function Zt(a,t,e,s,i,n){return k(t,k(a,e,s),k(a,i,n))}function We(a,t,e,s,i,n,r,o,h,c,l){return k(e,Zt(a,t,s,i,n,r),Zt(a,t,o,h,c,l))}function ft(a,t,e){return e<0?a:e>1?t:k(e,a,t)}function Pe(a,t,e){return(a-t)/(e-t)}function Ut(a){return a*a*a*(a*(6*a-15)+10)}function W(a,t,e,s,i){return k(Pe(a,t,e),s,i)}function $e(a,t,e,s,i){return ft(s,i,Pe(a,t,e))}function qe(a,t,e){let s=t-a;for(;s>0;){const i=Math.floor(s/2),n=a+i;e(n)?s=i:(a=n+1,s-=i+1)}return a}function Fe(a,t,e){let s=BigInt(3129871*a)^BigInt(e)*BigInt(116129781)^BigInt(t);return s=s*s*BigInt(42317861)+s*BigInt(11),s>>BigInt(16)}function Wt(a,t,e,s,i,n,r,o){return BigInt(a)<<BigInt(56)|BigInt(t)<<BigInt(48)|BigInt(e)<<BigInt(40)|BigInt(s)<<BigInt(32)|BigInt(i)<<BigInt(24)|BigInt(n)<<BigInt(16)|BigInt(r)<<BigInt(8)|BigInt(o)}class R{constructor(t){this.seed=BigInt(0),this.setSeed(t)}fork(){return new R(this.nextLong())}forkPositional(){return new Qe(this.seed)}setSeed(t){this.seed=t^R.MULTIPLIER&R.MODULUS_MASK}advance(){this.seed=this.seed*R.MULTIPLIER+R.INCREMENT&R.MODULUS_MASK}consume(t){for(let e=0;e<t;e+=1)this.advance()}next(t){this.advance();const e=Number(this.seed>>BigInt(R.MODULUS_BITS-t));return e>2147483647?e-4294967296:e}nextInt(t){if(t===void 0)return this.next(32);if((t&t-1)==0)return Number(BigInt(t)*BigInt(this.next(31))>>BigInt(31));let e,s;for(;(e=this.next(31))-(s=e%t)+(t-1)<0;);return s}nextLong(){return(BigInt(this.next(32))<<BigInt(32))+BigInt(this.next(32))}nextFloat(){return this.next(24)*R.FLOAT_MULTIPLIER}nextDouble(){const t=this.next(30);return this.advance(),t*R.DOUBLE_MULTIPLIER}}R.MODULUS_BITS=48,R.MODULUS_MASK=BigInt("281474976710655"),R.MULTIPLIER=BigInt("25214903917"),R.INCREMENT=BigInt("11"),R.FLOAT_MULTIPLIER=1/Math.pow(2,24),R.DOUBLE_MULTIPLIER=1/Math.pow(2,30);class Qe{constructor(t){this.seed=t}at(t,e,s){const i=Fe(t,e,s);return new R(i^this.seed)}fromHashOf(t){const e=Ee(t,{asBytes:!0}),s=Wt(e[0],e[1],e[2],e[3],e[4],e[5],e[6],e[7]);return new R(s^this.seed)}}class P{constructor(t){this.seed=[BigInt(0),BigInt(0)],this.seed=t}static create(t){return new P(P.upgradeSeedTo128bit(t))}static mixStafford13(t){return((t=((t=(t^t>>BigInt(30))*BigInt("-4658895280553007687")&BigInt("0xFFFFFFFFFFFFFFFF"))^t>>BigInt(27))*BigInt("-7723592293110705685")&BigInt("0xFFFFFFFFFFFFFFFF"))^t>>BigInt(31))&BigInt("0xFFFFFFFFFFFFFFFF")}static upgradeSeedTo128bit(t){t<0&&(t+=BigInt("0x10000000000000000"));const e=t^P.SILVER_RATIO_64,s=e+P.GOLDEN_RATIO_64&BigInt("0xFFFFFFFFFFFFFFFF");return[P.mixStafford13(e),P.mixStafford13(s)]}static rotateLeft(t,e){return t<<e&BigInt("0xFFFFFFFFFFFFFFFF")|t>>BigInt(64)-e}setSeed(t){this.seed=P.upgradeSeedTo128bit(t)}fork(){return new P([this.next(),this.next()])}forkPositional(){return new Ke(this.next(),this.next())}next(){const t=this.seed[0];let e=this.seed[1];const s=P.rotateLeft(t+e&BigInt("0xFFFFFFFFFFFFFFFF"),BigInt(17))+t&BigInt("0xFFFFFFFFFFFFFFFF");return e^=t,this.seed=[P.rotateLeft(t,BigInt(49))^e^e<<BigInt(21)&BigInt("0xFFFFFFFFFFFFFFFF"),P.rotateLeft(e,BigInt(28))],s}nextLong(){let t=this.next();return t>BigInt("0x8000000000000000")&&(t-=BigInt("0x10000000000000000")),t}consume(t){let e=this.seed[0],s=this.seed[1];for(let i=0;i<t;i+=1)s^=e,e=P.rotateLeft(e,BigInt(49))^s^s<<BigInt(21),s=P.rotateLeft(s,BigInt(28));this.seed=[e,s]}nextBits(t){return this.next()>>BigInt(64-t)}nextInt(t){let e=this.next()&BigInt(4294967295);if(t){const s=BigInt(t);let i=e*s,n=i&BigInt(4294967295);if(n<s){const o=((~s&BigInt(4294967295))+BigInt(1))%s;for(;n<o;)e=this.next()&BigInt(4294967295),i=e*s,n=i&BigInt(4294967295)}const r=i>>BigInt(32);return Number(r)}{let s=Number(e);return s>=2147483648&&(s-=4294967296),s}}nextFloat(){return Number(this.nextBits(24))*P.FLOAT_MULTIPLIER}nextDouble(){return Number(this.nextBits(53))*P.DOUBLE_MULTIPLIER}parityConfigString(){return"seedLo: "+this.seed[0]+", seedHi: "+this.seed[1]}}P.SILVER_RATIO_64=BigInt("7640891576956012809"),P.GOLDEN_RATIO_64=BigInt("-7046029254386353131"),P.FLOAT_MULTIPLIER=1/Math.pow(2,24),P.DOUBLE_MULTIPLIER=11102230246251565e-32;class Ke{constructor(t,e){this.seedLo=t,this.seedHi=e}at(t,e,s){const i=Fe(t,e,s)^this.seedLo;return new P([i,this.seedHi])}fromHashOf(t){const e=Ee(t,{asBytes:!0}),s=Wt(e[0],e[1],e[2],e[3],e[4],e[5],e[6],e[7]),i=Wt(e[8],e[9],e[10],e[11],e[12],e[13],e[14],e[15]);return new P([s^this.seedLo,i^this.seedHi])}}class x{constructor(t){this.xo=256*t.nextDouble(),this.yo=256*t.nextDouble(),this.zo=256*t.nextDouble(),this.p=Array(256);for(let e=0;e<256;e+=1)this.p[e]=e;for(let e=0;e<256;e+=1){const s=t.nextInt(256-e),i=this.p[e];this.p[e]=this.p[e+s],this.p[e+s]=i}}sample2D(t,e){let s,i,n;const r=(t+e)*x.F2,o=Math.floor(t+r),h=t-(o-(s=(o+(i=Math.floor(e+r)))*x.G2));let c,l;h>(n=e-(i-s))?(c=1,l=0):(c=0,l=1);const u=h-c+x.G2,d=n-l+x.G2,f=h-1+2*x.G2,g=n-1+2*x.G2,m=255&o,b=255&i,E=this.P(m+this.P(b))%12,I=this.P(m+c+this.P(b+l))%12,N=this.P(m+1+this.P(b+1))%12;return 70*(this.getCornerNoise3D(E,h,n,0,.5)+this.getCornerNoise3D(I,u,d,0,.5)+this.getCornerNoise3D(N,f,g,0,.5))}sample(t,e,s){const i=.3333333333333333*(t+e+s),n=Math.floor(t+i),r=Math.floor(e+i),o=Math.floor(s+i),h=.16666666666666666*(n+r+o),c=t-(n-h),l=e-(r-h),u=s-(o-h);let d,f,g,m,b,E;c>=l?l>=u?(d=1,f=0,g=0,m=1,b=1,E=0):c>=u?(d=1,f=0,g=0,m=1,b=0,E=1):(d=0,f=0,g=1,m=1,b=0,E=1):l<u?(d=0,f=0,g=1,m=0,b=1,E=1):c<u?(d=0,f=1,g=0,m=0,b=1,E=1):(d=0,f=1,g=0,m=1,b=1,E=0);const I=c-d+.16666666666666666,N=l-f+.16666666666666666,w=u-g+.16666666666666666,S=c-m+.3333333333333333,A=l-b+.3333333333333333,y=u-E+.3333333333333333,T=c-.5,Q=l-.5,V=u-.5,Y=255&n,z=255&r,G=255&o,O=this.P(Y+this.P(z+this.P(G)))%12,pt=this.P(Y+d+this.P(z+f+this.P(G+g)))%12,U=this.P(Y+m+this.P(z+b+this.P(G+E)))%12,D=this.P(Y+1+this.P(z+1+this.P(G+1)))%12;return 32*(this.getCornerNoise3D(O,c,l,u,.6)+this.getCornerNoise3D(pt,I,N,w,.6)+this.getCornerNoise3D(U,S,A,y,.6)+this.getCornerNoise3D(D,T,Q,V,.6))}P(t){return this.p[255&t]}getCornerNoise3D(t,e,s,i,n){let r,o=n-e*e-s*s-i*i;return o<0?r=0:(o*=o,r=o*o*x.gradDot(t,e,s,i)),r}static gradDot(t,e,s,i){const n=x.GRADIENT[15&t];return n[0]*e+n[1]*s+n[2]*i}}x.GRADIENT=[[1,1,0],[-1,1,0],[1,-1,0],[-1,-1,0],[1,0,1],[-1,0,1],[1,0,-1],[-1,0,-1],[0,1,1],[0,-1,1],[0,1,-1],[0,-1,-1],[1,1,0],[0,-1,1],[-1,1,0],[0,-1,-1]],x.F2=.5*(Math.sqrt(3)-1),x.G2=(3-Math.sqrt(3))/6;class ce{constructor(t){this.xo=256*t.nextDouble(),this.yo=256*t.nextDouble(),this.zo=256*t.nextDouble(),this.p=Array(256);for(let e=0;e<256;e+=1)this.p[e]=e>127?e-256:e;for(let e=0;e<256;e+=1){const s=t.nextInt(256-e),i=this.p[e];this.p[e]=this.p[e+s],this.p[e+s]=i}}sample(t,e,s,i=0,n=0){const r=t+this.xo,o=e+this.yo,h=s+this.zo,c=Math.floor(r),l=Math.floor(o),u=Math.floor(h),d=r-c,f=o-l,g=h-u;let m=0;if(i!==0){const b=n>=0&&n<f?n:f;m=Math.floor(b/i+1e-7)*i}return this.sampleAndLerp(c,l,u,d,f-m,g,f)}sampleAndLerp(t,e,s,i,n,r,o){const h=this.P(t),c=this.P(t+1),l=this.P(h+e),u=this.P(h+e+1),d=this.P(c+e),f=this.P(c+e+1),g=x.gradDot(this.P(l+s),i,n,r),m=x.gradDot(this.P(d+s),i-1,n,r),b=x.gradDot(this.P(u+s),i,n-1,r),E=x.gradDot(this.P(f+s),i-1,n-1,r),I=x.gradDot(this.P(l+s+1),i,n,r-1),N=x.gradDot(this.P(d+s+1),i-1,n,r-1),w=x.gradDot(this.P(u+s+1),i,n-1,r-1),S=x.gradDot(this.P(f+s+1),i-1,n-1,r-1);return We(Ut(i),Ut(o),Ut(r),g,m,b,E,I,N,w,S)}P(t){return 255&this.p[255&t]}}class L{constructor(t,e,s){if(t instanceof P){const i=t.forkPositional();this.noiseLevels=Array(s.length);for(let n=0;n<s.length;n++)if(s[n]!==0){const r=e+n;this.noiseLevels[n]=new ce(i.fromHashOf("octave_"+r))}}else{if(1-e<s.length)throw new Error("Positive octaves are not allowed when using LegacyRandom");this.noiseLevels=Array(s.length);for(let i=-e;i>=0;i-=1)i<s.length&&s[i]!==0?this.noiseLevels[i]=new ce(t):t.consume(262)}this.amplitudes=s,this.lowestFreqInputFactor=Math.pow(2,e),this.lowestFreqValueFactor=Math.pow(2,s.length-1)/(Math.pow(2,s.length)-1)}sample(t,e,s,i=0,n=0,r=!1){let o=0,h=this.lowestFreqInputFactor,c=this.lowestFreqValueFactor;for(let l=0;l<this.noiseLevels.length;l+=1){const u=this.noiseLevels[l];u&&(o+=this.amplitudes[l]*c*u.sample(L.wrap(t*h),r?-u.yo:L.wrap(e*h),L.wrap(s*h),i*h,n*h)),h*=2,c/=2}return o}getOctaveNoise(t){return this.noiseLevels[this.noiseLevels.length-1-t]}static wrap(t){return t-33554432*Math.floor(t/33554432+.5)}}class de{constructor(t,e,s,i){this.cellWidth=s,this.cellHeight=i,this.minLimitNoise=new L(t,-15,[1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0]),this.maxLimitNoise=new L(t,-15,[1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0]),this.mainNoise=new L(t,-7,[1,1,1,1,1,0,0,0]),this.xzScale=684.412*e.xzScale,this.yScale=684.412*e.yScale,this.xzMainScale=this.xzScale/e.xzFactor,this.yMainScale=this.yScale/e.yFactor}sample(t,e,s){let i;t=Math.floor(t/this.cellWidth),e=Math.floor(e/this.cellHeight),s=Math.floor(s/this.cellWidth);let n=0,r=1;for(let c=0;c<8;c+=1){if(i=this.mainNoise.getOctaveNoise(c),i){const l=this.xzMainScale*r,u=this.yMainScale*r,d=L.wrap(t*l),f=L.wrap(e*u),g=L.wrap(s*l);n+=i.sample(d,f,g,u,e*u)/r}r/=2}n=(n/10+1)/2,r=1;let o=0,h=0;for(let c=0;c<16;c+=1){const l=this.xzScale*r,u=this.yScale*r,d=L.wrap(t*l),f=L.wrap(e*u),g=L.wrap(s*l);n<1&&(i=this.minLimitNoise.getOctaveNoise(c))&&(o+=i.sample(d,f,g,u,e*u)/r),n>0&&(i=this.maxLimitNoise.getOctaveNoise(c))&&(h+=i.sample(d,f,g,u,e*u)/r),r/=2}return ft(o/512,h/512,n)/128}}(function(a){a.fromJson=function(t){var e,s,i,n,r;const o=(e=p.readObject(t))!==null&&e!==void 0?e:{};return{xzScale:(s=p.readNumber(o.xz_scale))!==null&&s!==void 0?s:1,yScale:(i=p.readNumber(o.y_scale))!==null&&i!==void 0?i:1,xzFactor:(n=p.readNumber(o.xz_factor))!==null&&n!==void 0?n:80,yFactor:(r=p.readNumber(o.y_factor))!==null&&r!==void 0?r:80}}})(Xt||(Xt={}));class J{constructor(t,{firstOctave:e,amplitudes:s}){this.first=new L(t,e,s),this.second=new L(t,e,s);let i=1/0,n=-1/0;for(let o=0;o<s.length;o+=1)s[o]!==0&&(i=Math.min(i,o),n=Math.max(n,o));const r=.1*(1+1/(n-i+1));this.valueFactor=1/6/r}sample(t,e,s){const i=t*J.INPUT_FACTOR,n=e*J.INPUT_FACTOR,r=s*J.INPUT_FACTOR;return(this.first.sample(t,e,s)+this.second.sample(i,n,r))*this.valueFactor}}J.INPUT_FACTOR=1.0181268882175227,function(a){a.create=function(t,e){return{firstOctave:t,amplitudes:e}},a.fromJson=function(t){var e,s,i;const n=(e=p.readObject(t))!==null&&e!==void 0?e:{};return{firstOctave:(s=p.readInt(n.firstOctave))!==null&&s!==void 0?s:0,amplitudes:(i=p.readArray(n.amplitudes,r=>{var o;return(o=p.readNumber(r))!==null&&o!==void 0?o:0}))!==null&&i!==void 0?i:[]}}}(it||(it={}));class Ss{constructor(t,e){const s=e[e.length-1],i=-e[0]+s+1,n=new Set(e),r=new x(t);this.noiseLevels=Array(i),s>=0&&s<i&&n.has(0)&&(this.noiseLevels[s]=r);for(let o=s+1;o<i;o+=1)o>=0&&n.has(s-o)?this.noiseLevels[o]=new x(t):t.consume(262);if(s>0)throw new Error("Positive octaves are not allowed");this.highestFreqInputFactor=Math.pow(2,s),this.highestFreqValueFactor=1/(Math.pow(2,i)-1)}sample(t,e,s){let i=0,n=this.highestFreqInputFactor,r=this.highestFreqValueFactor;for(let o=0;o<this.noiseLevels.length;o+=1){const h=this.noiseLevels[o];h&&(i+=r*h.sample2D(t*n+(s?h.xo:0),e*n+(s?h.yo:0))),n/=2,r*=2}return i}}(function(a){a.fromJson=function(t,e){var s,i,n,r;if(typeof t=="number")return new $t(t);const o=(s=p.readObject(t))!==null&&s!==void 0?s:{},h=new _(e(o.coordinate)),c=(i=p.readArray(o.points,l=>{var u;return(u=p.readObject(l))!==null&&u!==void 0?u:{}}))!==null&&i!==void 0?i:[];if(c.length===0)return new $t(0);for(const l of c){const u=(n=p.readNumber(l.location))!==null&&n!==void 0?n:0,d=a.fromJson(l.value,e),f=(r=p.readNumber(l.derivative))!==null&&r!==void 0?r:0;h.addPoint(u,d,f)}return h}})(ct||(ct={}));class $t{constructor(t){this.value=t}apply(){return this.value}toJson(){return this.value}}class _{constructor(t,e=[],s=[],i=[]){this.coordinate=t,this.locations=e,this.values=s,this.derivatives=i}apply(t){const e=this.coordinate.apply(t),s=qe(0,this.locations.length,g=>e<this.locations[g])-1,i=this.locations.length-1;if(s<0)return this.values[0].apply(t)+this.derivatives[0]*(e-this.locations[0]);if(s===i)return this.values[i].apply(t)+this.derivatives[i]*(e-this.locations[i]);const n=this.locations[s],r=this.locations[s+1],o=this.derivatives[s],h=this.derivatives[s+1],c=(e-n)/(r-n),l=this.values[s].apply(t),u=this.values[s+1].apply(t),d=o*(r-n)-(u-l),f=-h*(r-n)+(u-l);return k(c,l,u)+c*(1-c)*k(c,d,f)}addPoint(t,e,s=0){return this.locations.push(t),this.values.push(typeof e=="number"?new $t(e):e),this.derivatives.push(s),this}toJson(){return{coordinate:this.coordinate.toJson(),points:this.locations.map((t,e)=>({location:t,value:this.values[e].toJson(),derivative:this.derivatives[e]}))}}}const ot=a=>[(a>>16&255)/256,(a>>8&255)/256,(255&a)/256],q=[124/256,189/256,107/256],ts=ot(6396257),es=ot(8431445),ht=ot(4764952),Gt=ot(4159204),fe=ot(8431445),ss=ot(2129968),ge=a=>[a/8,1-a/32,64*a],pe={large_fern:()=>q,tall_grass:()=>q,grass_block:()=>q,fern:()=>q,grass:()=>q,potted_fern:()=>q,spruce_leaves:()=>ts,birch_leaves:()=>es,oak_leaves:()=>ht,jungle_leaves:()=>ht,acacia_leaves:()=>ht,dark_oak_leaves:()=>ht,vine:()=>ht,water:()=>Gt,bubble_column:()=>Gt,cauldron:()=>Gt,redstone_wire:a=>{var t;return(e=>{const s=e/15;return[.6*s+(s>0?.4:.3),Z(s*s*.7-.5,0,1),Z(s*s*.6-.7,0,1)]})(parseInt((t=a.power)!==null&&t!==void 0?t:"0"))},sugar_cane:()=>q,attached_melon_stem:()=>fe,attached_pumpkin_stem:()=>fe,melon_stem:a=>{var t;return ge(parseInt((t=a.age)!==null&&t!==void 0?t:"0"))},pumpkin_stem:a=>{var t;return ge(parseInt((t=a.age)!==null&&t!==void 0?t:"0"))},lily_pad:()=>ss};var qt;function Et(...a){let t=0;for(const i of a)t+=i.length;const e=new Float32Array(t);let s=0;for(const i of a)e.set(i,s),s+=i.length;return e}function It(a,t){const e=He();for(let s=0;s<a.length;s+=3)e[0]=a[s],e[1]=a[s+1],e[2]=a[s+2],Ve(e,e,t),a[s]=e[0],a[s+1]=e[1],a[s+2]=e[2]}(function(a){a.rotate=function(t,e,s){let{up:i,down:n,north:r,east:o,south:h,west:c}=t;switch(s){case 90:[r,o,h,c]=[o,h,c,r];break;case 180:[r,o,h,c]=[h,c,r,o];break;case 270:[r,o,h,c]=[c,r,o,h]}switch(e){case 90:[i,r,n,h]=[r,n,h,i];break;case 180:[i,r,n,h]=[n,h,i,r];break;case 270:[i,r,n,h]=[h,i,r,n]}return{up:i,down:n,north:r,east:o,south:h,west:c}}})(qt||(qt={}));class oe{constructor(t,e,s){this.id=t,this.variants=e,this.multipart=s,this.variants=e}getModelVariants(t){if(this.variants){const e=Object.keys(this.variants).filter(i=>this.matchesVariant(i,t));if(e.length===0)return[];const s=this.variants[e[0]];return[Array.isArray(s)?s[0]:s]}return this.multipart?this.multipart.filter(e=>!e.when||this.matchesCase(e.when,t)).map(e=>Array.isArray(e.apply)?e.apply[0]:e.apply):[]}getBuffers(t,e,s,i,n,r){var o,h,c,l;const u=this.getModelVariants(e),d=[],f=[],g=[],m=[];for(const I of u){const N=qt.rotate(r,(o=I.x)!==null&&o!==void 0?o:0,(h=I.y)!==null&&h!==void 0?h:0),w=i.getBlockModel(I.model).getBuffers(t,e,s,n,N);if(I.x||I.y){const S=et();zt(S),nt(S,S,[8,8,8]),De(S,S,-jt((c=I.y)!==null&&c!==void 0?c:0)),Me(S,S,-jt((l=I.x)!==null&&l!==void 0?l:0)),nt(S,S,[-8,-8,-8]),It(w.position,S)}d.push(w.position),f.push(...w.texCoord),g.push(...w.tintColor),m.push(...w.index),n+=w.texCoord.length/2}const b=et();zt(b),Ie(b,b,[.0625,.0625,.0625]);const E=Et(...d);return It(E,b),{position:E,texCoord:f,tintColor:g,index:m}}matchesVariant(t,e){return t.split(",").every(s=>{const[i,n]=s.split("=");return e[i]===n})}matchesCase(t,e){if(Array.isArray(t.OR))return t.OR.some(i=>this.matchesCase(i,e));const s=t;return Object.keys(s).every(i=>s[i].split("|").includes(e[i]))}static fromJson(t,e){return new oe(t,e.variants,e.multipart)}}const is={0:[0,3,2,3,2,1,0,1],90:[2,3,2,1,0,1,0,3],180:[2,1,0,1,0,3,2,3],270:[0,1,0,3,2,3,2,1]},ns={x:[1,0,0],y:[0,1,0],z:[0,0,1]},K=1.41421356237,rs={x:[1,K,K],y:[K,1,K],z:[K,K,1]};class Nt{constructor(t,e,s,i){this.id=t,this.parent=e,this.textures=s,this.elements=i,this.flattened=!1}getBuffers(t,e,s,i,n){var r;const o=[],h=[],c=[],l=[];for(const u of(r=this.elements)!==null&&r!==void 0?r:[]){const d=this.getElementBuffers(t,e,u,i,s,n);o.push(d.position),h.push(...d.texCoord),c.push(...d.tintColor),l.push(...d.index),i+=d.texCoord.length/2}return{position:Et(...o),texCoord:h,tintColor:c,index:l}}getElementBuffers(t,e,s,i,n,r){var o,h,c,l,u,d,f,g,m,b,E,I;const N=s.from[0],w=s.from[1],S=s.from[2],A=s.to[0],y=s.to[1],T=s.to[2],Q=[],V=[],Y=[],z=[],G=(U,D,Ce)=>{var At,yt,Pt,Ft,Rt,Bt,xt,Tt,Ct,_t,kt,Dt;const[at,lt,_e,ke]=n.getTextureUV(this.getTexture(U.texture)),Mt=(_e-at)/16,Ot=(ke-lt)/16,ae=Mt/16,le=Ot/16;D[0]=((yt=(At=U.uv)===null||At===void 0?void 0:At[0])!==null&&yt!==void 0?yt:D[0])*Mt+ae,D[1]=((Ft=(Pt=U.uv)===null||Pt===void 0?void 0:Pt[1])!==null&&Ft!==void 0?Ft:D[1])*Ot+le,D[2]=((Bt=(Rt=U.uv)===null||Rt===void 0?void 0:Rt[2])!==null&&Bt!==void 0?Bt:D[2])*Mt-ae,D[3]=((Tt=(xt=U.uv)===null||xt===void 0?void 0:xt[3])!==null&&Tt!==void 0?Tt:D[3])*Ot-le;const X=is[(Ct=U.rotation)!==null&&Ct!==void 0?Ct:0];V.push(at+D[X[0]],lt+D[X[1]],at+D[X[2]],lt+D[X[3]],at+D[X[4]],lt+D[X[5]],at+D[X[6]],lt+D[X[7]]);const mt=((_t=U.tintindex)!==null&&_t!==void 0?_t:-1)>=0&&(Dt=(kt=pe[t.slice(10)])===null||kt===void 0?void 0:kt.call(pe,e))!==null&&Dt!==void 0?Dt:[1,1,1];Y.push(...mt,...mt,...mt,...mt),Q.push(...Ce),z.push(i,i+1,i+2,i,i+2,i+3),i+=4};!(!((h=(o=s.faces)===null||o===void 0?void 0:o.up)===null||h===void 0)&&h.texture)||s.faces.up.cullface&&r[s.faces.up.cullface]||G(s.faces.up,[N,16-T,A,16-S],[N,y,T,A,y,T,A,y,S,N,y,S]),!(!((l=(c=s.faces)===null||c===void 0?void 0:c.down)===null||l===void 0)&&l.texture)||s.faces.down.cullface&&r[s.faces.down.cullface]||G(s.faces.down,[16-T,16-A,16-S,16-N],[N,w,S,A,w,S,A,w,T,N,w,T]),!(!((d=(u=s.faces)===null||u===void 0?void 0:u.south)===null||d===void 0)&&d.texture)||s.faces.south.cullface&&r[s.faces.south.cullface]||G(s.faces.south,[N,16-y,A,16-w],[N,w,T,A,w,T,A,y,T,N,y,T]),!(!((g=(f=s.faces)===null||f===void 0?void 0:f.north)===null||g===void 0)&&g.texture)||s.faces.north.cullface&&r[s.faces.north.cullface]||G(s.faces.north,[16-A,16-y,16-N,16-w],[A,w,S,N,w,S,N,y,S,A,y,S]),!(!((b=(m=s.faces)===null||m===void 0?void 0:m.east)===null||b===void 0)&&b.texture)||s.faces.east.cullface&&r[s.faces.east.cullface]||G(s.faces.east,[16-T,16-y,16-S,16-w],[A,w,T,A,w,S,A,y,S,A,y,T]),!(!((I=(E=s.faces)===null||E===void 0?void 0:E.west)===null||I===void 0)&&I.texture)||s.faces.west.cullface&&r[s.faces.west.cullface]||G(s.faces.west,[S,16-y,T,16-w],[N,w,S,N,w,T,N,y,T,N,y,S]);const O=et();if(zt(O),s.rotation){const U=bt(...s.rotation.origin);nt(O,O,U),Oe(O,O,jt(s.rotation.angle),ns[s.rotation.axis]),s.rotation.rescale&&Ie(O,O,rs[s.rotation.axis]),Le(U,U),nt(O,O,U)}const pt=new Float32Array(Q);return It(pt,O),{position:pt,texCoord:V,tintColor:Y,index:z}}getTexture(t){for(var e,s;t.startsWith("#");)t=(s=(e=this.textures)===null||e===void 0?void 0:e[t.slice(1)])!==null&&s!==void 0?s:"";return t.startsWith("minecraft:")||(t="minecraft:"+t),t}flatten(t){var e;if(!this.flattened&&this.parent){const s=t.getBlockModel(this.parent);if(!s)return console.warn(`parent ${this.parent} does not exist!`),void(this.flattened=!0);s.flatten(t),this.elements||(this.elements=s.elements),this.textures||(this.textures={}),Object.keys((e=s.textures)!==null&&e!==void 0?e:{}).forEach(i=>{this.textures[i]||(this.textures[i]=s.textures[i])}),this.flattened=!0}}static fromJson(t,e){let s=e.parent;return s&&!s.startsWith("minecraft:")&&(s="minecraft:"+s),new Nt(t,s,e.textures,e.elements)}}class Yt{constructor(t,e,s){this.gl=t,this.program=this.initShaderProgram(e,s)}getProgram(){return this.program}initShaderProgram(t,e){const s=this.loadShader(this.gl.VERTEX_SHADER,t),i=this.loadShader(this.gl.FRAGMENT_SHADER,e),n=this.gl.createProgram();if(this.gl.attachShader(n,s),this.gl.attachShader(n,i),this.gl.linkProgram(n),!this.gl.getProgramParameter(n,this.gl.LINK_STATUS))throw new Error(`Unable to link shader program: ${this.gl.getProgramInfoLog(n)}`);return n}loadShader(t,e){const s=this.gl.createShader(t);if(this.gl.shaderSource(s,e),this.gl.compileShader(s),!this.gl.getShaderParameter(s,this.gl.COMPILE_STATUS)){const i=new Error(`Compiling ${t===this.gl.VERTEX_SHADER?"vertex":"fragment"} shader: ${this.gl.getShaderInfoLog(s)}`);throw this.gl.deleteShader(s),i}return s}}function Re(a,t,e,s,i){const n=new oe("",{"":{model:""}},void 0),r={getBlockModel:()=>i};return i.flatten(r),n.getBuffers(a,{},t,r,e,s)}function me(a,t,e,s,i,n){const r=i.up?16:[14.2,12.5,10.5,9,7,5.3,3.7,1.9,16,16,16,16,16,16,16,16][e];return Re(`minecraft:${a}`,s,t,i,new Nt("","",{still:`minecraft:block/${a}_still`,flow:`minecraft:block/${a}_flow`},[{from:[0,0,0],to:[16,r,16],faces:{up:{texture:"#still",tintindex:n,cullface:F.UP},down:{texture:"#still",tintindex:n,cullface:F.DOWN},north:{texture:"#flow",tintindex:n,cullface:F.NORTH},east:{texture:"#flow",tintindex:n,cullface:F.EAST},south:{texture:"#flow",tintindex:n,cullface:F.SOUTH},west:{texture:"#flow",tintindex:n,cullface:F.WEST}}}]))}const Be={"minecraft:water":(a,t,e,s)=>me("water",a,parseInt(t.level),e,s,0),"minecraft:lava":(a,t,e,s)=>me("lava",a,parseInt(t.level),e,s),"minecraft:chest":(a,t,e)=>function(s,i,n,r){return Re("minecraft:chest",r,s,{},new Nt("","",{0:"minecraft:block/chest"},[{from:[1,0,1],to:[15,14,15],faces:{up:{texture:"#0"},down:{texture:"#0"},north:{texture:"#0"},east:{texture:"#0"},south:{texture:"#0"},west:{texture:"#0"}}}]))}(a,t.facing,t.type,e)},os=new Set(Object.keys(Be));class Es{constructor(t,e,s,i){var n,r;this.gl=t,this.structure=e,this.resources=s,this.chunks=[],i!=null&&i.facesPerBuffer&&console.warn("webgl render warning: facesPerBuffer option has been removed in favor of chunkSize"),this.chunkSize=(n=i==null?void 0:i.chunkSize)!==null&&n!==void 0?n:16,this.useInvisibleBlockBuffer=(r=i==null?void 0:i.useInvisibleBlockBuffer)===null||r===void 0||r,this.shaderProgram=new Yt(t,`
attribute vec4 vertPos;
attribute vec2 texCoord;
attribute vec3 tintColor;
attribute vec3 normal;
uniform mat4 mView;
uniform mat4 mProj;
varying highp vec2 vTexCoord;
varying highp vec3 vTintColor;
varying highp float vLighting;
void main(void) {
gl_Position = mProj * mView * vertPos;
vTexCoord = texCoord;
vTintColor = tintColor;
vLighting = normal.y * 0.2 + abs(normal.z) * 0.1 + 0.8;
}
`,`
precision highp float;
varying highp vec2 vTexCoord;
varying highp vec3 vTintColor;
varying highp float vLighting;
uniform sampler2D sampler;
void main(void) {
vec4 texColor = texture2D(sampler, vTexCoord);
if(texColor.a < 0.01) discard;
gl_FragColor = vec4(texColor.xyz * vTintColor * vLighting, texColor.a);
}
`).getProgram(),this.gridShaderProgram=new Yt(t,`
attribute vec4 vertPos;
attribute vec3 vertColor;
uniform mat4 mView;
uniform mat4 mProj;
varying highp vec3 vColor;
void main(void) {
gl_Position = mProj * mView * vertPos;
vColor = vertColor;
}
`,`
precision highp float;
varying highp vec3 vColor;
void main(void) {
gl_FragColor = vec4(vColor, 1.0);
}
`).getProgram(),this.colorShaderProgram=new Yt(t,`
attribute vec4 vertPos;
attribute vec3 blockPos;
uniform mat4 mView;
uniform mat4 mProj;
varying highp vec3 vColor;
void main(void) {
gl_Position = mProj * mView * vertPos;
vColor = blockPos / 256.0;
}
`,`
precision highp float;
varying highp vec3 vColor;
void main(void) {
gl_FragColor = vec4(vColor, 1.0);
}
`).getProgram(),this.updateStructureBuffers(),this.gridBuffers=this.getGridBuffers(),this.outlineBuffers=this.getOutlineBuffers(),this.invisibleBlockBuffers=this.getInvisibleBlockBuffers(),this.atlasTexture=this.getBlockTexture(),this.projMatrix=this.getPerspective(),this.activeShader=this.shaderProgram,this.initialize()}setStructure(t){this.structure=t,this.updateStructureBuffers(),this.gridBuffers=this.getGridBuffers(),this.invisibleBlockBuffers=this.getInvisibleBlockBuffers()}initialize(){this.gl.enable(this.gl.DEPTH_TEST),this.gl.depthFunc(this.gl.LEQUAL),this.gl.enable(this.gl.BLEND),this.gl.blendFunc(this.gl.SRC_ALPHA,this.gl.ONE_MINUS_SRC_ALPHA),this.gl.enable(this.gl.CULL_FACE),this.gl.cullFace(this.gl.BACK)}getBlockTexture(){const t=this.gl.createTexture();return this.gl.bindTexture(this.gl.TEXTURE_2D,t),this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,this.gl.RGBA,this.gl.UNSIGNED_BYTE,this.resources.getTextureAtlas()),this.gl.generateMipmap(this.gl.TEXTURE_2D),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MAG_FILTER,this.gl.NEAREST),t}getPerspective(){const t=70*Math.PI/180,e=this.gl.canvas.clientWidth/this.gl.canvas.clientHeight,s=et();return Ue(s,t,e,.1,500),s}getChunk(t){const e=2*Math.abs(t[0])+(t[0]<0?1:0),s=2*Math.abs(t[1])+(t[1]<0?1:0),i=2*Math.abs(t[2])+(t[2]<0?1:0);return this.chunks[e]||(this.chunks[e]=[]),this.chunks[e][s]||(this.chunks[e][s]=[]),this.chunks[e][s][i]||(this.chunks[e][s][i]={positions:[],textureCoordinates:[],tintColors:[],blockPositions:[],normals:[],indices:[],indexOffset:0}),this.chunks[e][s][i]}updateStructureBuffers(t){var e;const s=(o,h,c)=>{const l=et();nt(l,l,h),It(o.position,l),c.positions.push(o.position),c.textureCoordinates.push(...o.texCoord),c.tintColors.push(...o.tintColor);for(let u=0;u<o.position.length;u+=12){const d=bt(o.position[u],o.position[u+1],o.position[u+2]),f=bt(o.position[u+3],o.position[u+4],o.position[u+5]),g=bt(o.position[u+6],o.position[u+7],o.position[u+8]);he(f,f,d),he(g,g,d),ze(f,f,g),je(f,f),c.normals.push(...f,...f,...f,...f)}for(let u=0;u<o.texCoord.length/2;u+=1)c.blockPositions.push(...h);c.indices.push(...o.index),c.indexOffset+=o.texCoord.length/2},i=o=>{o.positions=[],o.textureCoordinates=[],o.tintColors=[],o.blockPositions=[],o.normals=[],o.indices=[],o.indexOffset=0},n=o=>{o.buffer?(this.updateBuffer(o.buffer.position,this.gl.ARRAY_BUFFER,Et(...o.positions)),this.updateBuffer(o.buffer.texCoord,this.gl.ARRAY_BUFFER,new Float32Array(o.textureCoordinates)),this.updateBuffer(o.buffer.tintColor,this.gl.ARRAY_BUFFER,new Float32Array(o.tintColors)),this.updateBuffer(o.buffer.normal,this.gl.ARRAY_BUFFER,new Float32Array(o.normals)),this.updateBuffer(o.buffer.blockPos,this.gl.ARRAY_BUFFER,new Float32Array(o.blockPositions)),this.updateBuffer(o.buffer.index,this.gl.ELEMENT_ARRAY_BUFFER,new Uint16Array(o.indices)),o.buffer.length=o.indices.length):o.buffer={position:this.createBuffer(this.gl.ARRAY_BUFFER,Et(...o.positions)),texCoord:this.createBuffer(this.gl.ARRAY_BUFFER,new Float32Array(o.textureCoordinates)),tintColor:this.createBuffer(this.gl.ARRAY_BUFFER,new Float32Array(o.tintColors)),blockPos:this.createBuffer(this.gl.ARRAY_BUFFER,new Float32Array(o.blockPositions)),normal:this.createBuffer(this.gl.ARRAY_BUFFER,new Float32Array(o.normals)),index:this.createBuffer(this.gl.ELEMENT_ARRAY_BUFFER,new Uint16Array(o.indices)),length:o.indices.length}};let r;t?t.forEach(o=>{const h=this.getChunk(o);i(h)}):this.chunks.forEach(o=>o.forEach(h=>h.forEach(c=>{i(c)})));for(const o of this.structure.getBlocks()){const h=o.state.getName(),c=o.state.getProperties(),l=(e=this.resources.getDefaultBlockProperties(h))!==null&&e!==void 0?e:{};Object.entries(l).forEach(([f,g])=>{c[f]||(c[f]=g)});const u=[Math.floor(o.pos[0]/this.chunkSize),Math.floor(o.pos[1]/this.chunkSize),Math.floor(o.pos[2]/this.chunkSize)];if(t&&!t.some(f=>Ge(f,u)))continue;const d=this.getChunk(u);try{const f=this.resources.getBlockDefinition(h),g={up:this.needsCull(o,F.UP),down:this.needsCull(o,F.DOWN),west:this.needsCull(o,F.WEST),east:this.needsCull(o,F.EAST),north:this.needsCull(o,F.NORTH),south:this.needsCull(o,F.SOUTH)};f&&(r=f.getBuffers(h,c,this.resources,this.resources,d.indexOffset,g),s(r,o.pos,d)),os.has(h)&&(r=Be[h](d.indexOffset,c,this.resources,g),s(r,o.pos,d))}catch(f){console.error(`Error rendering block ${h}`,f)}}t?t.forEach(o=>{const h=this.getChunk(o);n(h)}):this.chunks.forEach(o=>o.forEach(h=>h.forEach(c=>{n(c)})))}needsCull(t,e){var s,i;const n=(s=this.structure.getBlock(rt.towards(t.pos,e)))===null||s===void 0?void 0:s.state;return!!n&&(!((i=this.resources.getBlockFlags(n.getName()))===null||i===void 0)&&i.opaque?!(e===F.UP&&t.state.isFluid()):t.state.isFluid()&&n.isFluid())}getGridBuffers(){const[t,e,s]=this.structure.getSize(),i=[],n=[];i.push(0,0,0,t,0,0),n.push(1,0,0,1,0,0),i.push(0,0,0,0,0,s),n.push(0,0,1,0,0,1),i.push(0,0,0,0,e,0),i.push(t,0,0,t,e,0),i.push(0,0,s,0,e,s),i.push(t,0,s,t,e,s),i.push(0,e,0,0,e,s),i.push(t,e,0,t,e,s),i.push(0,e,0,t,e,0),i.push(0,e,s,t,e,s);for(let r=1;r<=t;r+=1)i.push(r,0,0,r,0,s);for(let r=1;r<=s;r+=1)i.push(0,0,r,t,0,r);for(let r=0;r<8+t+s;r+=1)n.push(.8,.8,.8,.8,.8,.8);return{position:this.createBuffer(this.gl.ARRAY_BUFFER,new Float32Array(i)),color:this.createBuffer(this.gl.ARRAY_BUFFER,new Float32Array(n)),length:i.length/3}}getOutlineBuffers(){const t=[],e=[];return this.addCube(t,e,[1,1,1],[0,0,0],[1,1,1]),{position:this.createBuffer(this.gl.ARRAY_BUFFER,new Float32Array(t)),color:this.createBuffer(this.gl.ARRAY_BUFFER,new Float32Array(e)),length:t.length/3}}getInvisibleBlockBuffers(){if(!this.useInvisibleBlockBuffer)return;const t=this.structure.getSize(),e=[],s=[];for(let i=0;i<t[0];i+=1)for(let n=0;n<t[1];n+=1)for(let r=0;r<t[2];r+=1){const o=this.structure.getBlock([i,n,r]);o!==void 0&&(o===null?this.addCube(e,s,[1,.25,.25],[i+.4375,n+.4375,r+.4375],[i+.5625,n+.5625,r+.5625]):o.state.getName()==="minecraft:air"?this.addCube(e,s,[.5,.5,1],[i+.375,n+.375,r+.375],[i+.625,n+.625,r+.625]):o.state.getName()==="minecraft:cave_air"&&this.addCube(e,s,[.5,1,.5],[i+.375,n+.375,r+.375],[i+.625,n+.625,r+.625]))}return{position:this.createBuffer(this.gl.ARRAY_BUFFER,new Float32Array(e)),color:this.createBuffer(this.gl.ARRAY_BUFFER,new Float32Array(s)),length:e.length/3}}addCube(t,e,s,i,n){t.push(i[0],i[1],i[2],i[0],i[1],n[2]),t.push(n[0],i[1],i[2],n[0],i[1],n[2]),t.push(i[0],i[1],i[2],n[0],i[1],i[2]),t.push(i[0],i[1],n[2],n[0],i[1],n[2]),t.push(i[0],i[1],i[2],i[0],n[1],i[2]),t.push(n[0],i[1],i[2],n[0],n[1],i[2]),t.push(i[0],i[1],n[2],i[0],n[1],n[2]),t.push(n[0],i[1],n[2],n[0],n[1],n[2]),t.push(i[0],n[1],i[2],i[0],n[1],n[2]),t.push(n[0],n[1],i[2],n[0],n[1],n[2]),t.push(i[0],n[1],i[2],n[0],n[1],i[2]),t.push(i[0],n[1],n[2],n[0],n[1],n[2]);for(let r=0;r<24;r+=1)e.push(...s)}createBuffer(t,e){const s=this.gl.createBuffer();return this.gl.bindBuffer(t,s),this.gl.bufferData(t,e,this.gl.DYNAMIC_DRAW),s}updateBuffer(t,e,s){this.gl.bindBuffer(e,t),this.gl.bufferData(e,s,this.gl.STATIC_DRAW)}drawGrid(t){this.setShader(this.gridShaderProgram),this.setVertexAttr("vertPos",3,this.gridBuffers.position),this.setVertexAttr("vertColor",3,this.gridBuffers.color),this.setUniform("mView",t),this.setUniform("mProj",this.projMatrix),this.gl.drawArrays(this.gl.LINES,0,this.gridBuffers.length)}drawInvisibleBlocks(t){this.useInvisibleBlockBuffer&&(this.setShader(this.gridShaderProgram),this.setVertexAttr("vertPos",3,this.invisibleBlockBuffers.position),this.setVertexAttr("vertColor",3,this.invisibleBlockBuffers.color),this.setUniform("mView",t),this.setUniform("mProj",this.projMatrix),this.gl.drawArrays(this.gl.LINES,0,this.invisibleBlockBuffers.length))}drawStructure(t){this.setShader(this.shaderProgram),this.gl.activeTexture(this.gl.TEXTURE0),this.gl.bindTexture(this.gl.TEXTURE_2D,this.atlasTexture),this.setUniform("mView",t),this.setUniform("mProj",this.projMatrix),this.chunks.forEach(e=>{e.forEach(s=>{s.forEach(i=>{i.buffer&&(this.setVertexAttr("vertPos",3,i.buffer.position),this.setVertexAttr("texCoord",2,i.buffer.texCoord),this.setVertexAttr("tintColor",3,i.buffer.tintColor),this.setVertexAttr("normal",3,i.buffer.normal),this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,i.buffer.index),this.gl.drawElements(this.gl.TRIANGLES,i.buffer.length,this.gl.UNSIGNED_SHORT,0))})})})}drawColoredStructure(t){this.setShader(this.colorShaderProgram),this.setUniform("mView",t),this.setUniform("mProj",this.projMatrix),this.chunks.forEach(e=>{e.forEach(s=>{s.forEach(i=>{i.buffer&&(this.setVertexAttr("vertPos",3,i.buffer.position),this.setVertexAttr("blockPos",3,i.buffer.blockPos),this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,i.buffer.index),this.gl.drawElements(this.gl.TRIANGLES,i.buffer.length,this.gl.UNSIGNED_SHORT,0))})})})}drawOutline(t,e){this.setShader(this.gridShaderProgram),this.setVertexAttr("vertPos",3,this.outlineBuffers.position),this.setVertexAttr("vertColor",3,this.outlineBuffers.color);const s=et();Ye(s,t),nt(s,s,e),this.setUniform("mView",s),this.setUniform("mProj",this.projMatrix),this.gl.drawArrays(this.gl.LINES,0,this.outlineBuffers.length)}setViewport(t,e,s,i){this.gl.viewport(t,e,s,i),this.projMatrix=this.getPerspective()}setShader(t){this.gl.useProgram(t),this.activeShader=t}setVertexAttr(t,e,s){const i=this.gl.getAttribLocation(this.activeShader,t);this.gl.bindBuffer(this.gl.ARRAY_BUFFER,s),this.gl.vertexAttribPointer(i,e,this.gl.FLOAT,!1,0,0),this.gl.enableVertexAttribArray(i)}setUniform(t,e){const s=this.gl.getUniformLocation(this.activeShader,t);this.gl.uniformMatrix4fv(s,!1,e)}}/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */function ve(a,t,e,s){return new(e||(e=Promise))(function(i,n){function r(c){try{h(s.next(c))}catch(l){n(l)}}function o(c){try{h(s.throw(c))}catch(l){n(l)}}function h(c){var l;c.done?i(c.value):(l=c.value,l instanceof e?l:new e(function(u){u(l)})).then(r,o)}h((s=s.apply(a,t||[])).next())})}class St{constructor(t,e){this.img=t,this.idMap=e,this.part=16/t.width}getTextureAtlas(){return this.img}getTextureUV(t){var e;return(e=this.idMap[t])!==null&&e!==void 0?e:[0,0,this.part,this.part]}static fromBlobs(t){return ve(this,void 0,void 0,function*(){const e=Math.sqrt(Object.keys(t).length+1),s=Math.pow(2,Math.ceil(Math.log(e)/Math.log(2))),i=16*s,n=1/s,r=document.createElement("canvas");r.width=i,r.height=i;const o=r.getContext("2d");this.drawInvalidTexture(o);const h={};let c=1;return yield Promise.all(Object.keys(t).map(l=>ve(this,void 0,void 0,function*(){const u=c%s,d=Math.floor(c/s);c+=1,h[l]=[n*u,n*d,n*u+n,n*d+n];const f=yield createImageBitmap(t[l]);o.drawImage(f,0,0,16,16,16*u,16*d,16,16)}))),new St(o.getImageData(0,0,i,i),h)})}static empty(){const t=document.createElement("canvas");t.width=16,t.height=16;const e=t.getContext("2d");return St.drawInvalidTexture(e),new St(e.getImageData(0,0,16,16),{})}static drawInvalidTexture(t){t.fillStyle="black",t.fillRect(0,0,16,16),t.fillStyle="magenta",t.fillRect(0,0,8,8),t.fillRect(8,8,8,8)}}var gt,Qt,B,tt,Kt,v,te,dt,ee,se,Ht,be,Vt;(function(a){function t(c,l){return typeof c=="number"?new e(c,l!=null?l:c):c}a.target=function(c,l,u,d,f,g){return new i(c,l,u,d,f,g)},a.parameters=function(c,l,u,d,f,g,m){return new s(t(c),t(l),t(u),t(d),t(f),t(g),m)},a.param=t;class e{constructor(l,u){this.min=l,this.max=u}distance(l){const u=(typeof l=="number"?l:l.min)-this.max,d=this.min-(typeof l=="number"?l:l.max);return u>0?u:Math.max(d,0)}union(l){return new e(Math.min(this.min,l.min),Math.max(this.max,l.max))}static fromJson(l){var u;if(typeof l=="number")return new e(l,l);const[d,f]=(u=p.readArray(l,g=>p.readNumber(g)))!==null&&u!==void 0?u:[];return new e(d!=null?d:0,f!=null?f:0)}}a.Param=e;class s{constructor(l,u,d,f,g,m,b){this.temperature=l,this.humidity=u,this.continentalness=d,this.erosion=f,this.depth=g,this.weirdness=m,this.offset=b}fittness(l){return j(this.temperature.distance(l.temperature))+j(this.humidity.distance(l.humidity))+j(this.continentalness.distance(l.continentalness))+j(this.erosion.distance(l.erosion))+j(this.depth.distance(l.depth))+j(this.weirdness.distance(l.weirdness))+j(this.offset-l.offset)}space(){return[this.temperature,this.humidity,this.continentalness,this.erosion,this.depth,this.weirdness,new e(this.offset,this.offset)]}static fromJson(l){var u,d;const f=(u=p.readObject(l))!==null&&u!==void 0?u:{};return new s(e.fromJson(f.temperature),e.fromJson(f.humidity),e.fromJson(f.continentalness),e.fromJson(f.erosion),e.fromJson(f.depth),e.fromJson(f.weirdness),(d=p.readInt(f.offset))!==null&&d!==void 0?d:0)}}a.ParamPoint=s;class i{constructor(l,u,d,f,g,m){this.temperature=l,this.humidity=u,this.continentalness=d,this.erosion=f,this.depth=g,this.weirdness=m}get offset(){return 0}toArray(){return[this.temperature,this.humidity,this.continentalness,this.erosion,this.depth,this.weirdness,this.offset]}}a.TargetPoint=i,a.Parameters=class{constructor(c){this.things=c,this.index=new n(c)}find(c){return this.index.search(c,(l,u)=>l.distance(u))}};class n{constructor(l){this.root=n.build(l.map(([u,d])=>new h(u,d)))}static build(l){if(l.length===1)return l[0];if(l.length<=n.CHILDREN_PER_NODE){const g=l.map(m=>{let b=0;for(let E=0;E<7;E+=1){const I=m.space[E];b+=Math.abs((I.min+I.max)/2)}return{key:b,node:m}}).sort((m,b)=>m.key-b.key).map(({node:m})=>m);return new o(g)}let u=1/0,d=-1,f=[];for(let g=0;g<7;++g){l=n.sort(l,g,!1),f=n.bucketize(l);let m=0;for(const b of f)m+=n.area(b.space);u>m&&(u=m,d=g)}return l=n.sort(l,d,!1),f=n.bucketize(l),f=n.sort(f,d,!0),new o(f.map(g=>n.build(g.children)))}static sort(l,u,d){return l.map(f=>{const g=f.space[u],m=(g.min+g.max)/2;return{key:d?Math.abs(m):m,node:f}}).sort((f,g)=>f.key-g.key).map(({node:f})=>f)}static bucketize(l){const u=[];let d=[];const f=Math.pow(10,Math.floor(Math.log(l.length-.01)/Math.log(10)));for(const g of l)d.push(g),d.length<f||(u.push(new o(d)),d=[]);return d.length!==0&&u.push(new o(d)),u}static area(l){let u=0;for(const d of l)u+=Math.abs(d.max-d.min);return u}search(l,u){return this.root.search(l.toArray(),u).thing()}}n.CHILDREN_PER_NODE=10,a.RTree=n;class r{constructor(l){this.space=l}distance(l){let u=0;for(let d=0;d<7;d+=1)u+=j(this.space[d].distance(l[d]));return u}}a.RNode=r;class o extends r{constructor(l){super(o.buildSpace(l)),this.children=l}static buildSpace(l){let u=[...Array(7)].map(()=>new e(1/0,-1/0));for(const d of l)u=[...Array(7)].map((f,g)=>u[g].union(d.space[g]));return u}search(l,u){let d=1/0,f=null;for(const g of this.children){const m=u(g,l);if(d<=m)continue;const b=g.search(l,u),E=g==b?m:u(b,l);d<=E||(d=E,f=b)}return f}}a.RSubTree=o;class h extends r{constructor(l,u){super(l.space()),this.thing=u}search(){return this}}a.RLeaf=h})(gt||(gt={}));class xe{constructor(t){this.biome=t}getBiome(){return this.biome}static fromJson(t){var e,s;const i=(e=p.readObject(t))!==null&&e!==void 0?e:{},n=(s=p.readString(i.biome))!==null&&s!==void 0?s:"minecraft:the_void";return new xe(n)}}class Te{constructor(t){this.parameters=t}getBiome(t,e,s,i){const n=i(t,e,s);return this.parameters.find(n)}static fromJson(t){var e,s;const i=(e=p.readObject(t))!==null&&e!==void 0?e:{},n=((s=p.readArray(i.biomes,r=>{var o;return(h=>{var c;return{biome:(c=p.readString(h.biome))!==null&&c!==void 0?c:"minecraft:the_void",parameters:gt.ParamPoint.fromJson(h.parameters)}})((o=p.readObject(r))!==null&&o!==void 0?o:{})}))!==null&&s!==void 0?s:[]).map(r=>[r.parameters,()=>r.biome]);return new Te(new gt.Parameters(n))}}class C{constructor(t,e,s){this.offsetSampler=t,this.factorSampler=e,this.jaggednessSampler=s}static extractor(t){return{apply:e=>e[t],toJson:()=>t}}static fromJson(t){var e;const s=(e=p.readObject(t))!==null&&e!==void 0?e:{};return new C(ct.fromJson(s.offset,this.EXTRACTOR),ct.fromJson(s.factor,this.EXTRACTOR),ct.fromJson(s.jaggedness,this.EXTRACTOR))}toJson(){return{offset:this.offsetSampler.toJson(),factor:this.factorSampler.toJson(),jaggedness:this.jaggednessSampler.toJson()}}offset(t){return this.offsetSampler.apply(t)+C.GLOBAL_OFFSET}factor(t){return this.factorSampler.apply(t)}jaggedness(t){return this.jaggednessSampler.apply(t)}static point(t,e,s){return{continents:t,erosion:e,weirdness:s,ridges:this.peaksAndValleys(s)}}static peaksAndValleys(t){return 3*-(Math.abs(Math.abs(t)-.6666667)-.33333334)}static overworld(){const t=this.buildErosionOffsetSpline(-.05,0,0,.1,0,-.03,!1,!1),e=this.buildErosionOffsetSpline(-.1,.03,.1,.1,.01,-.03,!1,!1),s=this.buildErosionOffsetSpline(-.1,.03,.1,.7,.01,-.03,!0,!0),i=this.buildErosionOffsetSpline(.3,.03,.1,1,.01,.01,!0,!0),n=new _(this.CONTINENTS).addPoint(-1.1,.044).addPoint(-1.02,-.2222).addPoint(-.51,-.2222).addPoint(-.44,-.12).addPoint(-.18,-.12).addPoint(-.16,t).addPoint(-.15,t).addPoint(-.1,e).addPoint(.25,s).addPoint(1,i),r=new _(this.CONTINENTS).addPoint(-.19,3.95).addPoint(-.15,this.getErosionFactor(6.25,!0)).addPoint(-.1,this.getErosionFactor(5.47,!0)).addPoint(.03,this.getErosionFactor(5.08,!0)).addPoint(.06,this.getErosionFactor(4.69,!1)),o=new _(this.CONTINENTS).addPoint(.11,0).addPoint(.03,this.buildErosionJaggednessSpline(1,.5,0,0)).addPoint(.65,this.buildErosionJaggednessSpline(1,1,1,0));return new C(n,r,o)}static getErosionFactor(t,e){const s=new _(this.WEIRDNESS).addPoint(-.2,6.3).addPoint(.2,t),i=new _(this.EROSION).addPoint(-.6,s).addPoint(-.5,new _(this.WEIRDNESS).addPoint(-.05,6.3).addPoint(.05,2.67)).addPoint(-.35,s).addPoint(-.25,s).addPoint(-.1,new _(this.WEIRDNESS).addPoint(-.05,2.67).addPoint(.05,6.3)).addPoint(.03,s);if(e){const n=new _(this.WEIRDNESS).addPoint(0,t).addPoint(.1,.625),r=new _(this.RIDGES).addPoint(-.9,t).addPoint(-.69,n);i.addPoint(.35,t).addPoint(.45,r).addPoint(.55,r).addPoint(.62,t)}else{const n=new _(this.RIDGES).addPoint(-.7,s).addPoint(-.15,1.37),r=new _(this.RIDGES).addPoint(.45,s).addPoint(.7,1.56);i.addPoint(.05,r).addPoint(.4,r).addPoint(.45,n).addPoint(.55,n).addPoint(.58,t)}return i}static buildErosionOffsetSpline(t,e,s,i,n,r,o,h){const c=this.buildMountainRidgeSplineWithPoints(k(i,.6,1.5),h),l=this.buildMountainRidgeSplineWithPoints(k(i,.6,1),h),u=this.buildMountainRidgeSplineWithPoints(i,h),d=this.ridgeSpline(t-.15,.5*i,k(.5,.5,.5)*i,.5*i,.6*i,.5),f=this.ridgeSpline(t,n*i,e*i,.5*i,.6*i,.5),g=this.ridgeSpline(t,n,n,e,s,.5),m=this.ridgeSpline(t,n,n,e,s,.5),b=new _(this.RIDGES).addPoint(-1,t).addPoint(-.4,g).addPoint(0,s+.07),E=this.ridgeSpline(-.02,r,r,e,s,0),I=new _(this.EROSION).addPoint(-.85,c).addPoint(-.7,l).addPoint(-.4,u).addPoint(-.35,d).addPoint(-.1,f).addPoint(.2,g);return o&&I.addPoint(.4,m).addPoint(.45,b).addPoint(.55,b).addPoint(.58,m),I.addPoint(.7,E),I}static buildMountainRidgeSplineWithPoints(t,e){const s=new _(this.RIDGES),i=this.mountainContinentalness(-1,t,-.7),n=this.mountainContinentalness(1,t,-.7),r=this.calculateMountainRidgeZeroContinentalnessPoint(t);if(-.65<r&&r<1){const o=this.mountainContinentalness(-.65,t,-.7),h=this.mountainContinentalness(-.75,t,-.7),c=this.calculateSlope(i,h,-1,-.75);s.addPoint(-1,i,c),s.addPoint(-.75,h),s.addPoint(-.65,o);const l=this.mountainContinentalness(r,t,-.7),u=this.calculateSlope(l,n,r,1);s.addPoint(r-.01,l),s.addPoint(r,l,u),s.addPoint(1,n,u)}else{const o=this.calculateSlope(i,n,-1,1);e?(s.addPoint(-1,Math.max(.2,i)),s.addPoint(0,k(.5,i,n),o)):s.addPoint(-1,i,o),s.addPoint(1,n,o)}return s}static mountainContinentalness(t,e,s){const i=.46082947*(t+1.17)*(1-.5*(1-e))-.5*(1-e);return t<s?Math.max(i,-.2222):Math.max(i,0)}static calculateMountainRidgeZeroContinentalnessPoint(t){return .5*(1-t)/(.46082947*(1-.5*(1-t)))-1.17}static calculateSlope(t,e,s,i){return(e-t)/(i-s)}static ridgeSpline(t,e,s,i,n,r){const o=Math.max(.5*(e-t),r),h=5*(s-e);return new _(this.RIDGES).addPoint(-1,t,o).addPoint(-.4,e,Math.min(o,h)).addPoint(0,s,h).addPoint(.4,i,2*(i-s)).addPoint(1,n,.7*(n-i))}static buildErosionJaggednessSpline(t,e,s,i){const n=this.buildRidgeJaggednessSpline(t,s),r=this.buildRidgeJaggednessSpline(e,i);return new _(this.EROSION).addPoint(-1,n).addPoint(-.78,r).addPoint(-.5775,r).addPoint(-.375,0)}static buildRidgeJaggednessSpline(t,e){const s=C.peaksAndValleys(.4),i=(s+C.peaksAndValleys(.56666666))/2;return new _(this.RIDGES).addPoint(s,0).addPoint(i,e>0?this.buildWeirdnessJaggednessSpline(e):0).addPoint(1,t>0?this.buildWeirdnessJaggednessSpline(t):0)}static buildWeirdnessJaggednessSpline(t){return new _(C.WEIRDNESS).addPoint(-.01,.63*t).addPoint(.01,.3*t)}}C.GLOBAL_OFFSET=-.50375,C.EXTRACTOR=a=>{var t;const e=(t=p.readString(a))!==null&&t!==void 0?t:"continents";return C.extractor(e)},C.CONTINENTS=C.extractor("continents"),C.EROSION=C.extractor("erosion"),C.WEIRDNESS=C.extractor("weirdness"),C.RIDGES=C.extractor("ridges"),function(a){a.fromList=function(t){return(e,s,i,n)=>{for(const r of t){const o=r(e,s,i,n);if(o)return o}return null}}}(Qt||(Qt={})),function(a){function t(e){return e.ySize<<2}a.fromJson=function(e){var s,i,n,r,o,h,c,l;const u=(s=p.readObject(e))!==null&&s!==void 0?s:{};return{minY:(i=p.readInt(u.min_y))!==null&&i!==void 0?i:0,height:(n=p.readInt(u.height))!==null&&n!==void 0?n:256,xzSize:(r=p.readInt(u.size_horizontal))!==null&&r!==void 0?r:1,ySize:(o=p.readInt(u.size_vertical))!==null&&o!==void 0?o:1,sampling:Xt.fromJson(u.sampling),topSlide:tt.fromJson(u.top_slide),bottomSlide:tt.fromJson(u.bottom_slide),terrainShaper:C.fromJson(u.terrain_shaper),islandNoiseOverride:(h=p.readBoolean(u.island_noise_override))!==null&&h!==void 0&&h,isAmplified:(c=p.readBoolean(u.amplified))!==null&&c!==void 0&&c,hasLargeBiomes:(l=p.readBoolean(u.large_biomes))!==null&&l!==void 0&&l}},a.cellHeight=t,a.cellWidth=function(e){return e.xzSize<<2},a.cellCountY=function(e){return e.height/t(e)},a.minCellY=function(e){return Math.floor(e.minY/t(e))}}(B||(B={})),function(a){a.fromJson=function(t){var e,s,i,n;const r=(e=p.readObject(t))!==null&&e!==void 0?e:{};return{target:(s=p.readNumber(r.target))!==null&&s!==void 0?s:0,size:(i=p.readInt(r.size))!==null&&i!==void 0?i:0,offset:(n=p.readInt(r.offset))!==null&&n!==void 0?n:0}},a.apply=function(t,e,s){if(t.size<=0)return e;const i=(s-t.offset)/t.size;return ft(t.target,e,i)}}(tt||(tt={}));class wt{constructor(t,e){this.chunk=t,this.filler=e,this.noise000=0,this.noise001=0,this.noise100=0,this.noise101=0,this.noise010=0,this.noise011=0,this.noise110=0,this.noise111=0,this.valueXZ00=0,this.valueXZ10=0,this.valueXZ01=0,this.valueXZ11=0,this.valueZ0=0,this.valueZ1=0,this.value=0,this.slice0=wt.allocateSlice(t.cellCountY,t.cellCountXZ),this.slice1=wt.allocateSlice(t.cellCountY,t.cellCountXZ)}static allocateSlice(t,e){const s=Array(e+1);for(let i=0;i<e+1;i+=1)s[i]=Array(t+1);return s}initializeForFirstCellX(){this.fillSlice(this.slice0,this.chunk.firstCellX)}advanceCellX(t){this.fillSlice(this.slice1,this.chunk.firstCellX+t+1)}fillSlice(t,e){const s=B.cellWidth(this.chunk.settings.noise),i=B.cellHeight(this.chunk.settings.noise),n=e*s;for(let r=0;r<this.chunk.cellCountXZ+1;r+=1){const o=(this.chunk.firstCellZ+r)*s;for(let h=0;h<this.chunk.cellCountY+1;h+=1){const c=(this.chunk.cellCountNoiseMinY+h)*i;t[r][h]=this.filler(n,c,o)}}}selectCellYZ(t,e){this.noise000=this.slice0[e][t],this.noise001=this.slice0[e+1][t],this.noise100=this.slice1[e][t],this.noise101=this.slice1[e+1][t],this.noise010=this.slice0[e][t+1],this.noise011=this.slice0[e+1][t+1],this.noise110=this.slice1[e][t+1],this.noise111=this.slice1[e+1][t+1]}updateForY(t){this.valueXZ00=k(t,this.noise000,this.noise010),this.valueXZ10=k(t,this.noise100,this.noise110),this.valueXZ01=k(t,this.noise001,this.noise011),this.valueXZ11=k(t,this.noise101,this.noise111)}updateForX(t){this.valueZ0=k(t,this.valueXZ00,this.valueXZ10),this.valueZ1=k(t,this.valueXZ01,this.valueXZ11)}updateForZ(t){this.value=k(t,this.valueZ0,this.valueZ1)}sample(){return this.value}swapSlices(){[this.slice0,this.slice1]=[this.slice1,this.slice0]}}class as{constructor(t,e,s,i,n,r,o,h){this.cellCountXZ=t,this.cellCountY=e,this.cellCountNoiseMinY=s,this.sampler=i,this.settings=h;const c=B.cellWidth(h.noise);this.firstCellX=Math.floor(n/c),this.firstCellZ=Math.floor(r/c),this.firstNoiseX=n>>2,this.firstNoiseZ=r>>2,this.interpolators=[];const l=t*c>>2;this.noiseData=Array(l+1);for(let u=0;u<=l;u+=1){const d=this.firstNoiseX+u;this.noiseData[u]=Array(l+1);for(let f=0;f<=l;f+=1){const g=this.firstNoiseZ+f;this.noiseData[u][f]=i.noiseData(d,g)}}this.preliminarySurfaceLevel=new Map,this.baseNoise=i.makeBaseNoiseFiller(this,o,h.noodleCavesEnabled)}getNoiseData(t,e){return this.noiseData[t-this.firstNoiseX][e-this.firstNoiseZ]}getPreliminarySurfaceLevel(t,e){return re(this.preliminarySurfaceLevel,H.asLong(t,e),()=>{const s=t-this.firstNoiseX,i=e-this.firstNoiseZ,n=this.noiseData.length,r=s>=0&&i>=0&&s<n&&i<n?this.noiseData[s][i].terrainInfo:this.sampler.noiseData(t,e).terrainInfo;return this.sampler.getPreliminarySurfaceLevel(t<<2,e<<2,r)})}createNoiseInterpolator(t){const e=new wt(this,t);return this.interpolators.push(e),e.sample.bind(e)}initializeForFirstCellX(){this.interpolators.forEach(t=>t.initializeForFirstCellX())}advanceCellX(t){this.interpolators.forEach(e=>e.advanceCellX(t))}selectCellYZ(t,e){this.interpolators.forEach(s=>s.selectCellYZ(t,e))}updateForY(t){this.interpolators.forEach(e=>e.updateForY(t))}updateForX(t){this.interpolators.forEach(e=>e.updateForX(t))}updateForZ(t){this.interpolators.forEach(e=>e.updateForZ(t))}swapSlices(){this.interpolators.forEach(t=>t.swapSlices())}updateNoiseAndGenerateBaseState(t,e,s){return this.baseNoise(t,e,s)}}(function(a){a.create=function(t,e,s){return{offset:t,factor:e,jaggedness:s}}})(Kt||(Kt={})),function(a){const t=new Map;function e(s,i,n){const r=Object.assign({name:`minecraft:${s}`},it.create(i,n));return t.set(s,r),r}a.TEMPERATURE=e("temperature",-10,[1.5,0,1,0,0,0]),a.VEGETATION=e("vegetation",-8,[1,1,0,0,0,0]),a.CONTINENTALNESS=e("continentalness",-9,[1,1,2,2,2,1,1,1,1]),a.EROSION=e("erosion",-9,[1,1,0,1,1]),a.TEMPERATURE_LARGE=e("temperature_large",-12,[1.5,0,1,0,0,0]),a.VEGETATION_LARGE=e("vegetation_large",-10,[1,1,0,0,0,0]),a.CONTINENTALNESS_LARGE=e("continentalness_large",-11,[1,1,2,2,2,1,1,1,1]),a.EROSION_LARGE=e("erosion_large",-11,[1,1,0,1,1]),a.RIDGE=e("ridge",-7,[1,2,1,0,0,0]),a.SHIFT=e("offset",-3,[1,1,1,0]),a.PILLAR=e("pillar",-7,[1,1]),a.PILLAR_RARENESS=e("pillar_rareness",-8,[1]),a.PILLAR_THICKNESS=e("pillar_thickness",-8,[1]),a.SPAGHETTI_2D=e("spaghetti_2d",-8,[1]),a.SPAGHETTI_2D_ELEVATION=e("spaghetti_2d_elevation",-8,[1]),a.SPAGHETTI_2D_MODULATOR=e("spaghetti_2d_modulator",-8,[1]),a.SPAGHETTI_2D_THICKNESS=e("spaghetti_2d_thickness",-8,[1]),a.SPAGHETTI_3D_1=e("spaghetti_3d_1",-8,[1]),a.SPAGHETTI_3D_2=e("spaghetti_3d_2",-8,[1]),a.SPAGHETTI_3D_RARITY=e("spaghetti_3d_rarity",-8,[1]),a.SPAGHETTI_3D_THICKNESS=e("spaghetti_3d_thickness",-8,[1]),a.SPAGHETTI_ROUGHNESS=e("spaghetti_roughness",-8,[1]),a.SPAGHETTI_ROUGHNESS_MODULATOR=e("spaghetti_roughness_modulator",-8,[1]),a.CAVE_ENTRANCE=e("cave_entrance",-7,[.4,.5,1]),a.CAVE_LAYER=e("cave_layer",-8,[1]),a.CAVE_CHEESE=e("cave_cheese",-8,[.5,1,2,1,2,1,0,2,0]),a.NOODLE=e("noodle",-8,[1]),a.NOODLE_THICKNESS=e("noodle_thickness",-8,[1]),a.NOODLE_RIDGE_A=e("noodle_ridge_a",-7,[1]),a.NOODLE_RIDGE_B=e("noodle_ridge_b",-7,[1]),a.JAGGED=e("jagged",-16,[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]),a.SURFACE=e("surface",-6,[1,1,1]),a.SURFACE_SECONDARY=e("surface_secondary",-6,[1,1,0,1]),a.instantiate=function(s,i){return new J(s.fromHashOf(i.name),i)}}(v||(v={}));class ls{constructor(t,e,s,i=!1){this.settings=t,this.isNoiseCavesEnabled=e;const n=t.hasLargeBiomes,r=(i?new R(s):P.create(s)).forkPositional();i?(this.blendedNoise=new de(new R(s),t.sampling,B.cellWidth(t),B.cellHeight(t)),this.temperatureNoise=new J(new R(s),it.create(-7,[1,1])),this.humidityNoise=new J(new R(s+BigInt(1)),it.create(-7,[1,1])),this.offsetNoise=new J(new R(s+BigInt(5)),it.create(0,[0]))):(this.blendedNoise=new de(r.fromHashOf("minecraft:terrain"),t.sampling,B.cellWidth(t),B.cellHeight(t)),this.temperatureNoise=v.instantiate(r,n?v.TEMPERATURE_LARGE:v.TEMPERATURE),this.humidityNoise=v.instantiate(r,n?v.VEGETATION_LARGE:v.VEGETATION),this.offsetNoise=v.instantiate(r,v.SHIFT)),this.continentalnessNoise=v.instantiate(r,n?v.CONTINENTALNESS_LARGE:v.CONTINENTALNESS),this.erosionNoise=v.instantiate(r,n?v.EROSION_LARGE:v.EROSION),this.weirdnessNoise=v.instantiate(r,v.RIDGE),this.pillarNoise=v.instantiate(r,v.PILLAR),this.pillarRarenessModulator=v.instantiate(r,v.PILLAR_RARENESS),this.pillarThicknessModulator=v.instantiate(r,v.PILLAR_THICKNESS),this.spaghetti2DNoise=v.instantiate(r,v.SPAGHETTI_2D),this.spaghetti2DElevationModulator=v.instantiate(r,v.SPAGHETTI_2D_ELEVATION),this.spaghetti2DRarityModulator=v.instantiate(r,v.SPAGHETTI_2D_MODULATOR),this.spaghetti2DThicknessModulator=v.instantiate(r,v.SPAGHETTI_2D_THICKNESS),this.spaghetti3DNoise1=v.instantiate(r,v.SPAGHETTI_3D_1),this.spaghetti3DNoise2=v.instantiate(r,v.SPAGHETTI_3D_2),this.spaghetti3DRarityModulator=v.instantiate(r,v.SPAGHETTI_3D_RARITY),this.spaghetti3DThicknessModulator=v.instantiate(r,v.SPAGHETTI_3D_THICKNESS),this.spaghettiRoughnessNoise=v.instantiate(r,v.SPAGHETTI_ROUGHNESS),this.spaghettiRoughnessModulator=v.instantiate(r,v.SPAGHETTI_ROUGHNESS_MODULATOR),this.bigEntranceNoise=v.instantiate(r,v.CAVE_ENTRANCE),this.layerNoise=v.instantiate(r,v.CAVE_LAYER),this.cheeseNoise=v.instantiate(r,v.CAVE_CHEESE);const o=t.minY+4,h=o+t.height;this.noodleToggleNoise=this.yLimitedInterpolatable(v.instantiate(r,v.NOODLE),o,h,-1,1),this.noodleThicknessNoise=this.yLimitedInterpolatable(v.instantiate(r,v.NOODLE_THICKNESS),o,h,0,1),this.noodleRidgeANoise=this.yLimitedInterpolatable(v.instantiate(r,v.NOODLE_RIDGE_A),o,h,0,8/3),this.noodleRidgeBNoise=this.yLimitedInterpolatable(v.instantiate(r,v.NOODLE_RIDGE_B),o,h,0,8/3),this.jaggedNoise=v.instantiate(r,v.JAGGED),this.shaper=t.terrainShaper,this.baseNoise=c=>c.createNoiseInterpolator((l,u,d)=>this.calculateBlendedBaseNoise(l,u,d,c.getNoiseData(l>>2,d>>2).terrainInfo))}yLimitedInterpolatable(t,e,s,i,n){const r=(o,h,c)=>h>s||h<e?i:t.sample(o*n,h*n,c*n);return o=>o.createNoiseInterpolator(r)}noiseData(t,e){const s=t+this.getOffset(t,0,e),i=e+this.getOffset(e,t,0),n=this.getContinentalness(s,i),r=this.getErosion(s,i),o=this.getWeirdness(s,i),h=this.terrainInfo(n,r,o);return te.create(s,i,n,r,o,h)}sample(t,e,s){return this.target(t,e,s,this.noiseData(t,s))}target(t,e,s,i){const n=i.shiftedX,r=e+this.getOffset(e,s,t),o=i.shiftedZ,h=this.getTemperature(n,r,o),c=this.getHumidity(n,r,o),l=this.computeDimensionDensity(e<<2,i.terrainInfo);return gt.target(h,c,i.continentalness,i.erosion,l,i.weirdness)}terrainInfo(t,e,s){const i=C.point(t,e,s),n=this.shaper.offset(i),r=this.shaper.factor(i),o=this.shaper.jaggedness(i);return Kt.create(n,r,o)}getOffset(t,e,s){return 4*this.offsetNoise.sample(t,e,s)}getTemperature(t,e,s){return this.temperatureNoise.sample(t,e,s)}getHumidity(t,e,s){return this.humidityNoise.sample(t,e,s)}getContinentalness(t,e){return this.continentalnessNoise.sample(t,0,e)}getErosion(t,e){return this.erosionNoise.sample(t,0,e)}getWeirdness(t,e){return this.weirdnessNoise.sample(t,0,e)}makeBaseNoiseFiller(t,e,s){const i=this.baseNoise(t),n=s?this.noodleToggleNoise(t):()=>-1,r=s?this.noodleThicknessNoise(t):()=>0,o=s?this.noodleRidgeANoise(t):()=>0,h=s?this.noodleRidgeBNoise(t):()=>0;return(c,l,u)=>{let d=i();if(d=Z(.64*d,-1,1),d=d/2-d*d*d/24,n()>=0){const f=$e(r(),-1,1,.05,.1),g=Math.abs(1.5*o())-f,m=Math.abs(1.5*h())-f;d=Math.min(d,Math.max(g,m))}return d+=e(c,l,u),d>0?null:M.AIR}}calculateBlendedBaseNoise(t,e,s,i){const n=this.blendedNoise.sample(t,e,s);return this.calculateBaseNoise(t,e,s,i,n,!this.isNoiseCavesEnabled,!0)}calculateBaseNoise(t,e,s,i,n,r,o){if(!this.settings.islandNoiseOverride){const l=o?this.sampleJaggedNoise(i.jaggedness,t,s):0,u=this.computeDimensionDensity(e,i),d=i.factor*(l+u);n+=d>0?4*d:d}let h=-64,c=64;if(!r&&n>=-64){const l=n-1.5625,u=this.getBigEntrances(t,e,s),d=this.getSpaghettiRoughness(t,e,s),f=this.getSpaghetti3D(t,e,s),g=Math.min(u,f+d);if(l<0)c=g;else{const m=this.getLayerizedCaverns(t,e,s);m>64?n=64:n=this.getCheese(t,e,s)+m+ft(.5,0,1.28*l);const b=this.getSpaghetti2D(t,e,s);h=this.getPillars(t,e,s),c=Math.min(g,b+d)}}return n=Z(n,h,c),n=Z(n=this.applySlide(n,e/B.cellHeight(this.settings)),-64,64)}sampleJaggedNoise(t,e,s){if(t===0)return 0;const i=this.jaggedNoise.sample(1500*e,0,1500*s);return i>0?t*i:t/2*i}computeDimensionDensity(t,e){return 1-t/128+e.offset}getBigEntrances(t,e,s){return this.bigEntranceNoise.sample(.75*t,.5*e,.75*s)+.37+ft(.3,0,(e+10)/40)}getSpaghettiRoughness(t,e,s){const i=this.spaghettiRoughnessNoise.sample(t,e,s),n=W(this.spaghettiRoughnessModulator.sample(t,e,s),-1,1,0,1);return(.4-Math.abs(i))*n}getSpaghetti2D(t,e,s){const i=this.quantizeSpaghettiRarity2D(this.spaghetti2DRarityModulator.sample(2*t,e,2*s)),n=W(this.spaghetti2DThicknessModulator.sample(2*t,e,2*s),-1,1,.6,1.3),r=this.sampleWithRarity(this.spaghetti2DNoise,t,e,s,i),o=Math.abs(i*r)-.083*n,h=B.minCellY(this.settings),c=W(this.spaghetti2DElevationModulator.sample(t,0,s),-1,1,h,8),l=Math.abs(c-e/8)-1*n;return Z(Math.max(l,o),-1,1)}getSpaghetti3D(t,e,s){const i=this.quantizeSpaghettiRarity3D(this.spaghetti3DRarityModulator.sample(2*t,e,2*s)),n=W(this.spaghetti3DThicknessModulator.sample(t,e,s),-1,1,.065,.088),r=this.sampleWithRarity(this.spaghetti3DNoise1,t,e,s,i),o=Math.abs(i*r)-n,h=this.sampleWithRarity(this.spaghetti3DNoise2,t,e,s,i),c=Math.abs(i*h)-n;return Z(Math.max(o,c),-1,1)}quantizeSpaghettiRarity2D(t){return t<-.75?.5:t<-.5?.75:t<.5?1:t<.75?2:3}quantizeSpaghettiRarity3D(t){return t<-.5?.75:t<0?1:t<.5?1.5:2}sampleWithRarity(t,e,s,i,n){return t.sample(e/n,s/n,i/n)}getLayerizedCaverns(t,e,s){return 4*j(this.layerNoise.sample(t,8*e,s))}getCheese(t,e,s){return Z(this.cheeseNoise.sample(t,e/1.5,s)+.27,-1,1)}getPillars(t,e,s){const i=W(this.pillarRarenessModulator.sample(t,e,s),-1,1,0,2),n=W(this.pillarThicknessModulator.sample(t,e,s),-1,1,0,1.1),r=this.pillarNoise.sample(25*t,.3*e,25*s),o=Math.pow(n,3)*(2*r-i);return o<=.03?Number.MIN_SAFE_INTEGER:o}applySlide(t,e){const s=e-B.minCellY(this.settings);return t=tt.apply(this.settings.topSlide,t,B.cellCountY(this.settings)-s),t=tt.apply(this.settings.bottomSlide,t,s)}getPreliminarySurfaceLevel(t,e,s){const i=B.minCellY(this.settings)+B.cellCountY(this.settings),n=B.minCellY(this.settings),r=B.cellHeight(this.settings);for(let o=i;o>=n;o-=1){const h=o*r;if(this.calculateBaseNoise(t,h,e,s,-.703125,!0,!1)>=.390625)return h}return Number.MAX_SAFE_INTEGER}}(function(a){a.create=function(t,e,s,i,n,r){return{shiftedX:t,shiftedZ:e,continentalness:s,weirdness:i,erosion:n,terrainInfo:r}}})(te||(te={})),function(a){a.fromJson=function(t){var e,s,i,n;const r=(e=p.readObject(t))!==null&&e!==void 0?e:{};return r.absolute!==void 0?(o=(s=p.readNumber(r.absolute))!==null&&s!==void 0?s:0,()=>o):r.above_bottom!==void 0?function(h){return c=>c.minY+h}((i=p.readNumber(r.above_bottom))!==null&&i!==void 0?i:0):r.below_top!==void 0?function(h){return c=>c.maxY-h}((n=p.readNumber(r.below_top))!==null&&n!==void 0?n:0):()=>0;var o}}(dt||(dt={})),function(a){a.create=function(t,e){return{minY:t,height:e,maxY:t+e-1}}}(ee||(ee={}));class hs{constructor(t,e,s){this.rule=t,this.defaultBlock=e,this.random=P.create(s).forkPositional(),this.surfaceNoise=v.instantiate(this.random,v.SURFACE),this.surfaceSecondaryNoise=v.instantiate(this.random,v.SURFACE_SECONDARY),this.positionalRandoms=new Map}buildSurface(t,e,s,i){const n=H.minBlockX(t.pos),r=H.minBlockZ(t.pos),o=new us(this,t,e,s,i),h=this.rule(o);for(let c=0;c<16;c+=1){const l=n+c;for(let u=0;u<1;u+=1){const d=r+u;o.updateXZ(l,d);let f=0,g=Number.MIN_SAFE_INTEGER,m=Number.MAX_SAFE_INTEGER;for(let b=t.maxY;b>=t.minY;b-=1){const E=rt.create(l,b,d),I=t.getBlockState(E);if(I.equals(M.AIR)){f=0,g=Number.MIN_SAFE_INTEGER;continue}if(I.isFluid()){g===Number.MIN_SAFE_INTEGER&&(g=b+1);continue}if(m>=b){m=Number.MIN_SAFE_INTEGER;for(let S=b-1;S>=t.minY;S-=1){const A=t.getBlockState(rt.create(l,S,d));if(A.equals(M.AIR)||A.isFluid()){m=S+1;break}}}f+=1;const N=b-m+1;if(!I.equals(this.defaultBlock))continue;o.updateY(f,N,g,b);const w=h(l,b,d);w&&t.setBlockState(E,w)}}}}getSurfaceDepth(t,e){return 2.75*this.surfaceNoise.sample(t,0,e)+3+.25*this.random.at(t,0,e).nextDouble()}getSurfaceSecondary(t,e){return this.surfaceSecondaryNoise.sample(t,0,e)}getRandom(t){return re(this.positionalRandoms,t,()=>this.random.fromHashOf(t))}}class us{constructor(t,e,s,i,n){this.system=t,this.chunk=e,this.noiseChunk=s,this.context=i,this.getBiome=n,this.blockX=0,this.blockY=0,this.blockZ=0,this.stoneDepthAbove=0,this.stoneDepthBelow=0,this.surfaceDepth=0,this.waterHeight=0,this.biome=()=>"",this.surfaceSecondary=()=>0,this.minSurfaceLevel=()=>0}updateXZ(t,e){this.blockX=t,this.blockZ=e,this.surfaceDepth=this.system.getSurfaceDepth(t,e),this.surfaceSecondary=Lt(()=>this.system.getSurfaceSecondary(t,e)),this.minSurfaceLevel=Lt(()=>this.calculateMinSurfaceLevel(t,e))}updateY(t,e,s,i){this.blockY=i,this.stoneDepthAbove=t,this.stoneDepthBelow=e,this.waterHeight=s,this.biome=Lt(()=>this.getBiome(rt.create(this.blockX,this.blockY,this.blockZ)))}calculateMinSurfaceLevel(t,e){const s=t>>4,i=e>>4,n=this.noiseChunk.getPreliminarySurfaceLevel(s<<4,i<<4),r=this.noiseChunk.getPreliminarySurfaceLevel(s+1<<4,i<<4),o=this.noiseChunk.getPreliminarySurfaceLevel(s<<4,i+1<<4),h=this.noiseChunk.getPreliminarySurfaceLevel(s+1<<4,i+1<<4);return Math.floor(Zt((15&t)/16,(15&e)/16,n,r,o,h))+this.surfaceDepth-8}}(function(a){function t(i){return()=>()=>i}function e(i){return n=>{const r=i.map(o=>o(n));return(o,h,c)=>{for(const l of r){const u=l(o,h,c);if(u)return u}}}}function s(i,n){return r=>(o,h,c)=>{if(i(r))return n(r)(o,h,c)}}a.NOOP=()=>()=>{},a.fromJson=function(i){var n,r,o;const h=(n=p.readObject(i))!==null&&n!==void 0?n:{};switch((r=p.readString(h.type))===null||r===void 0?void 0:r.replace(/^minecraft:/,"")){case"block":return t(M.fromJson(h.result_state));case"sequence":return e((o=p.readArray(h.sequence,a.fromJson))!==null&&o!==void 0?o:[]);case"condition":return s(Ht.fromJson(h.if_true),a.fromJson(h.then_run))}return a.NOOP},a.block=t,a.sequence=e,a.condition=s})(se||(se={})),function(a){function t(){return h=>h.blockY>=h.minSurfaceLevel()}function e(h){const c=new Set(h);return l=>c.has(l.biome())}function s(h){return c=>!h(c)}function i(h,c,l,u){return d=>{const f=u?d.stoneDepthBelow:d.stoneDepthAbove,g=c?d.surfaceDepth:0,m=l===0?0:W(d.surfaceSecondary(),-1,1,0,l);return f<=1+h+g+m}}function n(h,c,l){return u=>{const d=c(u.context),f=l(u.context);if(u.blockY<=d)return!0;if(u.blockY>=f)return!1;const g=u.system.getRandom(h),m=W(u.blockY,d,f,1,0);return g.nextFloat()<m}}function r(h,c,l){return u=>{if(u.waterHeight===Number.MIN_SAFE_INTEGER)return!0;const d=l?u.stoneDepthAbove:0;return u.blockY+d>=u.waterHeight+h+u.surfaceDepth*c}}function o(h,c,l){return u=>{const d=l?u.stoneDepthAbove:0;return u.blockY+d>=h(u.context)+u.surfaceDepth*c}}a.FALSE=()=>!1,a.TRUE=()=>!0,a.fromJson=function(h){var c,l,u,d,f,g,m,b,E,I,N,w;const S=(c=p.readObject(h))!==null&&c!==void 0?c:{};switch((l=p.readString(S.type))===null||l===void 0?void 0:l.replace(/^minecraft:/,"")){case"above_preliminary_surface":return A=>A.blockY>=A.minSurfaceLevel();case"biome":return e((u=p.readArray(S.biome_is,A=>{var y;return(y=p.readString(A))!==null&&y!==void 0?y:""}))!==null&&u!==void 0?u:[]);case"not":return s(a.fromJson(S.invert));case"stone_depth":return i((d=p.readInt(S.offset))!==null&&d!==void 0?d:0,(f=p.readBoolean(S.add_surface_depth))!==null&&f!==void 0&&f,(g=p.readInt(S.secondary_depth_range))!==null&&g!==void 0?g:0,p.readString(S.surface_type)==="ceiling");case"vertical_gradient":return n((m=p.readString(S.random_name))!==null&&m!==void 0?m:"",dt.fromJson(S.true_at_and_below),dt.fromJson(S.false_at_and_above));case"water":return r((b=p.readInt(S.offset))!==null&&b!==void 0?b:0,(E=p.readInt(S.surface_depth_multiplier))!==null&&E!==void 0?E:0,(I=p.readBoolean(S.add_surface_depth))!==null&&I!==void 0&&I);case"y_above":return o(dt.fromJson(S.anchor),(N=p.readInt(S.surface_depth_multiplier))!==null&&N!==void 0?N:0,(w=p.readBoolean(S.add_surface_depth))!==null&&w!==void 0&&w)}return a.FALSE},a.abovePreliminarySurface=t,a.biome=e,a.not=s,a.stoneDepth=i,a.verticalGradient=n,a.water=r,a.yAbove=o}(Ht||(Ht={}));class Is{constructor(t,e,s){this.biomeSource=e,this.settings=s,this.sampler=new ls(s.noise,s.noiseCavesEnabled,t,s.legacyRandomSource),this.noiseChunkCache=new Map,this.materialRule=Qt.fromList([(i,n,r,o)=>i.updateNoiseAndGenerateBaseState(n,r,o)]),this.surfaceSystem=new hs(s.surfaceRule,s.defaultBlock,t)}fill(t){var e;const s=Math.max(t.minY,this.settings.noise.minY),i=Math.min(t.maxY,this.settings.noise.minY+this.settings.noise.height),n=B.cellWidth(this.settings.noise),r=B.cellHeight(this.settings.noise),o=Math.floor(16/n),h=Math.floor(s/r),c=Math.floor((i-s)/r),l=H.minBlockX(t.pos),u=H.minBlockZ(t.pos),d=this.getNoiseChunk(t);d.initializeForFirstCellX();for(let f=0;f<o;f+=1){d.advanceCellX(f);for(let g=0;g<o;g+=1){let m=t.getOrCreateSection(t.sectionsCount-1);for(let b=c-1;b>=0;b-=1){d.selectCellYZ(b,g);for(let E=r-1;E>=0;E-=1){const I=(h+b)*r+E,N=15&I,w=t.getSectionIndex(I);t.getSectionIndex(m.minBlockY)!==w&&(m=t.getOrCreateSection(w));const S=E/r;d.updateForY(S);for(let A=0;A<n;A+=1){const y=l+f*n+A,T=15&y,Q=A/n;d.updateForX(Q);for(let V=0;V<n;V+=1){const Y=u+g*n+V,z=15&Y,G=V/n;d.updateForZ(G);let O=(e=this.materialRule(d,y,I,Y))!==null&&e!==void 0?e:this.settings.defaultBlock;if(O.equals(M.AIR)){if(!(I<this.settings.seaLevel))continue;O=this.settings.defaultFluid}m.setBlockState(T,N,z,O)}}}}}d.swapSlices()}}buildSurface(t,e="minecraft:plains"){const s=this.getNoiseChunk(t),i=ee.create(this.settings.noise.minY,this.settings.noise.height);this.surfaceSystem.buildSurface(t,s,i,()=>e)}getNoiseChunk(t){return re(this.noiseChunkCache,H.toLong(t.pos),()=>{const e=Math.max(t.minY,this.settings.noise.minY),s=Math.min(t.maxY,this.settings.noise.minY+this.settings.noise.height),i=B.cellWidth(this.settings.noise),n=B.cellHeight(this.settings.noise),r=Math.floor(16/i),o=Math.floor(e/n),h=Math.floor((s-e)/n),c=H.minBlockX(t.pos),l=H.minBlockZ(t.pos);return new as(r,h,o,this.sampler,c,l,()=>0,this.settings)})}}(function(a){a.fromJson=function(t){var e,s,i,n,r,o,h,c,l,u,d;const f=(e=p.readObject(t))!==null&&e!==void 0?e:{};return{structures:Vt.fromJson(f.structures),surfaceRule:se.fromJson(f.surface_rule),noise:B.fromJson(f.noise),defaultBlock:M.fromJson(f.default_block),defaultFluid:M.fromJson(f.default_fluid),bedrockRoofPosition:(s=p.readInt(f.bedrock_roof_position))!==null&&s!==void 0?s:0,bedrockFloorPosition:(i=p.readInt(f.bedrock_floor_position))!==null&&i!==void 0?i:0,seaLevel:(n=p.readInt(f.sea_level))!==null&&n!==void 0?n:0,disableMobGeneration:(r=p.readBoolean(f.disable_mob_generation))!==null&&r!==void 0&&r,aquifersEnabled:(o=p.readBoolean(f.aquifers_enabled))!==null&&o!==void 0&&o,noiseCavesEnabled:(h=p.readBoolean(f.noise_caves_enabled))!==null&&h!==void 0&&h,deepslateEnabled:(c=p.readBoolean(f.deepslate_enabled))!==null&&c!==void 0&&c,oreVeinsEnabled:(l=p.readBoolean(f.ore_veins_enabled))!==null&&l!==void 0&&l,noodleCavesEnabled:(u=p.readBoolean(f.noodle_caves_enabled))!==null&&u!==void 0&&u,legacyRandomSource:(d=p.readBoolean(f.legacy_random_source))!==null&&d!==void 0&&d}}})(be||(be={})),function(a){a.fromJson=function(t){var e;const s=(e=p.readObject(t))!==null&&e!==void 0?e:{};return{stronghold:p.compose(s.stronghold,p.readObject,i=>{var n,r,o;return{distance:(n=p.readInt(i.distance))!==null&&n!==void 0?n:0,spread:(r=p.readInt(i.spread))!==null&&r!==void 0?r:0,count:(o=p.readInt(i.count))!==null&&o!==void 0?o:0}}),structures:p.readMap(s.structures,i=>{var n;return(r=>{var o,h,c;return{spacing:(o=p.readInt(r.spacing))!==null&&o!==void 0?o:0,separation:(h=p.readInt(r.separation))!==null&&h!==void 0?h:0,salt:(c=p.readInt(r.salt))!==null&&c!==void 0?c:0}})((n=p.readObject(i))!==null&&n!==void 0?n:{})})}}}(Vt||(Vt={}));export{de as BlendedNoise,pe as BlockColors,oe as BlockDefinition,Nt as BlockModel,rt as BlockPos,M as BlockState,bs as Chunk,H as ChunkPos,$ as ChunkSection,gt as Climate,$t as ConstantProvider,F as Direction,xe as FixedBiome,te as FlatNoiseData,ce as ImprovedNoise,p as Json,Qe as LegacyPositionalRandom,R as LegacyRandom,Qt as MaterialRule,Te as MultiNoise,Xe as NbtReader,Ze as NbtWriter,as as NoiseChunk,Is as NoiseChunkGenerator,be as NoiseGeneratorSettings,wt as NoiseInterpolator,it as NoiseParameters,ls as NoiseSampler,Xt as NoiseSamplingSettings,B as NoiseSettings,tt as NoiseSlideSettings,v as Noises,J as NormalNoise,ct as NumberProvider,L as PerlinNoise,Ss as PerlinSimplexNoise,x as SimplexNoise,_ as Spline,ye as Structure,Es as StructureRenderer,Vt as StructureSettings,Ht as SurfaceCondition,us as SurfaceContext,se as SurfaceRule,hs as SurfaceSystem,Kt as TerrainInfo,C as TerrainShaper,St as TextureAtlas,dt as VerticalAnchor,ee as WorldgenContext,Ke as XoroshiroPositionalRandom,P as XoroshiroRandom,qe as binarySearch,Z as clamp,ft as clampedLerp,$e as clampedMap,re as computeIfAbsent,vt as getListTag,Ae as getOptional,Fe as getSeed,st as getTag,Pe as inverseLerp,Lt as lazy,k as lerp,Zt as lerp2,We as lerp3,Wt as longfromBytes,W as map,ds as read,gs as readChunk,we as readCompressed,fs as readRegion,ie as readUncompressed,Ut as smoothstep,j as square,ue as tagNames,ut as tagTypes,ps as write,vs as writeChunk,Jt as writeCompressed,ms as writeRegion,ne as writeUncompressed};
//# sourceMappingURL=deepslate.esm.c77f95a7.js.map