Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -14,6 +17,20 @@
@ModrinthNoNo
public class AxeSwap extends Module implements Listener {

private final ModuleSetting<Boolean> directionalShield = getGeneralSection().add(BooleanSetting.create()
.name("directional-shield")
.description("Only swap if the enemy is facing you")
.def(true)
.build());

private final ModuleSetting<Double> 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");
}
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down