PaperMC / Paper

The most widely used, high performance Minecraft server that aims to fix gameplay and mechanics inconsistencies
https://papermc.io/
Other
10.04k stars 2.34k forks source link

EntityRemoveFromWorldEvent EnderPearl has no owner when going through a Nether Portal #8397

Open MileyHollenberg opened 2 years ago

MileyHollenberg commented 2 years ago

Expected behavior

When shooting an Ender Pearl through a Nether Portal and it fires the EntityRemoveFromWorldEvent I would assume the EnderPearl to still have an owner as it would when the Ender Pearl gets destroyed by the void. Ender Pearls that get destroyed by the void do have their shooter still associated to them

Observed/Actual behavior

The owner property of the Ender Pearl entity is null

Steps/models to reproduce

The following snippet does some checks on the event, when you shoot an Ender Pearl into the void the console will print All good, but if you shoot it through a Nether Portal it will print Shooter is null.

    @EventHandler
    fun pearlDestroyed(event: EntityRemoveFromWorldEvent) {
        if (event.entity.type != EntityType.ENDER_PEARL) {
            logger.info("Not a pearl")
            return
        }

        val pearl = event.entity as EnderPearl
        if (pearl == null) {
            logger.info("Pearl is null")
            return
        }

        logger.info(pearl.entityId.toString())

        if (pearl.shooter == null) {
            logger.info("Shooter is null")
            return
        }

        val player = pearl.shooter as Player
        if (player == null) {
            logger.info("Shooter is not a player")
            return
        }

        logger.info("All good")
    }

Plugin and Datapack List

Plugins: TestPlugin (my own) and VoxelSniper Datapacks: None

Paper version

> version
[14:00:00 INFO]: Checking version, please wait...
[14:00:00 INFO]: This server is running Paper version git-Paper-176 (MC: 1.19.2) (Implementing API version 1.19.2-R0.1-SNAPSHOT) (Git: f7d16f6)
You are running the latest version
Previous version: git-Paper-175 (MC: 1.19.2)

Other

No response

lynxplay commented 2 years ago

Certainly a valid behaviour as paper disables unloaded enderpearls from maintaining their owner by default. This "reset" happens before the unload event is called.

I am unsure if we want to change this behaviour as the unload event is the last last thing that is called for an entity before it is untracked.

The EntityPortalReadyEvent is called early enough for you to catch the shooter if that is a valid alternative. Beyond that, this would need input from others as it is more of a philosophical question when to remove the shooter.

MileyHollenberg commented 2 years ago

Interesting, I would expect that the owner object would still have a value before going through the portal as that would match the behavior with the void as well as there it also gets destroyed and unloaded in the end.

I've already created a small workaround for my setup

lynxplay commented 2 years ago

It is still valid before going through the portal. The entity remove event is just far far beyond the "going through the portal" logic.

As stated, it is pretty much the last thing that touches the entity before it is erased. All logic for portals etc run before it.