From f73139a5ea15fa6543115ada61ac06090c67cd9d Mon Sep 17 00:00:00 2001 From: LetMePractice Date: Tue, 14 Apr 2026 15:26:24 +0000 Subject: [PATCH] add directional shield toggle to AxeSwap --- .../modules/modules/anchoring/AxeSwap.java | 19 ++++++++++++++++++- .../util/minecraft/EntityUtils.java | 18 ++++++++++++------ 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/main/java/io/github/itzispyder/clickcrystals/modules/modules/anchoring/AxeSwap.java b/src/main/java/io/github/itzispyder/clickcrystals/modules/modules/anchoring/AxeSwap.java index 4bdbd4e0..bebcaad6 100644 --- a/src/main/java/io/github/itzispyder/clickcrystals/modules/modules/anchoring/AxeSwap.java +++ b/src/main/java/io/github/itzispyder/clickcrystals/modules/modules/anchoring/AxeSwap.java @@ -6,6 +6,9 @@ import io.github.itzispyder.clickcrystals.modrinth.ModrinthNoNo; import io.github.itzispyder.clickcrystals.modules.Categories; import io.github.itzispyder.clickcrystals.modules.Module; +import io.github.itzispyder.clickcrystals.modules.ModuleSetting; +import io.github.itzispyder.clickcrystals.modules.settings.BooleanSetting; +import io.github.itzispyder.clickcrystals.modules.settings.DoubleSetting; import io.github.itzispyder.clickcrystals.util.minecraft.EntityUtils; import io.github.itzispyder.clickcrystals.util.minecraft.HotbarUtils; import net.minecraft.world.entity.player.Player; @@ -14,6 +17,20 @@ @ModrinthNoNo public class AxeSwap extends Module implements Listener { + private final ModuleSetting directionalShield = getGeneralSection().add(BooleanSetting.create() + .name("directional-shield") + .description("Only swap if the enemy is facing you") + .def(true) + .build()); + + private final ModuleSetting shieldFov = getGeneralSection().add(DoubleSetting.create() + .name("shield-fov") + .description("Detection angle for directional shield in degrees") + .def(60.0) + .min(10.0) + .max(180.0) + .build()); + public AxeSwap() { super("axe-swap", Categories.PVP, "Switch to axe if hitting a shielding opponent with a sword"); } @@ -30,7 +47,7 @@ protected void onDisable() { @EventHandler private void onAttack(PlayerAttackEntityEvent e) { - if (e.getEntity() instanceof Player p && EntityUtils.isBlocking(p)) { + if (e.getEntity() instanceof Player p && EntityUtils.isBlocking(p, directionalShield.getVal(), shieldFov.getVal())) { if (HotbarUtils.nameContains("sword") && HotbarUtils.has(item -> item.getItem() instanceof AxeItem)) { HotbarUtils.search(item -> item.getItem() instanceof AxeItem); } diff --git a/src/main/java/io/github/itzispyder/clickcrystals/util/minecraft/EntityUtils.java b/src/main/java/io/github/itzispyder/clickcrystals/util/minecraft/EntityUtils.java index 525aea97..3af3c45d 100644 --- a/src/main/java/io/github/itzispyder/clickcrystals/util/minecraft/EntityUtils.java +++ b/src/main/java/io/github/itzispyder/clickcrystals/util/minecraft/EntityUtils.java @@ -48,20 +48,26 @@ public static boolean isMoving(Entity ref) { } public static boolean isBlocking(Entity ref) { + if (!(ref instanceof LivingEntity liv)) + return false; + return liv.isBlocking(); + } + + public static boolean isBlocking(Entity ref, boolean directional, double fov) { if (!(ref instanceof LivingEntity liv)) return false; if (!liv.isBlocking()) return false; - - // Check if shield is facing the attacker + if (!directional) + return true; + + // shield only counts if they're facing you if (PlayerUtils.invalid()) return true; - + Vec3 targetLook = liv.getLookAngle().normalize(); Vec3 toAttacker = PlayerUtils.player().position().subtract(liv.position()).normalize(); - double dot = targetLook.dot(toAttacker); - - return dot > 0.3; // Shield blocks if target is facing attacker + return targetLook.dot(toAttacker) >= Math.cos(Math.toRadians(fov)); } public static boolean isColliding(Entity ref) {