类 FinalizeSpawnEvent
- 所有已实现的接口:
net.neoforged.bus.api.ICancellableEvent
Mob.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).
Canceling this event will result in Mob.finalizeSpawn(net.minecraft.world.level.ServerLevelAccessor, net.minecraft.world.DifficultyInstance, net.minecraft.world.entity.EntitySpawnReason, net.minecraft.world.entity.SpawnGroupData)
not being called, and the returned value always being null, instead of propagating the SpawnGroupData.
The entity will still be spawned. If you want to prevent the spawn, use setSpawnCancelled(boolean)
, which will cause Forge to prevent the spawn.
This event is fired on NeoForge.EVENT_BUS
, and is only fired on the logical server.
- 另请参阅:
- API Note:
- Callers do not need to check if the entity's spawn was cancelled, as the spawn will be blocked by Forge.
-
嵌套类概要
从类继承的嵌套类/接口 net.neoforged.neoforge.event.entity.living.MobSpawnEvent
MobSpawnEvent.PositionCheck, MobSpawnEvent.SpawnPlacementCheck
从类继承的嵌套类/接口 net.neoforged.neoforge.event.entity.EntityEvent
EntityEvent.EnteringSection, EntityEvent.EntityConstructing, EntityEvent.Size
-
字段概要
字段修饰符和类型字段说明private DifficultyInstance
private @Nullable SpawnGroupData
private final @Nullable com.mojang.datafixers.util.Either
<BlockEntity, Entity> private final EntitySpawnReason
-
构造器概要
构造器构造器说明FinalizeSpawnEvent
(Mob entity, ServerLevelAccessor level, double x, double y, double z, DifficultyInstance difficulty, EntitySpawnReason spawnType, @Nullable SpawnGroupData spawnData, @Nullable com.mojang.datafixers.util.Either<BlockEntity, Entity> spawner) -
方法概要
修饰符和类型方法说明Retrieves theDifficultyInstance
for the chunk where the mob is about to be spawned.@Nullable SpawnGroupData
Retrieves theSpawnGroupData
for this entity.@Nullable com.mojang.datafixers.util.Either
<BlockEntity, Entity> Retrieves the underlyingBlockEntity
orEntity
that performed the spawn.Retrieves the type of mob spawn that happened (the event that caused the spawn).boolean
Returns the current spawn cancellation status, which can be changed viasetSpawnCancelled(boolean)
.void
Sets the difficulty instance for this event, which will be propagated toMob.finalizeSpawn(net.minecraft.world.level.ServerLevelAccessor, net.minecraft.world.DifficultyInstance, net.minecraft.world.entity.EntitySpawnReason, net.minecraft.world.entity.SpawnGroupData)
unless cancelled.void
setSpawnCancelled
(boolean cancel) This method can be used to cancel the spawn of this mob.void
setSpawnData
(@Nullable SpawnGroupData data) Sets the spawn data for this entity.从类继承的方法 net.neoforged.neoforge.event.entity.living.MobSpawnEvent
getEntity, getLevel, getX, getY, getZ
从类继承的方法 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
从接口继承的方法 net.neoforged.bus.api.ICancellableEvent
isCanceled, setCanceled
-
字段详细资料
-
spawnType
-
spawner
-
difficulty
-
spawnData
-
-
构造器详细资料
-
FinalizeSpawnEvent
@Internal public FinalizeSpawnEvent(Mob entity, ServerLevelAccessor level, double x, double y, double z, DifficultyInstance difficulty, EntitySpawnReason spawnType, @Nullable @Nullable SpawnGroupData spawnData, @Nullable @Nullable com.mojang.datafixers.util.Either<BlockEntity, Entity> spawner) - API Note:
- Fire via
引用无效
EventHooks#onFinalizeSpawn
引用无效
EventHooks#onFinalizeSpawnSpawner
-
-
方法详细资料
-
getDifficulty
Retrieves theDifficultyInstance
for the chunk where the mob is about to be spawned.- 返回:
- The local difficulty instance
-
setDifficulty
Sets the difficulty instance for this event, which will be propagated toMob.finalizeSpawn(net.minecraft.world.level.ServerLevelAccessor, net.minecraft.world.DifficultyInstance, net.minecraft.world.entity.EntitySpawnReason, net.minecraft.world.entity.SpawnGroupData)
unless cancelled. The difficulty instance controls how likely certain random effects are to occur, or if certain mob abilities are enabled.- 参数:
inst
- The new difficulty instance.
-
getSpawnType
Retrieves the type of mob spawn that happened (the event that caused the spawn). The enum names are self-explanatory.- 返回:
- The mob spawn type.
- 另请参阅:
-
getSpawnData
Retrieves theSpawnGroupData
for this entity. When spawning mobs in a loop, this group data is used for the entire group and impacts future spawns. This is how entities like horses ensure that the whole group spawns as a single variant. How this is used varies on a per-entity basis.- 返回:
- The spawn group data.
-
setSpawnData
Sets the spawn data for this entity. If this event is cancelled, this value is not used, sinceMob.finalizeSpawn(net.minecraft.world.level.ServerLevelAccessor, net.minecraft.world.DifficultyInstance, net.minecraft.world.entity.EntitySpawnReason, net.minecraft.world.entity.SpawnGroupData)
will not be called.- 参数:
data
- The new spawn data- 另请参阅:
-
getSpawner
Retrieves the underlyingBlockEntity
orEntity
that performed the spawn. This may be aSpawnerBlockEntity
,TrialSpawnerBlockEntity
,MinecartSpawner
, or similar modded object.This is usually null unless the
spawn type
is a引用无效
spawner type
- 返回:
- The spawner responsible for triggering the spawn, or null if none is available.
-
setSpawnCancelled
public void setSpawnCancelled(boolean cancel) This method can be used to cancel the spawn of this mob.This method must be used if you want to block the spawn, as canceling the event only blocks the call to
Mob.finalizeSpawn(net.minecraft.world.level.ServerLevelAccessor, net.minecraft.world.DifficultyInstance, net.minecraft.world.entity.EntitySpawnReason, net.minecraft.world.entity.SpawnGroupData)
.Note that if the spawn is cancelled, but the event is not, then
Mob.finalizeSpawn(net.minecraft.world.level.ServerLevelAccessor, net.minecraft.world.DifficultyInstance, net.minecraft.world.entity.EntitySpawnReason, net.minecraft.world.entity.SpawnGroupData)
will still be called, but the entity will not be spawned. Usually that has no side effects, but callers should be aware.- 参数:
cancel
- If the spawn should be cancelled (or not).
-
isSpawnCancelled
public boolean isSpawnCancelled()Returns the current spawn cancellation status, which can be changed viasetSpawnCancelled(boolean)
.- 返回:
- If this mob's spawn is cancelled or not.
- Implementation Note:
- This is enforced in
NeoForgeEventHandler.builtinMobSpawnBlocker(net.neoforged.neoforge.event.entity.EntityJoinLevelEvent)
and a patch in引用无效
WorldGenRegion#addEntity
-