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

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

View File

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

View File

@@ -0,0 +1,40 @@
--- a/net/minecraft/world/level/gameevent/GameEventDispatcher.java
+++ b/net/minecraft/world/level/gameevent/GameEventDispatcher.java
@@ -11,6 +_,13 @@
import net.minecraft.world.level.chunk.ChunkAccess;
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 {
private final ServerLevel level;
@@ -21,6 +_,14 @@
public void post(Holder<GameEvent> gameEvent, Vec3 pos, GameEvent.Context context) {
int notificationRadius = gameEvent.value().notificationRadius();
BlockPos blockPos = BlockPos.containing(pos);
+ // CraftBukkit start
+ GenericGameEvent apiEvent = new GenericGameEvent(CraftGameEvent.minecraftToBukkit(gameEvent.value()), CraftLocation.toBukkit(blockPos, this.level.getWorld()), (context.sourceEntity() == null) ? null : context.sourceEntity().getBukkitEntity(), notificationRadius, !Bukkit.isPrimaryThread());
+ this.level.getCraftServer().getPluginManager().callEvent(apiEvent);
+ if (apiEvent.isCancelled()) {
+ return;
+ }
+ notificationRadius = apiEvent.getRadius();
+ // CraftBukkit end
int sectionPosCoord = SectionPos.blockToSectionCoord(blockPos.getX() - notificationRadius);
int sectionPosCoord1 = SectionPos.blockToSectionCoord(blockPos.getY() - notificationRadius);
int sectionPosCoord2 = SectionPos.blockToSectionCoord(blockPos.getZ() - notificationRadius);
@@ -39,7 +_,7 @@
for (int i = sectionPosCoord; i <= sectionPosCoord3; i++) {
for (int i1 = sectionPosCoord2; i1 <= sectionPosCoord5; i1++) {
- ChunkAccess chunkNow = this.level.getChunkSource().getChunkNow(i, i1);
+ ChunkAccess chunkNow = this.level.getChunkIfLoadedImmediately(i, i1); // Paper - Use getChunkIfLoadedImmediately
if (chunkNow != null) {
for (int i2 = sectionPosCoord1; i2 <= sectionPosCoord4; i2++) {
flag |= chunkNow.getListenerRegistry(i2).visitInRangeListeners(gameEvent, pos, context, listenerVisitor);