papermc/Spigot-Server-Patches/0287-Add-PhantomPreSpawnEvent.patch

91 lines
4.4 KiB
Diff
Raw Normal View History

From a23e2b70f800aa1c6beecc83497f32a23d53dc9d Mon Sep 17 00:00:00 2001
2018-08-27 06:51:20 +00:00
From: BillyGalbreath <Blake.Galbreath@GMail.com>
Date: Sat, 25 Aug 2018 19:56:51 -0500
Subject: [PATCH] Add PhantomPreSpawnEvent
diff --git a/src/main/java/net/minecraft/server/EntityPhantom.java b/src/main/java/net/minecraft/server/EntityPhantom.java
index b62a8227b..82323bf4a 100644
2018-08-27 06:51:20 +00:00
--- a/src/main/java/net/minecraft/server/EntityPhantom.java
+++ b/src/main/java/net/minecraft/server/EntityPhantom.java
@@ -130,6 +130,11 @@ public class EntityPhantom extends EntityFlying implements IMonster {
2018-08-27 06:51:20 +00:00
}
this.setSize(nbttagcompound.getInt("Size"));
+ // Paper start
+ if (nbttagcompound.hasUUID("Paper.SpawningEntity")) {
+ this.spawningEntity = nbttagcompound.getUUID("Paper.SpawningEntity");
+ }
+ // Paper end
2018-08-27 06:51:20 +00:00
}
2019-05-05 08:33:44 +00:00
@Override
@@ -139,6 +144,11 @@ public class EntityPhantom extends EntityFlying implements IMonster {
2019-05-05 08:33:44 +00:00
nbttagcompound.setInt("AY", this.d.getY());
nbttagcompound.setInt("AZ", this.d.getZ());
2018-08-27 06:51:20 +00:00
nbttagcompound.setInt("Size", this.getSize());
+ // Paper start
+ if (this.spawningEntity != null) {
+ nbttagcompound.setUUID("Paper.SpawningEntity", this.spawningEntity);
+ }
+ // Paper end
2018-08-27 06:51:20 +00:00
}
2019-05-05 08:33:44 +00:00
@Override
@@ -185,6 +195,14 @@ public class EntityPhantom extends EntityFlying implements IMonster {
2019-05-05 08:33:44 +00:00
return entitysize.a(f);
2018-08-27 06:51:20 +00:00
}
+ // Paper start
+ java.util.UUID spawningEntity;
+
+ public java.util.UUID getSpawningEntity() {
+ return spawningEntity;
+ }
+ // Paper end
+
class b extends PathfinderGoal {
2019-05-05 08:33:44 +00:00
private final PathfinderTargetCondition b;
2018-08-27 06:51:20 +00:00
diff --git a/src/main/java/net/minecraft/server/MobSpawnerPhantom.java b/src/main/java/net/minecraft/server/MobSpawnerPhantom.java
index add566ea4..f488c22ed 100644
2018-08-27 06:51:20 +00:00
--- a/src/main/java/net/minecraft/server/MobSpawnerPhantom.java
+++ b/src/main/java/net/minecraft/server/MobSpawnerPhantom.java
@@ -52,8 +52,17 @@ public class MobSpawnerPhantom {
2018-08-27 06:51:20 +00:00
int k = 1 + random.nextInt(difficultydamagescaler.a().a() + 1);
for (int l = 0; l < k; ++l) {
+ // Paper start
+ com.destroystokyo.paper.event.entity.PhantomPreSpawnEvent event = new com.destroystokyo.paper.event.entity.PhantomPreSpawnEvent(MCUtil.toLocation(worldserver, blockposition1), ((EntityPlayer) entityhuman).getBukkitEntity(), org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.NATURAL);
2018-08-27 06:51:20 +00:00
+ if (!event.callEvent()) {
+ if (event.shouldAbortSpawn()) {
+ break;
+ }
+ continue;
+ }
+ // Paper end
2019-05-05 08:33:44 +00:00
EntityPhantom entityphantom = (EntityPhantom) EntityTypes.PHANTOM.a((World) worldserver);
2018-08-27 06:51:20 +00:00
-
+ entityphantom.spawningEntity = entityhuman.uniqueID; // Paper
entityphantom.setPositionRotation(blockposition1, 0.0F, 0.0F);
2019-05-05 08:33:44 +00:00
groupdataentity = entityphantom.prepare(worldserver, difficultydamagescaler, EnumMobSpawn.NATURAL, groupdataentity, (NBTTagCompound) null);
worldserver.addEntity(entityphantom, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.NATURAL); // CraftBukkit
2018-08-27 06:51:20 +00:00
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPhantom.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPhantom.java
index 9f9ee9239..2b9731369 100644
2018-08-27 06:51:20 +00:00
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPhantom.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPhantom.java
@@ -35,4 +35,10 @@ public class CraftPhantom extends CraftFlying implements Phantom {
public EntityType getType() {
return EntityType.PHANTOM;
}
+
+ // Paper start
+ public java.util.UUID getSpawningEntity() {
+ return getHandle().getSpawningEntity();
+ }
+ // Paper end
}
--
2.25.0.windows.1
2018-08-27 06:51:20 +00:00