2021-06-11 14:02:28 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
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/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
2023-03-14 20:24:52 +01:00
|
|
|
index e46f18e342f2e682c4d5bbac22187a171df8eb33..58c1769ea15249df950a40e2f164e2ff7aeb05bd 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
2023-03-14 20:24:52 +01:00
|
|
|
@@ -1288,6 +1288,7 @@ public class ServerLevel extends Level implements WorldGenLevel {
|
2021-06-14 08:41:01 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// Paper end
|
2021-06-11 14:02:28 +02:00
|
|
|
+ if (entity.spawnReason == null) entity.spawnReason = spawnReason; // Paper
|
2021-06-13 11:41:07 +02:00
|
|
|
if (entity.isRemoved()) {
|
2021-06-14 08:41:01 +02:00
|
|
|
// Paper start
|
|
|
|
if (DEBUG_ENTITIES) {
|
2021-06-11 14:02:28 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
|
2023-05-12 13:10:08 +02:00
|
|
|
index 9f855fcbc9be12f7542557e1c32248748fad14c3..e261521d526cb2192761a0432b28f82c83258540 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
|
2023-05-12 13:10:08 +02:00
|
|
|
@@ -226,6 +226,11 @@ public abstract class PlayerList {
|
2023-04-02 20:37:53 +02:00
|
|
|
worldserver1 = worldserver;
|
|
|
|
}
|
|
|
|
|
2023-04-07 00:39:32 +02:00
|
|
|
+ // Paper start
|
2023-04-02 20:37:53 +02:00
|
|
|
+ if (nbttagcompound == null) {
|
|
|
|
+ player.spawnReason = org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.DEFAULT; // set Player SpawnReason to DEFAULT on first login
|
|
|
|
+ }
|
2023-04-07 00:39:32 +02:00
|
|
|
+ // Paper end
|
2023-04-02 20:37:53 +02:00
|
|
|
player.setLevel(worldserver1);
|
|
|
|
String s1 = "local";
|
|
|
|
|
2023-05-12 13:10:08 +02:00
|
|
|
@@ -366,7 +371,7 @@ public abstract class PlayerList {
|
2021-06-11 14:02:28 +02:00
|
|
|
// CraftBukkit start
|
|
|
|
ServerLevel finalWorldServer = worldserver1;
|
|
|
|
Entity entity = EntityType.loadEntityRecursive(nbttagcompound1.getCompound("Entity"), finalWorldServer, (entity1) -> {
|
|
|
|
- return !finalWorldServer.addWithUUID(entity1) ? null : entity1;
|
2021-11-24 03:05:49 +01:00
|
|
|
+ return !finalWorldServer.addWithUUID(entity1, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.MOUNT) ? null : entity1; // Paper
|
2021-06-11 14:02:28 +02:00
|
|
|
// CraftBukkit end
|
|
|
|
});
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
|
2023-05-12 13:10:08 +02:00
|
|
|
index 55658cdb2b5aca0bfebefc7fcec36aefe5f42e7b..7288d6d7f08b2e6b9696948d6c4451f479e419b6 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/entity/Entity.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
|
2023-05-12 13:10:08 +02:00
|
|
|
@@ -234,6 +234,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
2022-06-08 04:25:49 +02:00
|
|
|
}
|
2021-06-11 14:02:28 +02:00
|
|
|
// Paper end
|
2022-06-08 04:25:49 +02:00
|
|
|
+ public org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason spawnReason; // Paper
|
2021-06-11 14:02:28 +02:00
|
|
|
|
|
|
|
public com.destroystokyo.paper.loottable.PaperLootableInventoryData lootableData; // Paper
|
2022-06-08 04:25:49 +02:00
|
|
|
private CraftEntity bukkitEntity;
|
2023-05-12 13:10:08 +02:00
|
|
|
@@ -2062,6 +2063,9 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
|
2021-06-22 12:54:49 +02:00
|
|
|
}
|
2021-06-13 11:41:07 +02:00
|
|
|
nbt.put("Paper.Origin", this.newDoubleList(origin.getX(), origin.getY(), origin.getZ()));
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
+ if (spawnReason != null) {
|
2021-06-13 11:41:07 +02:00
|
|
|
+ nbt.putString("Paper.SpawnReason", spawnReason.name());
|
2021-06-11 14:02:28 +02:00
|
|
|
+ }
|
|
|
|
// Save entity's from mob spawner status
|
|
|
|
if (spawnedViaMobSpawner) {
|
2021-06-13 11:41:07 +02:00
|
|
|
nbt.putBoolean("Paper.FromMobSpawner", true);
|
2023-05-12 13:10:08 +02:00
|
|
|
@@ -2208,6 +2212,26 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
|
2021-06-13 11:41:07 +02:00
|
|
|
spawnedViaMobSpawner = nbt.getBoolean("Paper.FromMobSpawner"); // Restore entity's from mob spawner status
|
|
|
|
+ if (nbt.contains("Paper.SpawnReason")) {
|
|
|
|
+ String spawnReasonName = nbt.getString("Paper.SpawnReason");
|
2021-06-11 14:02:28 +02:00
|
|
|
+ try {
|
|
|
|
+ spawnReason = org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.valueOf(spawnReasonName);
|
|
|
|
+ } catch (Exception ignored) {
|
2022-02-28 22:43:31 +01:00
|
|
|
+ LOGGER.error("Unknown SpawnReason " + spawnReasonName + " for " + this);
|
2021-06-11 14:02:28 +02:00
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (spawnReason == null) {
|
|
|
|
+ if (spawnedViaMobSpawner) {
|
|
|
|
+ spawnReason = org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.SPAWNER;
|
2023-03-14 20:24:52 +01:00
|
|
|
+ } else if (this instanceof Mob && (this instanceof net.minecraft.world.entity.animal.Animal || this instanceof net.minecraft.world.entity.animal.AbstractFish) && !((Mob) this).removeWhenFarAway(0.0)) {
|
2021-06-13 11:41:07 +02:00
|
|
|
+ if (!nbt.getBoolean("PersistenceRequired")) {
|
2021-06-11 14:02:28 +02:00
|
|
|
+ spawnReason = org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.NATURAL;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (spawnReason == null) {
|
|
|
|
+ spawnReason = org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.DEFAULT;
|
|
|
|
+ }
|
|
|
|
// Paper end
|
|
|
|
|
|
|
|
} catch (Throwable throwable) {
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/BaseSpawner.java b/src/main/java/net/minecraft/world/level/BaseSpawner.java
|
2023-03-14 20:24:52 +01:00
|
|
|
index 405f36e9e115ad44bb91aad885785761786204ca..091c72b95e3c4c3528812ace4aec64d451f25462 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/level/BaseSpawner.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/BaseSpawner.java
|
2022-12-07 20:22:28 +01:00
|
|
|
@@ -185,6 +185,7 @@ public abstract class BaseSpawner {
|
2021-06-13 11:41:07 +02:00
|
|
|
// Spigot End
|
|
|
|
}
|
2021-06-11 14:02:28 +02:00
|
|
|
entity.spawnedViaMobSpawner = true; // Paper
|
2021-06-13 11:41:07 +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, pos).isCancelled()) {
|
2021-06-11 14:02:28 +02:00
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
2023-05-12 13:10:08 +02:00
|
|
|
index c69f5192f11f8bf080d752971264a01bdb91a30f..02ef4c66b18edd2138a92b609f837664ec20a559 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
2023-03-14 20:24:52 +01:00
|
|
|
@@ -1303,5 +1303,10 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
|
2021-06-11 14:02:28 +02:00
|
|
|
public boolean fromMobSpawner() {
|
|
|
|
return getHandle().spawnedViaMobSpawner;
|
|
|
|
}
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason getEntitySpawnReason() {
|
|
|
|
+ return getHandle().spawnReason;
|
|
|
|
+ }
|
|
|
|
// Paper end
|
|
|
|
}
|