3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-21 05:50:05 +01:00
Paper/nms-patches/EntityEnderDragon.patch

282 Zeilen
14 KiB
Diff

--- /home/matt/mc-dev-private//net/minecraft/server/EntityEnderDragon.java 2015-03-07 15:02:37.630567220 +0000
+++ src/main/java/net/minecraft/server/EntityEnderDragon.java 2015-03-07 15:02:37.630567220 +0000
@@ -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;
2015-02-26 23:41:06 +01:00
@@ -24,9 +35,10 @@
public float bv;
public boolean bw;
public boolean bx;
- private Entity bA;
+ public Entity bA; // CraftBukkit - public
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);
2015-02-26 23:41:06 +01:00
@@ -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
}
2015-02-26 23:41:06 +01:00
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
}
}
2015-02-26 23:41:06 +01:00
@@ -368,7 +389,19 @@
}
if (this.random.nextInt(2) == 0 && !arraylist.isEmpty()) {
2015-02-26 23:41:06 +01:00
- 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) {
2015-02-26 23:41:06 +01:00
+ this.bA = null;
+ } else {
2015-02-26 23:41:06 +01:00
+ this.bA = ((org.bukkit.craftbukkit.entity.CraftEntity) event.getTarget()).getHandle();
+ }
+ }
+ // CraftBukkit end
} else {
boolean flag;
2015-02-26 23:41:06 +01:00
@@ -404,6 +437,11 @@
boolean flag = false;
boolean flag1 = false;
2015-02-26 23:41:06 +01:00
+ // 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
2015-02-26 23:41:06 +01:00
+
for (int k1 = i; k1 <= l; ++k1) {
for (int l1 = j; l1 <= i1; ++l1) {
2015-02-26 23:41:06 +01:00
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")) {
2015-02-26 23:41:06 +01:00
- flag1 = this.world.setAir(blockposition) || flag1;
+ // CraftBukkit start - Add blocks to list rather than destroying them
2015-02-26 23:41:06 +01:00
+ // flag1 = this.world.setAir(new BlockPosition(blockposition)) || flag1;
+ flag1 = true;
+ destroyedBlocks.add(craftWorld.getBlockAt(k1, l1, i2));
+ // CraftBukkit end
} else {
flag = true;
}
2015-02-26 23:41:06 +01:00
@@ -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));
+ }
+ }
2015-02-26 23:41:06 +01:00
+ // 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();
2015-02-26 23:41:06 +01:00
@@ -469,6 +545,7 @@
}
2015-02-26 23:41:06 +01:00
protected void aZ() {
+ if (this.dead) return; // CraftBukkit - can't kill what's already dead
2015-02-26 23:41:06 +01:00
++this.by;
if (this.by >= 180 && this.by <= 200) {
float f = (this.random.nextFloat() - 0.5F) * 8.0F;
2015-02-26 23:41:06 +01:00
@@ -484,7 +561,7 @@
2015-02-26 23:41:06 +01:00
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);
2015-02-26 23:41:06 +01:00
@@ -494,7 +571,23 @@
}
2015-02-26 23:41:06 +01:00
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
}
}
2015-02-26 23:41:06 +01:00
@@ -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
2015-02-26 23:41:06 +01:00
while (i > 0) {
j = EntityExperienceOrb.getOrbValue(i);
@@ -522,6 +615,9 @@
double d0 = 12.25D;
double d1 = 6.25D;
2015-02-26 23:41:06 +01:00
+ // CraftBukkit start - Replace any "this.world" in the following with just "world"!
+ BlockStateListPopulator world = new BlockStateListPopulator(this.world.getWorld());
2015-02-26 23:41:06 +01:00
+
for (int i = -1; i <= 32; ++i) {
for (int j = -4; j <= 4; ++j) {
2015-02-26 23:41:06 +01:00
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() {}
2015-02-26 23:41:06 +01:00
@@ -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
}