Paper icon indicating copy to clipboard operation
Paper copied to clipboard

add PlayerBrushBlockEvent

Open chmodsayshello opened this issue 2 years ago • 8 comments

This is a small pull request adding an event that gets called whenever a player brushes a block. Closes #9774

chmodsayshello avatar Nov 01 '23 14:11 chmodsayshello

Welcome to paper :wave: thank you for your first PR!

I am a tad unsure if your current implementation does actually fix the related issue. Right now, this mostly looks like an event that is pretty much just a duplicate of the PlayerInteractEvent.

If I interpret the issue correctly, the event should be called when the player is basically done brushing the block instead of the start of the brushing process.

lynxplay avatar Nov 01 '23 16:11 lynxplay

Welcome to paper 👋 thank you for your first PR!

Thanks, but this isn't my first PR, have some old ones I have to clean up some day

If I interpret the issue correctly, the event should be called when the player is basically done brushing the block instead of the start of the brushing process.

Yeah, my bad, sorry, the event will no longer be cancel-able though, however, then, I can expose the dropped itemstack

chmodsayshello avatar Nov 01 '23 16:11 chmodsayshello

Ah sorry, just saw "first time contributor" :sweat: I mean, plugins can infer a not cancelled "PlayerBrushBlockEvent" that is called exactly how the issue describes it (cancellable, does not expose item drops) and the following BlockDropItem event stuff.

lynxplay avatar Nov 01 '23 16:11 lynxplay

As a follow up, warrior suggested internally that maybe an event called each time the block is "partially" brushed in the BrushItem useOnTick method would be useful.

Would work both as a "player starts brushing" and a progress event to do stuff with.

lynxplay avatar Nov 01 '23 16:11 lynxplay

As a follow up, warrior suggested internally that maybe an event called each time the block is "partially" brushed in the BrushItem useOnTick method would be useful.

What would be the use of that? The server cannot stop the client from showing the animation to my knowledge

chmodsayshello avatar Nov 01 '23 16:11 chmodsayshello

I'm sorry for this force push mess, had quite some trouble reverting my changes to the decompile-fixes patch... I'll squash the PR a final time soon

chmodsayshello avatar Nov 01 '23 18:11 chmodsayshello

No worries, we squash on merge xD Go wild with the commits. I mean, I guess the "per brush tick" event is not really needed if brush would properly call events when it converts the block types to the "more brushed" state

lynxplay avatar Nov 01 '23 18:11 lynxplay

I do not think this event is needed at all. You can accomplish the same things by listening to the BlockDropItemEvent which, contrary to the linked issue, is fired before the block is changed allowing you to change the dropped items.

You can then just add a call to the EntityChangeBlockEvent before the blockstate is changed when the brushing is completed which you can cancel to prevent the brushable block from changing.

In my opinion, having control over this in a singular event is better than having to listen to these two, as then, finding out if they were triggered due to that same block, same player, same time would be slightly harder. Also, couldn't a lot of events just be done plugin side using the PlayerInteractionEvent?

Anyways, feel free to close this PR as "won't add" if you disagree with me :)

chmodsayshello avatar Nov 12 '23 12:11 chmodsayshello

Hey @chmodsayshello, we're going to close this PR for the reason Machine-Maker mentioned above. Please join the Discord if you need any assistance with the API!

codebycam avatar Nov 08 '24 06:11 codebycam