import*as mc from"@minecraft/server";import*as vector from"../utils/vector";import*as gauntlet from"./earthrendGauntlet";export function robeEffect(e){let t=e.hurtEntity;if("minecraft:player"===t.typeId&&t.hasTag("hf_mzs_geomancer_robe")){let a=e.damageSource.damagingEntity;if(a&&a.isValid()&&Math.random()<.2){let e=Math.floor(1*Math.random()+2),a=1,o=Math.floor(1*Math.random()+2);Math.random()<.5&&(e*=-1),Math.random()<.5&&(o*=-1);let m=t.location;m.x=Math.floor(m.x)+.5+e,m.y=Math.floor(m.y)+a,m.z=Math.floor(m.z)+.5+o;const n=t.dimension.getBlock(m);if(!n||!n.isValid()||!n.isAir&&!n.isLiquid||!gauntlet.GeomancyWhitelist.includes(n.below().below().typeId))return;let i=t.dimension.spawnEntity("hf_mzs:boulder<hf_mzs:from_armor>",m);mc.system.runTimeout((()=>{i.runCommand("setblock ~ ~ ~ hf_mzs:invisible_block [] replace")}),4)}}if(t=e.damageSource.damagingEntity,t&&t.isValid()&&"minecraft:player"===t.typeId&&t.hasTag("hf_mzs_geomancer_robe")){if("hf_mzs:boulder"===e.hurtEntity.typeId)return;if(Math.random()<.2){let e=Math.floor(1*Math.random()+2),a=1,o=Math.floor(1*Math.random()+2);Math.random()<.5&&(e*=-1),Math.random()<.5&&(o*=-1);let m=t.location;m.x=Math.floor(m.x)+.5+e,m.y=Math.floor(m.y)+a,m.z=Math.floor(m.z)+.5+o;const n=t.dimension.getBlock(m);if(!n||!n.isValid()||!n.isAir&&!n.isLiquid||!gauntlet.GeomancyWhitelist.includes(n.below().below().typeId))return;let i=t.dimension.spawnEntity("hf_mzs:boulder<hf_mzs:from_armor>",m);mc.system.runTimeout((()=>{i.runCommand("setblock ~ ~ ~ hf_mzs:invisible_block [] replace")}),4)}}}export function tick1(){mc.system.run((()=>{for(const e of mc.world.getAllPlayers()){const t=e.getComponent("equippable").getEquipment(mc.EquipmentSlot.Mainhand);t&&"hf_mzs:earthrend_gauntlet"!=t.typeId?e.removeTag("hf_mzs_empty_hand"):(t&&t.typeId,e.addTag("hf_mzs_empty_hand"));const a=e.getComponent("equippable").getEquipment(mc.EquipmentSlot.Head),o=e.getComponent("equippable").getEquipment(mc.EquipmentSlot.Chest),m=e.getComponent("equippable").getEquipment(mc.EquipmentSlot.Legs),n=e.getComponent("equippable").getEquipment(mc.EquipmentSlot.Feet);if(a&&"hf_mzs:geomancer_beads"===a.typeId&&e.hasTag("hf_mzs_empty_hand")&&e.addEffect("strength",5,{amplifier:1,showParticles:!1}),o&&"hf_mzs:geomancer_robe"===o.typeId?e.addTag("hf_mzs_geomancer_robe"):e.hasTag("hf_mzs_geomancer_robe")&&e.removeTag("hf_mzs_geomancer_robe"),m&&("hf_mzs:geomancer_belt"===m.typeId||"hf_mzs:geomancer_belt_boost"===m.typeId)){const t=e.getEffect("slowness");if(t){const t=new mc.ItemStack("hf_mzs:geomancer_belt_boost",1);t.getComponent("minecraft:durability").damage=m.getComponent("minecraft:durability").damage,m.nameTag&&(t.nameTag=m.nameTag),t.setLore(m.getLore()),e.getComponent("equippable").setEquipment(mc.EquipmentSlot.Legs,t),e.addTag("hf_mzs_belt_boost")}else if(!t&&e.hasTag("hf_mzs_belt_boost")){const t=new mc.ItemStack("hf_mzs:geomancer_belt",1);t.getComponent("minecraft:durability").damage=m.getComponent("minecraft:durability").damage,m.nameTag&&(t.nameTag=m.nameTag),t.setLore(m.getLore()),e.getComponent("equippable").setEquipment(mc.EquipmentSlot.Legs,t),e.removeTag("hf_mzs_belt_boost")}}if(n&&"hf_mzs:geomancer_sandals"===n.typeId&&(e.isFalling&&!e.getDynamicProperty("hf_mzs:was_falling")&&(e.setDynamicProperty("hf_mzs:falling_from_y",e.location.y),e.setDynamicProperty("hf_mzs:was_falling",!0)),e.getDynamicProperty("hf_mzs:was_falling")&&e.isOnGround)){const t=parseFloat(e.getDynamicProperty("hf_mzs:falling_from_y")),a=e.location.y;if(t&&t-a>3.5){e.runCommand("/playsound hf_mzs:boulder.small.hit @a[r=32] ~ ~ ~ 100 1.25 1"),e.addEffect("speed",60,{amplifier:1,showParticles:!1}),e.setDynamicProperty("hf_mzs:falling_from_y",null);let t=new mc.MolangVariableMap;t.setFloat("variable.lifetime",.4),t.setFloat("variable.size",1);let a=vector.add(e.location,{x:0,y:.1,z:0});e.dimension.spawnParticle("hf_mzs:ring_grow_ground",a,t)}e.setDynamicProperty("hf_mzs:was_falling",!1)}}}))}