Skip to content

Conversation

@dktapps
Copy link
Member

@dktapps dktapps commented Dec 30, 2021

Introduction

this allows, for example, banning the usage of spawn eggs, without preventing opening of doors, without the need for item ID whitelists.

It also allows customizing the behaviour of item and block interactions when sneaking - it's now possible to force spawn eggs to work when sneaking, or force containers to open.

Finally, this also allows preventing any interaction at all without preventing block placement (by setting both to false). Since cancelling the event will typically prevent placement too (which might not be desired).

The naming of the functions is up for discussion, but the feature itself is stolen from Spigot and is much needed.

Relevant issues

Changes

API changes

  • Added the following new API methods:
    • PlayerInteractEvent->useBlock() - returns whether the clicked block's onInteract() will be called
    • PlayerInteractEvent->useItem() - returns whether the held item's onInteractBlock() will be called
    • PlayerInteractEvent->setUseBlock()
    • PlayerInteractEvent->setUseItem()
      Note that setting these both to false does NOT cancel the event; rather, it makes the action behave as if the player was sneaking.

Behavioural changes

Backwards compatibility

Backwards compatible, but could cause unexpected results for plugins not aware of these features - e.g. a plugin may assume that chests are never opened if the player was sneaking, which this change would violate.

Tests

This has not yet been tested.

…item and block

this allows, for example, banning the usage of spawn eggs, without preventing opening of doors, without the need for item ID whitelists.

It also allows customizing the behaviour of item and block interactions when sneaking - it's now possible to force spawn eggs to work when sneaking, or force containers to open.

Finally, this also allows preventing any interaction at all without preventing block placement (by setting both to false). Since cancelling the event will typically prevent placement too (which might not be desired).

The naming of the functions is up for discussion, but the feature itself is stolen from Spigot and is much needed.
@dktapps dktapps added Category: API Related to the plugin API Type: Contribution labels Dec 30, 2021
@dktapps
Copy link
Member Author

dktapps commented Dec 30, 2021

This causes some buggy behaviour when using setUseItem(false) and setUseBlock(true) when using a lava bucket on a door: a ghost lava block is placed (unexpected) and the door is opened (expected). The lava doesn't exist on the server side, so it doesn't burn or spread.

@ColinHDev
Copy link
Contributor

Would it help if I also test with this so the PR can get merged, or are you currently busy with the work on next-major?

@dktapps dktapps added Type: Enhancement Contributes features or other improvements to PocketMine-MP and removed Type: Contribution labels Nov 26, 2022
@ShockedPlot7560
Copy link
Member

I like the idea, I'd dig it up from the depths, soon

@dktapps
Copy link
Member Author

dktapps commented Nov 14, 2024

I think the main issue with this is that World->useItemOn() and Player->onInteractBlock() can only return true (succeeded, don't resync anything) or false (failed, resync held item & clicked block). This PR introduces a situation where the interaction succeeds, but resync of held item and/or clicked block is still necessary, which is not currently possible to represent with this API.

I think fixing this will probably require BC breaks, unless deprecated wrappers are used.

@dktapps dktapps added Status: Blocked Depends on other changes which are yet to be completed and removed Status: Insufficiently Tested labels Nov 14, 2024
@dktapps dktapps requested a review from a team as a code owner November 14, 2024 14:55
github-actions[bot]
github-actions bot previously approved these changes Nov 14, 2024
github-actions[bot]
github-actions bot previously approved these changes Nov 14, 2024
@dktapps
Copy link
Member Author

dktapps commented Nov 15, 2024

Turns out we can just always sync blocks during a block interaction. Since the client doesn't tell us what it expects, this is probably the best course of action anyway. Might even fix some issues in other areas.

this ensures that the blocks stay in sync, regardless of whether plugins altered the outcome.
@dktapps dktapps removed the Status: Blocked Depends on other changes which are yet to be completed label Nov 15, 2024
@dktapps dktapps merged commit ff695a5 into minor-next Nov 15, 2024
29 checks passed
@dktapps dktapps deleted the player-interact-item-block branch November 15, 2024 21:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Category: API Related to the plugin API Type: Enhancement Contributes features or other improvements to PocketMine-MP

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants