203 lines
9.8 KiB
Diff

--- a/net/minecraft/world/entity/boss/enderdragon/EntityEnderDragon.java
+++ b/net/minecraft/world/entity/boss/enderdragon/EntityEnderDragon.java
@@ -50,6 +50,18 @@
import net.minecraft.world.phys.Vec3D;
import org.slf4j.Logger;
+// CraftBukkit start
+import net.minecraft.world.item.ItemStack;
+import net.minecraft.world.level.Explosion;
+import net.minecraft.world.level.block.Block;
+import net.minecraft.world.level.block.entity.TileEntity;
+import net.minecraft.world.level.storage.loot.LootTableInfo;
+import net.minecraft.world.level.storage.loot.parameters.LootContextParameters;
+import org.bukkit.craftbukkit.block.CraftBlock;
+import org.bukkit.event.entity.EntityExplodeEvent;
+import org.bukkit.event.entity.EntityRegainHealthEvent;
+// CraftBukkit end
+
public class EntityEnderDragon extends EntityInsentient implements IMonster {
private static final Logger LOGGER = LogUtils.getLogger();
@@ -86,6 +98,7 @@
private final PathPoint[] nodes = new PathPoint[24];
private final int[] nodeAdjacency = new int[24];
private final Path openSet = new Path();
+ private Explosion explosionSource = new Explosion(null, this, null, null, Double.NaN, Double.NaN, Double.NaN, Float.NaN, true, Explosion.Effect.DESTROY); // CraftBukkit - reusable source for CraftTNTPrimed.getSource()
public EntityEnderDragon(EntityTypes<? extends EntityEnderDragon> entitytypes, World world) {
super(EntityTypes.ENDER_DRAGON, world);
@@ -233,7 +246,7 @@
Vec3D vec3d1 = idragoncontroller.getFlyTargetLocation();
- if (vec3d1 != null) {
+ if (vec3d1 != null && idragoncontroller.getPhase() != DragonControllerPhase.HOVERING) { // CraftBukkit - Don't move when hovering
d0 = vec3d1.x - this.getX();
d1 = vec3d1.y - this.getY();
d2 = vec3d1.z - this.getZ();
@@ -374,7 +387,14 @@
if (this.nearestCrystal.isRemoved()) {
this.nearestCrystal = null;
} else if (this.tickCount % 10 == 0 && this.getHealth() < this.getMaxHealth()) {
- this.setHealth(this.getHealth() + 1.0F);
+ // CraftBukkit start
+ EntityRegainHealthEvent event = new EntityRegainHealthEvent(this.getBukkitEntity(), 1.0F, EntityRegainHealthEvent.RegainReason.ENDER_CRYSTAL);
+ this.level.getCraftServer().getPluginManager().callEvent(event);
+
+ if (!event.isCancelled()) {
+ this.setHealth((float) (this.getHealth() + event.getAmount()));
+ }
+ // CraftBukkit end
}
}
@@ -449,6 +469,9 @@
int j1 = MathHelper.floor(axisalignedbb.maxZ);
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>();
+ // CraftBukkit end
for (int k1 = i; k1 <= l; ++k1) {
for (int l1 = j; l1 <= i1; ++l1) {
@@ -458,7 +481,11 @@
if (!iblockdata.isAir() && !iblockdata.is(TagsBlock.DRAGON_TRANSPARENT)) {
if (this.level.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING) && !iblockdata.is(TagsBlock.DRAGON_IMMUNE)) {
- flag1 = this.level.removeBlock(blockposition, false) || flag1;
+ // CraftBukkit start - Add blocks to list rather than destroying them
+ // flag1 = this.level.removeBlock(blockposition, false) || flag1;
+ flag1 = true;
+ destroyedBlocks.add(CraftBlock.at(level, blockposition));
+ // CraftBukkit end
} else {
flag = true;
}
@@ -467,6 +494,51 @@
}
}
+ // CraftBukkit start - Set off an EntityExplodeEvent for the dragon exploding all these blocks
+ // SPIGOT-4882: don't fire event if nothing hit
+ if (!flag1) {
+ return flag;
+ }
+
+ org.bukkit.entity.Entity bukkitEntity = this.getBukkitEntity();
+ EntityExplodeEvent event = new EntityExplodeEvent(bukkitEntity, bukkitEntity.getLocation(), destroyedBlocks, 0F);
+ bukkitEntity.getServer().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.level.removeBlock(new BlockPosition(block.getX(), block.getY(), block.getZ()), false);
+ }
+ } else {
+ for (org.bukkit.block.Block block : event.blockList()) {
+ org.bukkit.Material blockId = block.getType();
+ if (blockId.isAir()) {
+ continue;
+ }
+
+ CraftBlock craftBlock = ((CraftBlock) block);
+ BlockPosition blockposition = craftBlock.getPosition();
+
+ Block nmsBlock = craftBlock.getNMS().getBlock();
+ if (nmsBlock.dropFromExplosion(explosionSource)) {
+ TileEntity tileentity = craftBlock.getNMS().hasBlockEntity() ? this.level.getBlockEntity(blockposition) : null;
+ LootTableInfo.Builder loottableinfo_builder = (new LootTableInfo.Builder((WorldServer) this.level)).withRandom(this.level.random).withParameter(LootContextParameters.ORIGIN, Vec3D.atCenterOf(blockposition)).withParameter(LootContextParameters.TOOL, ItemStack.EMPTY).withParameter(LootContextParameters.EXPLOSION_RADIUS, 1.0F / event.getYield()).withOptionalParameter(LootContextParameters.BLOCK_ENTITY, tileentity);
+
+ craftBlock.getNMS().getDrops(loottableinfo_builder).forEach((itemstack) -> {
+ Block.popResource(level, blockposition, itemstack);
+ });
+ craftBlock.getNMS().spawnAfterBreak((WorldServer) level, blockposition, ItemStack.EMPTY, false);
+ }
+ nmsBlock.wasExploded(level, blockposition, explosionSource);
+
+ this.level.removeBlock(blockposition, false);
+ }
+ }
+ // CraftBukkit end
+
if (flag1) {
BlockPosition blockposition1 = new BlockPosition(i + this.random.nextInt(l - i + 1), j + this.random.nextInt(i1 - j + 1), k + this.random.nextInt(j1 - k + 1));
@@ -531,6 +603,21 @@
}
+ // CraftBukkit start - SPIGOT-2420: Special case, the ender dragon drops 12000 xp for the first kill and 500 xp for every other kill and this over time.
+ @Override
+ public int getExpReward() {
+ // CraftBukkit - Moved from #tickDeath method
+ boolean flag = this.level.getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT);
+ short short0 = 500;
+
+ if (this.dragonFight != null && !this.dragonFight.hasPreviouslyKilledDragon()) {
+ short0 = 12000;
+ }
+
+ return flag ? short0 : 0;
+ }
+ // CraftBukkit end
+
@Override
protected void tickDeath() {
if (this.dragonFight != null) {
@@ -546,15 +633,20 @@
this.level.addParticle(Particles.EXPLOSION_EMITTER, this.getX() + (double) f, this.getY() + 2.0D + (double) f1, this.getZ() + (double) f2, 0.0D, 0.0D, 0.0D);
}
+ // CraftBukkit start - SPIGOT-2420: Moved up to #getExpReward method
+ /*
boolean flag = this.level.getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT);
short short0 = 500;
if (this.dragonFight != null && !this.dragonFight.hasPreviouslyKilledDragon()) {
short0 = 12000;
}
+ */
+ int short0 = expToDrop;
+ // CraftBukkit end
if (this.level instanceof WorldServer) {
- if (this.dragonDeathTime > 150 && this.dragonDeathTime % 5 == 0 && flag) {
+ if (this.dragonDeathTime > 150 && this.dragonDeathTime % 5 == 0 && true) { // CraftBukkit - SPIGOT-2420: Already checked for the game rule when calculating the xp
EntityExperienceOrb.award((WorldServer) this.level, this.position(), MathHelper.floor((float) short0 * 0.08F));
}
@@ -567,7 +659,7 @@
this.setYRot(this.getYRot() + 20.0F);
this.yBodyRot = this.getYRot();
if (this.dragonDeathTime == 200 && this.level instanceof WorldServer) {
- if (flag) {
+ if (true) { // CraftBukkit - SPIGOT-2420: Already checked for the game rule when calculating the xp
EntityExperienceOrb.award((WorldServer) this.level, this.position(), MathHelper.floor((float) short0 * 0.2F));
}
@@ -788,6 +880,7 @@
super.addAdditionalSaveData(nbttagcompound);
nbttagcompound.putInt("DragonPhase", this.phaseManager.getCurrentPhase().getPhase().getId());
nbttagcompound.putInt("DragonDeathTime", this.dragonDeathTime);
+ nbttagcompound.putInt("Bukkit.expToDrop", expToDrop); // CraftBukkit - SPIGOT-2420: The ender dragon drops xp over time which can also happen between server starts
}
@Override
@@ -801,6 +894,11 @@
this.dragonDeathTime = nbttagcompound.getInt("DragonDeathTime");
}
+ // CraftBukkit start - SPIGOT-2420: The ender dragon drops xp over time which can also happen between server starts
+ if (nbttagcompound.contains("Bukkit.expToDrop")) {
+ this.expToDrop = nbttagcompound.getInt("Bukkit.expToDrop");
+ }
+ // CraftBukkit end
}
@Override