From 5ac2a187bac8ff46174a55c53983ac6b851b6252 Mon Sep 17 00:00:00 2001 From: alemi Date: Sat, 4 Mar 2023 01:25:04 +0100 Subject: feat: added trace, look, tool options to aura option to check for visibility, option to change player rotation before attacking, option to switch to best tool --- src/main/java/ftbsc/bscv/modules/defense/Aura.java | 84 +++++++++++++++++++++- 1 file changed, 82 insertions(+), 2 deletions(-) (limited to 'src/main/java/ftbsc') diff --git a/src/main/java/ftbsc/bscv/modules/defense/Aura.java b/src/main/java/ftbsc/bscv/modules/defense/Aura.java index 0ffe45c..8c02656 100644 --- a/src/main/java/ftbsc/bscv/modules/defense/Aura.java +++ b/src/main/java/ftbsc/bscv/modules/defense/Aura.java @@ -6,10 +6,17 @@ import ftbsc.bscv.Boscovicino; import ftbsc.bscv.ICommons; import ftbsc.bscv.api.ILoadable; import ftbsc.bscv.modules.QuickModule; +import ftbsc.bscv.modules.self.AutoTool; import ftbsc.bscv.tools.Setting; +import net.minecraft.command.arguments.EntityAnchorArgument; +import net.minecraft.command.arguments.EntityAnchorArgument.Type; import net.minecraft.entity.Entity; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.network.play.client.CPlayerPacket; +import net.minecraft.util.Hand; +import net.minecraft.util.math.MathHelper; +import net.minecraft.util.math.vector.Vector3d; import net.minecraftforge.common.ForgeConfigSpec; import net.minecraftforge.event.TickEvent; import net.minecraftforge.event.TickEvent.Phase; @@ -18,6 +25,13 @@ import net.minecraftforge.eventbus.api.SubscribeEvent; @AutoService(ILoadable.class) public class Aura extends QuickModule implements ICommons { + private enum LookType { + NONE, + PACKET, + ONCE, + // RESET + } + @Override protected int getDefaultKey() { return UNBOUND; @@ -25,9 +39,15 @@ public class Aura extends QuickModule implements ICommons { public final ForgeConfigSpec.ConfigValue reach; public final ForgeConfigSpec.ConfigValue strenght; + public final ForgeConfigSpec.ConfigValue tool; + public final ForgeConfigSpec.ConfigValue trace; + public final ForgeConfigSpec.ConfigValue look; + public final ForgeConfigSpec.ConfigValue swing; public final ForgeConfigSpec.ConfigValue neutral; public final ForgeConfigSpec.ConfigValue friends; + private AutoTool autotool; + public Aura() { super(); @@ -46,6 +66,30 @@ public class Aura extends QuickModule implements ICommons { .fallback(1.) .build(this); + this.tool = Setting.Bool.builder() + .fallback(true) + .name("tool") + .comment("trigger AutoTool when attacking") + .build(this); + + this.trace = Setting.Bool.builder() + .fallback(true) + .name("trace") + .comment("make sure mobs are visible before hitting") + .build(this); + + this.look = Setting.Switch.builder(LookType.class) + .fallback(LookType.PACKET) + .name("look") + .comment("look at mobs before attacking them") + .build(this); + + this.swing = Setting.Bool.builder() + .fallback(true) + .name("swing") + .comment("swing arm when attacking") + .build(this); + this.neutral = Setting.Bool.builder() .fallback(false) .name("neutral") @@ -59,6 +103,23 @@ public class Aura extends QuickModule implements ICommons { .build(this); } + @Override + protected void onEnabled() { + this.autotool = (AutoTool) Boscovicino.modManager.get(AutoTool.class); + } + + private void lookAtHidden(EntityAnchorArgument.Type anchor, Vector3d target) { + // This code comes from vanilla Minecraft, but we send a packet rather than turning player + Vector3d translated = anchor.apply(MC.player); + double d0 = target.x - translated.x; + double d1 = target.y - translated.y; + double d2 = target.z - translated.z; + double d3 = (double)MathHelper.sqrt(d0 * d0 + d2 * d2); + float xRot = MathHelper.wrapDegrees((float)(-(MathHelper.atan2(d1, d3) * (double)(180F / (float)Math.PI)))); + float yRot = MathHelper.wrapDegrees((float)(MathHelper.atan2(d2, d0) * (double)(180F / (float)Math.PI)) - 90.0F); + MC.player.connection.send(new CPlayerPacket.RotationPacket(yRot, xRot, MC.player.isOnGround())); + } + @SubscribeEvent public void onTick(TickEvent.ClientTickEvent event) { if (event.phase == Phase.END) return; @@ -79,9 +140,28 @@ public class Aura extends QuickModule implements ICommons { continue; } } - if (!this.friends.get() && Boscovicino.friends().isFriend(e.getDisplayName().getString())) continue; + if (this.trace.get() && !MC.player.canSee(e)) continue; + + switch (this.look.get()) { + case ONCE: + MC.player.lookAt(Type.EYES, e.getEyePosition(1.0F)); + MC.player.connection.send(new CPlayerPacket.RotationPacket(MC.player.yRot, MC.player.xRot, MC.player.isOnGround())); + break; + case PACKET: + this.lookAtHidden(Type.EYES, e.getEyePosition(1.0F)); + break; + case NONE: break; + } + + if (this.tool.get()) { + this.autotool.selectBestWeapon(); + } MC.gameMode.attack(MC.player, e); - break; + if (this.swing.get()) { + MC.player.swing(Hand.MAIN_HAND); + } + + break; // TODO should find all valid targets and choose one rather than stopping here } } } -- cgit v1.2.3-56-ga3b1