Don't fire sync events during worldgen

Fixes EntityPotionEffectEvent
Fixes EntityPoseChangeEvent

Asynchronous chunk generation provides an opportunity for things
to happen async that previously fired synchronous-only events. This
patch is for mitigating those issues by various methods.

Also fixes correctly marking/clearing the entity generation flag.
This patch sets the generation flag anytime an entity is created
via StructureTemplate before loading from NBT to catch uses of
the flag during the loading logic. This patch clears the generation
flag from an entity when added to a ServerLevel for the situation
where generation happened directly to a ServerLevel and the
entity still has the flag set.
This commit is contained in:
Jake Potrebic
2023-11-23 10:33:25 -08:00
parent 5f134afc4b
commit fff5d44a12
8 changed files with 252 additions and 218 deletions

View File

@@ -90,15 +90,17 @@ public abstract class DelegatedGeneratorAccess implements WorldGenLevel {
return this.handle.getLevel();
}
@Override
public void addFreshEntityWithPassengers(Entity entity) {
this.handle.addFreshEntityWithPassengers(entity);
}
@Override
public void addFreshEntityWithPassengers(Entity entity, CreatureSpawnEvent.SpawnReason reason) {
this.handle.addFreshEntityWithPassengers(entity, reason);
}
// Paper start - Don't fire sync event during generation; don't override these methods so all entities are run through addFreshEntity
// @Override
// public void addFreshEntityWithPassengers(Entity entity) {
// this.handle.addFreshEntityWithPassengers(entity);
// }
//
// @Override
// public void addFreshEntityWithPassengers(Entity entity, CreatureSpawnEvent.SpawnReason reason) {
// this.handle.addFreshEntityWithPassengers(entity, reason);
// }
// Paper end - Don't fire sync event during generation; don't override these methods so all entities are run through addFreshEntity
@Override
public ServerLevel getMinecraftWorld() {

View File

@@ -39,21 +39,23 @@ public class TransformerGeneratorAccess extends DelegatedGeneratorAccess {
return super.addFreshEntity(arg0, arg1);
}
@Override
public void addFreshEntityWithPassengers(Entity entity) {
if (this.structureTransformer != null && !this.structureTransformer.transformEntity(entity)) {
return;
}
super.addFreshEntityWithPassengers(entity);
}
@Override
public void addFreshEntityWithPassengers(Entity arg0, SpawnReason arg1) {
if (this.structureTransformer != null && !this.structureTransformer.transformEntity(arg0)) {
return;
}
super.addFreshEntityWithPassengers(arg0, arg1);
}
// Paper start - Don't fire sync event during generation; don't override these methods so all entities are run through addFreshEntity
// @Override
// public void addFreshEntityWithPassengers(Entity entity) {
// if (this.structureTransformer != null && !this.structureTransformer.transformEntity(entity)) {
// return;
// }
// super.addFreshEntityWithPassengers(entity);
// }
//
// @Override
// public void addFreshEntityWithPassengers(Entity arg0, SpawnReason arg1) {
// if (this.structureTransformer != null && !this.structureTransformer.transformEntity(arg0)) {
// return;
// }
// super.addFreshEntityWithPassengers(arg0, arg1);
// }
// Paper end - Don't fire sync event during generation; don't override these methods
public boolean setCraftBlock(BlockPos position, CraftBlockState craftBlockState, int i, int j) {
if (this.structureTransformer != null) {