Skip to content

Fix worth line duplication and visibility in creative mode - #18

Merged
Faboit1 merged 1 commit into
mainfrom
claude/item-worth-display-bugs-1hrf2y
Jul 29, 2026
Merged

Fix worth line duplication and visibility in creative mode#18
Faboit1 merged 1 commit into
mainfrom
claude/item-worth-display-bugs-1hrf2y

Conversation

@Faboit1

@Faboit1 Faboit1 commented Jul 29, 2026

Copy link
Copy Markdown
Owner

Summary

This PR fixes issues with the worth line display in item lore by preventing duplication when items are echoed back from creative mode clients, and ensuring worth lines are refreshed when items enter the player's inventory through various means.

Key Changes

  • Invisible marker system: Added a WORTH_MARKER constant composed of invisible formatting codes (§9§8§9§8§r) to reliably identify and strip injected worth lines without affecting item appearance.

  • Creative mode packet handling: Added a new creativeListener that intercepts SET_CREATIVE_SLOT packets from creative-mode clients and strips any injected worth lines before they get baked into the ItemStack, preventing duplicate lines.

  • Improved lore management:

    • Refactored addWorthLore() to always remove stale worth lines before adding new ones, preventing accumulation of duplicates
    • Added stripWorthLore() method to cleanly remove worth markers from items
    • Added removeWorthLines() helper that removes worth lines and their preceding blank separators in reverse iteration order
    • Added loreHasWorthLine() to detect if an item already has an injected worth line
  • New WorthRefreshListener: Created a new listener that triggers inventory updates when items arrive outside of normal packet flows (pickup events, inventory close, player join), ensuring worth lines are applied to items that wouldn't otherwise be resent to the client.

  • Plugin registration: Registered the new WorthRefreshListener in the main plugin class.

  • Improved cleanup: Enhanced the unregister() method to properly clean up both packet listeners with null checks.

Notable Implementation Details

  • Worth lines are only applied when items are sent to clients with open decoratable inventories, so items acquired outside those moments need explicit refresh triggers
  • The invisible marker approach ensures worth lines can be reliably identified and removed without parsing visible text, making the system robust against formatting variations
  • Lore cleanup always happens in reverse iteration order to safely remove items without index shifting issues

https://claude.ai/code/session_016mt4AzbsKNLtCpekgmSGGU

The worth line is applied purely via outgoing item packets, which caused
two issues:

- Items received while a non-decoratable inventory was open (server shop
  purchases, /give while a menu is open, pickups) stayed bare until the
  next full inventory resend, i.e. a relog. Added WorthRefreshListener,
  which re-sends the player's inventory on the next tick after pickups,
  inventory closes, and join so the packet listener can decorate them
  without requiring a rejoin.

- In creative mode the client echoes displayed items back to the server
  (SET_CREATIVE_SLOT), baking the injected worth line into the real item
  and producing duplicate lines on the next decoration. The injected line
  now carries an invisible marker; an inbound SET_CREATIVE_SLOT listener
  strips it before the server stores the item, and decoration always
  removes any pre-existing worth line before re-adding one.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016mt4AzbsKNLtCpekgmSGGU
@Faboit1
Faboit1 merged commit 40c9f87 into main Jul 29, 2026
1 check passed
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.

2 participants