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
|
2024-04-24 07:43:09 +02:00
|
|
|
index bf72cf288ade52ee8cc41ca978f368b3ad575951..798999be50d26be357ef3c6d5b9383ce4d1048c1 100644
|
2023-08-13 01:57:13 +02:00
|
|
|
--- 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());
|
2024-01-21 13:56:22 +01:00
|
|
|
+ entity1.spawnReason = org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.COMMAND; // Paper - Entity#getEntitySpawnReason
|
2023-08-13 01:57:13 +02:00
|
|
|
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
|
2024-04-25 05:40:32 +02:00
|
|
|
index 1beb2541cf799c7862685b5332ecbbfae1edc170..81b6ae88c37b0876dc24b1d85a6aa20e242eae8b 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
|
2024-04-24 07:43:09 +02:00
|
|
|
@@ -1209,6 +1209,7 @@ public class ServerLevel extends Level implements WorldGenLevel {
|
2021-06-14 08:41:01 +02:00
|
|
|
return true;
|
|
|
|
}
|
2024-01-21 17:39:05 +01:00
|
|
|
// Paper end - extra debug info
|
2024-01-21 13:56:22 +01:00
|
|
|
+ if (entity.spawnReason == null) entity.spawnReason = spawnReason; // Paper - Entity#getEntitySpawnReason
|
2021-06-13 11:41:07 +02:00
|
|
|
if (entity.isRemoved()) {
|
2024-01-21 17:39:05 +01:00
|
|
|
// WorldServer.LOGGER.warn("Tried to add entity {} but it was marked as removed already", EntityTypes.getKey(entity.getType())); // CraftBukkit
|
|
|
|
return false;
|
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
|
2024-04-24 08:44:48 +02:00
|
|
|
index f29cd4d7c528404ea8e77e82a5ae17a9d9d19ed5..24790ded773c8d041e7f43c9b8f8f8fe9fff3d74 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
|
2024-04-24 07:43:09 +02:00
|
|
|
@@ -223,6 +223,11 @@ public abstract class PlayerList {
|
2023-04-02 20:37:53 +02:00
|
|
|
worldserver1 = worldserver;
|
|
|
|
}
|
|
|
|
|
2024-01-21 13:56:22 +01:00
|
|
|
+ // Paper start - Entity#getEntitySpawnReason
|
2024-04-24 08:44:48 +02:00
|
|
|
+ if (optional.isEmpty()) {
|
2023-04-02 20:37:53 +02:00
|
|
|
+ player.spawnReason = org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.DEFAULT; // set Player SpawnReason to DEFAULT on first login
|
|
|
|
+ }
|
2024-01-21 13:56:22 +01:00
|
|
|
+ // Paper end - Entity#getEntitySpawnReason
|
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
|
|
|
|
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#10277)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing
Bukkit Changes:
9a80d38c SPIGOT-336, SPIGOT-3366, SPIGOT-5768, SPIGOT-6409, SPIGOT-6861, PR-722: Add EntityRemoveEvent
258086d9 SPIGOT-7417, PR-967: Add Sign#getTargetSide and Sign#getAllowedEditor
ffaba051 SPIGOT-7584: Add missing Tag.ITEMS_NON_FLAMMABLE_WOOD
CraftBukkit Changes:
98b6c1ac7 SPIGOT-7589 Fix NullPointerException when bans expire
a2736ddb0 SPIGOT-336, SPIGOT-3366, SPIGOT-5768, SPIGOT-6409, SPIGOT-6861, PR-1008: Add EntityRemoveEvent
5bf12cb89 SPIGOT-7565: Throw a more descriptive error message when a developer tries to spawn an entity from a CraftBukkit class
76d95fe7e SPIGOT-7417, PR-1343: Add Sign#getTargetSide and Sign#getAllowedEditor
Spigot Changes:
e9ec5485 Rebuild patches
f1b62e0c Rebuild patches
2024-02-23 14:37:33 +01:00
|
|
|
@@ -355,7 +360,7 @@ public abstract class PlayerList {
|
2024-04-24 07:43:09 +02:00
|
|
|
CompoundTag nbttagcompound = ((CompoundTag) optional.get()).getCompound("RootVehicle");
|
|
|
|
ServerLevel finalWorldServer = worldserver1; // CraftBukkit - decompile error
|
|
|
|
Entity entity = EntityType.loadEntityRecursive(nbttagcompound.getCompound("Entity"), worldserver1, (entity1) -> {
|
|
|
|
- return !finalWorldServer.addWithUUID(entity1) ? null : entity1; // CraftBukkit - decompile error
|
|
|
|
+ return !finalWorldServer.addWithUUID(entity1, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.MOUNT) ? null : entity1; // CraftBukkit - decompile error // Paper - Entity#getEntitySpawnReason
|
2021-06-11 14:02:28 +02:00
|
|
|
});
|
|
|
|
|
2024-04-24 07:43:09 +02:00
|
|
|
if (entity != null) {
|
2021-06-11 14:02:28 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
|
2024-04-24 07:43:09 +02:00
|
|
|
index 28708e1e8ade8fbfec24120478d250ddf1351bf4..ce2594baa8eb5cfff75a2fb9f3277676a7b08e18 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
|
2024-04-24 07:43:09 +02:00
|
|
|
@@ -241,6 +241,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
2022-06-08 04:25:49 +02:00
|
|
|
}
|
2024-01-23 14:34:17 +01:00
|
|
|
// Paper end - Share random for entities to make them more random
|
2024-01-21 13:56:22 +01:00
|
|
|
+ public org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason spawnReason; // Paper - Entity#getEntitySpawnReason
|
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;
|
2024-04-24 07:43:09 +02:00
|
|
|
@@ -2206,6 +2207,9 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
2024-02-23 23:13:37 +01:00
|
|
|
}
|
|
|
|
nbttagcompound.put("Paper.Origin", this.newDoubleList(origin.getX(), origin.getY(), origin.getZ()));
|
|
|
|
}
|
|
|
|
+ if (spawnReason != null) {
|
|
|
|
+ nbttagcompound.putString("Paper.SpawnReason", spawnReason.name());
|
|
|
|
+ }
|
|
|
|
// Save entity's from mob spawner status
|
|
|
|
if (spawnedViaMobSpawner) {
|
|
|
|
nbttagcompound.putBoolean("Paper.FromMobSpawner", true);
|
2024-04-24 07:43:09 +02:00
|
|
|
@@ -2352,6 +2356,26 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
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
|
2024-04-24 07:43:09 +02:00
|
|
|
index ee897b8c9462dbb3d7be9a2994753155065ce205..1d0964a7f544735a0213d5c7832c71f53db139a9 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
|
2024-04-24 07:43:09 +02:00
|
|
|
@@ -191,6 +191,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
|
2024-01-21 13:56:22 +01:00
|
|
|
+ entity.spawnReason = org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.SPAWNER; // Paper - Entity#getEntitySpawnReason
|
2021-06-13 11:41:07 +02:00
|
|
|
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
|
2024-04-24 07:43:09 +02:00
|
|
|
index 570957f00ad4817d5631c72060e85f85af634619..baa876db3a58a3c756a72ef1ad081964b358f58e 100644
|
2023-10-29 01:10:31 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/level/block/entity/SculkShriekerBlockEntity.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/block/entity/SculkShriekerBlockEntity.java
|
2024-04-24 07:43:09 +02:00
|
|
|
@@ -183,7 +183,7 @@ public class SculkShriekerBlockEntity extends BlockEntity implements GameEventLi
|
2023-10-29 01:10:31 +02:00
|
|
|
|
|
|
|
private boolean trySummonWarden(ServerLevel world) {
|
2024-04-12 21:14:06 +02:00
|
|
|
return this.warningLevel >= 4
|
|
|
|
- && SpawnUtil.trySpawnMob(EntityType.WARDEN, MobSpawnType.TRIGGERED, world, this.getBlockPos(), 20, 5, 6, SpawnUtil.Strategy.ON_TOP_OF_COLLIDER)
|
|
|
|
+ && 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) // Paper - Entity#getEntitySpawnReason
|
|
|
|
.isPresent();
|
2023-10-29 01:10:31 +02:00
|
|
|
}
|
|
|
|
|
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
|
2024-04-24 07:43:09 +02:00
|
|
|
index 621970006f21d219784dc58d7aa8d6062c4620f1..571b8352de4070622cdc47a50643beada0b16c36 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
|
2024-04-24 07:43:09 +02:00
|
|
|
@@ -1001,4 +1001,11 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
|
2024-04-06 22:38:37 +02:00
|
|
|
return this.getHandle().spawnedViaMobSpawner;
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
2024-04-06 22:38:37 +02:00
|
|
|
// Paper end - Entity#fromMobSpawner
|
2021-06-11 14:02:28 +02:00
|
|
|
+
|
2024-04-06 22:38:37 +02:00
|
|
|
+ // Paper start - entity spawn reason API
|
2021-06-11 14:02:28 +02:00
|
|
|
+ @Override
|
|
|
|
+ public org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason getEntitySpawnReason() {
|
|
|
|
+ return getHandle().spawnReason;
|
|
|
|
+ }
|
2024-04-06 22:38:37 +02:00
|
|
|
+ // Paper end - entity spawn reason API
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|