@@ -115,17 +115,17 @@ public class AttributeSwap extends Module {
115115 .build ()
116116 );
117117
118- private final Setting <Boolean > otherSwapping = sgSwappingOptions .add (new BoolSetting .Builder ()
119- .name ("other -swapping" )
120- .description ("Enables smart swapping for other enchantments like Impaling ." )
118+ private final Setting <Boolean > spearSwapping = sgSwappingOptions .add (new BoolSetting .Builder ()
119+ .name ("spear -swapping" )
120+ .description ("Enables smart swapping for spear enchantments." )
121121 .defaultValue (true )
122122 .visible (() -> mode .get () == Mode .Smart )
123123 .build ()
124124 );
125125
126- private final Setting <Boolean > spearSwapping = sgSwappingOptions .add (new BoolSetting .Builder ()
127- .name ("spear -swapping" )
128- .description ("Enables smart swapping for spear enchantments." )
126+ private final Setting <Boolean > otherSwapping = sgSwappingOptions .add (new BoolSetting .Builder ()
127+ .name ("other -swapping" )
128+ .description ("Enables smart swapping for other enchantments like Impaling ." )
129129 .defaultValue (true )
130130 .visible (() -> mode .get () == Mode .Smart )
131131 .build ()
@@ -321,19 +321,21 @@ public void onDeactivate() {
321321
322322 @ EventHandler
323323 private void onAttack (DoAttackEvent event ) {
324- if (mode . get () == Mode . Smart && spearSwapping . get ()) {
324+ if (mc . crosshairTarget . getType () == HitResult . Type . BLOCK || ! canSwapByWeapon ()) return ;
325325
326+ if (mode .get () == Mode .Smart && spearSwapping .get ()) {
326327 if (spearHitbox .get ()) {
327- Entity target = getTargetEntity (7 );
328+ Entity target = getTargetEntity ();
328329 if (target != null ) {
329- if (mc .player .distanceTo (target ) <= 3 .5 ) return ;
330+ if (mc .player .distanceTo (target ) <= mc . player . getEntityInteractionRange () + 0 .5 ) return ;
330331 int spearSlot = getSmartSpearSlot (false );
331332 if (spearSlot != -1 ) {
332333 doSwap (spearSlot );
333334 return ;
334335 }
335336 }
336337 }
338+
337339 // lunge spear for travelling (or when enemy isn't in spear range)
338340 if (enchantLunge .get ()) {
339341 int lungeSlot = getSmartSpearSlot (true );
@@ -344,9 +346,7 @@ private void onAttack(DoAttackEvent event) {
344346 }
345347 }
346348
347- if (!canSwapByWeapon () || mode .get () == Mode .Smart || !swapOnMiss .get ()) return ;
348- if (mc .crosshairTarget .getType () == HitResult .Type .BLOCK ) return ;
349-
349+ if (mode .get () == Mode .Smart || !swapOnMiss .get ()) return ;
350350 doSwap (targetSlot .get () - 1 );
351351 }
352352
@@ -452,10 +452,12 @@ private int getSmartSpearSlot(boolean requireLunge) {
452452
453453 return i ;
454454 }
455+
455456 return -1 ;
456457 }
457458
458- private Entity getTargetEntity (double maxDistance ) {
459+ private Entity getTargetEntity () {
460+ double maxDistance = 7 ;
459461 Vec3d start = mc .player .getCameraPosVec (1.0f );
460462 Vec3d look = mc .player .getRotationVec (1.0f );
461463 Vec3d end = start .add (look .multiply (maxDistance ));
0 commit comments