Skip to content

Commit

Permalink
Fixed Kill Aura and Crystal Aura rotation. Updated MaceAura to improv…
Browse files Browse the repository at this point in the history
…e responsiveness.
  • Loading branch information
coltonk9043 committed Sep 21, 2024
1 parent 75fb318 commit 42dfa18
Show file tree
Hide file tree
Showing 5 changed files with 174 additions and 169 deletions.
17 changes: 14 additions & 3 deletions src/main/java/net/aoba/module/modules/combat/CrystalAura.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import net.aoba.gui.colors.Color;
import net.aoba.utils.FindItemResult;
import net.aoba.utils.render.Render3D;
import net.aoba.utils.rotation.RotationManager.RotationMode;
import net.aoba.utils.rotation.Rotation;
import net.aoba.utils.rotation.RotationMode;
import net.aoba.module.Category;
import net.aoba.module.Module;
import net.aoba.module.modules.misc.MCA.Mode;
import net.aoba.settings.types.*;
import net.aoba.utils.entity.DamageUtils;
import net.minecraft.block.Block;
Expand Down Expand Up @@ -477,7 +477,18 @@ private void attackCrystal() {
break;
case SMOOTH:
// Instant rotation for now because im too dumb to figure out smooth rotation
MC.player.lookAt(EntityAnchorArgumentType.EntityAnchor.EYES, targetPos);
float rotationDegreesPerTick = 10f;
Rotation rotation = Rotation.getPlayerRotationDeltaFromEntity(bestCrystal);

float maxYawRotationDelta = Math.clamp((float) -rotation.yaw(), -rotationDegreesPerTick,
rotationDegreesPerTick);
float maxPitchRotation = Math.clamp((float) -rotation.pitch(), -rotationDegreesPerTick,
rotationDegreesPerTick);

Rotation newRotation = new Rotation(MC.player.getYaw() + maxYawRotationDelta,
MC.player.getPitch() + maxPitchRotation);
MC.player.setYaw((float) newRotation.yaw());
MC.player.setPitch((float) newRotation.pitch());

MC.player.networkHandler.sendPacket(PlayerInteractEntityC2SPacket.attack(bestCrystal, MC.player.isSneaking()));
if (swingHand.getValue()) MC.player.swingHand(hand);
Expand Down
37 changes: 22 additions & 15 deletions src/main/java/net/aoba/module/modules/combat/KillAura.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@
import net.aoba.settings.types.FloatSetting;
import net.aoba.settings.types.KeybindSetting;
import net.aoba.utils.rotation.Rotation;
import net.aoba.utils.rotation.RotationManager.RotationMode;
import net.aoba.utils.rotation.RotationMode;
import net.minecraft.client.util.InputUtil;
import net.minecraft.command.argument.EntityAnchorArgumentType.EntityAnchor;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.mob.Monster;
Expand Down Expand Up @@ -209,20 +210,26 @@ public void onTick(TickEvent.Pre event) {

// If the entity is found, we want to attach it.
if (found) {
if (legit.getValue()) {

float rotationDegreesPerTick = 10f;
Rotation rotation = Rotation.getPlayerRotationDeltaFromEntity(entityToAttack);

float maxYawRotationDelta = Math.clamp((float) -rotation.yaw(), -rotationDegreesPerTick,
rotationDegreesPerTick);
float maxPitchRotation = Math.clamp((float) -rotation.pitch(), -rotationDegreesPerTick,
rotationDegreesPerTick);

Rotation newRotation = new Rotation(MC.player.getYaw() + maxYawRotationDelta,
MC.player.getPitch() + maxPitchRotation);
MC.player.setYaw((float) newRotation.yaw());
MC.player.setPitch((float) newRotation.pitch());
switch(rotationMode.getValue()) {
case RotationMode.NONE:
break;
case RotationMode.SMOOTH:
float rotationDegreesPerTick = 10f;
Rotation rotation = Rotation.getPlayerRotationDeltaFromEntity(entityToAttack);

float maxYawRotationDelta = Math.clamp((float) -rotation.yaw(), -rotationDegreesPerTick,
rotationDegreesPerTick);
float maxPitchRotation = Math.clamp((float) -rotation.pitch(), -rotationDegreesPerTick,
rotationDegreesPerTick);

Rotation newRotation = new Rotation(MC.player.getYaw() + maxYawRotationDelta,
MC.player.getPitch() + maxPitchRotation);
MC.player.setYaw((float) newRotation.yaw());
MC.player.setPitch((float) newRotation.pitch());
break;
case RotationMode.INSTANT:
MC.player.lookAt(EntityAnchor.EYES, entityToAttack.getEyePos());
break;
}

if (MC.player.getAttackCooldownProgress(0) == 1) {
Expand Down
280 changes: 133 additions & 147 deletions src/main/java/net/aoba/module/modules/combat/MaceAura.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,157 +36,143 @@
import net.minecraft.entity.passive.AnimalEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Items;
import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket;
import net.minecraft.util.Hand;
import net.minecraft.util.math.Vec3d;
import org.lwjgl.glfw.GLFW;

import java.util.ArrayList;

enum MaceState {
OnGround, InAir, Descending,
}

public class MaceAura extends Module implements TickListener {
private FloatSetting radius= FloatSetting.builder()
.id("maceaura_radius")
.displayName("Radius")
.description("Radius that MaceAura will trigger")
.defaultValue(5f)
.minValue(0.1f)
.maxValue(10f)
.step(0.1f)
.build();

private BooleanSetting targetAnimals = BooleanSetting.builder()
.id("maceaura_target_animals")
.displayName("Target Animals")
.description("Target animals.")
.defaultValue(false)
.build();

private BooleanSetting targetMonsters = BooleanSetting.builder()
.id("maceaura_target_monsters")
.displayName("Target Monsters")
.description("Target Monsters.")
.defaultValue(true)
.build();

private BooleanSetting targetPlayers = BooleanSetting.builder()
.id("maceaura_target_players")
.displayName("Target Players")
.description("Target Players.")
.defaultValue(true)
.build();

private BooleanSetting targetFriends = BooleanSetting.builder()
.id("maceaura_target_friends")
.displayName("Target Friends")
.description("Target Friends.")
.defaultValue(false)
.build();

private MaceState state = MaceState.OnGround;
private LivingEntity entityToAttack;

public MaceAura() {
super(KeybindSetting.builder().id("key.maceaura").displayName("Mace Aura Key").defaultValue(InputUtil.fromKeyCode(GLFW.GLFW_KEY_UNKNOWN, 0)).build());

this.setName("MaceAura");
this.setCategory(Category.of("Combat"));
this.setDescription("Smashes players in your personal space with a Mace with extreme damage. Be sure to enable NoFall for best results.");

this.addSetting(radius);
this.addSetting(targetAnimals);
this.addSetting(targetMonsters);
this.addSetting(targetPlayers);
this.addSetting(targetFriends);
}

@Override
public void onDisable() {
Aoba.getInstance().eventManager.RemoveListener(TickListener.class, this);
}

@Override
public void onEnable() {
Aoba.getInstance().eventManager.AddListener(TickListener.class, this);
}

@Override
public void onToggle() {

}

@Override
public void onTick(TickEvent.Pre event) {

}

@Override
public void onTick(TickEvent.Post event) {
if (state == MaceState.OnGround) {
if (MC.player.getMainHandStack().getItem() == Items.MACE && MC.player.getAttackCooldownProgress(0) == 1) {
ArrayList<Entity> hitList = new ArrayList<Entity>();

// Add all potential entities to the 'hitlist'
if (this.targetAnimals.getValue() || this.targetMonsters.getValue()) {
for (Entity entity : MC.world.getEntities()) {
if (entity == MC.player)
continue;
if (MC.player.squaredDistanceTo(entity) > radius.getValueSqr())
continue;

if ((entity instanceof AnimalEntity && this.targetAnimals.getValue())
|| (entity instanceof Monster && this.targetMonsters.getValue())) {
hitList.add(entity);
}
}
}

// Add all potential players to the 'hitlist'
if (this.targetPlayers.getValue()) {
for (PlayerEntity player : MC.world.getPlayers()) {
if (!targetFriends.getValue() && Aoba.getInstance().friendsList.contains(player))
continue;

if (player == MC.player || MC.player
.squaredDistanceTo(player) > (this.radius.getValue() * this.radius.getValue())) {
continue;
}
hitList.add(player);
}
}

// For each entity, get the entity that matches a criteria.
for (Entity entity : hitList) {
LivingEntity le = (LivingEntity) entity;
if (entityToAttack == null) {
entityToAttack = le;
} else {
if (MC.player.squaredDistanceTo(le) <= MC.player.squaredDistanceTo(entityToAttack)) {
entityToAttack = le;
}
}
}

// If the entity is found, we want to attach it.
if (entityToAttack != null) {
Vec3d velocity = MC.player.getVelocity().add(0, 20, 0);
MC.player.setVelocity(velocity);
state = MaceState.InAir;
}
}
} else if (state == MaceState.InAir) {
Vec3d velocity = MC.player.getVelocity().add(0, -39, 0);
MC.player.setVelocity(velocity);
state = MaceState.Descending;
} else if (state == MaceState.Descending) {
MC.interactionManager.attackEntity(MC.player, entityToAttack);
MC.player.swingHand(Hand.MAIN_HAND);
entityToAttack = null;
Vec3d velocity = MC.player.getVelocity().add(0, 39, 0);
MC.player.setVelocity(velocity);
state = MaceState.OnGround;
}
}
private FloatSetting radius = FloatSetting.builder().id("maceaura_radius").displayName("Radius")
.description("Radius that MaceAura will trigger").defaultValue(5f).minValue(0.1f).maxValue(10f).step(0.1f)
.build();

private FloatSetting height = FloatSetting.builder().id("maceaura_height").displayName("Height")
.description("Determines how high MaceAura will jump. Higher distance = more damage.").defaultValue(100f)
.minValue(1f).maxValue(255f).build();

private BooleanSetting targetAnimals = BooleanSetting.builder().id("maceaura_target_animals")
.displayName("Target Animals").description("Target animals.").defaultValue(false).build();

private BooleanSetting targetMonsters = BooleanSetting.builder().id("maceaura_target_monsters")
.displayName("Target Monsters").description("Target Monsters.").defaultValue(true).build();

private BooleanSetting targetPlayers = BooleanSetting.builder().id("maceaura_target_players")
.displayName("Target Players").description("Target Players.").defaultValue(true).build();

private BooleanSetting targetFriends = BooleanSetting.builder().id("maceaura_target_friends")
.displayName("Target Friends").description("Target Friends.").defaultValue(false).build();

private LivingEntity entityToAttack;

public MaceAura() {
super(KeybindSetting.builder().id("key.maceaura").displayName("Mace Aura Key")
.defaultValue(InputUtil.fromKeyCode(GLFW.GLFW_KEY_UNKNOWN, 0)).build());

this.setName("MaceAura");
this.setCategory(Category.of("Combat"));
this.setDescription(
"Smashes players in your personal space with a Mace with extreme damage. Be sure to enable NoFall for best results.");

this.addSetting(radius);
this.addSetting(height);
this.addSetting(targetAnimals);
this.addSetting(targetMonsters);
this.addSetting(targetPlayers);
this.addSetting(targetFriends);
}

@Override
public void onDisable() {
Aoba.getInstance().eventManager.RemoveListener(TickListener.class, this);
}

@Override
public void onEnable() {
Aoba.getInstance().eventManager.AddListener(TickListener.class, this);
}

@Override
public void onToggle() {

}

@Override
public void onTick(TickEvent.Pre event) {

}

@Override
public void onTick(TickEvent.Post event) {
if (MC.player.getMainHandStack().getItem() == Items.MACE && MC.player.getAttackCooldownProgress(0) == 1) {

if(entityToAttack == null) {
ArrayList<Entity> hitList = new ArrayList<Entity>();

// Add all potential entities to the 'hitlist'
if (this.targetAnimals.getValue() || this.targetMonsters.getValue()) {
for (Entity entity : MC.world.getEntities()) {
if (entity == MC.player)
continue;
if (MC.player.squaredDistanceTo(entity) > radius.getValueSqr())
continue;

if ((entity instanceof AnimalEntity && this.targetAnimals.getValue())
|| (entity instanceof Monster && this.targetMonsters.getValue())) {
hitList.add(entity);
}
}
}

// Add all potential players to the 'hitlist'
if (this.targetPlayers.getValue()) {
for (PlayerEntity player : MC.world.getPlayers()) {
if (!targetFriends.getValue() && Aoba.getInstance().friendsList.contains(player))
continue;

if (player == MC.player || MC.player
.squaredDistanceTo(player) > (this.radius.getValue() * this.radius.getValue())) {
continue;
}
hitList.add(player);
}
}

// For each entity, get the entity that matches a criteria.
for (Entity entity : hitList) {
LivingEntity le = (LivingEntity) entity;
if (entityToAttack == null) {
entityToAttack = le;
} else {
if (MC.player.squaredDistanceTo(le) <= MC.player.squaredDistanceTo(entityToAttack)) {
entityToAttack = le;
}
}
}

if(entityToAttack != null) {
// If the entity is found, we want to attach it.
int packetsRequired = Math.round((float) Math.ceil(Math.abs(height.getValue() / 10.0f)));
for (int i = 0; i < packetsRequired; i++) {
MC.player.networkHandler.sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(false));
}

Vec3d newPos = MC.player.getPos().add(0, height.getValue(), 0);
MC.player.networkHandler.sendPacket(new PlayerMoveC2SPacket.PositionAndOnGround(newPos.x, newPos.y, newPos.z, false));
}
}else {
int packetsRequired = Math.round((float) Math.ceil(Math.abs(height.getValue() / 10.0f)));
for (int i = 0; i < packetsRequired; i++) {
MC.player.networkHandler.sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(false));
}

Vec3d newPos = MC.player.getPos();
MC.player.networkHandler.sendPacket(new PlayerMoveC2SPacket.PositionAndOnGround(newPos.x, newPos.y, newPos.z, false));

MC.interactionManager.attackEntity(MC.player, entityToAttack);
MC.player.swingHand(Hand.MAIN_HAND);
entityToAttack = null;
}
}
}
}
4 changes: 0 additions & 4 deletions src/main/java/net/aoba/utils/rotation/RotationManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@
import net.minecraft.network.packet.s2c.play.PlayerPositionLookS2CPacket;

public class RotationManager implements SendPacketListener {
public enum RotationMode {
NONE, INSTANT, SMOOTH
}

private static MinecraftClient MC = MinecraftClient.getInstance();

public static Rotation serverRotation = new Rotation(0, 0);
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/net/aoba/utils/rotation/RotationMode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package net.aoba.utils.rotation;

public enum RotationMode {
NONE, INSTANT, SMOOTH
}

0 comments on commit 42dfa18

Please sign in to comment.