Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions docs/entities/livingentity.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,73 @@ DeferredItem<SpawnEggItem> MY_ENTITY_SPAWN_EGG = ITEMS.registerItem("my_entity_s

As an item like any other, the item should be added to a [creative tab][creative], and a [client item][clientitem], [model] and [translation] should be added.

### Spawn Placements

By default, spawning will be possible anywhere, including inside blocks and in midair. To prevent this, a spawn placement must be registered. This happens in the `RegisterSpawnPlacementsEvent` like so:

```java
@SubscribeEvent // on the mod event bus
public static void registerSpawnPlacements(RegisterSpawnPlacementsEvent event) {
event.register(
// The EntityType<?> to register the spawn placement for.
MY_ENTITY.get(),
// SpawnPlacementType is a functional interface that checks whether a given position is valid
// for spawning. You can add your own SpawnPlacementType if needed,
// see the implementation of SpawnPlacementTypes for reference.
// Vanilla values include NO_RESTRICTIONS, IN_WATER, IN_LAVA and ON_GROUND.
SpawnPlacementTypes.ON_GROUND,
// The heightmap type to use. This provides the initial height to check during world generation,
// later this is ignored and just uses the world surface. Possible values are

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can get rid of the latter half of this sentence. Saying it's only used during worldgen is good enough.

// WORLD_SURFACE, OCEAN_FLOOR, MOTION_BLOCKING and MOTION_BLOCKING_NO_LEAVES.
Heightmap.Types.WORLD_SURFACE,
// A predicate to check additional spawn rules, e.g. light. Can either be specified here
// as a lambda, or (more commonly) as a static method in the entity class.
(entityType, level, spawnReason, pos, random) -> {
// Make our mob only spawn on grass blocks.
return level.getBlockState(pos.below()).is(Blocks.GRASS_BLOCK)
|| Mob.checkMobSpawnRules(entityType, level, spawnReason, pos, random);
},
// For our own mobs, any operation may be used.
RegisterSpawnPlacementsEvent.Operation.OR
);
}
```

It is also possible to modify vanilla's or other mods' spawn placements. You can use one of `Operation.AND` (for extra spawn restrictions), `Operation.OR` (for alternate spawn mechanisms) or `Operation.REPLACE` (to completely replace the spawn placement, use a [low-priority event listener][priority] in this case) like so:

```java
@SubscribeEvent // on the mod event bus
public static void registerSpawnPlacements(RegisterSpawnPlacementsEvent event) {
event.register(
// The EntityType<?> to register the spawn placement for.
MY_ENTITY.get(),
// When not using Operation.REPLACE, leave the spawn placement type
// and the heightmap type at null.
null,
null,
Comment thread
IchHabeHunger54 marked this conversation as resolved.
// Like above, check the additional/alternate spawn rules.
(entityType, level, spawnReason, pos, random) -> {
return level.getBlockState(pos.below()).is(Blocks.GRASS_BLOCK)
|| Mob.checkMobSpawnRules(entityType, level, spawnReason, pos, random);
},
// Use the appropriate Operation here.
RegisterSpawnPlacementsEvent.Operation.AND
);
}
```

The event also provides two utility overloads (where `spawnPredicate` is the lambda we used earlier):

```java
@SubscribeEvent // on the mod event bus
public static void registerSpawnPlacements(RegisterSpawnPlacementsEvent event) {
// Identical to event.register(MY_ENTITY.get(), null, null, spawnPredicate, Operation.OR)
event.register(MY_ENTITY.get(), spawnPredicate);
// Identical to event.register(MY_ENTITY.get(), null, null, spawnPredicate, operation)
event.register(MY_ENTITY.get(), spawnPredicate, operation);
}
```

### Natural Spawning

_See also [Entities/`MobCategory`][mobcategory], [Worldgen/Biome Modifers/Add Spawns][addspawns], [Worldgen/Biome Modifers/Add Spawn Costs][addspawncosts]; and [Spawn Cycle][spawncycle] on the [Minecraft Wiki][mcwiki]._
Expand Down
67 changes: 67 additions & 0 deletions versioned_docs/version-1.21.10/entities/livingentity.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,73 @@ DeferredItem<SpawnEggItem> MY_ENTITY_SPAWN_EGG = ITEMS.registerItem("my_entity_s

As an item like any other, the item should be added to a [creative tab][creative], and a [client item][clientitem], [model] and [translation] should be added.

### Spawn Placements

By default, spawning will be possible anywhere, including inside blocks and in midair. To prevent this, a spawn placement must be registered. This happens in the `RegisterSpawnPlacementsEvent` like so:

```java
@SubscribeEvent // on the mod event bus
public static void registerSpawnPlacements(RegisterSpawnPlacementsEvent event) {
event.register(
// The EntityType<?> to register the spawn placement for.
MY_ENTITY.get(),
// SpawnPlacementType is a functional interface that checks whether a given position is valid
// for spawning. You can add your own SpawnPlacementType if needed,
// see the implementation of SpawnPlacementTypes for reference.
// Vanilla values include NO_RESTRICTIONS, IN_WATER, IN_LAVA and ON_GROUND.
SpawnPlacementTypes.ON_GROUND,
// The heightmap type to use. This provides the initial height to check during world generation,
// later this is ignored and just uses the world surface. Possible values are
// WORLD_SURFACE, OCEAN_FLOOR, MOTION_BLOCKING and MOTION_BLOCKING_NO_LEAVES.
Heightmap.Types.WORLD_SURFACE,
// A predicate to check additional spawn rules, e.g. light. Can either be specified here
// as a lambda, or (more commonly) as a static method in the entity class.
(entityType, level, spawnReason, pos, random) -> {
// Make our mob only spawn on grass blocks.
return level.getBlockState(pos.below()).is(Blocks.GRASS_BLOCK)
|| Mob.checkMobSpawnRules(entityType, level, spawnReason, pos, random);
},
// For our own mobs, any operation may be used.
RegisterSpawnPlacementsEvent.Operation.OR
);
}
```

It is also possible to modify vanilla's or other mods' spawn placements. You can use one of `Operation.AND` (for extra spawn restrictions), `Operation.OR` (for alternate spawn mechanisms) or `Operation.REPLACE` (to completely replace the spawn placement, use a [low-priority event listener][priority] in this case) like so:

```java
@SubscribeEvent // on the mod event bus
public static void registerSpawnPlacements(RegisterSpawnPlacementsEvent event) {
event.register(
// The EntityType<?> to register the spawn placement for.
MY_ENTITY.get(),
// When not using Operation.REPLACE, leave the spawn placement type
// and the heightmap type at null.
null,
null,
// Like above, check the additional/alternate spawn rules.
(entityType, level, spawnReason, pos, random) -> {
return level.getBlockState(pos.below()).is(Blocks.GRASS_BLOCK)
|| Mob.checkMobSpawnRules(entityType, level, spawnReason, pos, random);
},
// Use the appropriate Operation here.
RegisterSpawnPlacementsEvent.Operation.AND
);
}
```

The event also provides two utility overloads (where `spawnPredicate` is the lambda we used earlier):

```java
@SubscribeEvent // on the mod event bus
public static void registerSpawnPlacements(RegisterSpawnPlacementsEvent event) {
// Identical to event.register(MY_ENTITY.get(), null, null, spawnPredicate, Operation.OR)
event.register(MY_ENTITY.get(), spawnPredicate);
// Identical to event.register(MY_ENTITY.get(), null, null, spawnPredicate, operation)
event.register(MY_ENTITY.get(), spawnPredicate, operation);
}
```

### Natural Spawning

_See also [Entities/`MobCategory`][mobcategory], [Worldgen/Biome Modifers/Add Spawns][addspawns], [Worldgen/Biome Modifers/Add Spawn Costs][addspawncosts]; and [Spawn Cycle][spawncycle] on the [Minecraft Wiki][mcwiki]._
Expand Down
67 changes: 67 additions & 0 deletions versioned_docs/version-1.21.11/entities/livingentity.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,73 @@ DeferredItem<SpawnEggItem> MY_ENTITY_SPAWN_EGG = ITEMS.registerItem("my_entity_s

As an item like any other, the item should be added to a [creative tab][creative], and a [client item][clientitem], [model] and [translation] should be added.

### Spawn Placements

By default, spawning will be possible anywhere, including inside blocks and in midair. To prevent this, a spawn placement must be registered. This happens in the `RegisterSpawnPlacementsEvent` like so:

```java
@SubscribeEvent // on the mod event bus
public static void registerSpawnPlacements(RegisterSpawnPlacementsEvent event) {
event.register(
// The EntityType<?> to register the spawn placement for.
MY_ENTITY.get(),
// SpawnPlacementType is a functional interface that checks whether a given position is valid
// for spawning. You can add your own SpawnPlacementType if needed,
// see the implementation of SpawnPlacementTypes for reference.
// Vanilla values include NO_RESTRICTIONS, IN_WATER, IN_LAVA and ON_GROUND.
SpawnPlacementTypes.ON_GROUND,
// The heightmap type to use. This provides the initial height to check during world generation,
// later this is ignored and just uses the world surface. Possible values are
// WORLD_SURFACE, OCEAN_FLOOR, MOTION_BLOCKING and MOTION_BLOCKING_NO_LEAVES.
Heightmap.Types.WORLD_SURFACE,
// A predicate to check additional spawn rules, e.g. light. Can either be specified here
// as a lambda, or (more commonly) as a static method in the entity class.
(entityType, level, spawnReason, pos, random) -> {
// Make our mob only spawn on grass blocks.
return level.getBlockState(pos.below()).is(Blocks.GRASS_BLOCK)
|| Mob.checkMobSpawnRules(entityType, level, spawnReason, pos, random);
},
// For our own mobs, any operation may be used.
RegisterSpawnPlacementsEvent.Operation.OR
);
}
```

It is also possible to modify vanilla's or other mods' spawn placements. You can use one of `Operation.AND` (for extra spawn restrictions), `Operation.OR` (for alternate spawn mechanisms) or `Operation.REPLACE` (to completely replace the spawn placement, use a [low-priority event listener][priority] in this case) like so:

```java
@SubscribeEvent // on the mod event bus
public static void registerSpawnPlacements(RegisterSpawnPlacementsEvent event) {
event.register(
// The EntityType<?> to register the spawn placement for.
MY_ENTITY.get(),
// When not using Operation.REPLACE, leave the spawn placement type
// and the heightmap type at null.
null,
null,
// Like above, check the additional/alternate spawn rules.
(entityType, level, spawnReason, pos, random) -> {
return level.getBlockState(pos.below()).is(Blocks.GRASS_BLOCK)
|| Mob.checkMobSpawnRules(entityType, level, spawnReason, pos, random);
},
// Use the appropriate Operation here.
RegisterSpawnPlacementsEvent.Operation.AND
);
}
```

The event also provides two utility overloads (where `spawnPredicate` is the lambda we used earlier):

```java
@SubscribeEvent // on the mod event bus
public static void registerSpawnPlacements(RegisterSpawnPlacementsEvent event) {
// Identical to event.register(MY_ENTITY.get(), null, null, spawnPredicate, Operation.OR)
event.register(MY_ENTITY.get(), spawnPredicate);
// Identical to event.register(MY_ENTITY.get(), null, null, spawnPredicate, operation)
event.register(MY_ENTITY.get(), spawnPredicate, operation);
}
```

### Natural Spawning

_See also [Entities/`MobCategory`][mobcategory], [Worldgen/Biome Modifers/Add Spawns][addspawns], [Worldgen/Biome Modifers/Add Spawn Costs][addspawncosts]; and [Spawn Cycle][spawncycle] on the [Minecraft Wiki][mcwiki]._
Expand Down
67 changes: 67 additions & 0 deletions versioned_docs/version-1.21.4/entities/livingentity.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,73 @@ DeferredItem<SpawnEggItem> MY_ENTITY_SPAWN_EGG = ITEMS.registerItem("my_entity_s

As an item like any other, the item should be added to a [creative tab][creative], and a [client item][clientitem], [model] and [translation] should be added.

### Spawn Placements

By default, spawning will be possible anywhere, including inside blocks and in midair. To prevent this, a spawn placement must be registered. This happens in the `RegisterSpawnPlacementsEvent` like so:

```java
@SubscribeEvent // on the mod event bus
public static void registerSpawnPlacements(RegisterSpawnPlacementsEvent event) {
event.register(
// The EntityType<?> to register the spawn placement for.
MY_ENTITY.get(),
// SpawnPlacementType is a functional interface that checks whether a given position is valid
// for spawning. You can add your own SpawnPlacementType if needed,
// see the implementation of SpawnPlacementTypes for reference.
// Vanilla values include NO_RESTRICTIONS, IN_WATER, IN_LAVA and ON_GROUND.
SpawnPlacementTypes.ON_GROUND,
// The heightmap type to use. This provides the initial height to check during world generation,
// later this is ignored and just uses the world surface. Possible values are
// WORLD_SURFACE, OCEAN_FLOOR, MOTION_BLOCKING and MOTION_BLOCKING_NO_LEAVES.
Heightmap.Types.WORLD_SURFACE,
// A predicate to check additional spawn rules, e.g. light. Can either be specified here
// as a lambda, or (more commonly) as a static method in the entity class.
(entityType, level, spawnReason, pos, random) -> {
// Make our mob only spawn on grass blocks.
return level.getBlockState(pos.below()).is(Blocks.GRASS_BLOCK)
|| Mob.checkMobSpawnRules(entityType, level, spawnReason, pos, random);
},
// For our own mobs, any operation may be used.
RegisterSpawnPlacementsEvent.Operation.OR
);
}
```

It is also possible to modify vanilla's or other mods' spawn placements. You can use one of `Operation.AND` (for extra spawn restrictions), `Operation.OR` (for alternate spawn mechanisms) or `Operation.REPLACE` (to completely replace the spawn placement, use a [low-priority event listener][priority] in this case) like so:

```java
@SubscribeEvent // on the mod event bus
public static void registerSpawnPlacements(RegisterSpawnPlacementsEvent event) {
event.register(
// The EntityType<?> to register the spawn placement for.
MY_ENTITY.get(),
// When not using Operation.REPLACE, leave the spawn placement type
// and the heightmap type at null.
null,
null,
// Like above, check the additional/alternate spawn rules.
(entityType, level, spawnReason, pos, random) -> {
return level.getBlockState(pos.below()).is(Blocks.GRASS_BLOCK)
|| Mob.checkMobSpawnRules(entityType, level, spawnReason, pos, random);
},
// Use the appropriate Operation here.
RegisterSpawnPlacementsEvent.Operation.AND
);
}
```

The event also provides two utility overloads (where `spawnPredicate` is the lambda we used earlier):

```java
@SubscribeEvent // on the mod event bus
public static void registerSpawnPlacements(RegisterSpawnPlacementsEvent event) {
// Identical to event.register(MY_ENTITY.get(), null, null, spawnPredicate, Operation.OR)
event.register(MY_ENTITY.get(), spawnPredicate);
// Identical to event.register(MY_ENTITY.get(), null, null, spawnPredicate, operation)
event.register(MY_ENTITY.get(), spawnPredicate, operation);
}
```

### Natural Spawning

_See also [Entities/`MobCategory`][mobcategory], [Worldgen/Biome Modifers/Add Spawns][addspawns], [Worldgen/Biome Modifers/Add Spawn Costs][addspawncosts]; and [Spawn Cycle][spawncycle] on the [Minecraft Wiki][mcwiki]._
Expand Down
67 changes: 67 additions & 0 deletions versioned_docs/version-1.21.5/entities/livingentity.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,73 @@ DeferredItem<SpawnEggItem> MY_ENTITY_SPAWN_EGG = ITEMS.registerItem("my_entity_s

As an item like any other, the item should be added to a [creative tab][creative], and a [client item][clientitem], [model] and [translation] should be added.

### Spawn Placements

By default, spawning will be possible anywhere, including inside blocks and in midair. To prevent this, a spawn placement must be registered. This happens in the `RegisterSpawnPlacementsEvent` like so:

```java
@SubscribeEvent // on the mod event bus
public static void registerSpawnPlacements(RegisterSpawnPlacementsEvent event) {
event.register(
// The EntityType<?> to register the spawn placement for.
MY_ENTITY.get(),
// SpawnPlacementType is a functional interface that checks whether a given position is valid
// for spawning. You can add your own SpawnPlacementType if needed,
// see the implementation of SpawnPlacementTypes for reference.
// Vanilla values include NO_RESTRICTIONS, IN_WATER, IN_LAVA and ON_GROUND.
SpawnPlacementTypes.ON_GROUND,
// The heightmap type to use. This provides the initial height to check during world generation,
// later this is ignored and just uses the world surface. Possible values are
// WORLD_SURFACE, OCEAN_FLOOR, MOTION_BLOCKING and MOTION_BLOCKING_NO_LEAVES.
Heightmap.Types.WORLD_SURFACE,
// A predicate to check additional spawn rules, e.g. light. Can either be specified here
// as a lambda, or (more commonly) as a static method in the entity class.
(entityType, level, spawnReason, pos, random) -> {
// Make our mob only spawn on grass blocks.
return level.getBlockState(pos.below()).is(Blocks.GRASS_BLOCK)
|| Mob.checkMobSpawnRules(entityType, level, spawnReason, pos, random);
},
// For our own mobs, any operation may be used.
RegisterSpawnPlacementsEvent.Operation.OR
);
}
```

It is also possible to modify vanilla's or other mods' spawn placements. You can use one of `Operation.AND` (for extra spawn restrictions), `Operation.OR` (for alternate spawn mechanisms) or `Operation.REPLACE` (to completely replace the spawn placement, use a [low-priority event listener][priority] in this case) like so:

```java
@SubscribeEvent // on the mod event bus
public static void registerSpawnPlacements(RegisterSpawnPlacementsEvent event) {
event.register(
// The EntityType<?> to register the spawn placement for.
MY_ENTITY.get(),
// When not using Operation.REPLACE, leave the spawn placement type
// and the heightmap type at null.
null,
null,
// Like above, check the additional/alternate spawn rules.
(entityType, level, spawnReason, pos, random) -> {
return level.getBlockState(pos.below()).is(Blocks.GRASS_BLOCK)
|| Mob.checkMobSpawnRules(entityType, level, spawnReason, pos, random);
},
// Use the appropriate Operation here.
RegisterSpawnPlacementsEvent.Operation.AND
);
}
```

The event also provides two utility overloads (where `spawnPredicate` is the lambda we used earlier):

```java
@SubscribeEvent // on the mod event bus
public static void registerSpawnPlacements(RegisterSpawnPlacementsEvent event) {
// Identical to event.register(MY_ENTITY.get(), null, null, spawnPredicate, Operation.OR)
event.register(MY_ENTITY.get(), spawnPredicate);
// Identical to event.register(MY_ENTITY.get(), null, null, spawnPredicate, operation)
event.register(MY_ENTITY.get(), spawnPredicate, operation);
}
```

### Natural Spawning

_See also [Entities/`MobCategory`][mobcategory], [Worldgen/Biome Modifers/Add Spawns][addspawns], [Worldgen/Biome Modifers/Add Spawn Costs][addspawncosts]; and [Spawn Cycle][spawncycle] on the [Minecraft Wiki][mcwiki]._
Expand Down
Loading
Loading