summaryrefslogtreecommitdiffstats
path: root/nms-patches/EntityFallingBlock.patch
blob: 37b5e8280db11ca2d8584039a663e21302d5696e (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
--- a/net/minecraft/server/EntityFallingBlock.java
+++ b/net/minecraft/server/EntityFallingBlock.java
@@ -4,6 +4,8 @@
 import java.util.ArrayList;
 import java.util.Iterator;
 
+import org.bukkit.craftbukkit.event.CraftEventFactory; // CraftBukkit
+
 public class EntityFallingBlock extends Entity {
 
     private IBlockData block;
@@ -71,7 +73,7 @@
 
             if (this.ticksLived++ == 0) {
                 blockposition = new BlockPosition(this);
-                if (this.world.getType(blockposition).getBlock() == block) {
+                if (this.world.getType(blockposition).getBlock() == block && !CraftEventFactory.callEntityChangeBlockEvent(this, blockposition, Blocks.AIR.getBlockData()).isCancelled()) {
                     this.world.setAir(blockposition);
                 } else if (!this.world.isClientSide) {
                     this.die();
@@ -112,7 +114,7 @@
 
                     if (!flag1 && BlockFalling.canFallThrough(this.world.getType(new BlockPosition(this.locX, this.locY - 0.009999999776482582D, this.locZ)))) {
                         this.onGround = false;
-                        return;
+                        // return; // CraftBukkit
                     }
 
                     this.motX *= 0.699999988079071D;
@@ -121,7 +123,13 @@
                     if (iblockdata.getBlock() != Blocks.MOVING_PISTON) {
                         this.die();
                         if (!this.f) {
-                            if (iblockdata.getMaterial().isReplaceable() && (flag1 || !BlockFalling.canFallThrough(this.world.getType(blockposition.down()))) && this.world.setTypeAndData(blockposition, this.block, 3)) {
+                            // CraftBukkit start
+                            if (iblockdata.getMaterial().isReplaceable() && (flag1 || !BlockFalling.canFallThrough(this.world.getType(blockposition.down())))) {
+                                if (CraftEventFactory.callEntityChangeBlockEvent(this, blockposition, this.block).isCancelled()) {
+                                    return;
+                                }
+                                this.world.setTypeAndData(blockposition, this.block, 3);
+                                // CraftBukkit end
                                 if (block instanceof BlockFalling) {
                                     ((BlockFalling) block).a(this.world, blockposition, this.block, iblockdata);
                                 }
@@ -175,7 +183,9 @@
                 while (iterator.hasNext()) {
                     Entity entity = (Entity) iterator.next();
 
+                    CraftEventFactory.entityDamage = this; // CraftBukkit
                     entity.damageEntity(damagesource, (float) Math.min(MathHelper.d((float) i * this.fallHurtAmount), this.fallHurtMax));
+                    CraftEventFactory.entityDamage = null; // CraftBukkit
                 }
 
                 if (flag && (double) this.random.nextFloat() < 0.05000000074505806D + (double) i * 0.05D) {