PreCreatureSpawnEvent fires before vanilla placement checks in isValidSpawnPostitionForType, inflating per-player mobBackoffCounts in air/water

Đang mở
#14,475 0 bình luận 1 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
68/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
java
Lĩnh vực
backend, game-dev

Hướng nghiên cứu

Start in NaturalSpawner.isValidSpawnPostitionForType and trace how its return status reaches spawnCategoryForPosition and updateFailurePlayerMobTypeMap. Check the existing placement checks and PreCreatureSpawnEvent call order, then run the relevant spawning tests. Done means the event fires only after placement checks pass and invalid coordinates do not inflate player mob backoff counts.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

status: needs triage version: 26.3
Expected behavior

In NaturalSpawner.isValidSpawnPostitionForType, PreCreatureSpawnEvent should only be called after the vanilla placement checks (SpawnPlacements.isSpawnPositionOk, SpawnPlacements.checkSpawnRules, level.noCollision) succeed, so that impossible mid-air/water coordinates return PreSpawnStatus.FAIL instead of triggering plugin cancellations and inflating mobBackoffCounts via updateFailurePlayerMobTypeMap.

Observed/Actual behavior

In NaturalSpawner.isValidSpawnPostitionForType (lines 387–406), PreCreatureSpawnEvent is fired at the very start of the method, before SpawnPlacements.isSpawnPositionOk, SpawnPlacements.checkSpawnRules, and level.noCollision:

  1. NaturalSpawner.getRandomPosWithin picks a random (x, y, z) between minY and the highest block in the chunk.
  2. isValidSpawnPostitionForType immediately fires PreCreatureSpawnEvent even if pos is mid-air (void) or water where the chosen mob could never spawn.
  3. When a plugin (such as WorldGuard with regions.use-pre-creature-spawn-event: true and mob-spawning: deny) cancels the event, isValidSpawnPostitionForType returns PreSpawnStatus.CANCELLED.
  4. NaturalSpawner.spawnCategoryForPosition (line 303) then calls chunkMap.updateFailurePlayerMobTypeMap, incrementing ServerPlayer.mobBackoffCounts for every random mid-air/water hit.
  5. As a result, /paper playermobcaps immediately maxes out (e.g. 70/70 monsters with 0 actual monsters in the world) and completely starves natural spawning in valid areas above/outside the region.

Moving the PreCreatureSpawnEvent call to the end of isValidSpawnPostitionForType (after the boolean placement checks pass) still avoids entity instantiation (getMobForSpawn / finalizeSpawn), avoids spamming plugins with thousands of mid-air events, and prevents false backoff inflation.

Steps/models to reproduce
  1. Start a Paper server with WorldGuard installed and set regions.use-pre-creature-spawn-event: true in plugins/WorldGuard/config.yml (WorldGuard had to disable this by default in 7.0.20 due to this exact issue, see EngineHub/WorldGuard#2314).
  2. Create a flat water world (/mv create waterworld normal -t FLAT -gs {"biome":"minecraft:ocean","layers":[{"block":"minecraft:water","height":128}]}) or a Skyblock/void world.
  3. Create a WorldGuard region covering the water/air layer (-200, -64, -200 to 200, 64, 200) with mob-spawning: deny.
  4. Build a closed dark stone box above the region (e.g. from -50, 70, -50 to 50, 100, 50) and stand near it.
  5. Check /paper playermobcaps: the MONSTER cap is permanently full via mobBackoffCounts with 0 real monsters, and almost nothing spawns in the dark box.
Plugin and Datapack List

Plugins (3): Multiverse-Core, WorldEdit, WorldGuard
Datapacks: vanilla, paper

Paper version

This server is running Paper version 26.3-248-main@0727243 (2026-11-10T11:35:52Z) (Implementing API version 26.3.build.248-stable)
You are running the latest version

Other

Related WorldGuard issue: https://github.com/EngineHub/WorldGuard/issues/2314

Ngôn ngữ chính
Java
Star
12.8k
Fork
3.6k
Merge trung bình
3 ngày 7 giờ
Pull request đã merge (30 ngày)
19

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của PaperMC/Paper

Tất cả issue của PaperMC/Paper

Issue tương tự

Thêm issue về Java

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.