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
|
2021-05-16 01:42:36 +02:00
|
|
|
index ecb4cb5df868673e5aa2eec3fdd8618dbea09655..d7c6f49ba1c84c45b387e155d9ae7452e5171df6 100644
|
2021-03-16 08:19:45 +01:00
|
|
|
--- a/src/main/java/net/minecraft/server/level/WorldServer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/level/WorldServer.java
|
2021-04-07 07:17:32 +02:00
|
|
|
@@ -1041,6 +1041,7 @@ public class WorldServer extends World implements GeneratorAccessSeed {
|
2021-03-16 08:19:45 +01: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
|
|
|
|
// 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
|
2021-05-16 01:42:36 +02:00
|
|
|
index 1ae969aff1d44ad9af28fc94d8821884b9ad0563..47aa69dfe43390b811c264adc0af1d01bcd5ce4d 100644
|
2021-03-16 08:19:45 +01:00
|
|
|
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
|
2021-03-16 14:04:28 +01:00
|
|
|
@@ -335,7 +335,7 @@ public abstract class PlayerList {
|
2021-03-16 08:19:45 +01:00
|
|
|
// 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
|
2021-03-16 16:50:45 +01:00
|
|
|
index e9b535622d6c33083c575ee4691598014dba0e2c..cbdd75feb7250e771111184b1fac7c4a6bf6e575 100644
|
2021-03-16 08:19:45 +01:00
|
|
|
--- a/src/main/java/net/minecraft/world/entity/Entity.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
|
2021-03-16 14:04:28 +01:00
|
|
|
@@ -63,6 +63,8 @@ import net.minecraft.world.EnumHand;
|
|
|
|
import net.minecraft.world.EnumInteractionResult;
|
|
|
|
import net.minecraft.world.INamableTileEntity;
|
|
|
|
import net.minecraft.world.damagesource.DamageSource;
|
|
|
|
+import net.minecraft.world.entity.animal.EntityAnimal;
|
|
|
|
+import net.minecraft.world.entity.animal.EntityFish;
|
|
|
|
import net.minecraft.world.entity.item.EntityItem;
|
|
|
|
import net.minecraft.world.entity.player.EntityHuman;
|
|
|
|
import net.minecraft.world.entity.vehicle.EntityBoat;
|
|
|
|
@@ -158,6 +160,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, ne
|
2019-03-24 06:00:55 +01:00
|
|
|
}
|
|
|
|
};
|
2021-03-16 16:50:45 +01:00
|
|
|
public List<Entity> entitySlice = null;
|
2019-03-24 06:00:55 +01:00
|
|
|
+ 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 14:04:28 +01:00
|
|
|
@@ -1673,6 +1676,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 14:04:28 +01:00
|
|
|
@@ -1807,6 +1813,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
|
2021-03-16 16:50:45 +01:00
|
|
|
index 867478484c0ba4ff467b96e458689937299b981d..34bcee4ff55ba118ba393e94b3c25ee2b84feaa2 100644
|
2021-03-16 08:19:45 +01:00
|
|
|
--- a/src/main/java/net/minecraft/world/level/MobSpawnerAbstract.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/MobSpawnerAbstract.java
|
2021-03-16 16:50:45 +01:00
|
|
|
@@ -183,6 +183,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
|
|
|
|
}
|