Skip to content

EntitySpawnEvent

Namespace Mc.Scripting.Events · Kind struct (ref)

public ref struct EntitySpawnEvent : IEvent

An entity is about to be added to the world. Cancel to prevent it.

Id 30
Key mc:entity_spawn
Cancellable yes
Fired by the engine yes
Field Type Handlers may write Description
Entity Entity no (readonly) The entity (already created).
EntityType key.entity_type no (readonly) The entity type key, e.g. minecraft:zombie.
Position Vec3d no (readonly) Where it appears.
Reason enum:SpawnReason no (readonly) Why it spawns.

Set e.Cancelled = true in a handler to cancel it; lower-priority handlers are skipped unless they subscribed with receiveCancelled: true.

Member Description
EntitySpawnEvent(Entity entity, int entityType, Vec3d position, SpawnReason reason) Creates the event (for firing it from a plugin; native code builds its own).
public EntitySpawnEvent(Entity entity, int entityType, Vec3d position, SpawnReason reason)

Creates the event (for firing it from a plugin; native code builds its own). Signature of API 1.0.

Parameters

Name Type Description
entity Entity
entityType int
position Vec3d
reason SpawnReason
Member Description
bool Cancelled { get; set; } Cancelling stops lower-priority handlers (unless they opt in) and the action itself.
Entity Entity { get; } The entity (already created).
string EntityType { get; } The entity type key, e.g.
Vec3d Position { get; } Where it appears.
SpawnReason Reason { get; } Why it spawns.
static ushort CatalogueId { get; } Catalogue id (stable ABI).
static bool IsCancellable { get; } Whether handlers can cancel the event.
static string Key { get; } Registry key of the event.
public bool Cancelled { get; set; }

Cancelling stops lower-priority handlers (unless they opt in) and the action itself.

public Entity Entity { get; }

The entity (already created).

public string EntityType { get; }

The entity type key, e.g. minecraft:zombie. (a registry key such as “minecraft:entity”; resolved on first access).

public Vec3d Position { get; }

Where it appears.

public SpawnReason Reason { get; }

Why it spawns.

public static ushort CatalogueId { get; }

Catalogue id (stable ABI).

public static bool IsCancellable { get; }

Whether handlers can cancel the event.

public static string Key { get; }

Registry key of the event.

Entity · IEvent · SpawnReason · Vec3d