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:
Aikar
2019-03-24 00:24:52 -04:00
parent 19bd3b2655
commit 0b77748b35
15 changed files with 322 additions and 173 deletions

View File

@@ -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
}
}
}

View File

@@ -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
}
}
}

View File

@@ -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();
}

View File

@@ -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()) {