Skip to content

Commit b17bfef

Browse files
committed
auto hit swap
1 parent 19679a7 commit b17bfef

File tree

2 files changed

+80
-7
lines changed

2 files changed

+80
-7
lines changed

src/client/java/autumnvn/autumn/Options.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public Options() {
5252
options.put("autoAttack", autoAttack);
5353
ignorePlayer = SimpleOption.ofBoolean("Ignore Player", value -> Tooltip.of(Text.of("Auto Attack will ignore player")), false);
5454
options.put("ignorePlayer", ignorePlayer);
55-
autoHitSwap = SimpleOption.ofBoolean("Auto Hit Swap", value -> Tooltip.of(Text.of("Swap item in main hand to another item in hotbar when attacking, then swap back after attack so it uses base damage & cooldown of original item and enchantments & ability to disable shield of swapped item\nPriority: axe when target is using shield, enchanted sword")), true);
55+
autoHitSwap = SimpleOption.ofBoolean("Auto Hit Swap", value -> Tooltip.of(Text.of("Swap item in main hand to another item in hotbar when attacking, then swap back after attack so it uses base damage & cooldown of original item and enchantments & ability to disable shield of swapped item\nPriority:\nAxe if target is using shield\n\nSmite sword if target is undead\nBane of arthropods sword if target is arthropod\nImpaling trident if target is aquatic\nEnchanted sword\nNon-weapon if holding unenchanted sword/non-sharpness axe/other weapons")), true);
5656
options.put("autoHitSwap", autoHitSwap);
5757
autoSprint = SimpleOption.ofBoolean("Auto Sprint", value -> Tooltip.of(Text.of("Automatically sprint when moving forward")), true);
5858
options.put("autoSprint", autoSprint);

src/client/java/autumnvn/autumn/mixin/client/ClientPlayerInteractionManagerMixin.java

Lines changed: 79 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
import autumnvn.autumn.AutumnClient;
44
import net.minecraft.client.MinecraftClient;
55
import net.minecraft.client.network.ClientPlayerInteractionManager;
6+
import net.minecraft.enchantment.EnchantmentHelper;
7+
import net.minecraft.enchantment.Enchantments;
68
import net.minecraft.entity.Entity;
9+
import net.minecraft.entity.EntityGroup;
10+
import net.minecraft.entity.LivingEntity;
711
import net.minecraft.entity.player.PlayerEntity;
812
import net.minecraft.item.*;
913
import org.spongepowered.asm.mixin.Final;
@@ -53,13 +57,34 @@ private void attackEntity2(PlayerEntity player, Entity target, CallbackInfo ci)
5357
slot = player.getInventory().selectedSlot;
5458
ItemStack stack = player.getMainHandStack();
5559
Item item = stack.getItem();
56-
boolean targetIsUsingShield = target instanceof PlayerEntity playerEntity && playerEntity.getActiveItem().isOf(Items.SHIELD);
57-
if (!(item instanceof AxeItem) && targetIsUsingShield && getAxeHotbarSlot(player) != -1) {
60+
61+
if (getAxeHotbarSlot(player) != -1 && target instanceof PlayerEntity playerEntity && playerEntity.getActiveItem().isOf(Items.SHIELD)) {
5862
player.getInventory().selectedSlot = getAxeHotbarSlot(player);
59-
} else if (!(item instanceof AxeItem) || !targetIsUsingShield) {
60-
if (!(item instanceof SwordItem && !stack.getEnchantments().isEmpty()) && getEnchantedSwordHotbarSlot(player) != -1) {
61-
player.getInventory().selectedSlot = getEnchantedSwordHotbarSlot(player);
62-
}
63+
return;
64+
}
65+
66+
if (getSmiteSwordHotbarSlot(player) != -1 && target instanceof LivingEntity livingEntity && livingEntity.getGroup() == EntityGroup.UNDEAD) {
67+
player.getInventory().selectedSlot = getSmiteSwordHotbarSlot(player);
68+
return;
69+
}
70+
71+
if (getBaneOfArthropodsSwordHotbarSlot(player) != -1 && target instanceof LivingEntity livingEntity && livingEntity.getGroup() == EntityGroup.ARTHROPOD) {
72+
player.getInventory().selectedSlot = getBaneOfArthropodsSwordHotbarSlot(player);
73+
return;
74+
}
75+
76+
if (getImpalingTridentHotbarSlot(player) != -1 && target instanceof LivingEntity livingEntity && livingEntity.getGroup() == EntityGroup.AQUATIC) {
77+
player.getInventory().selectedSlot = getImpalingTridentHotbarSlot(player);
78+
return;
79+
}
80+
81+
if (getEnchantedSwordHotbarSlot(player) != -1) {
82+
player.getInventory().selectedSlot = getEnchantedSwordHotbarSlot(player);
83+
return;
84+
}
85+
86+
if (getNonWeaponHotbarSlot(player) != -1 && ((item instanceof SwordItem && stack.getEnchantments().isEmpty()) || (item instanceof AxeItem && EnchantmentHelper.getLevel(Enchantments.SHARPNESS, stack) > 0) || item instanceof PickaxeItem || item instanceof ShovelItem || item instanceof HoeItem || item instanceof TridentItem)) {
87+
player.getInventory().selectedSlot = getNonWeaponHotbarSlot(player);
6388
}
6489
}
6590
}
@@ -83,6 +108,42 @@ int getAxeHotbarSlot(PlayerEntity player) {
83108
return -1;
84109
}
85110

111+
@Unique
112+
int getSmiteSwordHotbarSlot(PlayerEntity player) {
113+
for (int i = 0; i < 9; i++) {
114+
ItemStack stack = player.getInventory().getStack(i);
115+
Item item = stack.getItem();
116+
if (item instanceof SwordItem && EnchantmentHelper.getLevel(Enchantments.SMITE, stack) > 0) {
117+
return i;
118+
}
119+
}
120+
return -1;
121+
}
122+
123+
@Unique
124+
int getBaneOfArthropodsSwordHotbarSlot(PlayerEntity player) {
125+
for (int i = 0; i < 9; i++) {
126+
ItemStack stack = player.getInventory().getStack(i);
127+
Item item = stack.getItem();
128+
if (item instanceof SwordItem && EnchantmentHelper.getLevel(Enchantments.BANE_OF_ARTHROPODS, stack) > 0) {
129+
return i;
130+
}
131+
}
132+
return -1;
133+
}
134+
135+
@Unique
136+
int getImpalingTridentHotbarSlot(PlayerEntity player) {
137+
for (int i = 0; i < 9; i++) {
138+
ItemStack stack = player.getInventory().getStack(i);
139+
Item item = stack.getItem();
140+
if (item instanceof TridentItem && EnchantmentHelper.getLevel(Enchantments.IMPALING, stack) > 0) {
141+
return i;
142+
}
143+
}
144+
return -1;
145+
}
146+
86147
@Unique
87148
int getEnchantedSwordHotbarSlot(PlayerEntity player) {
88149
for (int i = 0; i < 9; i++) {
@@ -94,4 +155,16 @@ int getEnchantedSwordHotbarSlot(PlayerEntity player) {
94155
}
95156
return -1;
96157
}
158+
159+
@Unique
160+
int getNonWeaponHotbarSlot(PlayerEntity player) {
161+
for (int i = 0; i < 9; i++) {
162+
ItemStack stack = player.getInventory().getStack(i);
163+
Item item = stack.getItem();
164+
if (!(item instanceof SwordItem) && !(item instanceof AxeItem) && !(item instanceof PickaxeItem) && !(item instanceof ShovelItem) && !(item instanceof HoeItem) && !(item instanceof TridentItem)) {
165+
return i;
166+
}
167+
}
168+
return -1;
169+
}
97170
}

0 commit comments

Comments
 (0)