类 MobSpawnEvent
java.lang.Object
net.minecraftforge.eventbus.api.Event
net.minecraftforge.event.entity.EntityEvent
net.minecraftforge.event.entity.living.MobSpawnEvent
This class holds all events relating to the entire flow of mob spawns.
Currently, the events have the following flow for any given mob spawn:
Currently, the events have the following flow for any given mob spawn:
Before the spawn is attempted MobSpawnEvent.SpawnPlacementCheck
is fired, to determine if the spawn may occur based on mob-specific rules.
After the entity is created MobSpawnEvent.PositionCheck
is fired, to determine if the selected position is legal for the entity.
If both checks succeeded, MobSpawnEvent.FinalizeSpawn
is fired, which performs initialization on the newly-spawned entity.
Finally, if the spawn was not cancelled via MobSpawnEvent.FinalizeSpawn.setSpawnCancelled(boolean)
, then
is fired as the entity enters the world.
引用无效
EntityJoinLevelEvent
MobSpawnEvent.AllowDespawn
is not related to the mob spawn event flow, as it fires when a despawn is attempted.
-
嵌套类概要
嵌套类修饰符和类型类说明static class
This event is fired fromMob.checkDespawn()
.
It fires once per tick per mob that is attempting to despawn.
It is not fired if the mob is persistent (meaning it may not despawn).static class
This event is fired beforeMob.finalizeSpawn(net.minecraft.world.level.ServerLevelAccessor, net.minecraft.world.DifficultyInstance, net.minecraft.world.entity.EntitySpawnReason, net.minecraft.world.entity.SpawnGroupData)
is called.
This allows mods to control mob initialization.
In vanilla code, this event is injected by a transformer and not via patch, so calls cannot be traced via call hierarchy (it is not source-visible).static class
This event is fired when a mob checks for a valid spawn position, afterSpawnPlacements.checkSpawnRules(net.minecraft.world.entity.EntityType<T>, net.minecraft.world.level.ServerLevelAccessor, net.minecraft.world.entity.EntitySpawnReason, net.minecraft.core.BlockPos, net.minecraft.util.RandomSource)
has been evaluated.
Conditions validated here include the following: Obstruction - mobs inside blocks or fluids. Pathfinding - if the spawn block is valid for pathfinding. Sea Level - Ocelots check if the position is above sea level. Spawn Block - Ocelots check if the below block is grass or leaves.static class
This event is fired when Spawn Placements (aka Spawn Rules) are checked, before a mob attempts to spawn.
Spawn Placement checks include light levels, slime chunks, grass blocks for animals, and others in the same vein.
The purpose of this event is to permit runtime changes to any or all spawn placement logic without having to wrap the placement for each entity.从类继承的嵌套类/接口 net.minecraftforge.event.entity.EntityEvent
EntityEvent.EnteringSection, EntityEvent.EntityConstructing
从类继承的嵌套类/接口 net.minecraftforge.eventbus.api.Event
net.minecraftforge.eventbus.api.Event.HasResult, net.minecraftforge.eventbus.api.Event.Result
-
字段概要
字段修饰符和类型字段说明private final ServerLevelAccessor
private final double
private final double
private final double
-
构造器概要
构造器限定符构造器说明protected
MobSpawnEvent
(Mob mob, ServerLevelAccessor level, double x, double y, double z) -
方法概要
从类继承的方法 net.minecraftforge.eventbus.api.Event
getListenerList, getPhase, getResult, hasResult, isCancelable, isCanceled, setCanceled, setPhase, setResult
-
字段详细资料
-
level
-
x
private final double x -
y
private final double y -
z
private final double z
-
-
构造器详细资料
-
MobSpawnEvent
-
-
方法详细资料
-
getEntity
- 覆盖:
getEntity
在类中EntityEvent
-
getLevel
- 返回:
- The level relating to the mob spawn action
-
getX
public double getX()- 返回:
- The x-coordinate relating to the mob spawn action
-
getY
public double getY()- 返回:
- The y-coordinate relating to the mob spawn action
-
getZ
public double getZ()- 返回:
- The z-coordinate relating to the mob spawn action
-