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
2024-07-15 23:35:51 +02:00
Subject: [PATCH] Fixes and additions to the spawn reason API
2021-06-11 14:02:28 +02:00
2024-07-15 23:35:51 +02:00
Expose an entities spawn reason on the entity.
2021-06-11 14:02:28 +02:00
Pre existing entities will return NATURAL if it was a non
persistenting Living Entity, SPAWNER for spawners,
or DEFAULT since data was not stored.
2024-07-15 23:35:51 +02:00
Additionally, add missing spawn reasons.
Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
Co-authored-by: Doc <nachito94@msn.com>
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-10-23 15:02:51 +02:00
index f55832ce841621daab4d3a910650ab6562cefcda..f635da34335cd2901adf975fcd74c5c6f9785836 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();
2024-10-23 15:02:51 +02:00
Entity entity = EntityType.loadEntityRecursive(nbttagcompound1, worldserver, EntitySpawnReason.COMMAND, (entity1) -> {
2023-08-13 01:57:13 +02:00
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-12-03 19:21:12 +01:00
index 52e2137f759e52d210abda7b47c1fd4b5f831d1f..209257ed04623ea41b7aba40b0b03a88a7f4eb21 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-12-03 19:21:12 +01:00
@@ -1178,6 +1178,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
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;
2024-10-23 15:02:51 +02:00
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
2024-12-03 19:21:12 +01:00
index 71352f1b86c594ea2edf5d1735410054d909291a..49d4feda5b352bd135aadf3c4677d236134861b0 100644
2024-10-23 15:02:51 +02:00
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
2024-12-03 19:21:12 +01:00
@@ -714,7 +714,7 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player {
2024-10-23 15:02:51 +02:00
ServerLevel worldserver = (ServerLevel) world;
CompoundTag nbttagcompound = ((CompoundTag) nbt.get()).getCompound("RootVehicle");
Entity entity = EntityType.loadEntityRecursive(nbttagcompound.getCompound("Entity"), worldserver, EntitySpawnReason.LOAD, (entity1) -> {
- return !worldserver.addWithUUID(entity1) ? null : entity1;
+ return !worldserver.addWithUUID(entity1, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.MOUNT) ? null : entity1; // CraftBukkit - decompile error // Paper - Entity#getEntitySpawnReason
});
if (entity == null) {
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-11-04 18:42:38 +01:00
index 97b48186a48ca037645d4a5ae84e3a95fd413a33..a04cfa09d9f8594a7ad3120855efe1641abb7a47 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-10-27 18:11:15 +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
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
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-12-03 19:21:12 +01:00
index 3cc210dc92f74c37f4de6eaf31ff3ec7aa11248a..e932bd4c922d7015bba0ef06e349d74f5c1a209c 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-11-04 18:42:38 +01:00
@@ -256,6 +256,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
2022-06-08 04:25:49 +02:00
private CraftEntity bukkitEntity;
2024-05-26 21:51:15 +02:00
2024-12-03 19:21:12 +01:00
@@ -2414,6 +2415,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-12-03 19:21:12 +01:00
@@ -2563,6 +2567,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) {
2024-07-15 23:35:51 +02:00
diff --git a/src/main/java/net/minecraft/world/entity/EntityType.java b/src/main/java/net/minecraft/world/entity/EntityType.java
2024-12-03 19:21:12 +01:00
index 768edafa018961ce38306f87e5cfe6aa99537305..d62c17c01f39d41d7cd422d37326a66791804090 100644
2024-07-15 23:35:51 +02:00
--- a/src/main/java/net/minecraft/world/entity/EntityType.java
+++ b/src/main/java/net/minecraft/world/entity/EntityType.java
2024-10-27 18:11:15 +01:00
@@ -433,7 +433,7 @@ public class EntityType<T extends Entity> implements FeatureElement, EntityTypeT
2024-07-15 23:35:51 +02:00
@Nullable
2024-10-23 15:02:51 +02:00
public T spawn(ServerLevel world, @Nullable ItemStack stack, @Nullable Player player, BlockPos pos, EntitySpawnReason spawnReason, boolean alignPosition, boolean invertY) {
2024-07-15 23:35:51 +02:00
// CraftBukkit start
- return this.spawn(world, stack, player, pos, spawnReason, alignPosition, invertY, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.SPAWNER_EGG);
2024-10-23 15:02:51 +02:00
+ return this.spawn(world, stack, player, pos, spawnReason, alignPosition, invertY, spawnReason == EntitySpawnReason.DISPENSER ? org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.DISPENSE_EGG : org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.SPAWNER_EGG); // Paper - use correct spawn reason for dispenser spawn eggs
2024-07-15 23:35:51 +02:00
}
@Nullable
diff --git a/src/main/java/net/minecraft/world/entity/OminousItemSpawner.java b/src/main/java/net/minecraft/world/entity/OminousItemSpawner.java
2024-10-23 15:02:51 +02:00
index 1fc9f883305e150f4bdf478bf0f43e301460cbf2..7b75dbb79e0d2a92cc10838a6e4da973e69125fb 100644
2024-07-15 23:35:51 +02:00
--- a/src/main/java/net/minecraft/world/entity/OminousItemSpawner.java
+++ b/src/main/java/net/minecraft/world/entity/OminousItemSpawner.java
2024-10-23 15:02:51 +02:00
@@ -76,7 +76,7 @@ public class OminousItemSpawner extends Entity {
entity = this.spawnProjectile(serverLevel, projectileItem, itemStack);
} else {
entity = new ItemEntity(serverLevel, this.getX(), this.getY(), this.getZ(), itemStack);
- serverLevel.addFreshEntity(entity);
+ serverLevel.addFreshEntity(entity, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.OMINOUS_ITEM_SPAWNER); // Paper - fixes and addition to spawn reason API
}
2024-07-15 23:35:51 +02:00
2024-10-23 15:02:51 +02:00
serverLevel.levelEvent(3021, this.blockPosition(), 1);
@@ -90,7 +90,7 @@ public class OminousItemSpawner extends Entity {
ProjectileItem.DispenseConfig dispenseConfig = item.createDispenseConfig();
dispenseConfig.overrideDispenseEvent().ifPresent(dispenseEvent -> world.levelEvent(dispenseEvent, this.blockPosition(), 0));
Direction direction = Direction.DOWN;
- Projectile projectile = Projectile.spawnProjectileUsingShoot(
+ Projectile projectile = Projectile.spawnProjectileUsingShootDelayed( // Paper - fixes and addition to spawn reason API
item.asProjectile(world, this.position(), stack, direction),
world,
stack,
@@ -99,7 +99,7 @@ public class OminousItemSpawner extends Entity {
(double)direction.getStepZ(),
dispenseConfig.power(),
dispenseConfig.uncertainty()
- );
+ ).spawn(org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.OMINOUS_ITEM_SPAWNER); // Paper - fixes and addition to spawn reason API
projectile.setOwner(this);
return projectile;
}
2024-07-15 23:35:51 +02:00
diff --git a/src/main/java/net/minecraft/world/entity/projectile/DragonFireball.java b/src/main/java/net/minecraft/world/entity/projectile/DragonFireball.java
2024-10-23 15:02:51 +02:00
index 2eecdcbea3d51b1fb6e0c3db0667464a699ca0df..c68ddccd5fbe27f6a62cedbdc2337f1b6e4d3273 100644
2024-07-15 23:35:51 +02:00
--- a/src/main/java/net/minecraft/world/entity/projectile/DragonFireball.java
+++ b/src/main/java/net/minecraft/world/entity/projectile/DragonFireball.java
2024-10-23 15:02:51 +02:00
@@ -64,7 +64,7 @@ public class DragonFireball extends AbstractHurtingProjectile {
2024-07-15 23:35:51 +02:00
if (new com.destroystokyo.paper.event.entity.EnderDragonFireballHitEvent((org.bukkit.entity.DragonFireball) this.getBukkitEntity(), list.stream().map(LivingEntity::getBukkitLivingEntity).collect(java.util.stream.Collectors.toList()), (org.bukkit.entity.AreaEffectCloud) entityareaeffectcloud.getBukkitEntity()).callEvent()) { // Paper - EnderDragon Events
this.level().levelEvent(2006, this.blockPosition(), this.isSilent() ? -1 : 1);
- this.level().addFreshEntity(entityareaeffectcloud);
+ this.level().addFreshEntity(entityareaeffectcloud, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.EXPLOSION); // Paper - use correct spawn reason
} else entityareaeffectcloud.discard(null); // Paper - EnderDragon Events
this.discard(EntityRemoveEvent.Cause.HIT); // CraftBukkit - add Bukkit remove cause
}
2024-10-23 15:02:51 +02:00
diff --git a/src/main/java/net/minecraft/world/entity/projectile/Projectile.java b/src/main/java/net/minecraft/world/entity/projectile/Projectile.java
2024-12-03 19:21:12 +01:00
index 23b7894761ef8871a7771e228b39ff01702afbcd..ae18b23e07b1aa7505b54f0512b1612e5f3da6db 100644
2024-10-23 15:02:51 +02:00
--- a/src/main/java/net/minecraft/world/entity/projectile/Projectile.java
+++ b/src/main/java/net/minecraft/world/entity/projectile/Projectile.java
@@ -214,7 +214,12 @@ public abstract class Projectile extends Entity implements TraceableEntity {
}
public static <T extends Projectile> T spawnProjectileUsingShoot(T projectile, ServerLevel world, ItemStack projectileStack, double velocityX, double velocityY, double velocityZ, float power, float divergence) {
- return Projectile.spawnProjectile(projectile, world, projectileStack, (iprojectile) -> {
+ // Paper start - fixes and addition to spawn reason API
+ return spawnProjectileUsingShootDelayed(projectile, world, projectileStack, velocityX, velocityY, velocityZ, power, divergence).spawn();
+ }
+ public static <T extends Projectile> Delayed<T> spawnProjectileUsingShootDelayed(T projectile, ServerLevel world, ItemStack projectileStack, double velocityX, double velocityY, double velocityZ, float power, float divergence) {
+ return Projectile.spawnProjectileDelayed(projectile, world, projectileStack, (iprojectile) -> {
+ // Paper end - fixes and addition to spawn reason API
projectile.shoot(velocityX, velocityY, velocityZ, power, divergence);
});
}
@@ -241,6 +246,17 @@ public abstract class Projectile extends Entity implements TraceableEntity {
this.attemptSpawn();
return projectile();
}
+
+ public boolean attemptSpawn(final org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason reason) {
+ if (!world.addFreshEntity(projectile, reason)) return false;
+ projectile.applyOnProjectileSpawned(this.world, this.projectileStack);
+ return true;
+ }
+
+ public T spawn(final org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason reason) {
+ this.attemptSpawn(reason);
+ return projectile();
+ }
}
// Paper end - delayed projectile spawning
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/world/level/BaseSpawner.java b/src/main/java/net/minecraft/world/level/BaseSpawner.java
2024-10-23 15:02:51 +02:00
index 261de9ea37d22023da6a306b58b1b62a54dc03da..299137519dba07c8b2cb35437742b5d40eb9e5d2 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()) {
2024-07-15 23:35:51 +02:00
diff --git a/src/main/java/net/minecraft/world/level/block/FrogspawnBlock.java b/src/main/java/net/minecraft/world/level/block/FrogspawnBlock.java
2024-10-23 15:02:51 +02:00
index 524f94a00f7b76a3847b68f0ab0cf82cc524b01e..aee71779f31def5f1ef7438cf06219d1de7092ec 100644
2024-07-15 23:35:51 +02:00
--- a/src/main/java/net/minecraft/world/level/block/FrogspawnBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/FrogspawnBlock.java
2024-10-23 15:02:51 +02:00
@@ -121,7 +121,7 @@ public class FrogspawnBlock extends Block {
2024-07-15 23:35:51 +02:00
int k = random.nextInt(1, 361);
tadpole.moveTo(d, (double)pos.getY() - 0.5, e, (float)k, 0.0F);
tadpole.setPersistenceRequired();
- world.addFreshEntity(tadpole);
+ world.addFreshEntity(tadpole, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.EGG); // Paper - use correct spawn reason
}
}
}
diff --git a/src/main/java/net/minecraft/world/level/block/SnifferEggBlock.java b/src/main/java/net/minecraft/world/level/block/SnifferEggBlock.java
2024-10-23 15:02:51 +02:00
index fc26713a869d0c1fad1634ef4a6c6282fef5aa31..4f8224841865f956aaa969ab7f543c80b3c24319 100644
2024-07-15 23:35:51 +02:00
--- a/src/main/java/net/minecraft/world/level/block/SnifferEggBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/SnifferEggBlock.java
2024-10-23 15:02:51 +02:00
@@ -74,7 +74,7 @@ public class SnifferEggBlock extends Block {
2024-07-15 23:35:51 +02:00
Vec3 vec3 = pos.getCenter();
sniffer.setBaby(true);
sniffer.moveTo(vec3.x(), vec3.y(), vec3.z(), Mth.wrapDegrees(world.random.nextFloat() * 360.0F), 0.0F);
- world.addFreshEntity(sniffer);
+ world.addFreshEntity(sniffer, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.EGG); // Paper - use correct spawn reason
}
}
}
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-12-03 19:21:12 +01:00
index 32f0493bac35e8c931ba2950f604a1f2cdd883c6..4bc3eded897b067e00c8e310c1be603aa7097ac4 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-12-03 19:21:12 +01:00
@@ -190,7 +190,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
2024-12-03 19:21:12 +01:00
&& SpawnUtil.trySpawnMob(
- EntityType.WARDEN, EntitySpawnReason.TRIGGERED, world, this.getBlockPos(), 20, 5, 6, SpawnUtil.Strategy.ON_TOP_OF_COLLIDER, false
+ EntityType.WARDEN, EntitySpawnReason.TRIGGERED, world, this.getBlockPos(), 20, 5, 6, SpawnUtil.Strategy.ON_TOP_OF_COLLIDER, false, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.NATURAL, null // Paper - Entity#getEntitySpawnReason
)
2024-04-12 21:14:06 +02:00
.isPresent();
2023-10-29 01:10:31 +02:00
}
2024-08-11 00:19:54 +02:00
diff --git a/src/main/java/net/minecraft/world/level/block/entity/trialspawner/TrialSpawner.java b/src/main/java/net/minecraft/world/level/block/entity/trialspawner/TrialSpawner.java
2024-12-03 19:21:12 +01:00
index 150a525772dd87f0aca39ad74f0bcefa0693d7d8..476caf7fb4f0124daa35822f2161e11620f18621 100644
2024-08-11 00:19:54 +02:00
--- a/src/main/java/net/minecraft/world/level/block/entity/trialspawner/TrialSpawner.java
+++ b/src/main/java/net/minecraft/world/level/block/entity/trialspawner/TrialSpawner.java
2024-08-17 21:39:11 +02:00
@@ -231,6 +231,7 @@ public final class TrialSpawner {
2024-08-11 00:19:54 +02:00
}
entity.spawnedViaMobSpawner = true; // Paper
+ entity.spawnReason = org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.TRIAL_SPAWNER; // Paper - Entity#getEntitySpawnReason
// CraftBukkit start
if (org.bukkit.craftbukkit.event.CraftEventFactory.callTrialSpawnerSpawnEvent(entity, pos).isCancelled()) {
return Optional.empty();
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-11-09 21:17:42 +01:00
index d6241e2db362de034ae610694c49c1883ffabd07..73788d702a0a814fe7b1e64b33a3b97ca1777662 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-11-09 21:17:42 +01:00
@@ -1014,4 +1014,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
}