Skip to content

Add Shelf#getSlot using Vector - #13453

Open
Doc94 wants to merge 8 commits into
PaperMC:mainfrom
Doc94:feature/13398-get-slot-shelf
Open

Doc94 wants to merge 8 commits into
PaperMC:mainfrom
Doc94:feature/13398-get-slot-shelf

Conversation

@Doc94

@Doc94 Doc94 commented Dec 28, 2025 •

Copy link
Copy Markdown
Member

Close #13398 by adding a method for determinate the slot using a Vector, works like the same than the logic for ChiseledBookshelf

test:

@EventHandler
    public void onPlayerInteractEvent(PlayerInteractEvent event) {
        final Player player = event.getPlayer();
        final Block block = event.getClickedBlock();
        if (block == null) return;
        if (block.getState() instanceof Shelf shelfState) {
            player.sendMessage(Component.text("Shelf: " + shelfState.getSlot(event.getClickedPosition())));
        } else if (block.getState() instanceof ChiseledBookshelf chiseledBookshelfState) {
            player.sendMessage(Component.text("ChiseledBookshelf: " + chiseledBookshelfState.getSlot(event.getClickedPosition())));
        }
    }
javaw_2025-12-28_13-06-20.mp4

@Doc94
Doc94 requested a review from a team as a code owner December 28, 2025 16:07
@github-project-automation github-project-automation Bot moved this to Awaiting review in Paper PR Queue Dec 28, 2025

@Lulu13022002 Lulu13022002 left a comment

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.

Can you move the implementation to a common class like CraftSelectable or something.
PlayerInteractEvent#getClickedPosition should probably be renamed too but it can be done in another PR to not rely on a deprecated method.

Also next time don't show an image for your test code it's not convenient.


@Override
public int getSlot(Vector clickVector) {
BlockFace facing = ((Directional) this.getBlockData()).getFacing();

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.

It's not safe to cast the block data cause a plugin could simply change it to something else.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Well i base in the other implementation... Maybe a Precondition.checkState can be good here?

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.

A precondition is better -1 has some other meaning here, i did the change for you. But from a quick look it's impossible for this method to return -1?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

looks like but not sure.. i prefer keep that docs xd

@Doc94

Doc94 commented Dec 28, 2025

Copy link
Copy Markdown
Member Author

Can you move the implementation to a common class like CraftSelectable or something.
PlayerInteractEvent#getClickedPosition should probably be renamed too but it can be done in another PR to not rely on a deprecated method.

Also next time don't show an image for your test code it's not convenient.

Okay, for the common class just move all to a new class with static methods not?

@Doc94
Doc94 force-pushed the feature/13398-get-slot-shelf branch 2 times, most recently from 8967805 to ff6432f Compare January 4, 2026 20:34
@Doc94
Doc94 requested a review from Lulu13022002 April 27, 2026 18:58
@Lulu13022002 Lulu13022002 added the status: blocked Issue or Request is waiting on some other issue or change. label Apr 30, 2026
@Doc94
Doc94 force-pushed the feature/13398-get-slot-shelf branch from 56e6983 to a8b7863 Compare August 31, 2026 14:57
@Doc94
Doc94 force-pushed the feature/13398-get-slot-shelf branch from a8b7863 to 62a4c2b Compare August 31, 2026 15:11
@Doc94

Doc94 commented Aug 31, 2026

Copy link
Copy Markdown
Member Author

Rebased... looking the code the only way for get the -1 its a case where the block can has 0 rows and columns... and unless anybode mess with the server its not a expected behaviour for document like spigot does years ago...
So i feel the PR is ready @Lulu13022002

@Doc94 Doc94 removed the status: blocked Issue or Request is waiting on some other issue or change. label Oct 27, 2026
@Warriorrrr Warriorrrr added type: feature Request for a new Feature. scope: api labels Oct 27, 2026
@Lulu13022002 Lulu13022002 added the status: blocked Issue or Request is waiting on some other issue or change. label Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: api status: blocked Issue or Request is waiting on some other issue or change. type: feature Request for a new Feature.

Projects

Status: Awaiting review

Development

Successfully merging this pull request may close these issues.

Implement getSlot method for Shelf block

3 participants