Skip to content

Commit

Permalink
killaura targeting priority setting
Browse files Browse the repository at this point in the history
  • Loading branch information
rfresh2 committed Feb 19, 2025
1 parent 33c224f commit 3ab543a
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 11 deletions.
20 changes: 18 additions & 2 deletions src/main/java/com/zenith/command/impl/KillAuraCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.zenith.command.brigadier.CommandContext;
import com.zenith.discord.Embed;
import com.zenith.module.impl.KillAura;
import com.zenith.util.Config;
import org.geysermc.mcprotocollib.protocol.data.game.entity.type.EntityType;

import java.util.stream.Collectors;
Expand Down Expand Up @@ -43,7 +44,8 @@ public CommandUsage commandUsage() {
"targetArmorStands on/off",
"targetCustom on/off",
"targetCustom add/del <entityType>",
"weaponSwitch on/off"
"weaponSwitch on/off",
"priority <none/nearest>"
),
asList("ka")
);
Expand Down Expand Up @@ -153,7 +155,20 @@ public LiteralArgumentBuilder<CommandContext> register() {
.errorColor();
}
return 1;
}))));
}))))
.then(literal("priority")
.then(literal("none").executes(c -> {
CONFIG.client.extra.killAura.priority = Config.Client.Extra.KillAura.Priority.NONE;
c.getSource().getEmbed()
.title("Priority Set");
return OK;
}))
.then(literal("nearest").executes(c -> {
CONFIG.client.extra.killAura.priority = Config.Client.Extra.KillAura.Priority.NEAREST;
c.getSource().getEmbed()
.title("Priority Set");
return OK;
})));
}

@Override
Expand All @@ -169,6 +184,7 @@ public void postPopulate(Embed builder) {
.addField("Target Armor Stands", toggleStr(CONFIG.client.extra.killAura.targetArmorStands), false)
.addField("Weapon Switching", toggleStr(CONFIG.client.extra.killAura.switchWeapon), false)
.addField("Attack Delay Ticks", CONFIG.client.extra.killAura.attackDelayTicks, false)
.addField("Priority", CONFIG.client.extra.killAura.priority.name().toLowerCase(), false)
.primaryColor();
if (CONFIG.client.extra.killAura.targetCustom) {
builder.description("**Custom Targets**\n" + CONFIG.client.extra.killAura.customTargets.stream().map(Enum::name).collect(
Expand Down
27 changes: 18 additions & 9 deletions src/main/java/com/zenith/module/impl/KillAura.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.zenith.module.impl;

import com.github.rfresh2.EventConsumer;
import com.zenith.cache.data.entity.Entity;
import com.zenith.cache.data.entity.EntityLiving;
import com.zenith.cache.data.entity.EntityPlayer;
import com.zenith.cache.data.entity.EntityStandard;
Expand All @@ -17,6 +16,7 @@

import javax.annotation.Nullable;
import java.lang.ref.WeakReference;
import java.util.Comparator;
import java.util.List;
import java.util.Set;

Expand Down Expand Up @@ -123,14 +123,23 @@ private void onAttackInputExecuted(InputRequestFuture future) {

@Nullable
private EntityLiving findTarget() {
for (Entity e : CACHE.getEntityCache().getEntities().values()) {
if (!(e instanceof EntityLiving entity)) continue;
if (!entity.isAlive()) continue;
if (!validTarget(entity)) continue;
if (!canPossiblyReach(entity)) continue;
return entity;
}
return null;
// todo: check if its worth it to copy the entity cache to a list to avoid streams
var entityStream = CACHE.getEntityCache().getEntities().values().stream()
.filter(e -> e instanceof EntityLiving)
.map(e -> (EntityLiving) e)
.filter(e -> e != CACHE.getPlayerCache().getThePlayer())
.filter(EntityLiving::isAlive);
entityStream = switch (CONFIG.client.extra.killAura.priority) {
case NONE -> entityStream;
case NEAREST -> entityStream
.sorted(Comparator.comparingDouble(e -> CACHE.getPlayerCache().distanceSqToSelf(e)));
};

return entityStream
.filter(this::validTarget)
.filter(this::canPossiblyReach)
.findFirst()
.orElse(null);
}

private boolean validTarget(EntityLiving entity) {
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/zenith/util/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,12 @@ public static final class KillAura {
public boolean targetArmorStands = false;
public int attackDelayTicks = 10;
public final ArrayList<EntityType> customTargets = new ArrayList<>();
public Priority priority = Priority.NONE;

public enum Priority {
NONE,
NEAREST
}
}

public static final class AutoEat {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2324,6 +2324,10 @@
}
]
},
{
"type": "com.zenith.util.Config$Client$Extra$KillAura$Priority",
"allDeclaredFields": true
},
{
"type": "com.zenith.util.Config$Client$Extra$QueueWarning",
"allDeclaredFields": true,
Expand Down

0 comments on commit 3ab543a

Please sign in to comment.