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.
|
|
|
|
|
2023-08-13 01:57:13 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/commands/SummonCommand.java b/src/main/java/net/minecraft/server/commands/SummonCommand.java
|
|
|
|
index 2eddeb8d5239bbfeefbf4d3bd363f1ad083299b6..a7c89cdf20cb63792c76de81c1ff9f2cbbfcea84 100644
|
|
|
|
--- a/src/main/java/net/minecraft/server/commands/SummonCommand.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/commands/SummonCommand.java
|
|
|
|
@@ -57,6 +57,7 @@ public class SummonCommand {
|
|
|
|
ServerLevel worldserver = source.getLevel();
|
|
|
|
Entity entity = EntityType.loadEntityRecursive(nbttagcompound1, worldserver, (entity1) -> {
|
|
|
|
entity1.moveTo(pos.x, pos.y, pos.z, entity1.getYRot(), entity1.getXRot());
|
|
|
|
+ entity1.spawnReason = org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.COMMAND; // Paper
|
|
|
|
return entity1;
|
|
|
|
});
|
|
|
|
|
2021-06-11 14:02:28 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
2023-12-05 23:21:44 +01:00
|
|
|
index 08a1fdd0b6fb688897a7813e8c298265afedf02b..a26138470065a720045e3079e5e96d6c4fa765ce 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-12-05 23:21:44 +01:00
|
|
|
@@ -1450,6 +1450,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-12-05 23:21:44 +01:00
|
|
|
index 59fcb123cb1a49cca4072a62aa304e7382a07ccb..f7e0364b4f5cf73d36f26ad169c93259b727082c 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-12-05 23:21:44 +01:00
|
|
|
@@ -223,6 +223,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-06-07 23:14:56 +02:00
|
|
|
player.setServerLevel(worldserver1);
|
2023-09-22 04:17:21 +02:00
|
|
|
String s1 = connection.getLoggableAddress(this.server.logIPs());
|
2023-04-02 20:37:53 +02:00
|
|
|
|
2023-12-05 23:21:44 +01:00
|
|
|
@@ -354,7 +359,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-12-05 23:21:44 +01:00
|
|
|
index 760bb3bfa47ee1e4c6a6add7ab823a24ffd9e15e..75effaa34f06d85ee4e26d9a598acc85c94e9767 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-12-05 23:21:44 +01:00
|
|
|
@@ -235,6 +235,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
|
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-12-05 23:21:44 +01:00
|
|
|
@@ -2212,6 +2213,9 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
|
2021-06-22 12:54:49 +02:00
|
|
|
}
|
2023-12-05 23:21:44 +01:00
|
|
|
nbttagcompound.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-12-05 23:21:44 +01:00
|
|
|
@@ -2358,6 +2362,26 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
|
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-12-05 23:21:44 +01:00
|
|
|
index 713608239cc7518d05b04d3dd79c3af0c358c64e..231674f1483ad71630ac71ba92efc50f94a5659b 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
|
2023-12-05 23:21:44 +01:00
|
|
|
@@ -189,6 +189,7 @@ public abstract class BaseSpawner {
|
2021-06-13 11:41:07 +02:00
|
|
|
}
|
2023-06-13 01:51:45 +02:00
|
|
|
|
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
|
2023-06-13 01:51:45 +02:00
|
|
|
// CraftBukkit start
|
2021-06-13 11:41:07 +02:00
|
|
|
if (org.bukkit.craftbukkit.event.CraftEventFactory.callSpawnerSpawnEvent(entity, pos).isCancelled()) {
|
2023-10-29 01:10:31 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/block/entity/SculkShriekerBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/SculkShriekerBlockEntity.java
|
|
|
|
index faad948f089575e4988d989790cc1dd13f8a79cd..ee11a52e82091911aa3a196bcc1f7ab829626cef 100644
|
|
|
|
--- a/src/main/java/net/minecraft/world/level/block/entity/SculkShriekerBlockEntity.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/block/entity/SculkShriekerBlockEntity.java
|
|
|
|
@@ -186,7 +186,7 @@ public class SculkShriekerBlockEntity extends BlockEntity implements GameEventLi
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean trySummonWarden(ServerLevel world) {
|
|
|
|
- return this.warningLevel < 4 ? false : SpawnUtil.trySpawnMob(EntityType.WARDEN, MobSpawnType.TRIGGERED, world, this.getBlockPos(), 20, 5, 6, SpawnUtil.Strategy.ON_TOP_OF_COLLIDER).isPresent();
|
|
|
|
+ return this.warningLevel < 4 ? false : SpawnUtil.trySpawnMob(EntityType.WARDEN, MobSpawnType.TRIGGERED, world, this.getBlockPos(), 20, 5, 6, SpawnUtil.Strategy.ON_TOP_OF_COLLIDER, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.NATURAL, null).isPresent(); // Paper
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
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-12-05 23:21:44 +01:00
|
|
|
index 93363aabee8bafeb1bc1d0d5a94e80b647175509..b06c338ee9205d1f4d562571aba83c83f9abd20b 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-12-05 23:21:44 +01:00
|
|
|
@@ -1367,5 +1367,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
|
|
|
|
}
|