Skip to content
Merged
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
2 changes: 2 additions & 0 deletions docs/wiki/Commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -1893,6 +1893,8 @@ Aggressive mobs are mobs that are actively targeting and attacking the player.

```killAura targetCustom add/del <entityType>```

```killAura ignoreNamedMobs on/off```

```killAura weaponSwitch on/off```

```killAura weaponType <any/sword/axe>```
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/com/zenith/cache/data/entity/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,21 @@ public double distanceSqTo(Entity entity) {
}

public <T> @Nullable T getMetadataValue(int index, MetadataType<T> metadataType, Class<T> valueClass) {
return getMetadataValue(index, metadataType);
}

public <T> @Nullable T getMetadataValue(int index, MetadataType<T> metadataType) {
var metadata = this.metadata.get(index);
if (metadata == null) return null;
if (metadata.getType() == metadataType) {
var metadataValue = metadata.getValue();
if (metadataValue == null) {
return null;
}
if (valueClass.isInstance(metadataValue)) {
return valueClass.cast(metadata.getValue());
try {
return (T) metadataValue;
} catch (ClassCastException e) {
return null;
}
}
return null;
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/zenith/command/impl/KillAuraCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public CommandUsage commandUsage() {
"targetNeutralMobs onlyAggressive on/off",
"targetCustom on/off",
"targetCustom add/del <entityType>",
"ignoreNamedMobs on/off",
"weaponSwitch on/off",
"weaponType <any/sword/axe>",
"weaponMaterial <any/diamond/netherite>",
Expand Down Expand Up @@ -103,6 +104,11 @@ public LiteralArgumentBuilder<CommandContext> register() {
c.getSource().getEmbed()
.title("Target Neutral Mobs Only Aggressive " + toggleStrCaps(CONFIG.client.extra.killAura.onlyNeutralAggressive));
}))))
.then(literal("ignoreNamedMobs").then(argument("toggle", toggle()).executes(c -> {
CONFIG.client.extra.killAura.ignoreNamedMobs = getToggle(c, "toggle");
c.getSource().getEmbed()
.title("Ignore Named Mobs " + toggleStrCaps(CONFIG.client.extra.killAura.ignoreNamedMobs));
})))
.then(literal("weaponSwitch").then(argument("toggle", toggle()).executes(c -> {
CONFIG.client.extra.killAura.switchWeapon = getToggle(c, "toggle");
c.getSource().getEmbed()
Expand Down Expand Up @@ -165,6 +171,7 @@ public void defaultEmbed(Embed builder) {
.addField("Target Hostile Mobs", toggleStr(CONFIG.client.extra.killAura.targetHostileMobs) + " [onlyAggressive: " + toggleStr(CONFIG.client.extra.killAura.onlyHostileAggressive) + "]")
.addField("Target Neutral Mobs", toggleStr(CONFIG.client.extra.killAura.targetNeutralMobs) + " [onlyAggressive: " + toggleStr(CONFIG.client.extra.killAura.onlyNeutralAggressive) + "]")
.addField("Target Custom", toggleStr(CONFIG.client.extra.killAura.targetCustom))
.addField("Ignore Named Mobs", toggleStr(CONFIG.client.extra.killAura.ignoreNamedMobs))
.addField("Weapon Switching", toggleStr(CONFIG.client.extra.killAura.switchWeapon))
.addField("Weapon Type", CONFIG.client.extra.killAura.weaponType.name().toLowerCase())
.addField("Weapon Material", CONFIG.client.extra.killAura.weaponMaterial.name().toLowerCase())
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/zenith/module/impl/KillAura.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ private boolean validTarget(EntityLiving entity) {
&& !PLAYER_LISTS.getSpectatorWhitelist().contains(player.getUuid());

} else if (entity instanceof EntityStandard e) {
if (CONFIG.client.extra.killAura.ignoreNamedMobs && hasCustomName(e)) return false;
if (CONFIG.client.extra.killAura.targetCustom) {
if (CONFIG.client.extra.killAura.customTargets.contains(e.getEntityType())) {
return true;
Expand Down Expand Up @@ -196,6 +197,11 @@ private boolean validTarget(EntityLiving entity) {
return false;
}

private static boolean hasCustomName(final EntityLiving entity) {
var customName = entity.getMetadataValue(2, MetadataTypes.OPTIONAL_CHAT);
return customName != null && customName.isPresent();
}

private static boolean isAggressive(final EntityLiving entity) {
// https://minecraft.wiki/w/Java_Edition_protocol/Entity_metadata#Mob
var byteData = entity.getMetadataValue(15, MetadataTypes.BYTE, Byte.class);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/zenith/util/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ public static final class KillAura {
public boolean targetHostileMobs = true;
public boolean targetNeutralMobs = false;
public boolean targetCustom = false;
public boolean ignoreNamedMobs = false;
public boolean onlyNeutralAggressive = false;
public boolean onlyHostileAggressive = false;
public boolean switchWeapon = true;
Expand Down
Loading