Skip to content

Commit 0bdce44

Browse files
committed
Refactor the KillAura weapons setting to add more weapon types and allow you to select combinations of weapons
1 parent c69800f commit 0bdce44

2 files changed

Lines changed: 46 additions & 47 deletions

File tree

src/main/java/meteordevelopment/meteorclient/gui/screens/settings/base/CollectionListSettingScreen.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ private void initTable() {
6161
if (v != null) addValue(v);
6262
});
6363

64-
if (!left.cells.isEmpty()) table.add(theme.verticalSeparator()).expandWidgetY();
64+
if (Config.get().syncListSettingWidths.get() || !left.cells.isEmpty()) {
65+
table.add(theme.verticalSeparator()).expandWidgetY();
66+
}
6567

6668
// Right (selected)
6769
WTable right = abc(collection, false, t -> {

src/main/java/meteordevelopment/meteorclient/systems/modules/combat/KillAura.java

Lines changed: 43 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,7 @@
3333
import net.minecraft.entity.passive.AnimalEntity;
3434
import net.minecraft.entity.passive.WolfEntity;
3535
import net.minecraft.entity.player.PlayerEntity;
36-
import net.minecraft.item.AxeItem;
37-
import net.minecraft.item.ItemStack;
38-
import net.minecraft.item.MaceItem;
39-
import net.minecraft.item.TridentItem;
36+
import net.minecraft.item.*;
4037
import net.minecraft.network.packet.c2s.play.UpdateSelectedSlotC2SPacket;
4138
import net.minecraft.registry.tag.ItemTags;
4239
import net.minecraft.util.Hand;
@@ -47,7 +44,6 @@
4744
import java.util.ArrayList;
4845
import java.util.List;
4946
import java.util.Set;
50-
import java.util.function.Predicate;
5147

5248
public class KillAura extends Module {
5349
private final SettingGroup sgGeneral = settings.getDefaultGroup();
@@ -56,10 +52,19 @@ public class KillAura extends Module {
5652

5753
// General
5854

59-
private final Setting<Weapon> weapon = sgGeneral.add(new EnumSetting.Builder<Weapon>()
60-
.name("weapon")
61-
.description("Only attacks an entity when a specified weapon is in your hand.")
62-
.defaultValue(Weapon.All)
55+
private final Setting<AttackItems> attackWhenHolding = sgGeneral.add(new EnumSetting.Builder<AttackItems>()
56+
.name("attack-when-holding")
57+
.description("Only attacks an entity when a specified item is in your hand.")
58+
.defaultValue(AttackItems.Weapons)
59+
.build()
60+
);
61+
62+
private final Setting<List<Item>> weapons = sgGeneral.add(new ItemListSetting.Builder()
63+
.name("selected-weapon-types")
64+
.description("Which types of weapons to attack with (if you select the diamond sword, any type of sword may be used to attack).")
65+
.defaultValue(Items.DIAMOND_SWORD, Items.DIAMOND_AXE, Items.TRIDENT)
66+
.filter(FILTER::contains)
67+
.visible(() -> attackWhenHolding.get() == AttackItems.Weapons)
6368
.build()
6469
);
6570

@@ -72,7 +77,7 @@ public class KillAura extends Module {
7277

7378
private final Setting<Boolean> autoSwitch = sgGeneral.add(new BoolSetting.Builder()
7479
.name("auto-switch")
75-
.description("Switches to your selected weapon when attacking the target.")
80+
.description("Switches to an acceptable weapon when attacking the target.")
7681
.defaultValue(false)
7782
.build()
7883
);
@@ -85,6 +90,14 @@ public class KillAura extends Module {
8590
.build()
8691
);
8792

93+
private final Setting<ShieldMode> shieldMode = sgGeneral.add(new EnumSetting.Builder<ShieldMode>()
94+
.name("shield-mode")
95+
.description("Will try and use an axe to break target shields.")
96+
.defaultValue(ShieldMode.Break)
97+
.visible(autoSwitch::get)
98+
.build()
99+
);
100+
88101
private final Setting<Boolean> onlyOnClick = sgGeneral.add(new BoolSetting.Builder()
89102
.name("only-on-click")
90103
.description("Only attacks when holding left click.")
@@ -106,14 +119,6 @@ public class KillAura extends Module {
106119
.build()
107120
);
108121

109-
private final Setting<ShieldMode> shieldMode = sgGeneral.add(new EnumSetting.Builder<ShieldMode>()
110-
.name("shield-mode")
111-
.description("Will try and use an axe to break target shields.")
112-
.defaultValue(ShieldMode.Break)
113-
.visible(() -> autoSwitch.get() && weapon.get() != Weapon.Axe)
114-
.build()
115-
);
116-
117122
// Targeting
118123

119124
private final Setting<Set<EntityType<?>>> entities = sgTargeting.add(new EntityTypeListSetting.Builder()
@@ -243,6 +248,7 @@ public class KillAura extends Module {
243248
.build()
244249
);
245250

251+
private final static ArrayList<Item> FILTER = new ArrayList<>(List.of(Items.DIAMOND_SWORD, Items.DIAMOND_AXE, Items.DIAMOND_PICKAXE, Items.DIAMOND_SHOVEL, Items.DIAMOND_HOE, Items.MACE, Items.DIAMOND_SPEAR, Items.TRIDENT));
246252
private final List<Entity> targets = new ArrayList<>();
247253
private int switchTimer, hitTimer;
248254
private boolean wasPathing = false;
@@ -310,15 +316,8 @@ private void onTick(TickEvent.Pre event) {
310316
Entity primary = targets.getFirst();
311317

312318
if (autoSwitch.get()) {
313-
Predicate<ItemStack> predicate = switch (weapon.get()) {
314-
case Axe -> stack -> stack.getItem() instanceof AxeItem;
315-
case Sword -> stack -> stack.isIn(ItemTags.SWORDS);
316-
case Mace -> stack -> stack.getItem() instanceof MaceItem;
317-
case Trident -> stack -> stack.getItem() instanceof TridentItem;
318-
case All -> stack -> stack.getItem() instanceof AxeItem || stack.isIn(ItemTags.SWORDS) || stack.getItem() instanceof MaceItem || stack.getItem() instanceof TridentItem;
319-
default -> o -> true;
320-
};
321-
FindItemResult weaponResult = InvUtils.find(predicate, 0, 8);
319+
FindItemResult weaponResult = new FindItemResult(mc.player.getInventory().getSelectedSlot(), -1);
320+
if (attackWhenHolding.get() == AttackItems.Weapons) weaponResult = InvUtils.find(this::acceptableWeapon, 0, 8);
322321

323322
if (shouldShieldBreak()) {
324323
FindItemResult axeResult = InvUtils.find(itemStack -> itemStack.getItem() instanceof AxeItem, 0, 8);
@@ -329,10 +328,11 @@ private void onTick(TickEvent.Pre event) {
329328
previousSlot = mc.player.getInventory().getSelectedSlot();
330329
swapped = true;
331330
}
331+
332332
InvUtils.swap(weaponResult.slot(), false);
333333
}
334334

335-
if (!itemInHand()) {
335+
if (!acceptableWeapon(mc.player.getMainHandStack())) {
336336
stopAttacking();
337337
return;
338338
}
@@ -448,17 +448,18 @@ private void attack(Entity target) {
448448
hitTimer = 0;
449449
}
450450

451-
private boolean itemInHand() {
452-
if (shouldShieldBreak()) return mc.player.getMainHandStack().getItem() instanceof AxeItem;
453-
454-
return switch (weapon.get()) {
455-
case Axe -> mc.player.getMainHandStack().getItem() instanceof AxeItem;
456-
case Sword -> mc.player.getMainHandStack().isIn(ItemTags.SWORDS);
457-
case Mace -> mc.player.getMainHandStack().getItem() instanceof MaceItem;
458-
case Trident -> mc.player.getMainHandStack().getItem() instanceof TridentItem;
459-
case All -> mc.player.getMainHandStack().getItem() instanceof AxeItem || mc.player.getMainHandStack().isIn(ItemTags.SWORDS) || mc.player.getMainHandStack().getItem() instanceof MaceItem || mc.player.getMainHandStack().getItem() instanceof TridentItem;
460-
default -> true;
461-
};
451+
private boolean acceptableWeapon(ItemStack stack) {
452+
if (shouldShieldBreak()) return stack.getItem() instanceof AxeItem;
453+
if (attackWhenHolding.get() == AttackItems.All) return true;
454+
455+
if (weapons.get().contains(Items.DIAMOND_SWORD) && stack.isIn(ItemTags.SWORDS)) return true;
456+
if (weapons.get().contains(Items.DIAMOND_AXE) && stack.isIn(ItemTags.AXES)) return true;
457+
if (weapons.get().contains(Items.DIAMOND_PICKAXE) && stack.isIn(ItemTags.PICKAXES)) return true;
458+
if (weapons.get().contains(Items.DIAMOND_SHOVEL) && stack.isIn(ItemTags.SHOVELS)) return true;
459+
if (weapons.get().contains(Items.DIAMOND_HOE) && stack.isIn(ItemTags.HOES)) return true;
460+
if (weapons.get().contains(Items.MACE) && stack.getItem() instanceof MaceItem) return true;
461+
if (weapons.get().contains(Items.DIAMOND_SPEAR) && stack.isIn(ItemTags.SPEARS)) return true;
462+
return weapons.get().contains(Items.TRIDENT) && stack.getItem() instanceof TridentItem;
462463
}
463464

464465
public Entity getTarget() {
@@ -472,13 +473,9 @@ public String getInfoString() {
472473
return null;
473474
}
474475

475-
public enum Weapon {
476-
Sword,
477-
Axe,
478-
Mace,
479-
Trident,
480-
All,
481-
Any
476+
public enum AttackItems {
477+
Weapons,
478+
All
482479
}
483480

484481
public enum RotationMode {

0 commit comments

Comments
 (0)