mirror of
https://hub.spigotmc.org/stash/scm/spigot/craftbukkit.git
synced 2024-11-22 17:06:16 +00:00
234 lines
11 KiB
Diff
234 lines
11 KiB
Diff
--- a/net/minecraft/world/entity/boss/enderdragon/EntityEnderDragon.java
|
|
+++ b/net/minecraft/world/entity/boss/enderdragon/EntityEnderDragon.java
|
|
@@ -52,6 +52,22 @@
|
|
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.ServerExplosion;
|
|
+import net.minecraft.world.level.block.Block;
|
|
+import net.minecraft.world.level.block.entity.TileEntity;
|
|
+import net.minecraft.world.level.storage.loot.LootParams;
|
|
+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;
|
|
+import org.bukkit.event.entity.EntityRemoveEvent;
|
|
+import org.bukkit.craftbukkit.event.CraftEventFactory;
|
|
+// CraftBukkit end
|
|
+
|
|
public class EntityEnderDragon extends EntityInsentient implements IMonster {
|
|
|
|
private static final Logger LOGGER = LogUtils.getLogger();
|
|
@@ -88,6 +104,7 @@
|
|
private final PathPoint[] nodes;
|
|
private final int[] nodeAdjacency;
|
|
private final Path openSet;
|
|
+ private final Explosion explosionSource; // CraftBukkit - reusable source for CraftTNTPrimed.getSource()
|
|
|
|
public EntityEnderDragon(EntityTypes<? extends EntityEnderDragon> entitytypes, World world) {
|
|
super(EntityTypes.ENDER_DRAGON, world);
|
|
@@ -108,6 +125,7 @@
|
|
this.setHealth(this.getMaxHealth());
|
|
this.noPhysics = true;
|
|
this.phaseManager = new DragonControllerManager(this);
|
|
+ this.explosionSource = new ServerExplosion(world.getMinecraftWorld(), this, null, null, new Vec3D(Double.NaN, Double.NaN, Double.NaN), Float.NaN, true, Explosion.Effect.DESTROY); // CraftBukkit
|
|
}
|
|
|
|
public void setDragonFight(EnderDragonBattle enderdragonbattle) {
|
|
@@ -218,7 +236,7 @@
|
|
|
|
Vec3D vec3d1 = idragoncontroller.getFlyTargetLocation();
|
|
|
|
- if (vec3d1 != null) {
|
|
+ if (vec3d1 != null && idragoncontroller.getPhase() != DragonControllerPhase.HOVERING) { // CraftBukkit - Don't move when hovering
|
|
double d0 = vec3d1.x - this.getX();
|
|
double d1 = vec3d1.y - this.getY();
|
|
double d2 = vec3d1.z - this.getZ();
|
|
@@ -379,7 +397,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
|
|
}
|
|
}
|
|
|
|
@@ -458,6 +483,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) {
|
|
@@ -467,7 +495,11 @@
|
|
|
|
if (!iblockdata.isAir() && !iblockdata.is(TagsBlock.DRAGON_TRANSPARENT)) {
|
|
if (worldserver.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING) && !iblockdata.is(TagsBlock.DRAGON_IMMUNE)) {
|
|
- flag1 = worldserver.removeBlock(blockposition, false) || flag1;
|
|
+ // CraftBukkit start - Add blocks to list rather than destroying them
|
|
+ // flag1 = worldserver.removeBlock(blockposition, false) || flag1;
|
|
+ flag1 = true;
|
|
+ destroyedBlocks.add(CraftBlock.at(worldserver, blockposition));
|
|
+ // CraftBukkit end
|
|
} else {
|
|
flag = true;
|
|
}
|
|
@@ -476,6 +508,49 @@
|
|
}
|
|
}
|
|
|
|
+ // 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;
|
|
+ }
|
|
+
|
|
+ EntityExplodeEvent event = CraftEventFactory.callEntityExplodeEvent(this, destroyedBlocks, 0F, explosionSource.getBlockInteraction());
|
|
+ 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;
|
|
+ LootParams.a loottableinfo_builder = (new LootParams.a((WorldServer) this.level())).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(this.level(), blockposition, itemstack);
|
|
+ });
|
|
+ craftBlock.getNMS().spawnAfterBreak((WorldServer) this.level(), blockposition, ItemStack.EMPTY, false);
|
|
+ }
|
|
+ nmsBlock.wasExploded((WorldServer) this.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,7 +606,7 @@
|
|
|
|
@Override
|
|
public void kill(WorldServer worldserver) {
|
|
- this.remove(Entity.RemovalReason.KILLED);
|
|
+ this.remove(Entity.RemovalReason.KILLED, EntityRemoveEvent.Cause.DEATH); // CraftBukkit - add Bukkit remove cause
|
|
this.gameEvent(GameEvent.ENTITY_DIE);
|
|
if (this.dragonFight != null) {
|
|
this.dragonFight.updateDragon(this);
|
|
@@ -540,6 +615,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(WorldServer worldserver, Entity entity) {
|
|
+ // CraftBukkit - Moved from #tickDeath method
|
|
+ boolean flag = worldserver.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) {
|
|
@@ -555,16 +645,21 @@
|
|
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
|
|
+ /*
|
|
short short0 = 500;
|
|
|
|
if (this.dragonFight != null && !this.dragonFight.hasPreviouslyKilledDragon()) {
|
|
short0 = 12000;
|
|
}
|
|
+ */
|
|
+ int short0 = expToDrop;
|
|
+ // CraftBukkit end
|
|
|
|
World world = this.level();
|
|
|
|
if (world instanceof WorldServer worldserver) {
|
|
- if (this.dragonDeathTime > 150 && this.dragonDeathTime % 5 == 0 && worldserver.getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT)) {
|
|
+ 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.position(), MathHelper.floor((float) short0 * 0.08F));
|
|
}
|
|
|
|
@@ -577,8 +672,8 @@
|
|
if (this.dragonDeathTime == 200) {
|
|
world = this.level();
|
|
if (world instanceof WorldServer) {
|
|
- worldserver = (WorldServer) world;
|
|
- if (worldserver.getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT)) {
|
|
+ WorldServer worldserver = (WorldServer) world; // CraftBukkit - decompile error
|
|
+ if (true) { // CraftBukkit - SPIGOT-2420: Already checked for the game rule when calculating the xp
|
|
EntityExperienceOrb.award(worldserver, this.position(), MathHelper.floor((float) short0 * 0.2F));
|
|
}
|
|
|
|
@@ -586,7 +681,7 @@
|
|
this.dragonFight.setDragonKilled(this);
|
|
}
|
|
|
|
- this.remove(Entity.RemovalReason.KILLED);
|
|
+ this.remove(Entity.RemovalReason.KILLED, EntityRemoveEvent.Cause.DEATH); // CraftBukkit - add Bukkit remove cause
|
|
this.gameEvent(GameEvent.ENTITY_DIE);
|
|
}
|
|
}
|
|
@@ -800,6 +895,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
|
|
@@ -813,6 +909,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
|