This commit is contained in:
Nassim Jahnke
2024-12-13 20:30:07 +01:00
parent 4091c6ac4d
commit c3d5f253fe
12 changed files with 155 additions and 170 deletions

View File

@@ -1,11 +0,0 @@
--- a/net/minecraft/world/level/gameevent/DynamicGameEventListener.java
+++ b/net/minecraft/world/level/gameevent/DynamicGameEventListener.java
@@ -41,7 +41,7 @@
private static void ifChunkExists(LevelReader world, @Nullable SectionPos sectionPos, Consumer<GameEventListenerRegistry> dispatcherConsumer) {
if (sectionPos != null) {
- ChunkAccess chunkAccess = world.getChunk(sectionPos.x(), sectionPos.z(), ChunkStatus.FULL, false);
+ ChunkAccess chunkAccess = world.getChunkIfLoadedImmediately(sectionPos.getX(), sectionPos.getZ()); // Paper - Perf: can cause sync loads while completing a chunk, resulting in deadlock
if (chunkAccess != null) {
dispatcherConsumer.accept(chunkAccess.getListenerRegistry(sectionPos.y()));
}

View File

@@ -1,11 +0,0 @@
--- a/net/minecraft/world/level/gameevent/GameEvent.java
+++ b/net/minecraft/world/level/gameevent/GameEvent.java
@@ -85,7 +85,7 @@
}
private static Holder.Reference<GameEvent> register(String id, int range) {
- return Registry.registerForHolder(BuiltInRegistries.GAME_EVENT, ResourceLocation.withDefaultNamespace(id), new GameEvent(range));
+ return io.papermc.paper.registry.PaperRegistryListenerManager.INSTANCE.registerForHolderWithListeners(BuiltInRegistries.GAME_EVENT, ResourceLocation.withDefaultNamespace(id), new GameEvent(range)); // Paper - run with listeners
}
public static record Context(@Nullable Entity sourceEntity, @Nullable BlockState affectedState) {

View File

@@ -1,39 +0,0 @@
--- a/net/minecraft/world/level/gameevent/GameEventDispatcher.java
+++ b/net/minecraft/world/level/gameevent/GameEventDispatcher.java
@@ -11,6 +11,12 @@
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraft.world.phys.Vec3;
+// CraftBukkit start
+import org.bukkit.Bukkit;
+import org.bukkit.craftbukkit.CraftGameEvent;
+import org.bukkit.craftbukkit.util.CraftLocation;
+import org.bukkit.event.world.GenericGameEvent;
+// CraftBukkit end
public class GameEventDispatcher {
@@ -23,6 +29,14 @@
public void post(Holder<GameEvent> event, Vec3 emitterPos, GameEvent.Context emitter) {
int i = ((GameEvent) event.value()).notificationRadius();
BlockPos blockposition = BlockPos.containing(emitterPos);
+ // CraftBukkit start
+ GenericGameEvent event1 = new GenericGameEvent(CraftGameEvent.minecraftToBukkit(event.value()), CraftLocation.toBukkit(blockposition, this.level.getWorld()), (emitter.sourceEntity() == null) ? null : emitter.sourceEntity().getBukkitEntity(), i, !Bukkit.isPrimaryThread());
+ this.level.getCraftServer().getPluginManager().callEvent(event1);
+ if (event1.isCancelled()) {
+ return;
+ }
+ i = event1.getRadius();
+ // CraftBukkit end
int j = SectionPos.blockToSectionCoord(blockposition.getX() - i);
int k = SectionPos.blockToSectionCoord(blockposition.getY() - i);
int l = SectionPos.blockToSectionCoord(blockposition.getZ() - i);
@@ -42,7 +56,7 @@
for (int l1 = j; l1 <= i1; ++l1) {
for (int i2 = l; i2 <= k1; ++i2) {
- LevelChunk chunk = this.level.getChunkSource().getChunkNow(l1, i2);
+ LevelChunk chunk = (LevelChunk) this.level.getChunkIfLoadedImmediately(l1, i2); // Paper - Use getChunkIfLoadedImmediately
if (chunk != null) {
for (int j2 = k; j2 <= j1; ++j2) {