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-01-21 13:56:22 +01:00
|
|
|
index 2eddeb8d5239bbfeefbf4d3bd363f1ad083299b6..e2b44b8ddb8afc6e1f7dddadb434c2268f284809 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-01-24 13:07:40 +01:00
|
|
|
index 46b71a140ab8a1b997415184db09cb8a3ea39c52..c67ef9387f1d7ddfda89a096e764133118167175 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-01-24 13:07:40 +01:00
|
|
|
@@ -1203,6 +1203,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-01-24 13:07:40 +01:00
|
|
|
index c137899597bf94b75b1ff80fae910db72f791bb8..6555d1e199f49c693270fb7068bc4c495038f77b 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;
|
|
|
|
}
|
|
|
|
|
2024-01-21 13:56:22 +01:00
|
|
|
+ // Paper start - Entity#getEntitySpawnReason
|
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
|
|
|
|
+ }
|
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
|
|
|
|
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;
|
2024-01-21 13:56:22 +01:00
|
|
|
+ return !finalWorldServer.addWithUUID(entity1, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.MOUNT) ? null : entity1; // Paper - Entity#getEntitySpawnReason
|
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
|
2024-01-24 13:07:40 +01:00
|
|
|
index 5baf85f179c096a9e2be170d7def110d02952dae..c601bd02a75e10af7ad7040b3a4d974c585bbaaf 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-01-14 10:46:04 +01:00
|
|
|
@@ -237,6 +237,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
|
|
|
}
|
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-01-24 13:07:40 +01:00
|
|
|
@@ -2307,6 +2308,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
|
2024-01-24 11:45:17 +01:00
|
|
|
index 1b0093a23011f7d1c0da88c0a934d94ad4d6b3e2..ef7da9043f2a6e2041d2a2850aaf19b7c95f706a 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
|
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-01-21 13:56:22 +01:00
|
|
|
index faad948f089575e4988d989790cc1dd13f8a79cd..e143f42e71ac774d49b75e6d85591aa1189ee210 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
|
|
|
|
@@ -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();
|
2024-01-21 13:56:22 +01:00
|
|
|
+ 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 - Entity#getEntitySpawnReason
|
2023-10-29 01:10:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@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-31 00:45:24 +01:00
|
|
|
index 388c9db9d130071122e9f80749fb2eef05455408..3da7fbec0fb55fb590fc9ff4bd0f984a5cac9fba 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
|
Updated Upstream (Bukkit/CraftBukkit) (#10034)
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:
f29cb801 Separate checkstyle-suppressions file is not required
86f99bbe SPIGOT-7540, PR-946: Add ServerTickManager API
d4119585 SPIGOT-6903, PR-945: Add BlockData#getMapColor
b7a2ed41 SPIGOT-7530, PR-947: Add Player#removeResourcePack
9dd56255 SPIGOT-7527, PR-944: Add WindCharge#explode()
994a6163 Attempt upgrade of resolver libraries
CraftBukkit Changes:
b3b43a6ad Add Checkstyle check for unused imports
13fb3358e SPIGOT-7544: Scoreboard#getEntries() doesn't get entries but class names
3dda99c06 SPIGOT-7540, PR-1312: Add ServerTickManager API
2ab4508c0 SPIGOT-6903, PR-1311: Add BlockData#getMapColor
1dbdbbed4 PR-1238: Remove unnecessary sign ticking
659728d2a MC-264285, SPIGOT-7439, PR-1237: Fix unbreakable flint and steel is completely consumed while igniting creeper
e37e29ce0 Increase outdated build delay
c00438b39 SPIGOT-7530, PR-1313: Add Player#removeResourcePack
492dd80ce SPIGOT-7527, PR-1310: Add WindCharge#explode()
e11fbb9d7 Upgrade MySQL driver
9f3a0bd2a Attempt upgrade of resolver libraries
60d16d7ca PR-1306: Centralize Bukkit and Minecraft entity conversion
Spigot Changes:
06d602e7 Rebuild patches
2023-12-17 03:09:28 +01:00
|
|
|
@@ -1018,5 +1018,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
|
|
|
|
}
|