Skip to content

feat(combat): implement 1.8 block priority and void knockback priority in AutoWeapon#8432

Open
m1trenv0 wants to merge 4 commits into
CCBlueX:nextgenfrom
m1trenv0:feat/autoweapon-legacy-priority
Open

feat(combat): implement 1.8 block priority and void knockback priority in AutoWeapon#8432
m1trenv0 wants to merge 4 commits into
CCBlueX:nextgenfrom
m1trenv0:feat/autoweapon-legacy-priority

Conversation

@m1trenv0

@m1trenv0 m1trenv0 commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

This pull request introduces two new PvP priority mechanics to the AutoWeapon module:

1. 1.8 Block Priority

  • Prioritizes swords during legacy PvP/1.8 combat when KillAura's AutoBlock is configured to block 'Only When in Danger' and we are actively in danger.
  • Exposes isOnlyWhenInDanger via a clean property accessor instead of coupling to configuration internals.

2. Void Knockback Priority

  • Automatically prioritizes weapons or items with the highest Knockback enchantment level (e.g. knockback sticks) if the target is standing close to the void and the knockback direction will push them off.
  • Fully addresses Copilot's review and performance comments:
    • Uses floor-based coordinate mapping (floor(checkX).toInt()) instead of truncation (toInt()) to prevent coordinate shift on negative values.
    • Avoids allocations and high RNG lookup counts by making check distances a static constant and early exiting once the threshold is achieved.
    • Caches isNearVoid results per tick per target entity, resulting in zero overhead on subsequent calls.

Copilot AI review requested due to automatic review settings June 1, 2026 14:16

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR extends AutoWeapon’s weapon selection logic to prioritize legacy sword blocking (1.8-style) and knockback weapons when fighting near the void, and exposes a KillAuraAutoBlock setting needed for that decision-making.

Changes:

  • Expose onlyWhenInDanger as a readable property (isOnlyWhenInDanger) in KillAuraAutoBlock.
  • Add AutoWeapon toggles for 1.8 blocking priority and void knockback priority, and update weapon ranking comparator accordingly.
  • Add a cached “near void” detection routine to drive knockback prioritization.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
.../killaura/features/KillAuraAutoBlock.kt Exposes onlyWhenInDanger via a public getter for cross-module logic.
.../combat/ModuleAutoWeapon.kt Adds new prioritization settings, comparator-based weapon ranking, and near-void detection with per-tick caching.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

return bestSlot?.itemSlot as HotbarItemSlot?
}

private val CHECK_DISTANCES = doubleArrayOf(1.5, 3.0, 4.5, 6.0)
Comment on lines +268 to +285
for (dy in 0..16) {
val p = blockPos.below(dy)
if (p.y < level.minBuildHeight) {
break
}
val state = level.getBlockState(p)
if (!state.isAir && !state.getCollisionShape(level, p).isEmpty) {
hasBlockBelow = true
break
}
}

if (!hasBlockBelow) {
voidBlocksCount++
if (voidBlocksCount >= 2) {
return true
}
}
Comment on lines +273 to +277
val state = level.getBlockState(p)
if (!state.isAir && !state.getCollisionShape(level, p).isEmpty) {
hasBlockBelow = true
break
}
@m1trenv0 m1trenv0 force-pushed the feat/autoweapon-legacy-priority branch from a1cc737 to f301e09 Compare June 1, 2026 15:01
return true
}

private fun isSupportingBlock(level: Level, pos: BlockPos, state: BlockState): Boolean {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

val itemCategorization = ItemCategorization(Slots.Hotbar)
val requiresShield = autoShieldBreak && (enforceShield || target?.wouldBlockHit == true)
val requiresMace = autoMace && canMaceSmash
val requiresLegacySword = isOlderThanOrEqual1_8 && KillAuraAutoBlock.enabled &&

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sword block is not a "legacy" feature. Any item can be used to block on 1.21.5+. Your AI needs latest info. Directly check vanilla jar file.

// An axe will stun the target if it is blocking with a shield
requiresShield -> weaponFacets.firstBestMatching { WeaponType.AXE.test(it.itemStack) }
// Legacy blocking favors swords when only blocking on danger
requiresLegacySword -> weaponFacets.firstBestMatching { WeaponType.SWORD.test(it.itemStack) }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See prev msg

m1trenv0 and others added 3 commits June 3, 2026 01:45
- Reuse the existing BlockPos.collisionShape extension for the void
  check instead of duplicating air/collision-shape detection.
- Sword blocking is not a 1.8-only feature; gate the blocking-sword
  preference on isBlocksAttacksExisting so it also applies on 1.21.5+
  where any item can block. Rename requiresLegacySword accordingly.
- Drop the redundant isOnlyWhenInDanger wrapper by exposing
  onlyWhenInDanger directly.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…gles

Both behaviors were previously unconditional. Now exposed as user-facing
boolean settings (both enabled by default — no behavior change):

- PreferBlockingSword: favors a sword when KillAura AutoBlock only blocks
  on danger and the player is currently in danger, so a blockable item is
  ready in hand. Applies on 1.8 and 1.21.5+ (isBlocksAttacksExisting).
- PrioritizeVoidKnockback: prefers a weapon enchanted with Knockback when
  the target stands next to the void, to push them off the edge.

Also adds tooltip descriptions for both new settings in all 12 bundled
language files (+2 lines each, JSON valid).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The old heuristic cast a single ray behind the target and required 3 of 5
samples to be void. On a narrow strip (not a solid platform) a single ray
rarely collected 3 void samples, so AutoWeapon kept the sword and the target
survived a knockback that should have thrown them off.

Now:
- Fan out three rays (center + two angled) from the target along the knockback
  direction, accounting for knockback spread and thin ledges.
- A ray fires if its nearest contiguous samples are all void, instead of an
  any-3-of-5 majority — so a clear drop right behind the target is enough,
  while a distant pit beyond solid ground still does not trigger.
- Start sampling at 1.0 (behind the hitbox) out to 3.5 blocks, matching the
  knockback throw distance.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants