3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-24 15:20:11 +01:00
Paper/nms-patches/EntityEnderDragon.patch
2020-08-12 07:00:00 +10:00

125 Zeilen
6.3 KiB
Diff

--- a/net/minecraft/server/EntityEnderDragon.java
+++ b/net/minecraft/server/EntityEnderDragon.java
@@ -6,7 +6,13 @@
import javax.annotation.Nullable;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
+// CraftBukkit start
+import org.bukkit.craftbukkit.block.CraftBlock;
+import org.bukkit.event.entity.EntityExplodeEvent;
+import org.bukkit.event.entity.EntityRegainHealthEvent;
+// CraftBukkit end
+// PAIL: Fixme
public class EntityEnderDragon extends EntityInsentient implements IMonster {
private static final Logger LOGGER = LogManager.getLogger();
@@ -38,6 +44,7 @@
private final PathPoint[] bJ = new PathPoint[24];
private final int[] bK = new int[24];
private final Path bL = 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);
@@ -175,7 +182,7 @@
Vec3D vec3d1 = idragoncontroller.g();
- if (vec3d1 != null) {
+ if (vec3d1 != null && idragoncontroller.getControllerPhase() != DragonControllerPhase.HOVER) { // CraftBukkit - Don't move when hovering
d0 = vec3d1.x - this.locX();
d1 = vec3d1.y - this.locY();
d2 = vec3d1.z - this.locZ();
@@ -313,7 +320,14 @@
if (this.currentEnderCrystal.dead) {
this.currentEnderCrystal = 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.0F, EntityRegainHealthEvent.RegainReason.ENDER_CRYSTAL);
+ this.world.getServer().getPluginManager().callEvent(event);
+
+ if (!event.isCancelled()) {
+ this.setHealth((float) (this.getHealth() + event.getAmount()));
+ }
+ // CraftBukkit end
}
}
@@ -388,6 +402,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) {
@@ -398,7 +415,11 @@
if (!iblockdata.isAir() && iblockdata.getMaterial() != Material.FIRE) {
if (this.world.getGameRules().getBoolean(GameRules.MOB_GRIEFING) && !TagsBlock.DRAGON_IMMUNE.isTagged(block)) {
- flag1 = this.world.a(blockposition, false) || flag1;
+ // CraftBukkit start - Add blocks to list rather than destroying them
+ // flag1 = this.world.a(blockposition, false) || flag1;
+ flag1 = true;
+ destroyedBlocks.add(CraftBlock.at(world, blockposition));
+ // CraftBukkit end
} else {
flag = true;
}
@@ -407,6 +428,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.world.a(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.a(explosionSource)) {
+ TileEntity tileentity = nmsBlock.isTileEntity() ? this.world.getTileEntity(blockposition) : null;
+ LootTableInfo.Builder loottableinfo_builder = (new LootTableInfo.Builder((WorldServer) this.world)).a(this.world.random).set(LootContextParameters.ORIGIN, Vec3D.a(blockposition)).set(LootContextParameters.TOOL, ItemStack.b).set(LootContextParameters.EXPLOSION_RADIUS, 1.0F / event.getYield()).setOptional(LootContextParameters.BLOCK_ENTITY, tileentity);
+
+ craftBlock.getNMS().a(loottableinfo_builder).forEach((itemstack) -> {
+ Block.a(world, blockposition, itemstack);
+ });
+ craftBlock.getNMS().dropNaturally((WorldServer) world, blockposition, ItemStack.b);
+ }
+ nmsBlock.wasExploded(world, blockposition, explosionSource);
+
+ this.world.a(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));