import*as mc from"@minecraft/server";export const up={x:0,y:1,z:0};export const down={x:0,y:-1,z:0};export const left={x:-1,y:0,z:0};export const right={x:1,y:0,z:0};export const forward={x:0,y:0,z:1};export const back={x:0,y:0,z:-1};export function add(t,r){return{x:t.x+r.x,y:t.y+r.y,z:t.z+r.z}}export function subtract(t,r){return{x:t.x-r.x,y:t.y-r.y,z:t.z-r.z}}export function multiply(t,r){return{x:t.x*r,y:t.y*r,z:t.z*r}}export function magnitude(t){return Math.sqrt(t.x*t.x+t.y*t.y+t.z*t.z)}export function normalize(t){const r=magnitude(t);return{x:t.x/r,y:t.y/r,z:t.z/r}}export function random(t){return{x:(Math.random()-.5)*t,y:(Math.random()-.5)*t,z:(Math.random()-.5)*t}}export function cross(t,r){return{x:t.y*r.z-t.z*r.y,y:t.z*r.x-t.x*r.z,z:t.x*r.y-t.y*r.x}}export function flatten(t,r,n=!0){let o;return"x"===r&&(o={x:0,y:t.y,z:t.z}),"y"===r&&(o={x:t.x,y:0,z:t.z}),"z"===r&&(o={x:t.x,y:t.y,z:0}),n?normalize(o):o}export function copy(t){return{x:t.x,y:t.y,z:t.z}}export function rotateY(t,r){let n=t.x,o=t.z;return t.x=Math.cos(r)*n+Math.sin(r)*o,t.z=Math.sin(r)*-n+Math.cos(r)*o,t}export function sqr(t){return t*t}export function distance(t,r){return Math.sqrt(sqr(t.x-r.x)+sqr(t.y-r.y)+sqr(t.z-r.z))}export function string(t){return`${Math.round(10*t.x)/10} ${Math.round(10*t.y)/10} ${Math.round(10*t.z)/10}`}export function getCenterFromXYZ(t,r,n){return Math.sqrt((t/2)**2+(r/2)**2+(n/2)**2)+1}export function getBlockLocalCoord(t,r,n){let o=t.permutation;n&&(o=n);let e=o.getState("facing_direction");if(!e){const t=o.getState("minecraft:facing_direction");if(t)e=t;else{const t=o.getState("minecraft:cardinal_direction");if(t)switch(t){case"north":e=2;break;case"south":e=3;break;case"west":e=4;break;case"east":e=5}else e=3}}let x=0,a=0,c=0;switch(e){case 0:x=r.x,a=-r.y,c=r.z;break;case 1:case 3:x=r.x,a=r.y,c=r.z;break;case 2:x=-r.x,a=r.y,c=-r.z;break;case 4:x=-r.z,a=r.y,c=r.x;break;case 5:x=r.z,a=r.y,c=-r.x}return{x:x+t.location.x,y:a+t.location.y,z:c+t.location.z}}export function getLocalCoords(t,r){if(1==t.isValid()){const n=t?.getViewDirection(),o=normalize({x:n.z,y:0,z:-n.x}),e=normalize(cross(n,o)),x={x:r.x*o.x+r.y*e.x+r.z*n.x,y:r.x*o.y+r.y*e.y+r.z*n.y,z:r.x*o.z+r.y*e.z+r.z*n.z};return add(t.location,x)}}export function getRaycastDirection(t,r,n){const o=r*Math.PI/180,e=n*Math.PI/180,x={x:-t.z,y:0,z:t.x},a=Math.sqrt(x.x**2+x.z**2);a>0&&(x.x/=a,x.z/=a);const c=Math.cos(o),i=Math.sin(o),z={x:t.x*c+x.x*i*t.y,y:t.y*c-i,z:t.z*c+x.z*i*t.y},s=Math.cos(e),y=Math.sin(e),u=z.x*s-z.z*y,h=z.y,f=z.x*y+z.z*s,p=Math.sqrt(u**2+h**2+f**2);return{x:u/p,y:h/p,z:f/p}}export function directionFromRotation(t,r){const n=t*(Math.PI/180),o=r*(Math.PI/180);return{x:Math.cos(n)*-Math.sin(o),y:-Math.sin(n),z:Math.cos(n)*Math.cos(o)}}