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

Aperta
#14,475 0 commenti 1 reazione 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
68/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
java
Ambito
backend, game-dev

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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

Lingua principale
Java
Stelle
12.8k
Fork
3.6k
Merge medio
3g 7h
PR unite (30g)
19

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di PaperMC/Paper

Tutte le issue di PaperMC/Paper

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.