2020-05-06 11:48:49 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
2019-03-24 06:00:55 +01: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.
|
|
|
|
|
2021-03-16 08:19:45 +01:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/level/WorldServer.java b/src/main/java/net/minecraft/server/level/WorldServer.java
|
|
|
|
index 690e40aeed96a8d83e86c9aff0e910f6aa97c1c9..2a510940525fda83707e2a587e18ce34e5822af1 100644
|
|
|
|
--- a/src/main/java/net/minecraft/server/level/WorldServer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/level/WorldServer.java
|
|
|
|
@@ -1039,6 +1039,7 @@ public class WorldServer extends World implements GeneratorAccessSeed {
|
|
|
|
// 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
|
|
|
|
// Paper start
|
|
|
|
if (entity.valid) {
|
|
|
|
MinecraftServer.LOGGER.error("Attempted Double World add on " + entity, new Throwable());
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
|
|
index 587fb2246b1ede6d292afe42b826e32423ca3a56..59155d9b39ed6b27dd46ea586ab07360840db5e7 100644
|
|
|
|
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
|
|
@@ -333,7 +333,7 @@ public abstract class PlayerList {
|
|
|
|
// CraftBukkit start
|
|
|
|
WorldServer finalWorldServer = worldserver1;
|
|
|
|
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
|
|
|
|
});
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
|
|
index 6f4dd6226a23323c1af95380a8d38ee6d19caf60..f024db3fe2a9fb9af536fe144b9e871712ae327a 100644
|
|
|
|
--- a/src/main/java/net/minecraft/world/entity/Entity.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
|
|
@@ -157,6 +157,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, ne
|
2019-03-24 06:00:55 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
List<Entity> entitySlice = null;
|
|
|
|
+ public org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason spawnReason;
|
|
|
|
// Paper end
|
2019-12-12 17:20:43 +01:00
|
|
|
|
|
|
|
public com.destroystokyo.paper.loottable.PaperLootableInventoryData lootableData; // Paper
|
2021-03-16 08:19:45 +01:00
|
|
|
@@ -1672,6 +1673,9 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, ne
|
2019-05-06 04:58:04 +02:00
|
|
|
if (this.origin != null) {
|
2019-03-24 06:00:55 +01: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);
|
2021-03-16 08:19:45 +01:00
|
|
|
@@ -1806,6 +1810,26 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, ne
|
2019-03-24 06:00:55 +01: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 19:19:34 +02:00
|
|
|
+ } else if (this instanceof EntityInsentient && (this instanceof EntityAnimal || this instanceof EntityFish) && !((EntityInsentient) this).isTypeNotPersistent(0.0)) {
|
2019-03-24 06:00:55 +01: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) {
|
2021-03-16 08:19:45 +01:00
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/MobSpawnerAbstract.java b/src/main/java/net/minecraft/world/level/MobSpawnerAbstract.java
|
|
|
|
index 0a23fc173cca32b9e910e6c8c638b0b51a94cac2..ca753267a06643b6f7224140950aa7f47cea64ad 100644
|
|
|
|
--- a/src/main/java/net/minecraft/world/level/MobSpawnerAbstract.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/MobSpawnerAbstract.java
|
|
|
|
@@ -182,6 +182,7 @@ public abstract class MobSpawnerAbstract {
|
2020-08-25 04:22:08 +02:00
|
|
|
// Spigot End
|
|
|
|
}
|
2020-07-05 03:54:39 +02:00
|
|
|
entity.spawnedViaMobSpawner = true; // Paper
|
2020-08-25 04:22:08 +02:00
|
|
|
+ entity.spawnReason = org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.SPAWNER; // Paper
|
|
|
|
flag = true; // Paper
|
|
|
|
// Spigot Start
|
|
|
|
if (org.bukkit.craftbukkit.event.CraftEventFactory.callSpawnerSpawnEvent(entity, blockposition).isCancelled()) {
|
2019-03-24 06:00:55 +01:00
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
2021-03-16 08:19:45 +01:00
|
|
|
index 3642b17cafffd2818ee7a18d26bc25645f596115..93bbf63e9d38f32d5528c7693633d4b65655bb9d 100644
|
2019-03-24 06:00:55 +01:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
2021-03-16 08:19:45 +01:00
|
|
|
@@ -1106,5 +1106,10 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
|
2019-03-24 06:00:55 +01:00
|
|
|
public boolean fromMobSpawner() {
|
|
|
|
return getHandle().spawnedViaMobSpawner;
|
|
|
|
}
|
|
|
|
+
|
2019-05-05 19:19:34 +02:00
|
|
|
+ @Override
|
2019-03-24 06:00:55 +01:00
|
|
|
+ public org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason getEntitySpawnReason() {
|
|
|
|
+ return getHandle().spawnReason;
|
|
|
|
+ }
|
|
|
|
// Paper end
|
|
|
|
}
|