Skip to content

Conversation

@IvanCraft623
Copy link
Member

Introduction

The current solution presents some problems as first of all Tiles should not handle the behavior of blocks, instead of using the jukebox API to eject the disc directly boradcasts RecordStopSound, which causes the loss of the disc by destroying the jukebox which at the same time does not match the Vanilla behavior.

This PR addresses the problems mentioned above by adding the Block::onDestroy() method, making the block not dependent on the Tile to manage this logic, which as a plus eliminates duplicate code in Block::onBreak() and Explosion::explodeB().

Copy link
Member

@dktapps dktapps left a comment

Choose a reason for hiding this comment

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

I agree that something like this is needed, but I'm not super happy with the "destroy" terminology. It feels too ambiguous.

@dktapps dktapps added Category: API Related to the plugin API Category: Core Related to internal functionality Type: Enhancement Contributes features or other improvements to PocketMine-MP labels Jun 5, 2023
/**
* Called when this block is destroyed either when a player breaks it or is hit by an explosion.
*/
public function onDestroy() : void{
Copy link
Member

Choose a reason for hiding this comment

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

Like @dktapps I don't think that destroy terminology is appropriate in this case. Perhaps, as with the placement logic, an onPostBreak would be preferable? It would be less ambiguous and not so funny in the sense that the block would already have been destroyed.

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure that's desirable. If the block was already destroyed, contents of stuff like tiles wouldn't be accessible.

Personally I would lean towards an onExplode() method or something similar. We already have the likes of onIncinerate() for fire. The problem is that this would require multiple handlers to be implemented for dealing with tile drops.

if($tile !== null){
$tile->onBlockDestroyed();
}
$target->onDestroy();
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this function only be called if the onBreak returns true? There is a return value, but it's never used, and yet it would make sense in this case. If the broken action has been confirmed, then we can call this function, which is there to perform post-broken actions.

@dktapps
Copy link
Member

dktapps commented Jul 13, 2023

Has anyone considered using Block::onBreak() for this instead of adding an extra method? It does allow passing null for the player parameter.

I haven't thought much about the pros and cons of this approach, but I think it should be considered.

Joshy3282 added a commit to Joshy3282/PocketMine-MP that referenced this pull request Oct 2, 2024
@dktapps
Copy link
Member

dktapps commented Nov 14, 2024

Linking #4652 as I think these are two different solutions for essentially the same problem

@github-actions
Copy link
Contributor

github-actions bot commented Dec 7, 2024

This PR has been marked as "Waiting on Author", but we haven't seen any activity in 7 days.

If there is no further activity, it will be closed in 28 days.

Note for maintainers: Adding an assignee to the PR will prevent it from being marked as stale.

$t->onBlockDestroyed();
}
$world->setBlock($this->position, VanillaBlocks::AIR());
$this->position->getWorld()->setBlock($this->position, VanillaBlocks::AIR());
Copy link
Member

Choose a reason for hiding this comment

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

Noting this is probably BC breaking, since the behaviour is now changed for non-core consumers of onBreak()

@dktapps
Copy link
Member

dktapps commented Oct 3, 2025

The disc does actually appear to drop on an explosion. It's probably because the yield is less than 100% that you didn't see that.

The main deviation from vanilla would appear to be that the disc doesn't drop when the jukebox is broken by a creative player. So something akin to #4652 would probably be better suited to dealing with that problem, or we could have it drop in onBreak().

There is also the issue of containers dropping their contents in onBlockDestroyedHook() that nobody seems to have paid any mind to. Perhaps that should be considered for this too.

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 Category: Core Related to internal functionality Type: Enhancement Contributes features or other improvements to PocketMine-MP

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

3 participants