问题
I'm trying to find in the code which class or classes trigger mob spawns. For example if I wanted to change the Y at which slimes spawn or allow a custom mob like an elephant spawn on the Savannah biome.
Intent is to do this for a forge mod, but I assume the answer is standard for minecraft?
Thanks!
回答1:
For mod-added entities, EntityRegistry.addSpawn(...)
is used to register which biomes the entity will spawn in using the existing per-biome spawn rules.
For slimes, the class EntitySlime controls what Y heights it is allowed to spawn at, see the getCanSpawnHere()
method. However, you cannot modify this class. In order to override what heights are valid, you would need to subscribe to the LivingSpawnEvent
(there are three subclasses, you would want to subscribe to one of the three) and set the result to Result.ALLOW
to force the entity to spawn regardless of its usual spawn checks (conversely, Result.DENY
to prevent it).
来源:https://stackoverflow.com/questions/45467830/which-java-class-triggers-natural-mob-spawns