Fixes and additions to the spawn reason API
Expose an entities spawn reason on the entity. Pre existing entities will return NATURAL if it was a non persistenting Living Entity, SPAWNER for spawners, or DEFAULT since data was not stored. Additionally, add missing spawn reasons. Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com> Co-authored-by: Doc <nachito94@msn.com>
This commit is contained in:
@@ -40,12 +40,10 @@
|
||||
} else {
|
||||
boolean flag = false;
|
||||
RandomSource randomsource = world.getRandom();
|
||||
@@ -123,8 +130,22 @@
|
||||
continue;
|
||||
}
|
||||
@@ -125,6 +132,20 @@
|
||||
} else if (!SpawnPlacements.checkSpawnRules((EntityType) optional.get(), world, EntitySpawnReason.SPAWNER, blockposition1, world.getRandom())) {
|
||||
+ continue;
|
||||
+ }
|
||||
continue;
|
||||
}
|
||||
+ // Paper start - PreCreatureSpawnEvent
|
||||
+ com.destroystokyo.paper.event.entity.PreSpawnerSpawnEvent event = new com.destroystokyo.paper.event.entity.PreSpawnerSpawnEvent(
|
||||
+ io.papermc.paper.util.MCUtil.toLocation(world, d0, d1, d2),
|
||||
@@ -57,13 +55,13 @@
|
||||
+ if (event.shouldAbortSpawn()) {
|
||||
+ break;
|
||||
+ }
|
||||
continue;
|
||||
}
|
||||
+ continue;
|
||||
+ }
|
||||
+ // Paper end - PreCreatureSpawnEvent
|
||||
|
||||
Entity entity = EntityType.loadEntityRecursive(nbttagcompound, world, EntitySpawnReason.SPAWNER, (entity1) -> {
|
||||
entity1.moveTo(d0, d1, d2, entity1.getYRot(), entity1.getXRot());
|
||||
@@ -157,13 +178,26 @@
|
||||
@@ -157,13 +178,27 @@
|
||||
((Mob) entity).finalizeSpawn(world, world.getCurrentDifficultyAt(entity.blockPosition()), EntitySpawnReason.SPAWNER, (SpawnGroupData) null);
|
||||
}
|
||||
|
||||
@@ -82,6 +80,7 @@
|
||||
|
||||
- if (!world.tryAddFreshEntityWithPassengers(entity)) {
|
||||
+ entity.spawnedViaMobSpawner = true; // Paper
|
||||
+ entity.spawnReason = org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.SPAWNER; // Paper - Entity#getEntitySpawnReason
|
||||
+ flag = true; // Paper
|
||||
+ // CraftBukkit start
|
||||
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callSpawnerSpawnEvent(entity, pos).isCancelled()) {
|
||||
@@ -92,7 +91,7 @@
|
||||
this.delay(world, pos);
|
||||
return;
|
||||
}
|
||||
@@ -174,7 +208,7 @@
|
||||
@@ -174,7 +209,7 @@
|
||||
((Mob) entity).spawnAnim();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
--- a/net/minecraft/world/level/block/FrogspawnBlock.java
|
||||
+++ b/net/minecraft/world/level/block/FrogspawnBlock.java
|
||||
@@ -121,7 +121,7 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
--- a/net/minecraft/world/level/block/SnifferEggBlock.java
|
||||
+++ b/net/minecraft/world/level/block/SnifferEggBlock.java
|
||||
@@ -74,7 +74,7 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
--- a/net/minecraft/world/level/block/entity/SculkShriekerBlockEntity.java
|
||||
+++ b/net/minecraft/world/level/block/entity/SculkShriekerBlockEntity.java
|
||||
@@ -190,7 +190,7 @@
|
||||
private boolean trySummonWarden(ServerLevel world) {
|
||||
return this.warningLevel >= 4
|
||||
&& 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
|
||||
)
|
||||
.isPresent();
|
||||
}
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
public final class TrialSpawner {
|
||||
|
||||
@@ -219,13 +224,19 @@
|
||||
@@ -219,14 +224,21 @@
|
||||
}
|
||||
|
||||
entityinsentient.setPersistenceRequired();
|
||||
@@ -25,16 +25,18 @@
|
||||
|
||||
- if (!world.tryAddFreshEntityWithPassengers(entity)) {
|
||||
+ 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();
|
||||
return Optional.empty();
|
||||
+ }
|
||||
+ if (!world.tryAddFreshEntityWithPassengers(entity, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.TRIAL_SPAWNER)) {
|
||||
+ // CraftBukkit end
|
||||
return Optional.empty();
|
||||
+ return Optional.empty();
|
||||
} else {
|
||||
TrialSpawner.FlameParticle trialspawner_a = this.isOminous ? TrialSpawner.FlameParticle.OMINOUS : TrialSpawner.FlameParticle.NORMAL;
|
||||
@@ -248,6 +259,15 @@
|
||||
|
||||
@@ -248,6 +260,15 @@
|
||||
ObjectArrayList<ItemStack> objectarraylist = loottable.getRandomItems(lootparams);
|
||||
|
||||
if (!objectarraylist.isEmpty()) {
|
||||
|
||||
Reference in New Issue
Block a user