Skip to content

Add Display Jar tile rect match and placement validation#3233

Open
ACaiCat wants to merge 7 commits intoPryaxis:general-develfrom
ACaiCat:jar
Open

Add Display Jar tile rect match and placement validation#3233
ACaiCat wants to merge 7 commits intoPryaxis:general-develfrom
ACaiCat:jar

Conversation

@ACaiCat
Copy link
Member

@ACaiCat ACaiCat commented Feb 28, 2026

Fix Display Jar placement

@greptile-apps
Copy link

greptile-apps bot commented Feb 28, 2026

Greptile Summary

This PR implements comprehensive support for Dead Cells Display Jar tile entities in TShock. The changes add packet handling, permission checks, and tile rect matching to properly handle Display Jar item placement and removal.

Key Changes:

  • Added DisplayJarTryPlacing event handler and packet processing in GetDataHandlers
  • Implemented validation logic in Bouncer for placement permissions, range checks, and disabled state
  • Added special tile rect handling in SendTileRectHandler to accommodate client sending 2x2 rect for 1x2 tile
  • Added Display Jar to tile breaking exceptions (can be modified without pickaxe)
  • Implemented tile entity synchronization for Display Jar drops

The implementation follows established patterns from similar tile entities like Food Platter and Item Frame, ensuring consistency with the existing codebase.

Confidence Score: 5/5

  • This PR is safe to merge with no identified issues
  • The implementation follows established patterns from similar tile entities (Food Platter, Item Frame), includes all necessary security checks (permissions, range validation, disabled state), and properly handles the Display Jar's quirk where the client sends a 2x2 rect for a 1x2 tile. All changes are well-structured and consistent with the codebase.
  • No files require special attention

Important Files Changed

Filename Overview
TShockAPI/Handlers/SendTileRectHandler.cs Added Display Jar tile rect matching logic to handle client's 2x2 rect by extracting the relevant 1x2 column, and registered placement pattern for 1x2 Display Jar tiles
TShockAPI/GetDataHandlers.cs Added packet handler, event args class, and event for Display Jar item placement, following the same pattern as Food Platter implementation
TShockAPI/Bouncer.cs Registered Display Jar event handler, added tile entity synchronization for item drops, exempted Display Jar from pickaxe requirement, and implemented placement validation (permissions, range, disabled state)

Sequence Diagram

sequenceDiagram
    participant Client
    participant GetDataHandlers
    participant Bouncer
    participant Player
    
    Client->>GetDataHandlers: TEDeadCellsDisplayJar packet
    GetDataHandlers->>GetDataHandlers: HandleDisplayJar()
    GetDataHandlers->>GetDataHandlers: Parse packet (tileX, tileY, itemID, prefix, stack)
    GetDataHandlers->>GetDataHandlers: OnDisplayJarTryPlacing()
    GetDataHandlers->>Bouncer: Invoke DisplayJarTryPlacing event
    
    Bouncer->>Bouncer: Validate tile placement position
    alt Invalid position
        Bouncer->>Client: Reject (handled=true)
    end
    
    Bouncer->>Bouncer: Check item in hand matches itemID
    alt Item mismatch
        Bouncer->>Client: SendTileSquareCentered + Reject
    end
    
    Bouncer->>Player: Check IsBeingDisabled()
    alt Player disabled
        Bouncer->>Player: GiveItemCheck (return item)
        Bouncer->>Client: SendTileSquareCentered + Reject
    end
    
    Bouncer->>Player: HasBuildPermission()
    alt No permission
        Bouncer->>Player: GiveItemCheck (return item)
        Bouncer->>Client: SendTileSquareCentered + Reject
    end
    
    Bouncer->>Player: IsInRange(range: 13)
    alt Out of range
        Bouncer->>Client: SendTileSquareCentered + Reject
    end
    
    Bouncer->>GetDataHandlers: Return (not handled)
    GetDataHandlers->>Client: Allow placement
Loading

Last reviewed commit: 81993b3

@lost-werewolf
Copy link
Contributor

lost-werewolf commented Mar 2, 2026

This seems good. Could you also fix the Bouncer rejecting item removal from the jar when not using a pickaxe before I approve? This is about the same case as torches, right clicking removes the item without pickaxing the jar. Feel it would be good to squash here along with this match.

Edit: Attached image
image

Double edit: attached clip:
https://github.com/user-attachments/assets/1f692fca-02c7-4d5c-a1de-dd747cfe405c

@ACaiCat
Copy link
Member Author

ACaiCat commented Mar 2, 2026

Maybe we need a new GetDataHandler...
image

@lost-werewolf
Copy link
Contributor

lost-werewolf commented Mar 2, 2026

Maybe we need a new GetDataHandler...

If every packet sent by clients had a handler AND a hook to subscribe to, it would be great. Noticed once when making a plugin that I couldn't subscribe to the SpawnBoss handler, so I had to manually do so through OnGetData. Perhaps good for another PR.

@pull-request-size pull-request-size bot added size/L and removed size/S labels Mar 2, 2026
@ACaiCat
Copy link
Member Author

ACaiCat commented Mar 2, 2026

@greptile-apps review

@ACaiCat ACaiCat changed the title Add Display Jar tile rect match Add Display Jar tile rect match and placement validation Mar 2, 2026
Copy link
Contributor

@lost-werewolf lost-werewolf left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants