summaryrefslogtreecommitdiffstats
path: root/nms-patches/ItemMonsterEgg.patch
blob: 8685820b25dcbd0a21feb90e7347bc27b12f2729 (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
32
33
34
35
36
37
38
39
40
41
--- /home/matt/mc-dev-private//net/minecraft/server/ItemMonsterEgg.java	2015-02-26 22:40:22.843608137 +0000
+++ src/main/java/net/minecraft/server/ItemMonsterEgg.java	2015-02-26 22:40:22.843608137 +0000
@@ -19,7 +19,8 @@
     }
 
     public boolean interactWith(ItemStack itemstack, EntityHuman entityhuman, World world, BlockPosition blockposition, EnumDirection enumdirection, float f, float f1, float f2) {
-        if (world.isClientSide) {
+        // CraftBukkit - check ItemStack data
+        if (world.isClientSide || itemstack.getData() == 48 || itemstack.getData() == 49 || itemstack.getData() == 63 || itemstack.getData() == 64) {
             return true;
         } else if (!entityhuman.a(blockposition.shift(enumdirection), enumdirection, itemstack)) {
             return false;
@@ -109,6 +110,12 @@
     }
 
     public static Entity a(World world, int i, double d0, double d1, double d2) {
+        // CraftBukkit start - delegate to spawnCreature
+        return spawnCreature(world, i, d0, d1, d2, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.SPAWNER_EGG);
+    }
+
+    public static Entity spawnCreature(World world, int i, double d0, double d1, double d2, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason spawnReason) {
+        // CraftBukkit end
         if (!EntityTypes.eggInfo.containsKey(Integer.valueOf(i))) {
             return null;
         } else {
@@ -123,8 +130,13 @@
                     entityinsentient.aK = entityinsentient.yaw;
                     entityinsentient.aI = entityinsentient.yaw;
                     entityinsentient.prepare(world.E(new BlockPosition(entityinsentient)), (GroupDataEntity) null);
-                    world.addEntity(entity);
-                    entityinsentient.x();
+                    // CraftBukkit start - don't return an entity when CreatureSpawnEvent is canceled
+                    if (!world.addEntity(entity, spawnReason)) {
+                        entity = null;
+                    } else {
+                        entityinsentient.x();
+                    }
+                    // CraftBukkit end
                 }
             }