summaryrefslogtreecommitdiffstats
path: root/nms-patches/ItemMonsterEgg.patch
blob: 2069ea11bf98dc02aa891c464288d784872a9b3b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
--- a/net/minecraft/server/ItemMonsterEgg.java
+++ b/net/minecraft/server/ItemMonsterEgg.java
@@ -152,6 +152,11 @@
 
     @Nullable
     public static Entity a(World world, @Nullable MinecraftKey minecraftkey, double d0, double d1, double d2) {
+        return spawnCreature(world, minecraftkey, d0, d1, d2, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.SPAWNER_EGG);
+    }
+
+    @Nullable
+    public static Entity spawnCreature(World world, @Nullable MinecraftKey minecraftkey, double d0, double d1, double d2, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason spawnReason) {
         if (minecraftkey != null && EntityTypes.eggInfo.containsKey(minecraftkey)) {
             Entity entity = null;
 
@@ -164,8 +169,13 @@
                     entityinsentient.aP = entityinsentient.yaw;
                     entityinsentient.aN = entityinsentient.yaw;
                     entityinsentient.prepare(world.D(new BlockPosition(entityinsentient)), (GroupDataEntity) null);
-                    world.addEntity(entity);
-                    entityinsentient.D();
+                    // CraftBukkit start - don't return an entity when CreatureSpawnEvent is canceled
+                    if (!world.addEntity(entity, spawnReason)) {
+                        entity = null;
+                    } else {
+                        entityinsentient.D();
+                    }
+                    // CraftBukkit end
                 }
             }