import*as mc from"@minecraft/server";import*as vector from"../utils/vector";import*as boulder from"../entities/boulderProjectile";export function using(e){const{itemStack:t,source:o}=e;t&&"hf_mzs:sculptor_staff"===t.typeId&&mc.system.run((()=>{if(t.getComponent("minecraft:cooldown").getCooldownTicksRemaining(o)<39)return;if(o.getGameMode()!=mc.GameMode.creative&&o.getGameMode()!=mc.GameMode.spectator){const e=t.clone();e.getComponent("minecraft:durability").damage+=1,o.getComponent("minecraft:equippable").setEquipment(mc.EquipmentSlot.Mainhand,e)}const e=o.location;e.x=Math.floor(e.x)+.5,e.y=Math.floor(e.y)+.25,e.z=Math.floor(e.z)+.5;const r=o.getViewDirection();let i=o.getViewDirection();r.y=0;const a=vector.normalize(r),l=vector.cross(a,vector.up),n=vector.multiply(l,-1),c=vector.add(e,vector.multiply(a,3)),m=vector.add(e,vector.multiply(l,3)),s=vector.add(e,vector.multiply(n,3));i=vector.multiply(vector.normalize(i),.5),shootPebble(c,i,o.dimension),shootPebble(m,i,o.dimension),shootPebble(s,i,o.dimension)}))}function shootPebble(e,t,o){let r=new mc.MolangVariableMap;r.setFloat("variable.lifetime",.4),r.setFloat("variable.size",.5);let i=vector.subtract(e,{x:0,y:.2,z:0});o.spawnParticle("hf_mzs:ring_grow_ground",i,r),o.spawnParticle("hf_mzs:boulder_dirt",e);const a=o.spawnEntity("hf_mzs:boulder<hf_mzs:from_staff>",e);mc.system.runTimeout((()=>{if(a&&a.isValid()){let r=new mc.MolangVariableMap;r.setFloat("variable.lifetime",.4),r.setFloat("variable.size",.5);let i=-180*Math.atan2(t.x,t.z)/Math.PI;r.setFloat("variable.direction",i),a.triggerEvent("hf_mzs:flying"),a.setProperty("hf_mzs:launched",!0);let l=vector.add(e,{x:0,y:.25,z:0});o.spawnParticle("hf_mzs:ring_grow",l,r),boulder.shootBoulder(a,vector.multiply(vector.normalize(t),.8))}}),10)}