summaryrefslogtreecommitdiffstats
path: root/nms-patches/EntityWither.patch
blob: 920308caf21de3e9ba3fc0a4f9ecdb6ebd420478 (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
--- a/net/minecraft/server/EntityWither.java
+++ b/net/minecraft/server/EntityWither.java
@@ -5,6 +5,12 @@
 import java.util.function.Predicate;
 import javax.annotation.Nullable;
 
+// CraftBukkit start
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.event.entity.EntityRegainHealthEvent;
+import org.bukkit.event.entity.ExplosionPrimeEvent;
+// CraftBukkit end
+
 public class EntityWither extends EntityMonster implements IRangedEntity {
 
     private static final DataWatcherObject<Integer> a = DataWatcher.a(EntityWither.class, DataWatcherRegistry.b);
@@ -19,7 +25,7 @@
     private final int[] bI = new int[2];
     private final int[] bJ = new int[2];
     private int bK;
-    private final BossBattleServer bL;
+    public final BossBattleServer bL; // PAIL private -> public, rename bossBattleServer
     private static final Predicate<Entity> bM = (entity) -> {
         return entity instanceof EntityLiving && ((EntityLiving) entity).getMonsterType() != EnumMonsterType.UNDEAD && ((EntityLiving) entity).df();
     };
@@ -181,13 +187,38 @@
         if (this.dz() > 0) {
             i = this.dz() - 1;
             if (i <= 0) {
-                this.world.createExplosion(this, this.locX, this.locY + (double) this.getHeadHeight(), this.locZ, 7.0F, false, this.world.getGameRules().getBoolean("mobGriefing"));
-                this.world.a(1023, new BlockPosition(this), 0);
+                // CraftBukkit start
+                // this.world.createExplosion(this, this.locX, this.locY + (double) this.getHeadHeight(), this.locZ, 7.0F, false, this.world.getGameRules().getBoolean("mobGriefing"));
+                ExplosionPrimeEvent event = new ExplosionPrimeEvent(this.getBukkitEntity(), 7.0F, false);
+                this.world.getServer().getPluginManager().callEvent(event);
+
+                if (!event.isCancelled()) {
+                    this.world.createExplosion(this, this.locX, this.locY + (double) this.getHeadHeight(), this.locZ, event.getRadius(), event.getFire(), this.world.getGameRules().getBoolean("mobGriefing"));
+                }
+                // CraftBukkit end
+
+                // CraftBukkit start - Use relative location for far away sounds
+                // this.world.a(1023, new BlockPosition(this), 0);
+                int viewDistance = ((WorldServer) this.world).getServer().getViewDistance() * 16;
+                for (EntityPlayer player : (List<EntityPlayer>) MinecraftServer.getServer().getPlayerList().players) {
+                    double deltaX = this.locX - player.locX;
+                    double deltaZ = this.locZ - player.locZ;
+                    double distanceSquared = deltaX * deltaX + deltaZ * deltaZ;
+                    if (distanceSquared > viewDistance * viewDistance) {
+                        double deltaLength = Math.sqrt(distanceSquared);
+                        double relativeX = player.locX + (deltaX / deltaLength) * viewDistance;
+                        double relativeZ = player.locZ + (deltaZ / deltaLength) * viewDistance;
+                        player.playerConnection.sendPacket(new PacketPlayOutWorldEvent(1023, new BlockPosition((int) relativeX, (int) this.locY, (int) relativeZ), 0, true));
+                    } else {
+                        player.playerConnection.sendPacket(new PacketPlayOutWorldEvent(1023, new BlockPosition((int) this.locX, (int) this.locY, (int) this.locZ), 0, true));
+                    }
+                }
+                // CraftBukkit end
             }
 
             this.d(i);
             if (this.ticksLived % 10 == 0) {
-                this.heal(10.0F);
+                this.heal(10.0F, EntityRegainHealthEvent.RegainReason.WITHER_SPAWN); // CraftBukkit
             }
 
         } else {
@@ -278,6 +309,11 @@
                                 Block block = iblockdata.getBlock();
 
                                 if (!iblockdata.isAir() && a(block)) {
+                                    // CraftBukkit start
+                                    if (CraftEventFactory.callEntityChangeBlockEvent(this, blockposition, Blocks.AIR.getBlockData()).isCancelled()) {
+                                        continue;
+                                    }
+                                    // CraftBukkit end
                                     flag = this.world.setAir(blockposition, true) || flag;
                                 }
                             }
@@ -291,7 +327,7 @@
             }
 
             if (this.ticksLived % 20 == 0) {
-                this.heal(1.0F);
+                this.heal(1.0F, EntityRegainHealthEvent.RegainReason.REGEN); // CraftBukkit
             }
 
             this.bL.setProgress(this.getHealth() / this.getMaxHealth());