SpawnPlacementTypes .java

net.minecraft.world.entity.SpawnPlacementTypes (interface): members: ON_GROUND, IN_WATER, IN_LAVA, NO_RESTRICTIONS. imports: NaturalSpawner, FluidTags.

net.minecraft.world.entityinterface51 linescommon2.1 KB

API Surface (2)

boolean isSpawnPositionOk(final LevelReader level, final BlockPos blockPos, final @Nullable EntityType<?> type)
BlockPos adjustSpawnPosition(final LevelReader level, final BlockPos candidate)

Fields & Constants (4)

NO_RESTRICTIONS
IN_WATER
IN_LAVA
ON_GROUND

Code Graph: Dependencies (7)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

SpawnPlacementTypes.java51 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.entity;
2
3
import net.minecraft.core.BlockPos;
4
import net.minecraft.tags.FluidTags;
5
import net.minecraft.world.level.LevelReader;
6
import net.minecraft.world.level.NaturalSpawner;
7
import net.minecraft.world.level.block.state.BlockState;
8
import net.minecraft.world.level.pathfinder.PathComputationType;
9
import org.jspecify.annotations.Nullable;
10
11
public interface SpawnPlacementTypes {
12
	SpawnPlacementType NO_RESTRICTIONS = (level, blockPos, type) -> true;
13
	SpawnPlacementType IN_WATER = (level, blockPos, type) -> {
14
		if (type != null && level.getWorldBorder().isWithinBounds(blockPos)) {
15
			BlockPos above = blockPos.above();
16
			return level.getFluidState(blockPos).is(FluidTags.WATER) && !level.getBlockState(above).isRedstoneConductor(level, above);
17
		} else {
18
			return false;
19
		}
20
	};
21
	SpawnPlacementType IN_LAVA = (level, blockPos, type) -> type != null && level.getWorldBorder().isWithinBounds(blockPos)
22
		? level.getFluidState(blockPos).is(FluidTags.LAVA)
23
		: false;
24
	SpawnPlacementType ON_GROUND = new SpawnPlacementType() {
25
		@Override
26
		public boolean isSpawnPositionOk(final LevelReader level, final BlockPos blockPos, final @Nullable EntityType<?> type) {
27
			if (type != null && level.getWorldBorder().isWithinBounds(blockPos)) {
28
				BlockPos above = blockPos.above();
29
				BlockPos below = blockPos.below();
30
				BlockState belowState = level.getBlockState(below);
31
				return !belowState.isValidSpawn(level, below, type)
32
					? false
33
					: this.isValidEmptySpawnBlock(level, blockPos, type) && this.isValidEmptySpawnBlock(level, above, type);
34
			} else {
35
				return false;
36
			}
37
		}
38
39
		private boolean isValidEmptySpawnBlock(final LevelReader level, final BlockPos blockPos, final EntityType<?> type) {
40
			BlockState blockState = level.getBlockState(blockPos);
41
			return NaturalSpawner.isValidEmptySpawnBlock(level, blockPos, blockState, blockState.getFluidState(), type);
42
		}
43
44
		@Override
45
		public BlockPos adjustSpawnPosition(final LevelReader level, final BlockPos candidate) {
46
			BlockPos below = candidate.below();
47
			return level.getBlockState(below).isPathfindable(PathComputationType.LAND) ? below : candidate;
48
		}
49
	};
50
}
51

Decompiled Minecraft 26.3 source of SpawnPlacementTypes (net/minecraft/world/entity/SpawnPlacementTypes.java) with Mojang official mappings, stored verbatim on the site.