Which java class triggers natural mob spawns?

会有一股神秘感。 提交于 2021-01-29 02:50:53

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!