Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-12-15 02:50:09 +01:00
ac554ad46d
Updated Upstream (Bukkit/CraftBukkit) Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: fa99e752 PR-1007: Add ItemMeta#getAsComponentString() 94a91782 Fix copy-pasted BlockType.Typed documentation 9b34ac8c Largely restore deprecated PotionData API 51a6449b PR-1008: Deprecate ITEMS_TOOLS, removed in 1.20.5 702d15fe Fix Javadoc reference 42f6cdf4 PR-919: Add internal ItemType and BlockType, delegate Material methods to them 237bb37b SPIGOT-1166, SPIGOT-7647: Expose Damager BlockState in EntityDamageByBlockEvent 035ea146 SPIGOT-6993: Allow #setVelocity to change the speed of a fireball and add a note to #setDirection about it 8c7880fb PR-1004: Improve field rename handling and centralize conversion between bukkit and string more 87c90e93 SPIGOT-7650: Add DamageSource for EntityDeathEvent and PlayerDeathEvent CraftBukkit Changes: 4af0f22e8 SPIGOT-7664: Item meta should prevail over block states c2ccc46ec SPIGOT-7666: Fix access to llama and horse special slot 124ac66d7 SPIGOT-7665: Fix ThrownPotion#getEffects() implementation only bringing custom effects 66f1f439a Restore null page behaviour of signed books even though not strictly allowed by API 6118e5398 Fix regression listening to minecraft:brand custom payloads c1a26b366 Fix unnecessary and potential not thread-safe chat visibility check 12360a7ec Remove unused imports 147b098b4 PR-1397: Add ItemMeta#getAsComponentString() 428aefe0e Largely restore deprecated PotionData API afe5b5ee9 PR-1275: Add internal ItemType and BlockType, delegate Material methods to them 8afeafa7d SPIGOT-1166, SPIGOT-7647: Expose Damager BlockState in EntityDamageByBlockEvent 4e7d749d4 SPIGOT-6993: Allow #setVelocity to change the speed of a fireball and add a note to #setDirection about it 441880757 Support both entity_data and bucket_entity_data on axolotl/fish buckets 0e22fdd1e Fix custom direct BlockState being not correctly set in DamageSource f2182ed47 SPIGOT-7659: TropicalFishBucketMeta should use BUCKET_ENTITY_DATA 2a6207fe1 PR-1393: Improve field rename handling and centralize conversion between bukkit and string more c024a5039 SPIGOT-7650: Add DamageSource for EntityDeathEvent and PlayerDeathEvent 741b84480 PR-1390: Improve internal handling of damage sources 0364df4e1 SPIGOT-7657: Error when loading angry entities
209 Zeilen
12 KiB
Diff
209 Zeilen
12 KiB
Diff
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
|
|
index 2da315d288efa66f7bff96923ebd5eac5130ba39..39cf7ae086108d8077121829368b81605d046fab 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
@@ -1226,6 +1226,7 @@ public class ServerLevel extends Level implements WorldGenLevel {
|
|
// CraftBukkit start
|
|
private boolean addEntity(Entity entity, CreatureSpawnEvent.SpawnReason spawnReason) {
|
|
org.spigotmc.AsyncCatcher.catchOp("entity add"); // Spigot
|
|
+ entity.generation = false; // Paper - Don't fire sync event during generation; Reset flag if it was added during a ServerLevel generation process
|
|
// Paper start - extra debug info
|
|
if (entity.valid) {
|
|
MinecraftServer.LOGGER.error("Attempted Double World add on {}", entity, new Throwable());
|
|
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
index 7f2ffffa270f493224ea97fcd0e862baf36ae40c..df82f696dc3a3ce388cfedbede22f503575a888a 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/Entity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
@@ -650,7 +650,11 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
|
if (pose == this.getPose()) {
|
|
return;
|
|
}
|
|
- this.level.getCraftServer().getPluginManager().callEvent(new EntityPoseChangeEvent(this.getBukkitEntity(), Pose.values()[pose.ordinal()]));
|
|
+ // Paper start - Don't fire sync event during generation
|
|
+ if (!this.generation) {
|
|
+ this.level.getCraftServer().getPluginManager().callEvent(new EntityPoseChangeEvent(this.getBukkitEntity(), Pose.values()[pose.ordinal()]));
|
|
+ }
|
|
+ // Paper end - Don't fire sync event during generation
|
|
// 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
|
|
index d769dc472d3f12bf1e30ddd767a76659b734caac..8c7cc9c5af0b8d8bef9b6e2d3d3e723cd76f3212 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/EntityType.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/EntityType.java
|
|
@@ -592,9 +592,15 @@ public class EntityType<T extends Entity> implements FeatureElement, EntityTypeT
|
|
}
|
|
|
|
public static Optional<Entity> create(CompoundTag nbt, Level world) {
|
|
+ // Paper start - Don't fire sync event during generation
|
|
+ return create(nbt, world, false);
|
|
+ }
|
|
+ public static Optional<Entity> create(CompoundTag nbt, Level world, boolean generation) {
|
|
+ // Paper end - Don't fire sync event during generation
|
|
return Util.ifElse(EntityType.by(nbt).map((entitytypes) -> {
|
|
return entitytypes.create(world);
|
|
}), (entity) -> {
|
|
+ if (generation) entity.generation = true; // Paper - Don't fire sync event during generation
|
|
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
|
|
index c5cc7edd3d100b31a6319b6924de524305adb023..048e8dcdc56d02a5466085f4842fdd7f8f5f12a8 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
|
@@ -1163,6 +1163,11 @@ public abstract class LivingEntity extends Entity implements Attackable {
|
|
}
|
|
|
|
public boolean addEffect(MobEffectInstance mobeffect, @Nullable Entity entity, EntityPotionEffectEvent.Cause cause) {
|
|
+ // Paper start - Don't fire sync event during generation
|
|
+ return this.addEffect(mobeffect, entity, cause, true);
|
|
+ }
|
|
+ public boolean addEffect(MobEffectInstance mobeffect, @Nullable Entity entity, EntityPotionEffectEvent.Cause cause, boolean fireEvent) {
|
|
+ // Paper end - Don't fire sync event during generation
|
|
// org.spigotmc.AsyncCatcher.catchOp("effect add"); // Spigot // Paper - move to API
|
|
if (this.isTickingEffects) {
|
|
this.effectsToProcess.add(new ProcessableEffect(mobeffect, cause));
|
|
@@ -1182,10 +1187,13 @@ public abstract class LivingEntity extends Entity implements Attackable {
|
|
override = new MobEffectInstance(mobeffect1).update(mobeffect);
|
|
}
|
|
|
|
+ if (fireEvent) { // Paper - Don't fire sync event during generation
|
|
EntityPotionEffectEvent event = CraftEventFactory.callEntityPotionEffectChangeEvent(this, mobeffect1, mobeffect, cause, override);
|
|
+ override = event.isOverride(); // Paper - Don't fire sync event during generation
|
|
if (event.isCancelled()) {
|
|
return false;
|
|
}
|
|
+ } // Paper - Don't fire sync event during generation
|
|
// CraftBukkit end
|
|
|
|
if (mobeffect1 == null) {
|
|
@@ -1194,7 +1202,7 @@ public abstract class LivingEntity extends Entity implements Attackable {
|
|
flag = true;
|
|
mobeffect.onEffectAdded(this);
|
|
// CraftBukkit start
|
|
- } else if (event.isOverride()) {
|
|
+ } else if (override) { // Paper - Don't fire sync event during generation
|
|
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
|
|
index 6006480d9f6d60bb7b5628eabe6740013066cde4..f0127f1b55999aa4a841341ad02cbcde45702b50 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/monster/Spider.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/monster/Spider.java
|
|
@@ -172,7 +172,7 @@ public class Spider extends Monster {
|
|
Holder<MobEffect> holder = entityspider_groupdataspider.effect;
|
|
|
|
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
|
|
}
|
|
}
|
|
|
|
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
|
|
index b5365dce7882c98b5be4f5df877165eee80933dd..9b4e2f96299bb12af7090ef70ac158c825d49d19 100644
|
|
--- 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
|
|
@@ -525,7 +525,7 @@ public class StructureTemplate {
|
|
private static Optional<Entity> createEntityIgnoreException(ServerLevelAccessor world, CompoundTag nbt) {
|
|
// CraftBukkit start
|
|
// try {
|
|
- return EntityType.create(nbt, world.getLevel());
|
|
+ return EntityType.create(nbt, world.getLevel(), true); // Paper - Don't fire sync event during generation
|
|
// } 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
|
|
index 0794d92c42b0db6b367505ae28f09f1fd39fa312..cd7f1309cf01a5f01a28aded03a36fe15adb1756 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/util/DelegatedGeneratorAccess.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/util/DelegatedGeneratorAccess.java
|
|
@@ -92,15 +92,17 @@ public abstract class DelegatedGeneratorAccess implements WorldGenLevel {
|
|
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);
|
|
- }
|
|
+ // 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 arg0, CreatureSpawnEvent.SpawnReason arg1) {
|
|
+ // this.handle.addFreshEntityWithPassengers(arg0, arg1);
|
|
+ // }
|
|
+ //
|
|
+ // @Override
|
|
+ // public void addFreshEntityWithPassengers(Entity entity) {
|
|
+ // this.handle.addFreshEntityWithPassengers(entity);
|
|
+ // }
|
|
+ // Paper end - Don't fire sync event during generation; don't override these methods
|
|
|
|
@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
|
|
index 35ecf6f824aca56a20280dd683123df1d0c7d66e..1d1fdcf10498c421f106158254e052da6d68d8a5 100644
|
|
--- 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);
|
|
- }
|
|
+ // 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) {
|