Uploaded image for project: 'Spigot'
  1. Spigot
  2. SPIGOT-6415

CreatureSpawnEvent is called with SpawnReason.DEFAULT after cross-dimentional travel

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • None
    • None
    • 3036-Spigot-a25e8ed-c85efa8 (MC: 1.16.5)
    • Yes

      When a creature is teleported cross-dimensionally (nether<->overworld or end<->overworld), the CreatureSpawnEvent is called, despite no new creature being spawned (existing object is added). What is more, the event has SpawnReason.DEFAULT set.

      Reproduction (attached compiled plugin):

          @EventHandler(priority=EventPriority.MONITOR)
          private fun onEntityLastPortal(event: EntityPortalEvent) {
              plugin.server.broadcastMessage("LAST Teleport ${event.entity} from ${event.from} to ${event.to}")
          }
      
          @EventHandler(priority=EventPriority.MONITOR)
          private fun onEntityLastSpawn(event: CreatureSpawnEvent) {
              plugin.server.broadcastMessage("LAST Spawn ${event.entity} reason ${event.spawnReason}, cancelled ${event.isCancelled}")
          }
      

      Result:

      LAST Teleport CraftVillager from Location{world=CraftWorld{name=world},x=-186.78063652936024,y=82.0,z=21.53815669680222,pitch=0.0,yaw=-81.94037} to Location{world=CraftWorld{name=world_nether},x=-24.0,y=82.0,z=2.0,pitch=0.0,yaw=0.0}
      LAST Spawn CraftVillager reason DEFAULT, cancelled false
       

      This exists since at least Spigot 1.14.4.

      It might be controversial what exactly is an issue here, and how much breakage might be created in fixing it. Possible solutions:

      1. Don't call CreatureSpawnEvent for teleported entities - this breaks plugins wanting to prevent adding creatures to the world in any way
      2. Change SpawnReason with new PORTAL_TRAVEL value - this breaks plugins already working around this issue and listening on DEFAULT spawn reason
      3. Add independent value, defaulting to false, whether spawn was caused by cross-dimensional travel or not. I believe this solution should be backwards-compatible, albeit a bit messy.

      Opening mostly as a request for comment, whether these solutions are acceptable, maybe there's a better solution or do plugin developers need to be aware of this (a mention in JavaDocs would be nice) and need to work around this issue.

      Also see related: https://hub.spigotmc.org/jira/browse/SPIGOT-6138

            Unassigned Unassigned
            Prof_Bloodstone Prof Bloodstone
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: