Carpet

Carpet

2M Downloads

[Suggestion] Events termination statuses

BisUmTo opened this issue ยท 2 comments

commented

Be able to send termination statuses of events returning either 'pass', 'fail', 'success' or 'consume' to cause the call chain to stop and that status returned. If your callback doesn't return anything (null) then is not cancellable.

commented

For Scarpet __on_player_takes_damage specifically, if the event is canceled but player HP is modified during the event handler, the newly modified HP should be synced. If the victim's HP is set to 0 during the damage event handler, the death event should still trigger with the right parameters even if the damage event handler canceled the vanilla damage.

For entity events as set by entity_event, at least on_damaged should be cancellable just like __on_player_takes_damage, which would cause the vanilla damage to be nullified, leaving only the HP adjustment from the Scarpet event handler.

commented

Here is my rough draft of a list of cancellable events and their corresponding effects:

Scarpet Event Cancellation effects
__on_explosion The explosion does not process.
__on_player_uses_item The item use action does not process.
__on_player_clicks_block Any vanilla code related to the action does not run.
__on_player_breaks_block The block does not actually break.
__on_player_right_clicks_block The block interaction does not process.
__on_player_places_block Any further effects that happen after the block placement are nullified.
__on_player_interacts_with_entity The entity interaction does not process.
__on_player_trades The trade fails and is reverted.
__on_player_collides_with_entity Any vanilla code related to the collision does not run.
__on_player_attacks_entity The attack misses and has no effect.
__on_player_takes_damage The vanilla damage is not applied.
__on_player_rides The movement input is ignored.
__on_player_jumps The player does not jump.
__on_player_deploys_elytra The elytra does not deploy.
__on_player_starts_sneaking Sneaking fails.
__on_player_stops_sneaking Sneaking continues.
__on_player_starts_sprinting Sprinting fails.
__on_player_stops_sprinting Sprinting continues.
__on_player_drops_item The item does not get dropped.
__on_player_drops_stack The item does not get dropped.
__on_player_message The message is not sent nor is the command executed.

As an example, suppose a developer wanted to implement area protection as a Scarpet app. This would not be possible without many of the events above being cancellable.