2024-01-04 21:55:01 +01:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Jake Potrebic <jake.m.potrebic@gmail.com>
|
|
|
|
Date: Thu, 23 Nov 2023 10:33:25 -0800
|
|
|
|
Subject: [PATCH] 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.
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
2024-08-31 20:29:50 +02:00
|
|
|
index 60c75f7c4258efb26c2595ca7724b08d3c046c9d..34ece37aee68e4d8eeaa919e8bd489a672756049 100644
|
2024-01-04 21:55:01 +01:00
|
|
|
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
2024-06-14 10:17:11 +02:00
|
|
|
@@ -1224,6 +1224,7 @@ public class ServerLevel extends Level implements WorldGenLevel {
|
2024-01-04 21:55:01 +01:00
|
|
|
// CraftBukkit start
|
|
|
|
private boolean addEntity(Entity entity, CreatureSpawnEvent.SpawnReason spawnReason) {
|
|
|
|
org.spigotmc.AsyncCatcher.catchOp("entity add"); // Spigot
|
2024-01-13 18:34:33 +01:00
|
|
|
+ entity.generation = false; // Paper - Don't fire sync event during generation; Reset flag if it was added during a ServerLevel generation process
|
2024-01-21 17:39:05 +01:00
|
|
|
// Paper start - extra debug info
|
2024-01-04 21:55:01 +01:00
|
|
|
if (entity.valid) {
|
2024-01-21 17:39:05 +01:00
|
|
|
MinecraftServer.LOGGER.error("Attempted Double World add on {}", entity, new Throwable());
|
2024-01-04 21:55:01 +01:00
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
|
2024-08-31 20:29:50 +02:00
|
|
|
index bd0e205c760414784ae483452fd02292939dcb5c..f163cb3c75e90b96b3794a7e0c5b803268814c8c 100644
|
2024-01-04 21:55:01 +01:00
|
|
|
--- a/src/main/java/net/minecraft/world/entity/Entity.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
|
2024-07-29 00:28:28 +02:00
|
|
|
@@ -624,7 +624,11 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
2024-01-04 21:55:01 +01:00
|
|
|
if (pose == this.getPose()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
- this.level.getCraftServer().getPluginManager().callEvent(new EntityPoseChangeEvent(this.getBukkitEntity(), Pose.values()[pose.ordinal()]));
|
2024-01-13 18:34:33 +01:00
|
|
|
+ // Paper start - Don't fire sync event during generation
|
2024-01-04 21:55:01 +01:00
|
|
|
+ if (!this.generation) {
|
|
|
|
+ this.level.getCraftServer().getPluginManager().callEvent(new EntityPoseChangeEvent(this.getBukkitEntity(), Pose.values()[pose.ordinal()]));
|
|
|
|
+ }
|
2024-01-13 18:34:33 +01:00
|
|
|
+ // Paper end - Don't fire sync event during generation
|
2024-01-04 21:55:01 +01:00
|
|
|
// CraftBukkit end
|
|
|
|
this.entityData.set(Entity.DATA_POSE, pose);
|
|
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/EntityType.java b/src/main/java/net/minecraft/world/entity/EntityType.java
|
2024-06-14 10:17:11 +02:00
|
|
|
index 5fb3279342506611882b5780cfbee0371919c93c..b98f9246b60daf31460f41ce214dfa7c011f5684 100644
|
2024-01-04 21:55:01 +01:00
|
|
|
--- a/src/main/java/net/minecraft/world/entity/EntityType.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/entity/EntityType.java
|
2024-04-25 01:25:57 +02:00
|
|
|
@@ -592,9 +592,15 @@ public class EntityType<T extends Entity> implements FeatureElement, EntityTypeT
|
2024-01-04 21:55:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static Optional<Entity> create(CompoundTag nbt, Level world) {
|
2024-01-13 18:34:33 +01:00
|
|
|
+ // Paper start - Don't fire sync event during generation
|
2024-01-04 21:55:01 +01:00
|
|
|
+ return create(nbt, world, false);
|
|
|
|
+ }
|
|
|
|
+ public static Optional<Entity> create(CompoundTag nbt, Level world, boolean generation) {
|
2024-01-13 18:34:33 +01:00
|
|
|
+ // Paper end - Don't fire sync event during generation
|
2024-01-04 21:55:01 +01:00
|
|
|
return Util.ifElse(EntityType.by(nbt).map((entitytypes) -> {
|
|
|
|
return entitytypes.create(world);
|
|
|
|
}), (entity) -> {
|
2024-01-13 18:34:33 +01:00
|
|
|
+ if (generation) entity.generation = true; // Paper - Don't fire sync event during generation
|
2024-01-04 21:55:01 +01:00
|
|
|
entity.load(nbt);
|
|
|
|
}, () -> {
|
|
|
|
EntityType.LOGGER.warn("Skipping Entity with id {}", nbt.getString("id"));
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
2024-09-15 21:39:53 +02:00
|
|
|
index 04232f281ebd46954ef2259962c7bfc43b8a8aeb..0c67f04ae7eeaa10a90419031447ad5397c6b9e2 100644
|
2024-01-04 21:55:01 +01:00
|
|
|
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
2024-07-06 21:19:14 +02:00
|
|
|
@@ -1138,6 +1138,11 @@ public abstract class LivingEntity extends Entity implements Attackable {
|
2024-01-04 21:55:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean addEffect(MobEffectInstance mobeffect, @Nullable Entity entity, EntityPotionEffectEvent.Cause cause) {
|
2024-01-13 18:34:33 +01:00
|
|
|
+ // Paper start - Don't fire sync event during generation
|
2024-01-04 21:55:01 +01:00
|
|
|
+ return this.addEffect(mobeffect, entity, cause, true);
|
|
|
|
+ }
|
|
|
|
+ public boolean addEffect(MobEffectInstance mobeffect, @Nullable Entity entity, EntityPotionEffectEvent.Cause cause, boolean fireEvent) {
|
2024-01-13 18:34:33 +01:00
|
|
|
+ // Paper end - Don't fire sync event during generation
|
2024-01-04 21:55:01 +01:00
|
|
|
// org.spigotmc.AsyncCatcher.catchOp("effect add"); // Spigot // Paper - move to API
|
|
|
|
if (this.isTickingEffects) {
|
|
|
|
this.effectsToProcess.add(new ProcessableEffect(mobeffect, cause));
|
2024-07-06 21:19:14 +02:00
|
|
|
@@ -1157,10 +1162,13 @@ public abstract class LivingEntity extends Entity implements Attackable {
|
2024-01-04 21:55:01 +01:00
|
|
|
override = new MobEffectInstance(mobeffect1).update(mobeffect);
|
|
|
|
}
|
|
|
|
|
2024-01-13 18:34:33 +01:00
|
|
|
+ if (fireEvent) { // Paper - Don't fire sync event during generation
|
2024-01-04 21:55:01 +01:00
|
|
|
EntityPotionEffectEvent event = CraftEventFactory.callEntityPotionEffectChangeEvent(this, mobeffect1, mobeffect, cause, override);
|
2024-01-13 18:34:33 +01:00
|
|
|
+ override = event.isOverride(); // Paper - Don't fire sync event during generation
|
2024-01-04 21:55:01 +01:00
|
|
|
if (event.isCancelled()) {
|
|
|
|
return false;
|
|
|
|
}
|
2024-01-13 18:34:33 +01:00
|
|
|
+ } // Paper - Don't fire sync event during generation
|
2024-01-04 21:55:01 +01:00
|
|
|
// CraftBukkit end
|
|
|
|
|
|
|
|
if (mobeffect1 == null) {
|
2024-07-06 21:19:14 +02:00
|
|
|
@@ -1169,7 +1177,7 @@ public abstract class LivingEntity extends Entity implements Attackable {
|
2024-01-04 21:55:01 +01:00
|
|
|
flag = true;
|
2024-04-25 01:25:57 +02:00
|
|
|
mobeffect.onEffectAdded(this);
|
2024-01-04 21:55:01 +01:00
|
|
|
// CraftBukkit start
|
|
|
|
- } else if (event.isOverride()) {
|
2024-01-13 18:34:33 +01:00
|
|
|
+ } else if (override) { // Paper - Don't fire sync event during generation
|
2024-01-04 21:55:01 +01:00
|
|
|
mobeffect1.update(mobeffect);
|
|
|
|
this.onEffectUpdated(mobeffect1, true, entity);
|
|
|
|
// CraftBukkit end
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/monster/Spider.java b/src/main/java/net/minecraft/world/entity/monster/Spider.java
|
2024-09-07 21:49:28 +02:00
|
|
|
index f91ea9ac5a0d0d3bae5d1eb0c409f4f9c4e5a62b..9045f18f49a5c6685597d0a77126d7cb35bc5e88 100644
|
2024-01-04 21:55:01 +01:00
|
|
|
--- a/src/main/java/net/minecraft/world/entity/monster/Spider.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/entity/monster/Spider.java
|
2024-04-25 01:25:57 +02:00
|
|
|
@@ -172,7 +172,7 @@ public class Spider extends Monster {
|
|
|
|
Holder<MobEffect> holder = entityspider_groupdataspider.effect;
|
2024-01-04 21:55:01 +01:00
|
|
|
|
2024-04-25 01:25:57 +02:00
|
|
|
if (holder != null) {
|
|
|
|
- this.addEffect(new MobEffectInstance(holder, -1), org.bukkit.event.entity.EntityPotionEffectEvent.Cause.SPIDER_SPAWN); // CraftBukkit
|
|
|
|
+ this.addEffect(new MobEffectInstance(holder, -1), null, org.bukkit.event.entity.EntityPotionEffectEvent.Cause.SPIDER_SPAWN, world instanceof net.minecraft.server.level.ServerLevel); // CraftBukkit
|
2024-01-04 21:55:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/levelgen/structure/templatesystem/StructureTemplate.java b/src/main/java/net/minecraft/world/level/levelgen/structure/templatesystem/StructureTemplate.java
|
2024-06-14 10:17:11 +02:00
|
|
|
index cf8258e8d46ca7286a66c38fa24af369bd9a279f..0555abfda468c343af8244a122ebe769e70a0292 100644
|
2024-01-04 21:55:01 +01:00
|
|
|
--- a/src/main/java/net/minecraft/world/level/levelgen/structure/templatesystem/StructureTemplate.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/levelgen/structure/templatesystem/StructureTemplate.java
|
2024-04-25 01:25:57 +02:00
|
|
|
@@ -525,7 +525,7 @@ public class StructureTemplate {
|
2024-01-04 21:55:01 +01:00
|
|
|
private static Optional<Entity> createEntityIgnoreException(ServerLevelAccessor world, CompoundTag nbt) {
|
|
|
|
// CraftBukkit start
|
|
|
|
// try {
|
|
|
|
- return EntityType.create(nbt, world.getLevel());
|
2024-01-13 18:34:33 +01:00
|
|
|
+ return EntityType.create(nbt, world.getLevel(), true); // Paper - Don't fire sync event during generation
|
2024-01-04 21:55:01 +01:00
|
|
|
// } catch (Exception exception) {
|
|
|
|
// return Optional.empty();
|
|
|
|
// }
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/util/DelegatedGeneratorAccess.java b/src/main/java/org/bukkit/craftbukkit/util/DelegatedGeneratorAccess.java
|
2024-06-19 19:29:03 +02:00
|
|
|
index 524b51a0ab808a0629c871ad813115abd4b49dbd..fceed3d08ee6f4c171685986bb19d2be592eedc6 100644
|
2024-01-04 21:55:01 +01:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/util/DelegatedGeneratorAccess.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/util/DelegatedGeneratorAccess.java
|
2024-04-25 01:25:57 +02:00
|
|
|
@@ -92,15 +92,17 @@ public abstract class DelegatedGeneratorAccess implements WorldGenLevel {
|
2024-01-04 21:55:01 +01:00
|
|
|
return this.handle.getLevel();
|
|
|
|
}
|
|
|
|
|
|
|
|
- @Override
|
|
|
|
- public void addFreshEntityWithPassengers(Entity arg0, CreatureSpawnEvent.SpawnReason arg1) {
|
|
|
|
- this.handle.addFreshEntityWithPassengers(arg0, arg1);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public void addFreshEntityWithPassengers(Entity entity) {
|
|
|
|
- this.handle.addFreshEntityWithPassengers(entity);
|
|
|
|
- }
|
2024-01-13 18:34:33 +01:00
|
|
|
+ // Paper start - Don't fire sync event during generation; don't override these methods so all entities are run through addFreshEntity
|
2024-01-04 21:55:01 +01:00
|
|
|
+ // @Override
|
|
|
|
+ // public void addFreshEntityWithPassengers(Entity arg0, CreatureSpawnEvent.SpawnReason arg1) {
|
|
|
|
+ // this.handle.addFreshEntityWithPassengers(arg0, arg1);
|
|
|
|
+ // }
|
|
|
|
+ //
|
|
|
|
+ // @Override
|
|
|
|
+ // public void addFreshEntityWithPassengers(Entity entity) {
|
|
|
|
+ // this.handle.addFreshEntityWithPassengers(entity);
|
|
|
|
+ // }
|
2024-01-13 18:34:33 +01:00
|
|
|
+ // Paper end - Don't fire sync event during generation; don't override these methods
|
2024-01-04 21:55:01 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public ServerLevel getMinecraftWorld() {
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/util/TransformerGeneratorAccess.java b/src/main/java/org/bukkit/craftbukkit/util/TransformerGeneratorAccess.java
|
2024-04-25 01:25:57 +02:00
|
|
|
index 35ecf6f824aca56a20280dd683123df1d0c7d66e..1d1fdcf10498c421f106158254e052da6d68d8a5 100644
|
2024-01-04 21:55:01 +01:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/util/TransformerGeneratorAccess.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/util/TransformerGeneratorAccess.java
|
|
|
|
@@ -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);
|
|
|
|
- }
|
2024-01-13 18:34:33 +01:00
|
|
|
+ // Paper start - Don't fire sync event during generation; don't override these methods so all entities are run through addFreshEntity
|
2024-01-04 21:55:01 +01:00
|
|
|
+ // @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);
|
|
|
|
+ // }
|
2024-01-13 18:34:33 +01:00
|
|
|
+ // Paper end - Don't fire sync event during generation; don't override these methods
|
2024-01-04 21:55:01 +01:00
|
|
|
|
|
|
|
public boolean setCraftBlock(BlockPos position, CraftBlockState craftBlockState, int i, int j) {
|
|
|
|
if (this.structureTransformer != null) {
|