Detect if player is currently mining a block

Hey there!
Is it possible to somehow determine if a player is currently mining a block? I have been trying around with events a little, but there does not seem to be a suitable solution.

I basically want to make a barrier block breakable by first detecting if a player started hitting a block, then counting a specified amount of time, eventually replacing it with air and dropping an appropriate item, just like in vanilla fashion.

An InteractBlockEvent does not completely fill my needs, since it is only fired when a player performs the first hit. I hoped it would be fired every few ticks a player is trying to break it, but that is only the case for the secondary hand, not the primary. I think this way there is no way of detecting, if the mining process is still going on. TargetBlockEvent and ChangeBlockEvent don’t seem to work either.

I think detecting if the player is still mining should technically be possible since the player entity’s swinging arm is visible to other clients. My best guesses are the Data API or some networking stuff…

Thanks for advice!

You could check for InteractEvent then fire a repeating task that checks that the block is still in the blockRay of the player (if not then the player has stopped breaking the block) . You could then have a override stop when the BlockBreakEvent (with the same location) is fired.

Edit.

There is also AnimateHandEvent. Not sure if its implemented but you might be able to grab the cause from … Well the cause tracker.

There is also something like DataChangeEvent (can not remeber the name) but its not implemented. But once it is you could check that and check if the changed data is RightArmLocation.

AnimateHandEvent was a good idea. I had to go through some RayCasting trouble but it all works now. Thanks for your help!

1 Like

But once it is you could check that and check if the changed data is RightArmLocation.

Tricky situation there, since minecraft allows the player to switch right or left arms as their primary selection, no?

Yeah thats true. I always forget about newer stuff (i joined mc at 1.8beta … Havent really looked that deeply at the later stuff) maybe check both hands. If one has changed state then do whatever

It does send the events; the only thing is that the location is empty. I have an issue which has just been closed.