summaryrefslogtreecommitdiffstats
path: root/nms-patches/BlockSoil.patch
blob: 7c6475a055e9774ad959cc0636c1f405d7070cac (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
--- a/net/minecraft/server/BlockSoil.java
+++ b/net/minecraft/server/BlockSoil.java
@@ -3,6 +3,11 @@
 import java.util.Iterator;
 import java.util.Random;
 
+// CraftBukkit start
+import org.bukkit.event.entity.EntityInteractEvent;
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+// CraftBukkit end
+
 public class BlockSoil extends Block {
 
     public static final BlockStateInteger MOISTURE = BlockProperties.ah;
@@ -63,14 +68,37 @@
     }
 
     public void fallOn(World world, BlockPosition blockposition, Entity entity, float f) {
+        super.fallOn(world, blockposition, entity, f); // CraftBukkit - moved here as game rules / events shouldn't affect fall damage.
         if (!world.isClientSide && world.random.nextFloat() < f - 0.5F && entity instanceof EntityLiving && (entity instanceof EntityHuman || world.getGameRules().getBoolean("mobGriefing")) && entity.width * entity.width * entity.length > 0.512F) {
+            // CraftBukkit start - Interact soil
+            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(), world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ()));
+                world.getServer().getPluginManager().callEvent((EntityInteractEvent) cancellable);
+            }
+
+            if (cancellable.isCancelled()) {
+                return;
+            }
+
+            if (CraftEventFactory.callEntityChangeBlockEvent(entity, blockposition, Blocks.DIRT.getBlockData()).isCancelled()) {
+                return;
+            }
+            // CraftBukkit end
             b(world.getType(blockposition), world, blockposition);
         }
 
-        super.fallOn(world, blockposition, entity, f);
+        // super.fallOn(world, blockposition, entity, f); // CraftBukkit - moved up
     }
 
     protected static void b(IBlockData iblockdata, World world, BlockPosition blockposition) {
+        // CraftBukkit start
+        if (CraftEventFactory.callBlockFadeEvent(world, blockposition, Blocks.DIRT.getBlockData()).isCancelled()) {
+            return;
+        }
+        // CraftBukkit end
         world.setTypeUpdate(blockposition, a(iblockdata, Blocks.DIRT.getBlockData(), (GeneratorAccess) world, blockposition));
     }