2021-06-11 12:02:28 +00: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
|
2021-06-22 10:54:49 +00:00
|
|
|
index ab4dba5af019b60cbb82360eae7f6008aafcd38c..cdb19ab7e0d90dcd6885226aa2fd3a58ed53d29b 100644
|
2021-06-11 12:02:28 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
2021-06-14 06:41:01 +00:00
|
|
|
@@ -1111,6 +1111,7 @@ public class ServerLevel extends net.minecraft.world.level.Level implements Worl
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// Paper end
|
2021-06-11 12:02:28 +00:00
|
|
|
+ if (entity.spawnReason == null) entity.spawnReason = spawnReason; // Paper
|
2021-06-13 09:41:07 +00:00
|
|
|
if (entity.isRemoved()) {
|
2021-06-14 06:41:01 +00:00
|
|
|
// Paper start
|
|
|
|
if (DEBUG_ENTITIES) {
|
2021-06-11 12:02:28 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
|
2021-06-20 19:25:59 +00:00
|
|
|
index f1e3ea6b023119adc69eb0b414994bc7f9f3ed4a..42b7568d1c3ce145b2816202e6f5c8ca9e904de7 100644
|
2021-06-11 12:02:28 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
|
2021-06-20 19:25:59 +00:00
|
|
|
@@ -341,7 +341,7 @@ public abstract class PlayerList {
|
2021-06-11 12:02:28 +00:00
|
|
|
// CraftBukkit start
|
|
|
|
ServerLevel finalWorldServer = worldserver1;
|
|
|
|
Entity entity = EntityType.loadEntityRecursive(nbttagcompound1.getCompound("Entity"), finalWorldServer, (entity1) -> {
|
|
|
|
- return !finalWorldServer.addWithUUID(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
|
2021-06-22 10:54:49 +00:00
|
|
|
index 3518044845ec400ff6c2ddf7fc7dc32f1f7769b6..16c1b0135cbd466c7e404e2f3ee638c511dc8e37 100644
|
2021-06-11 12:02:28 +00:00
|
|
|
--- a/src/main/java/net/minecraft/world/entity/Entity.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
|
2021-06-13 09:41:07 +00:00
|
|
|
@@ -67,6 +67,8 @@ import net.minecraft.world.InteractionHand;
|
2021-06-11 12:02:28 +00:00
|
|
|
import net.minecraft.world.InteractionResult;
|
|
|
|
import net.minecraft.world.Nameable;
|
|
|
|
import net.minecraft.world.damagesource.DamageSource;
|
|
|
|
+import net.minecraft.world.entity.animal.AbstractFish;
|
|
|
|
+import net.minecraft.world.entity.animal.Animal;
|
|
|
|
import net.minecraft.world.entity.item.ItemEntity;
|
|
|
|
import net.minecraft.world.entity.player.Player;
|
|
|
|
import net.minecraft.world.entity.vehicle.Boat;
|
2021-06-13 09:41:07 +00:00
|
|
|
@@ -166,6 +168,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, n
|
|
|
|
}
|
2021-06-11 12:02:28 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
+ public org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason spawnReason;
|
|
|
|
// Paper end
|
|
|
|
|
|
|
|
public com.destroystokyo.paper.loottable.PaperLootableInventoryData lootableData; // Paper
|
2021-06-22 10:54:49 +00:00
|
|
|
@@ -1865,6 +1868,9 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, n
|
|
|
|
}
|
2021-06-13 09:41:07 +00:00
|
|
|
nbt.put("Paper.Origin", this.newDoubleList(origin.getX(), origin.getY(), origin.getZ()));
|
2021-06-11 12:02:28 +00:00
|
|
|
}
|
|
|
|
+ if (spawnReason != null) {
|
2021-06-13 09:41:07 +00:00
|
|
|
+ nbt.putString("Paper.SpawnReason", spawnReason.name());
|
2021-06-11 12:02:28 +00:00
|
|
|
+ }
|
|
|
|
// Save entity's from mob spawner status
|
|
|
|
if (spawnedViaMobSpawner) {
|
2021-06-13 09:41:07 +00:00
|
|
|
nbt.putBoolean("Paper.FromMobSpawner", true);
|
2021-06-22 10:54:49 +00:00
|
|
|
@@ -2010,6 +2016,26 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, n
|
2021-06-11 12:02:28 +00:00
|
|
|
}
|
|
|
|
|
2021-06-13 09:41:07 +00: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 12:02:28 +00:00
|
|
|
+ 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;
|
|
|
|
+ } else if (this instanceof Mob && (this instanceof Animal || this instanceof AbstractFish) && !((Mob) this).removeWhenFarAway(0.0)) {
|
2021-06-13 09:41:07 +00:00
|
|
|
+ if (!nbt.getBoolean("PersistenceRequired")) {
|
2021-06-11 12:02:28 +00: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
|
2021-06-15 05:49:09 +00:00
|
|
|
index 7bf688057d684aa1b60f29294c9a7e81ab6742d1..66ae43c40d4bad373b3a5269e8c78d7a3b3ac498 100644
|
2021-06-11 12:02:28 +00:00
|
|
|
--- a/src/main/java/net/minecraft/world/level/BaseSpawner.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/BaseSpawner.java
|
2021-06-14 05:38:49 +00:00
|
|
|
@@ -188,6 +188,7 @@ public abstract class BaseSpawner {
|
2021-06-13 09:41:07 +00:00
|
|
|
// Spigot End
|
|
|
|
}
|
2021-06-11 12:02:28 +00:00
|
|
|
entity.spawnedViaMobSpawner = true; // Paper
|
2021-06-13 09:41:07 +00: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 12:02:28 +00:00
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
2021-06-17 21:39:36 +00:00
|
|
|
index bcb616ade47b445dd6faec0fd938ee4d728d6d16..a28afbe66363e69a502b66d4124bb8fccf07be37 100644
|
2021-06-11 12:02:28 +00:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
2021-06-16 05:36:02 +00:00
|
|
|
@@ -1173,5 +1173,10 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
|
2021-06-11 12:02:28 +00:00
|
|
|
public boolean fromMobSpawner() {
|
|
|
|
return getHandle().spawnedViaMobSpawner;
|
|
|
|
}
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason getEntitySpawnReason() {
|
|
|
|
+ return getHandle().spawnReason;
|
|
|
|
+ }
|
|
|
|
// Paper end
|
|
|
|
}
|