summaryrefslogtreecommitdiffstats
path: root/nms-patches/ItemMonsterEgg.patch
blob: 357a36035303dd2c8c85d6c645d32ce9510471a3 (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
31
--- a/net/minecraft/server/ItemMonsterEgg.java
+++ b/net/minecraft/server/ItemMonsterEgg.java
@@ -130,7 +130,11 @@
     }
 
     @Nullable
-    public static Entity a(World world, @Nullable String s, double d0, double d1, double d2) {
+    public static Entity a(World world, @Nullable String s, double d0, double d1, double d2) {        // CraftBukkit start - delegate to spawnCreature
+        return spawnCreature(world, s, d0, d1, d2, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.SPAWNER_EGG);
+    }
+
+    public static Entity spawnCreature(World world, String s, double d0, double d1, double d2, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason spawnReason) {
         if (s != null && EntityTypes.eggInfo.containsKey(s)) {
             Entity entity = null;
 
@@ -143,8 +147,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
                 }
             }