mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-28 03:48:01 +01:00
282 lines
14 KiB
Diff
282 lines
14 KiB
Diff
--- a/net/minecraft/server/EntityEnderDragon.java
|
|
+++ b/net/minecraft/server/EntityEnderDragon.java
|
|
@@ -5,6 +5,17 @@
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
|
|
+// CraftBukkit start
|
|
+import org.bukkit.block.BlockState;
|
|
+import org.bukkit.craftbukkit.event.CraftEventFactory;
|
|
+import org.bukkit.craftbukkit.util.BlockStateListPopulator;
|
|
+import org.bukkit.event.entity.EntityCreatePortalEvent;
|
|
+import org.bukkit.event.entity.EntityExplodeEvent;
|
|
+import org.bukkit.event.entity.EntityRegainHealthEvent;
|
|
+import org.bukkit.event.entity.EntityTargetEvent;
|
|
+import org.bukkit.Bukkit;
|
|
+// CraftBukkit end
|
|
+
|
|
public class EntityEnderDragon extends EntityInsentient implements IComplex, IMonster {
|
|
|
|
public double a;
|
|
@@ -24,9 +35,10 @@
|
|
public float bv;
|
|
public boolean bw;
|
|
public boolean bx;
|
|
- private Entity bA;
|
|
+ public Entity bA; // CraftBukkit - public // PAIL: Target
|
|
public int by;
|
|
public EntityEnderCrystal bz;
|
|
+ private Explosion explosionSource = new Explosion(null, this, Double.NaN, Double.NaN, Double.NaN, Float.NaN, true, true); // CraftBukkit - reusable source for CraftTNTPrimed.getSource()
|
|
|
|
public EntityEnderDragon(World world) {
|
|
super(world);
|
|
@@ -294,12 +306,21 @@
|
|
if (this.bz != null) {
|
|
if (this.bz.dead) {
|
|
if (!this.world.isClientSide) {
|
|
+ CraftEventFactory.entityDamage = this.bz; // CraftBukkit
|
|
this.a(this.bn, DamageSource.explosion((Explosion) null), 10.0F);
|
|
+ CraftEventFactory.entityDamage = null; // CraftBukkit
|
|
}
|
|
|
|
this.bz = null;
|
|
} else if (this.ticksLived % 10 == 0 && this.getHealth() < this.getMaxHealth()) {
|
|
- this.setHealth(this.getHealth() + 1.0F);
|
|
+ // CraftBukkit start
|
|
+ EntityRegainHealthEvent event = new EntityRegainHealthEvent(this.getBukkitEntity(), 1.0D, EntityRegainHealthEvent.RegainReason.ENDER_CRYSTAL);
|
|
+ this.world.getServer().getPluginManager().callEvent(event);
|
|
+
|
|
+ if (!event.isCancelled()) {
|
|
+ this.setHealth((float) (this.getHealth() + event.getAmount()));
|
|
+ }
|
|
+ // CraftBukkit end
|
|
}
|
|
}
|
|
|
|
@@ -368,7 +389,19 @@
|
|
}
|
|
|
|
if (this.random.nextInt(2) == 0 && !arraylist.isEmpty()) {
|
|
- this.bA = (Entity) arraylist.get(this.random.nextInt(arraylist.size()));
|
|
+ // CraftBukkit start
|
|
+ Entity target = (Entity) this.world.players.get(this.random.nextInt(this.world.players.size()));
|
|
+ EntityTargetEvent event = new EntityTargetEvent(this.getBukkitEntity(), target.getBukkitEntity(), EntityTargetEvent.TargetReason.RANDOM_TARGET);
|
|
+ this.world.getServer().getPluginManager().callEvent(event);
|
|
+
|
|
+ if (!event.isCancelled()) {
|
|
+ if (event.getTarget() == null) {
|
|
+ this.bA = null;
|
|
+ } else {
|
|
+ this.bA = ((org.bukkit.craftbukkit.entity.CraftEntity) event.getTarget()).getHandle();
|
|
+ }
|
|
+ }
|
|
+ // CraftBukkit end
|
|
} else {
|
|
boolean flag;
|
|
|
|
@@ -404,6 +437,11 @@
|
|
boolean flag = false;
|
|
boolean flag1 = false;
|
|
|
|
+ // CraftBukkit start - Create a list to hold all the destroyed blocks
|
|
+ List<org.bukkit.block.Block> destroyedBlocks = new java.util.ArrayList<org.bukkit.block.Block>();
|
|
+ org.bukkit.craftbukkit.CraftWorld craftWorld = this.world.getWorld();
|
|
+ // CraftBukkit end
|
|
+
|
|
for (int k1 = i; k1 <= l; ++k1) {
|
|
for (int l1 = j; l1 <= i1; ++l1) {
|
|
for (int i2 = k; i2 <= j1; ++i2) {
|
|
@@ -412,7 +450,11 @@
|
|
|
|
if (block.getMaterial() != Material.AIR) {
|
|
if (block != Blocks.BARRIER && block != Blocks.OBSIDIAN && block != Blocks.END_STONE && block != Blocks.BEDROCK && block != Blocks.COMMAND_BLOCK && this.world.getGameRules().getBoolean("mobGriefing")) {
|
|
- flag1 = this.world.setAir(blockposition) || flag1;
|
|
+ // CraftBukkit start - Add blocks to list rather than destroying them
|
|
+ // flag1 = this.world.setAir(new BlockPosition(blockposition)) || flag1;
|
|
+ flag1 = true;
|
|
+ destroyedBlocks.add(craftWorld.getBlockAt(k1, l1, i2));
|
|
+ // CraftBukkit end
|
|
} else {
|
|
flag = true;
|
|
}
|
|
@@ -422,6 +464,40 @@
|
|
}
|
|
|
|
if (flag1) {
|
|
+ // CraftBukkit start - Set off an EntityExplodeEvent for the dragon exploding all these blocks
|
|
+ org.bukkit.entity.Entity bukkitEntity = this.getBukkitEntity();
|
|
+ EntityExplodeEvent event = new EntityExplodeEvent(bukkitEntity, bukkitEntity.getLocation(), destroyedBlocks, 0F);
|
|
+ Bukkit.getPluginManager().callEvent(event);
|
|
+ if (event.isCancelled()) {
|
|
+ // This flag literally means 'Dragon hit something hard' (Obsidian, White Stone or Bedrock) and will cause the dragon to slow down.
|
|
+ // We should consider adding an event extension for it, or perhaps returning true if the event is cancelled.
|
|
+ return flag;
|
|
+ } else if (event.getYield() == 0F) {
|
|
+ // Yield zero ==> no drops
|
|
+ for (org.bukkit.block.Block block : event.blockList()) {
|
|
+ this.world.setAir(new BlockPosition(block.getX(), block.getY(), block.getZ()));
|
|
+ }
|
|
+ } else {
|
|
+ for (org.bukkit.block.Block block : event.blockList()) {
|
|
+ org.bukkit.Material blockId = block.getType();
|
|
+ if (blockId == org.bukkit.Material.AIR) {
|
|
+ continue;
|
|
+ }
|
|
+
|
|
+ int blockX = block.getX();
|
|
+ int blockY = block.getY();
|
|
+ int blockZ = block.getZ();
|
|
+
|
|
+ Block nmsBlock = org.bukkit.craftbukkit.util.CraftMagicNumbers.getBlock(blockId);
|
|
+ if (nmsBlock.a(explosionSource)) {
|
|
+ nmsBlock.dropNaturally(this.world, new BlockPosition(blockX, blockY, blockZ), nmsBlock.fromLegacyData(block.getData()), event.getYield(), 0);
|
|
+ }
|
|
+ nmsBlock.wasExploded(world, new BlockPosition(blockX, blockY, blockZ), explosionSource);
|
|
+
|
|
+ this.world.setAir(new BlockPosition(blockX, blockY, blockZ));
|
|
+ }
|
|
+ }
|
|
+ // CraftBukkit end
|
|
double d0 = axisalignedbb.a + (axisalignedbb.d - axisalignedbb.a) * (double) this.random.nextFloat();
|
|
double d1 = axisalignedbb.b + (axisalignedbb.e - axisalignedbb.b) * (double) this.random.nextFloat();
|
|
double d2 = axisalignedbb.c + (axisalignedbb.f - axisalignedbb.c) * (double) this.random.nextFloat();
|
|
@@ -469,6 +545,7 @@
|
|
}
|
|
|
|
protected void aZ() {
|
|
+ if (this.dead) return; // CraftBukkit - can't kill what's already dead
|
|
++this.by;
|
|
if (this.by >= 180 && this.by <= 200) {
|
|
float f = (this.random.nextFloat() - 0.5F) * 8.0F;
|
|
@@ -484,7 +561,7 @@
|
|
|
|
if (!this.world.isClientSide) {
|
|
if (this.by > 150 && this.by % 5 == 0 && flag) {
|
|
- i = 1000;
|
|
+ i = this.expToDrop / 12; // CraftBukkit - drop experience as dragon falls from sky. use experience drop from death event. This is now set in getExpReward()
|
|
|
|
while (i > 0) {
|
|
j = EntityExperienceOrb.getOrbValue(i);
|
|
@@ -494,7 +571,23 @@
|
|
}
|
|
|
|
if (this.by == 1) {
|
|
- this.world.a(1018, new BlockPosition(this), 0);
|
|
+ // CraftBukkit start - Use relative location for far away sounds
|
|
+ // this.world.a(1018, 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(1018, new BlockPosition((int) relativeX, (int) this.locY, (int) relativeZ), 0, true));
|
|
+ } else {
|
|
+ player.playerConnection.sendPacket(new PacketPlayOutWorldEvent(1018, new BlockPosition((int) this.locX, (int) this.locY, (int) this.locZ), 0, true));
|
|
+ }
|
|
+ }
|
|
+ // CraftBukkit end
|
|
}
|
|
}
|
|
|
|
@@ -502,7 +595,7 @@
|
|
this.aI = this.yaw += 20.0F;
|
|
if (this.by == 200 && !this.world.isClientSide) {
|
|
if (flag) {
|
|
- i = 2000;
|
|
+ i = this.expToDrop - (10 * this.expToDrop / 12); // CraftBukkit - drop the remaining experience
|
|
|
|
while (i > 0) {
|
|
j = EntityExperienceOrb.getOrbValue(i);
|
|
@@ -522,6 +615,9 @@
|
|
double d0 = 12.25D;
|
|
double d1 = 6.25D;
|
|
|
|
+ // CraftBukkit start - Replace any "this.world" in the following with just "world"!
|
|
+ BlockStateListPopulator world = new BlockStateListPopulator(this.world.getWorld());
|
|
+
|
|
for (int i = -1; i <= 32; ++i) {
|
|
for (int j = -4; j <= 4; ++j) {
|
|
for (int k = -4; k <= 4; ++k) {
|
|
@@ -532,31 +628,51 @@
|
|
|
|
if (i < 0) {
|
|
if (d2 <= 6.25D) {
|
|
- this.world.setTypeUpdate(blockposition1, Blocks.BEDROCK.getBlockData());
|
|
+ world.setTypeUpdate(blockposition1, Blocks.BEDROCK.getBlockData());
|
|
}
|
|
} else if (i > 0) {
|
|
- this.world.setTypeUpdate(blockposition1, Blocks.AIR.getBlockData());
|
|
+ world.setTypeUpdate(blockposition1, Blocks.AIR.getBlockData());
|
|
} else if (d2 > 6.25D) {
|
|
- this.world.setTypeUpdate(blockposition1, Blocks.BEDROCK.getBlockData());
|
|
+ world.setTypeUpdate(blockposition1, Blocks.BEDROCK.getBlockData());
|
|
} else {
|
|
- this.world.setTypeUpdate(blockposition1, Blocks.END_PORTAL.getBlockData());
|
|
+ world.setTypeUpdate(blockposition1, Blocks.END_PORTAL.getBlockData());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
- this.world.setTypeUpdate(blockposition, Blocks.BEDROCK.getBlockData());
|
|
- this.world.setTypeUpdate(blockposition.up(), Blocks.BEDROCK.getBlockData());
|
|
+ world.setTypeUpdate(blockposition, Blocks.BEDROCK.getBlockData());
|
|
+ world.setTypeUpdate(blockposition.up(), Blocks.BEDROCK.getBlockData());
|
|
BlockPosition blockposition2 = blockposition.up(2);
|
|
|
|
- this.world.setTypeUpdate(blockposition2, Blocks.BEDROCK.getBlockData());
|
|
- this.world.setTypeUpdate(blockposition2.west(), Blocks.TORCH.getBlockData().set(BlockTorch.FACING, EnumDirection.EAST));
|
|
- this.world.setTypeUpdate(blockposition2.east(), Blocks.TORCH.getBlockData().set(BlockTorch.FACING, EnumDirection.WEST));
|
|
- this.world.setTypeUpdate(blockposition2.north(), Blocks.TORCH.getBlockData().set(BlockTorch.FACING, EnumDirection.SOUTH));
|
|
- this.world.setTypeUpdate(blockposition2.south(), Blocks.TORCH.getBlockData().set(BlockTorch.FACING, EnumDirection.NORTH));
|
|
- this.world.setTypeUpdate(blockposition.up(3), Blocks.BEDROCK.getBlockData());
|
|
- this.world.setTypeUpdate(blockposition.up(4), Blocks.DRAGON_EGG.getBlockData());
|
|
+ world.setTypeUpdate(blockposition2, Blocks.BEDROCK.getBlockData());
|
|
+ world.setTypeUpdate(blockposition2.west(), Blocks.TORCH.getBlockData().set(BlockTorch.FACING, EnumDirection.EAST));
|
|
+ world.setTypeUpdate(blockposition2.east(), Blocks.TORCH.getBlockData().set(BlockTorch.FACING, EnumDirection.WEST));
|
|
+ world.setTypeUpdate(blockposition2.north(), Blocks.TORCH.getBlockData().set(BlockTorch.FACING, EnumDirection.SOUTH));
|
|
+ world.setTypeUpdate(blockposition2.south(), Blocks.TORCH.getBlockData().set(BlockTorch.FACING, EnumDirection.NORTH));
|
|
+ world.setTypeUpdate(blockposition.up(3), Blocks.BEDROCK.getBlockData());
|
|
+ world.setTypeUpdate(blockposition.up(4), Blocks.DRAGON_EGG.getBlockData());
|
|
+
|
|
+ EntityCreatePortalEvent event = new EntityCreatePortalEvent((org.bukkit.entity.LivingEntity) this.getBukkitEntity(), java.util.Collections.unmodifiableList(world.getList()), org.bukkit.PortalType.ENDER);
|
|
+ this.world.getServer().getPluginManager().callEvent(event);
|
|
+
|
|
+ if (!event.isCancelled()) {
|
|
+ for (BlockState state : event.getBlocks()) {
|
|
+ state.update(true);
|
|
+ }
|
|
+ } else {
|
|
+ for (BlockState state : event.getBlocks()) {
|
|
+ PacketPlayOutBlockChange packet = new PacketPlayOutBlockChange(this.world, new BlockPosition(state.getX(), state.getY(), state.getZ()));
|
|
+ for (Iterator it = this.world.players.iterator(); it.hasNext();) {
|
|
+ EntityHuman entity = (EntityHuman) it.next();
|
|
+ if (entity instanceof EntityPlayer) {
|
|
+ ((EntityPlayer) entity).playerConnection.sendPacket(packet);
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ // CraftBukkit end
|
|
}
|
|
|
|
protected void D() {}
|
|
@@ -584,4 +700,12 @@
|
|
protected float bB() {
|
|
return 5.0F;
|
|
}
|
|
+
|
|
+ // CraftBukkit start
|
|
+ public int getExpReward() {
|
|
+ // This value is equal to the amount of experience dropped while falling from the sky (10 * 1000)
|
|
+ // plus what is dropped when the dragon hits the ground (2000)
|
|
+ return 12000;
|
|
+ }
|
|
+ // CraftBukkit end
|
|
}
|