summaryrefslogtreecommitdiffstats
path: root/nms-patches/BlockTurtleEgg.patch
blob: b56a20026d0006cd0a0797f89cc1d086849ce644 (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
--- a/net/minecraft/server/BlockTurtleEgg.java
+++ b/net/minecraft/server/BlockTurtleEgg.java
@@ -2,6 +2,12 @@
 
 import java.util.Random;
 import javax.annotation.Nullable;
+import org.bukkit.craftbukkit.block.CraftBlock;
+
+// CraftBukkit start
+import org.bukkit.event.entity.EntityInteractEvent;
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+// CraftBukkit end
 
 public class BlockTurtleEgg extends Block {
 
@@ -33,6 +39,19 @@
             super.stepOn(world, blockposition, entity);
         } else {
             if (!world.isClientSide && world.random.nextInt(i) == 0) {
+                // CraftBukkit start - Step on eggs
+                org.bukkit.event.Cancellable cancellable;
+                if (entity instanceof EntityHuman) {
+                    cancellable = CraftEventFactory.callPlayerInteractEvent((EntityHuman) entity, org.bukkit.event.block.Action.PHYSICAL, blockposition, null, null, null);
+                } else {
+                    cancellable = new EntityInteractEvent(entity.getBukkitEntity(), CraftBlock.at(world, blockposition));
+                    world.getServer().getPluginManager().callEvent((EntityInteractEvent) cancellable);
+                }
+
+                if (cancellable.isCancelled()) {
+                    return;
+                }
+                // CraftBukkit end
                 this.a(world, blockposition, world.getType(blockposition));
             }
 
@@ -70,7 +89,7 @@
                         entityturtle.setAgeRaw(-24000);
                         entityturtle.g(blockposition);
                         entityturtle.setPositionRotation((double) blockposition.getX() + 0.3D + (double) j * 0.2D, (double) blockposition.getY(), (double) blockposition.getZ() + 0.3D, 0.0F, 0.0F);
-                        world.addEntity(entityturtle);
+                        world.addEntity(entityturtle, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.EGG); // CraftBukkit
                     }
                 }
             }