import*as mc from"@minecraft/server";import*as vector from"./utils/vector";import*as earthrend from"./items/earthrendGauntlet";export function carveCave(e){if("hf_mzs:carve_cave"===e.id){const r=e.sourceEntity;if(r&&r.isValid()&&!r.hasTag("hf_mzs_cave_carver_triggered")){r.addTag("hf_mzs_cave_carver_triggered");caveCarver(r,Math.floor(2*Math.random()+3),Math.floor(10*Math.random())+20,1)}}}function caveCarver(e,r,a,t){if(t>a/3&&(t>a||!earthrend.isUnderground(e,r+2)))return void e.remove();const o=e.location,i=e.getViewDirection();for(let a=-r;a<=r;a++)for(let t=-r;t<=r;t++)for(let i=-r;i<=r;i++){if(o.y+i<=e.dimension.heightRange.min||o.y+i>e.dimension.heightRange.max)continue;let n=e.dimension.getBlock({x:o.x+a,y:o.y+i,z:o.z+t}),m=vector.distance(o,n);n&&n.isValid()&&"minecraft:bedrock"!==n.typeId&&m<r&&n.setPermutation(mc.BlockPermutation.resolve("minecraft:air"))}t>a/3&&(i.x+=(Math.round(2*Math.random())-1)*Math.random()*3,i.z+=(Math.round(2*Math.random())-1)*Math.random()*3),i.y=Math.random()/2,e.clearVelocity(),e.applyImpulse(i),mc.system.runTimeout((()=>{caveCarver(e,r,a,t+1)}),1)}