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.
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
|
2020-09-19 13:29:53 +02:00
|
|
|
index 0d4d619d89f0803eac78db8f167f88fe32e1f597..9b8ee66bea818a52b89acaf56d182b0ff7201d92 100644
|
2019-03-24 06:00:55 +01:00
|
|
|
--- a/src/main/java/net/minecraft/server/Entity.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/Entity.java
|
2020-09-11 00:02:39 +02:00
|
|
|
@@ -72,6 +72,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
|
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
|
2020-09-19 13:29:53 +02:00
|
|
|
@@ -1586,6 +1587,9 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
|
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);
|
2020-09-19 13:29:53 +02:00
|
|
|
@@ -1720,6 +1724,26 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
|
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) {
|
2020-07-05 03:54:39 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/MobSpawnerAbstract.java b/src/main/java/net/minecraft/server/MobSpawnerAbstract.java
|
2020-08-25 04:22:08 +02:00
|
|
|
index 1aecc84479b00a019a5b68f5e726d1c2965ae0f7..c3a5db97fd85b31c6b4bce93527b9d0e16a79a45 100644
|
2020-07-05 03:54:39 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/MobSpawnerAbstract.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/MobSpawnerAbstract.java
|
2020-08-25 04:22:08 +02:00
|
|
|
@@ -165,6 +165,7 @@ public abstract class MobSpawnerAbstract {
|
|
|
|
// 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 18:55:27 +01:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/PlayerList.java b/src/main/java/net/minecraft/server/PlayerList.java
|
2020-08-31 14:30:51 +02:00
|
|
|
index cb04de23dd8b506ebfd07d60acd082d6b7e14528..fbed3c1012c5b6fe61598ae6fae64edc2ad2e490 100644
|
2019-03-24 18:55:27 +01:00
|
|
|
--- a/src/main/java/net/minecraft/server/PlayerList.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/PlayerList.java
|
2020-06-29 00:44:34 +02:00
|
|
|
@@ -262,7 +262,7 @@ public abstract class PlayerList {
|
2019-05-05 19:19:34 +02:00
|
|
|
// CraftBukkit start
|
2020-06-25 16:09:55 +02:00
|
|
|
WorldServer finalWorldServer = worldserver1;
|
2019-05-05 19:19:34 +02:00
|
|
|
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 18:55:27 +01:00
|
|
|
|
2019-05-05 19:19:34 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java
|
2020-09-11 01:47:58 +02:00
|
|
|
index d6c86ce6a6a23ac8e889b0a9e7b8b7b8513ba5d1..21c0450d10e34ba066325af1b1bf77326149b0b1 100644
|
2019-05-05 19:19:34 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/WorldServer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/WorldServer.java
|
2020-09-11 00:02:39 +02:00
|
|
|
@@ -925,6 +925,7 @@ public class WorldServer extends World implements GeneratorAccessSeed {
|
2019-05-05 19:19:34 +02:00
|
|
|
// CraftBukkit start
|
|
|
|
private boolean addEntity0(Entity entity, CreatureSpawnEvent.SpawnReason spawnReason) {
|
2019-07-23 21:17:32 +02:00
|
|
|
org.spigotmc.AsyncCatcher.catchOp("entity add"); // Spigot
|
2019-05-05 19:19:34 +02:00
|
|
|
+ if (entity.spawnReason == null) entity.spawnReason = spawnReason; // Paper
|
2019-08-15 04:37:07 +02:00
|
|
|
// Paper start
|
|
|
|
if (entity.valid) {
|
|
|
|
MinecraftServer.LOGGER.error("Attempted Double World add on " + entity, new Throwable());
|
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
|
2020-08-25 04:22:08 +02:00
|
|
|
index d55383d8fb471fe3441dbbc8e9344b42f1d7465b..a479ca88dcf60866650c236e885dd55f47915858 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
|
2020-08-25 04:22:08 +02:00
|
|
|
@@ -1066,5 +1066,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
|
|
|
|
}
|