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

CreatureSpawnEvent is called with incorrect SpawnReason when using spawn eggs

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • None
    • None
    • This server is running CraftBukkit version 3616-Spigot-d90018e-eecb4c0 (MC: 1.19.3) (Implementing API version 1.19.3-R0.1-SNAPSHOT)
    • Yes

      It seems like when spawning entities using a spawn egg their spawn reason is "DEFAULT" instead of "SPAWNER_EGG". I dig into the code and it seems like the spawn reason parameter is not used:

      SpawnEggItem#useOn calls EntityType#spawn:

          @Nullable
          public T spawn(ServerLevel worldserver, @Nullable ItemStack itemstack, @Nullable Player entityhuman, BlockPos blockposition, MobSpawnType enummobspawn, boolean flag, boolean flag1, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason spawnReason) {
              // CraftBukkit end
              CompoundTag nbttagcompound;
              Consumer<T> consumer; // CraftBukkit - decompile error
      
              if (itemstack != null) {
                  nbttagcompound = itemstack.getTag();
                  consumer = EntityType.createDefaultStackConfig(worldserver, itemstack, entityhuman);
              } else {
                  consumer = (entity) -> {
                  };
                  nbttagcompound = null;
              }
      
              return this.spawn(worldserver, nbttagcompound, consumer, blockposition, enummobspawn, flag, flag1);
          }
      

      There the spawnReason is correct, however not used to spawn the entity.
      Then, the last EntityType#spawn call has its spawn reason set always to "DEFAULT", causing this behavior.

            Unassigned Unassigned
            Ome_R Omer Ben Gera
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: