Shuffle enchant table offers when item is put back #3

Merged
NotAlexNoyle merged 1 commits from codex/shuffle-enchantments-on-item-reposition into master 2026-03-24 12:51:28 -04:00
NotAlexNoyle commented 2026-03-24 12:50:43 -04:00 (Migrated from github.com)

Motivation

  • Ensure that removing an item from the enchanting slot and then putting it back reshuffles the enchantment offers, matching the requested behavior for the item slot (not the lapis slot).
  • The plugin already auto-fills lapis, but did not change the enchantment seed when the enchantable item was reinserted, so offers could remain the same.

Description

  • Added ENCHANTING_ITEM_SLOT (slot 0) and a per-player hadEnchantingItem map keyed by UUID to track whether the player had an item in the enchantable slot.
  • Track initial state on InventoryOpenEvent via trackEnchantingItem and clear tracked state on InventoryCloseEvent to avoid stale entries.
  • After click/drag actions the plugin now schedules updateEnchantingStateNextTick to re-evaluate the enchanting item slot and when the slot transitions from empty to filled it assigns a fresh seed using HumanEntity#setEnchantmentSeed(ThreadLocalRandom.current().nextInt()) so offers reroll.
  • Kept existing auto-lapis protection and refill logic intact and reused the next-tick scheduling pattern used for lapis refills.

Testing

  • Ran ./gradlew compileJava which failed in this environment with a Gradle/toolchain error (25.0.1) so compilation could not be verified here.

Codex Task

### Motivation - Ensure that removing an item from the enchanting slot and then putting it back reshuffles the enchantment offers, matching the requested behavior for the item slot (not the lapis slot). - The plugin already auto-fills lapis, but did not change the enchantment seed when the enchantable item was reinserted, so offers could remain the same. ### Description - Added `ENCHANTING_ITEM_SLOT` (slot `0`) and a per-player `hadEnchantingItem` map keyed by `UUID` to track whether the player had an item in the enchantable slot. - Track initial state on `InventoryOpenEvent` via `trackEnchantingItem` and clear tracked state on `InventoryCloseEvent` to avoid stale entries. - After click/drag actions the plugin now schedules `updateEnchantingStateNextTick` to re-evaluate the enchanting item slot and when the slot transitions from empty to filled it assigns a fresh seed using `HumanEntity#setEnchantmentSeed(ThreadLocalRandom.current().nextInt())` so offers reroll. - Kept existing auto-lapis protection and refill logic intact and reused the next-tick scheduling pattern used for lapis refills. ### Testing - Ran `./gradlew compileJava` which failed in this environment with a Gradle/toolchain error (`25.0.1`) so compilation could not be verified here. ------ [Codex Task](https://chatgpt.com/codex/tasks/task_e_69c2c063ee64832fb5607783d83ef7bc)
Sign in to join this conversation.