Assign BlockProjectileSource before dispenser projectiles spawn - #14201
Open
charlierichards13 wants to merge 1 commit into
Open
Assign BlockProjectileSource before dispenser projectiles spawn#14201charlierichards13 wants to merge 1 commit into
charlierichards13 wants to merge 1 commit into
Conversation
ProjectileDispenseBehavior assigned projectileSource only after spawnProjectileUsingShoot had already inserted the entity into the world, so ProjectileLaunchEvent observed a null shooter. Use the existing delayed spawn path instead: create and configure the projectile, attach the CraftBlockProjectileSource, then spawn it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #14194.
Problem
ProjectileLaunchEvent#getEntity().getShooter()returnednullfor projectiles fired from a dispenser, even though the expected shooter is aBlockProjectileSource. This PR addresses the dispenser path specifically, inProjectileDispenseBehavior.Root cause
ProjectileDispenseBehaviorusedProjectile.spawnProjectileUsingShoot(...), which delegates to the delayed implementation and then immediately calls.spawn(). That spawn call goes throughaddFreshEntity(...), the point at which the projectile enters the world andProjectileLaunchEventfires.Only once that call returned did the dispenser behavior assign:
So the effective ordering was:
The event therefore observed a shooter that had not been set yet.
Changes
Creation/configuration is now split from the actual spawn. The projectile is created via
asProjectile(...), configured withProjectile.spawnProjectileUsingShootDelayed(...)(which sets it up without inserting it into the world), assigned itsCraftBlockProjectileSourcewhile still unspawned, and only then spawned viadelayedProjectile.spawn().New ordering:
This reuses Paper's existing delayed-projectile mechanism rather than introducing new API or a new spawning path. Launch velocity calculation is unchanged;
spawnProjectileUsingShootDelayedruns the sameshoot(...)setup; it just postpones the final world insertion until after the source has been attached.Scope is one source patch against
ProjectileDispenseBehavior. No API changes and no persistenttest-pluginchanges.Testing
Manually verified the change against a dev server: temporarily enabled Paper's local
test-plugin, registered aProjectileLaunchEventlistener, started:paper-server:runDevServer, connected with Minecraft 26.2, and fired a snowball from a placed dispenser. During the event, the listener logged:That confirms the source is available during the event rather than only after the projectile has spawned. The dispenser also continued to launch the snowball normally during the test. The temporary listener was removed and
test-plugindisabled again afterward.Source patches rebuild and reapply cleanly, and a full
./gradlew buildpasses.