summaryrefslogtreecommitdiffstats
path: root/nms-patches/EntityEgg.patch
blob: 314bd2fe85ca22593606b5fb1a9006ebe5767bf8 (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
--- a/net/minecraft/server/EntityEgg.java
+++ b/net/minecraft/server/EntityEgg.java
@@ -1,5 +1,12 @@
 package net.minecraft.server;
 
+// CraftBukkit start
+import org.bukkit.entity.Ageable;
+import org.bukkit.entity.EntityType;
+import org.bukkit.entity.Player;
+import org.bukkit.event.player.PlayerEggThrowEvent;
+// CraftBukkit end
+
 public class EntityEgg extends EntityProjectile {
 
     public EntityEgg(World world) {
@@ -24,20 +31,40 @@
         }
 
         if (!this.world.isClientSide) {
-            if (this.random.nextInt(8) == 0) {
+            boolean hatching = this.random.nextInt(8) == 0; // CraftBukkit
+            if (true) {
                 byte b0 = 1;
 
                 if (this.random.nextInt(32) == 0) {
                     b0 = 4;
                 }
 
-                for (int i = 0; i < b0; ++i) {
-                    EntityChicken entitychicken = new EntityChicken(this.world);
+                // CraftBukkit start
+                if (!hatching) {
+                    b0 = 0;
+                }
+                EntityType hatchingType = EntityType.CHICKEN;
+
+                Entity shooter = this.getShooter();
+                if (shooter instanceof EntityPlayer) {
+                    PlayerEggThrowEvent event = new PlayerEggThrowEvent((Player) shooter.getBukkitEntity(), (org.bukkit.entity.Egg) this.getBukkitEntity(), hatching, b0, hatchingType);
+                    this.world.getServer().getPluginManager().callEvent(event);
+
+                    b0 = event.getNumHatches();
+                    hatching = event.isHatching();
+                    hatchingType = event.getHatchingType();
+                }
 
-                    entitychicken.setAgeRaw(-24000);
-                    entitychicken.setPositionRotation(this.locX, this.locY, this.locZ, this.yaw, 0.0F);
-                    this.world.addEntity(entitychicken);
+                if (hatching) {
+                    for (int i = 0; i < b0; ++i) {
+                        Entity entity = world.getWorld().createEntity(new org.bukkit.Location(world.getWorld(), this.locX, this.locY, this.locZ, this.yaw, 0.0F), hatchingType.getEntityClass());
+                        if (entity.getBukkitEntity() instanceof Ageable) {
+                            ((Ageable) entity.getBukkitEntity()).setBaby();
+                        }
+                        world.getWorld().addEntity(entity, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.EGG);
+                    }
                 }
+                // CraftBukkit end
             }
 
             this.world.broadcastEntityEffect(this, (byte) 3);