2019-05-27 09:13:41 +00:00
|
|
|
From ff16b5f55a5a4b182b35a3fcd8b704b7a1aedf03 Mon Sep 17 00:00:00 2001
|
2019-03-24 05:00:55 +00:00
|
|
|
From: Aikar <aikar@aikar.co>
|
|
|
|
Date: Sun, 24 Mar 2019 00:24:52 -0400
|
|
|
|
Subject: [PATCH] Entity#getEntitySpawnReason
|
|
|
|
|
|
|
|
Allows you to return the SpawnReason for why an Entity Spawned
|
|
|
|
|
|
|
|
Pre existing entities will return NATURAL if it was a non
|
|
|
|
persistenting Living Entity, SPAWNER for spawners,
|
|
|
|
or DEFAULT since data was not stored.
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
|
2019-05-27 09:13:41 +00:00
|
|
|
index 35ec15b39..7ded9bc6c 100644
|
2019-03-24 05:00:55 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/Entity.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/Entity.java
|
2019-05-06 02:58:04 +00:00
|
|
|
@@ -68,6 +68,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
|
2019-03-24 05:00:55 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
List<Entity> entitySlice = null;
|
|
|
|
+ public org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason spawnReason;
|
|
|
|
// Paper end
|
|
|
|
static boolean isLevelAtLeast(NBTTagCompound tag, int level) {
|
|
|
|
return tag.hasKey("Bukkit.updateLevel") && tag.getInt("Bukkit.updateLevel") >= level;
|
2019-05-26 01:56:30 +00:00
|
|
|
@@ -1592,6 +1593,9 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
|
2019-05-06 02:58:04 +00:00
|
|
|
if (this.origin != null) {
|
2019-03-24 05:00:55 +00:00
|
|
|
nbttagcompound.set("Paper.Origin", this.createList(origin.getX(), origin.getY(), origin.getZ()));
|
|
|
|
}
|
|
|
|
+ if (spawnReason != null) {
|
|
|
|
+ nbttagcompound.setString("Paper.SpawnReason", spawnReason.name());
|
|
|
|
+ }
|
|
|
|
// Save entity's from mob spawner status
|
|
|
|
if (spawnedViaMobSpawner) {
|
|
|
|
nbttagcompound.setBoolean("Paper.FromMobSpawner", true);
|
2019-05-26 01:56:30 +00:00
|
|
|
@@ -1726,6 +1730,26 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
|
2019-03-24 05:00:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
spawnedViaMobSpawner = nbttagcompound.getBoolean("Paper.FromMobSpawner"); // Restore entity's from mob spawner status
|
|
|
|
+ if (nbttagcompound.hasKey("Paper.SpawnReason")) {
|
|
|
|
+ String spawnReasonName = nbttagcompound.getString("Paper.SpawnReason");
|
|
|
|
+ try {
|
|
|
|
+ spawnReason = org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.valueOf(spawnReasonName);
|
|
|
|
+ } catch (Exception ignored) {
|
|
|
|
+ LogManager.getLogger().error("Unknown SpawnReason " + spawnReasonName + " for " + this);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (spawnReason == null) {
|
|
|
|
+ if (spawnedViaMobSpawner) {
|
|
|
|
+ spawnReason = org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.SPAWNER;
|
2019-05-05 17:19:34 +00:00
|
|
|
+ } else if (this instanceof EntityInsentient && (this instanceof EntityAnimal || this instanceof EntityFish) && !((EntityInsentient) this).isTypeNotPersistent(0.0)) {
|
2019-03-24 05:00:55 +00:00
|
|
|
+ if (!nbttagcompound.getBoolean("PersistenceRequired")) {
|
|
|
|
+ spawnReason = org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.NATURAL;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (spawnReason == null) {
|
|
|
|
+ spawnReason = org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.DEFAULT;
|
|
|
|
+ }
|
|
|
|
// Paper end
|
|
|
|
|
|
|
|
} catch (Throwable throwable) {
|
2019-03-24 17:55:27 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/PlayerList.java b/src/main/java/net/minecraft/server/PlayerList.java
|
2019-05-27 09:13:41 +00:00
|
|
|
index ce66596c6..5645147da 100644
|
2019-03-24 17:55:27 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/PlayerList.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/PlayerList.java
|
2019-05-14 02:20:58 +00:00
|
|
|
@@ -250,7 +250,7 @@ public abstract class PlayerList {
|
2019-05-05 17:19:34 +00:00
|
|
|
// CraftBukkit start
|
|
|
|
WorldServer finalWorldServer = worldserver;
|
|
|
|
Entity entity = EntityTypes.a(nbttagcompound1.getCompound("Entity"), finalWorldServer, (entity1) -> {
|
|
|
|
- return !finalWorldServer.addEntitySerialized(entity1) ? null : entity1;
|
|
|
|
+ return !finalWorldServer.addEntitySerialized(entity1, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.MOUNT) ? null : entity1; // Paper
|
|
|
|
// CraftBukkit end
|
|
|
|
});
|
2019-03-24 17:55:27 +00:00
|
|
|
|
2019-05-05 17:19:34 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java
|
2019-05-27 09:13:41 +00:00
|
|
|
index 9c4ef2e00..1a01e5e69 100644
|
2019-05-05 17:19:34 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/WorldServer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/WorldServer.java
|
2019-05-14 02:20:58 +00:00
|
|
|
@@ -932,6 +932,7 @@ public class WorldServer extends World {
|
2019-05-05 17:19:34 +00:00
|
|
|
// CraftBukkit start
|
|
|
|
private boolean addEntity0(Entity entity, CreatureSpawnEvent.SpawnReason spawnReason) {
|
|
|
|
org.spigotmc.AsyncCatcher.catchOp( "entity add"); // Spigot
|
|
|
|
+ if (entity.spawnReason == null) entity.spawnReason = spawnReason; // Paper
|
|
|
|
if (entity.valid) { MinecraftServer.LOGGER.error("Attempted Double World add on " + entity, new Throwable()); return true; } // Paper
|
|
|
|
if (entity.dead) {
|
|
|
|
// Paper start
|
2019-03-24 05:00:55 +00:00
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
2019-05-27 09:13:41 +00:00
|
|
|
index 1cd3448e5..15042943c 100644
|
2019-03-24 05:00:55 +00:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
2019-05-06 02:58:04 +00:00
|
|
|
@@ -1053,5 +1053,10 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
|
2019-03-24 05:00:55 +00:00
|
|
|
public boolean fromMobSpawner() {
|
|
|
|
return getHandle().spawnedViaMobSpawner;
|
|
|
|
}
|
|
|
|
+
|
2019-05-05 17:19:34 +00:00
|
|
|
+ @Override
|
2019-03-24 05:00:55 +00:00
|
|
|
+ public org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason getEntitySpawnReason() {
|
|
|
|
+ return getHandle().spawnReason;
|
|
|
|
+ }
|
|
|
|
// Paper end
|
|
|
|
}
|
|
|
|
--
|
|
|
|
2.21.0
|
|
|
|
|