Paper/nms-patches/EntityWither.patch

79 lines
4.1 KiB
Diff
Raw Normal View History

--- /home/matt/mc-dev-private//net/minecraft/server/EntityWither.java 2015-03-07 15:02:37.910567217 +0000
+++ src/main/java/net/minecraft/server/EntityWither.java 2015-03-07 15:02:37.910567217 +0000
@@ -5,6 +5,12 @@
import java.util.Iterator;
import java.util.List;
+// 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 {
2015-02-26 23:41:06 +01:00
private float[] a = new float[2];
@@ -168,13 +174,38 @@
if (this.cl() > 0) {
i = this.cl() - 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(1013, 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
2015-02-26 23:41:06 +01:00
+
+ // CraftBukkit start - Use relative location for far away sounds
+ // this.world.a(1013, 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(1013, new BlockPosition((int) relativeX, (int) this.locY, (int) relativeZ), 0, true));
+ } else {
+ player.playerConnection.sendPacket(new PacketPlayOutWorldEvent(1013, new BlockPosition((int) this.locX, (int) this.locY, (int) this.locZ), 0, true));
+ }
+ }
+ // CraftBukkit end
}
this.r(i);
if (this.ticksLived % 10 == 0) {
- this.heal(10.0F);
+ this.heal(10.0F, EntityRegainHealthEvent.RegainReason.WITHER_SPAWN); // CraftBukkit
}
} else {
2015-02-26 23:41:06 +01:00
@@ -264,6 +295,11 @@
Block block = this.world.getType(blockposition).getBlock();
2015-02-26 23:41:06 +01:00
if (block.getMaterial() != Material.AIR && a(block)) {
+ // CraftBukkit start
+ if (CraftEventFactory.callEntityChangeBlockEvent(this, j2, k2, l2, Blocks.AIR, 0).isCancelled()) {
+ continue;
+ }
+ // CraftBukkit end
2015-02-26 23:41:06 +01:00
flag = this.world.setAir(blockposition, true) || flag;
}
}
2015-02-26 23:41:06 +01:00
@@ -277,7 +313,7 @@
}
if (this.ticksLived % 20 == 0) {
- this.heal(1.0F);
+ this.heal(1.0F, EntityRegainHealthEvent.RegainReason.REGEN); // CraftBukkit
}
}