import*as mc from"@minecraft/server";import*as selectors from"../utils/selectors";import*as vector from"../utils/vector";import{ATTACK_RANGE}from"./bluff";import{EXCLUDED_ENTITIES}from"../playerAbilities";const SPEED=.3;export function tick1(o){if(o.hasTag("hf_mzs_finished"))return;if(void 0===o.getDynamicProperty("hf_mzs:dist")&&o.setDynamicProperty("hf_mzs:dist",0),o.getDynamicProperty("hf_mzs:dist")>=ATTACK_RANGE)return void finish(o,o.location);const i=selectors.union({location:{x:o.location.x,y:o.location.y,z:o.location.z},maxDistance:1,excludeFamilies:["inanimate","hf_mzs_bluff"],excludeTypes:EXCLUDED_ENTITIES},[],o.dimension,o.id);for(let t of i){if(!t.isValid())return;const i=t.dimension.getBlockFromRay(vector.add(t.location,vector.up),vector.down,{maxDistance:2,includeLiquidBlocks:!1,includePassableBlocks:!1});if(void 0===i)return;return void finish(o,{x:Math.floor(t.location.x)+.5,y:i.block.location.y+1,z:Math.floor(t.location.z)+.5})}let t;t=void 0!==o.getDynamicProperty("hf_mzs:x_dir")?{x:.3*o.getDynamicProperty("hf_mzs:x_dir"),y:1.5,z:.3*o.getDynamicProperty("hf_mzs:z_dir")}:vector.add(vector.multiply(vector.forward,.3),vector.up);const e=o.dimension.getBlockFromRay(vector.add(o.location,t),vector.down,{maxDistance:3.5,includeLiquidBlocks:!1,includePassableBlocks:!1});void 0!==e?(o.teleport(vector.add(e.block.location,e.faceLocation)),o.runCommand("/particle hf_mzs:bluff_projectile2 ~~~"),o.setDynamicProperty("hf_mzs:dist",o.getDynamicProperty("hf_mzs:dist")+.3)):o.remove()}export function finish(o,i){if(!o.isValid())return void o.remove();const t=o.dimension.spawnEntity("hf_mzs:bluff_boulder",i);t.setDynamicProperty("hf_mzs:x_dir",o.getDynamicProperty("hf_mzs:x_dir")),t.setDynamicProperty("hf_mzs:z_dir",o.getDynamicProperty("hf_mzs:z_dir")),t.setDynamicProperty("hf_mzs:shooter",o.getDynamicProperty("hf_mzs:shooter")),o.addTag("hf_mzs_finished"),o.runCommand("/tp @s ~~-5~")}