Paper/nms-patches/EntityEnderDragon.patch

117 lines
5.9 KiB
Diff
Raw Normal View History

2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/EntityEnderDragon.java
+++ b/net/minecraft/server/EntityEnderDragon.java
2019-04-23 04:00:00 +02:00
@@ -6,7 +6,13 @@
2016-05-10 13:47:39 +02:00
import javax.annotation.Nullable;
2016-02-29 22:32:46 +01:00
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
+// CraftBukkit start
2019-04-23 04:00:00 +02:00
+import org.bukkit.craftbukkit.block.CraftBlock;
+import org.bukkit.event.entity.EntityExplodeEvent;
+import org.bukkit.event.entity.EntityRegainHealthEvent;
+// CraftBukkit end
2016-02-29 22:32:46 +01:00
+// PAIL: Fixme
2019-04-23 04:00:00 +02:00
public class EntityEnderDragon extends EntityInsentient implements IMonster {
2019-04-25 04:00:00 +02:00
private static final Logger LOGGER = LogManager.getLogger();
2019-04-23 04:00:00 +02:00
@@ -35,6 +41,7 @@
private final PathPoint[] bT = new PathPoint[24];
private final int[] bU = new int[24];
private final Path bV = new Path();
+ private Explosion explosionSource = new Explosion(null, this, Double.NaN, Double.NaN, Double.NaN, Float.NaN, true, Explosion.Effect.DESTROY); // CraftBukkit - reusable source for CraftTNTPrimed.getSource()
2019-04-23 04:00:00 +02:00
public EntityEnderDragon(EntityTypes<? extends EntityEnderDragon> entitytypes, World world) {
2018-07-15 02:00:00 +02:00
super(EntityTypes.ENDER_DRAGON, world);
2019-04-23 04:00:00 +02:00
@@ -173,7 +180,7 @@
2019-04-23 04:00:00 +02:00
Vec3D vec3d1 = idragoncontroller.g();
2019-04-23 04:00:00 +02:00
- 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;
@@ -315,7 +322,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
}
}
2019-04-23 04:00:00 +02:00
@@ -388,6 +402,9 @@
2018-10-22 21:00:00 +02:00
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) {
2019-04-23 04:00:00 +02:00
@@ -398,7 +415,11 @@
if (!iblockdata.isAir() && iblockdata.getMaterial() != Material.FIRE) {
if (this.world.getGameRules().getBoolean("mobGriefing") && !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;
2019-04-23 04:00:00 +02:00
}
@@ -407,6 +428,43 @@
}
}
+ // 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);
+ 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()) {
2019-04-23 04:00:00 +02:00
+ 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 == org.bukkit.Material.AIR) {
+ continue;
+ }
+
2019-04-23 04:00:00 +02:00
+ CraftBlock craftBlock = ((CraftBlock) block);
+ BlockPosition blockposition = craftBlock.getPosition();
+
2019-04-23 04:00:00 +02:00
+ Block nmsBlock = craftBlock.getNMS().getBlock();
+ if (nmsBlock.a(explosionSource)) {
2019-04-23 04:00:00 +02:00
+ 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.POSITION, blockposition).set(LootContextParameters.TOOL, ItemStack.a).set(LootContextParameters.EXPLOSION_RADIUS, 1.0F / event.getYield()).setOptional(LootContextParameters.BLOCK_ENTITY, tileentity);
+
+ Block.b(craftBlock.getNMS(), loottableinfo_builder);
+ }
2019-04-23 04:00:00 +02:00
+ nmsBlock.wasExploded(world, blockposition, explosionSource);
+
2019-04-23 04:00:00 +02:00
+ this.world.a(blockposition, false);
+ }
+ }
+ // CraftBukkit end
+
if (flag1) {
2019-04-23 04:00:00 +02:00
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));