[SPIGOT-7200] CreatureSpawnEvent is called with incorrect SpawnReason when using spawn eggs Created: 10/Dec/22  Updated: 25/Dec/24  Resolved: 10/Dec/22

Status: Resolved
Project: Spigot
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Minor
Reporter: Omer Ben Gera Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: 1.19.3

Version: This server is running CraftBukkit version 3616-Spigot-d90018e-eecb4c0 (MC: 1.19.3) (Implementing API version 1.19.3-R0.1-SNAPSHOT)
Guidelines Read: Yes

 Description   

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.


Generated at Wed Apr 02 10:20:38 UTC 2025 using Jira 10.3.3#10030003-sha1:d220e3fefc8dfc6d47f522d3b9a20c1455e12b7b.